updates to include gemet service for VIVO search
This commit is contained in:
parent
f92ef300da
commit
405c399a92
9 changed files with 231 additions and 500 deletions
|
@ -1,2 +1,3 @@
|
|||
<http://link.informatics.stonybrook.edu/umls> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
|
||||
<http://aims.fao.org/aos/agrovoc/agrovocScheme> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
|
||||
<http://www.eionet.europa.eu/gemet/gemetThesaurus> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
|
|
@ -1,2 +1,3 @@
|
|||
<http://link.informatics.stonybrook.edu/umls> <http://www.w3.org/2000/01/rdf-schema#label> "UMLS"^^<http://www.w3.org/2001/XMLSchema#string> .
|
||||
<http://aims.fao.org/aos/agrovoc/agrovocScheme> <http://www.w3.org/2000/01/rdf-schema#label> "Agrovoc"^^<http://www.w3.org/2001/XMLSchema#string> .
|
||||
<http://aims.fao.org/aos/agrovoc/agrovocScheme> <http://www.w3.org/2000/01/rdf-schema#label> "AGROVOC"^^<http://www.w3.org/2001/XMLSchema#string> .
|
||||
<http://www.eionet.europa.eu/gemet/gemetThesaurus> <http://www.w3.org/2000/01/rdf-schema#label> "GEMET"^^<http://www.w3.org/2001/XMLSchema#string> .
|
|
@ -0,0 +1,221 @@
|
|||
package edu.cornell.mannlib.semservices.service.impl;
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.rpc.ServiceException;
|
||||
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
import net.sf.json.JSONSerializer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.fao.gilw.aims.webservices.AgrovocWS;
|
||||
import org.fao.gilw.aims.webservices.AgrovocWSServiceLocator;
|
||||
import org.w3c.dom.Attr;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import edu.cornell.mannlib.semservices.bo.Concept;
|
||||
import edu.cornell.mannlib.semservices.service.ExternalConceptService;
|
||||
import edu.cornell.mannlib.semservices.util.XMLUtils;
|
||||
|
||||
public class GemetService implements ExternalConceptService {
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
private final String GemetWS_address = "http://www.eionet.europa.eu/gemet/";
|
||||
private final String narrowerUri = "http://www.w3.org/2004/02/skos/core%23narrower";
|
||||
private final String broaderUri = "http://www.w3.org/2004/02/skos/core%23broader";
|
||||
private final String relatedUri = "http://www.w3.org/2004/02/skos/core%23related";
|
||||
private final String definitionUri = "http://www.w3.org/2004/02/skos/core%23definition";
|
||||
private final String prefLabelUri = "http://www.w3.org/2004/02/skos/core%23prefLabel";
|
||||
private final String scopeNoteUri = "http://www.w3.org/2004/02/skos/core%23scopeNote";
|
||||
private final String altLabelUri = "http://www.w3.org/2004/02/skos/core%23altLabel";
|
||||
private final String exampleUri = "http://www.w3.org/2004/02/skos/core%23example";
|
||||
private final String acronymLabelUri = "http://www.w3.org/2004/02/skos/core%23acronymLabel";
|
||||
|
||||
public List<Concept> processResults(String term) {
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
String results = getConceptsMatchingKeyword(term);
|
||||
conceptList = processOutput(results);
|
||||
return conceptList;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param results
|
||||
* @return
|
||||
*/
|
||||
private List<Concept> processOutput(String results) {
|
||||
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
|
||||
try {
|
||||
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON( results );
|
||||
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
Concept concept = new Concept();
|
||||
concept
|
||||
.setDefinedBy("http://www.eionet.europa.eu/gemet/gemetThesaurus");
|
||||
concept.setBestMatch("true");
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
String uri = getJsonValue(json, "uri");
|
||||
|
||||
concept.setUri(uri);
|
||||
concept.setConceptId(uri);
|
||||
if (json.has("preferredLabel")) {
|
||||
JSONObject preferredLabelObj = json
|
||||
.getJSONObject("preferredLabel");
|
||||
if (preferredLabelObj.has("string")) {
|
||||
concept.setLabel(getJsonValue(preferredLabelObj,
|
||||
"string"));
|
||||
}
|
||||
}
|
||||
if (json.has("definition")) {
|
||||
JSONObject definitionObj = json.getJSONObject("definition");
|
||||
if (definitionObj.has("string")) {
|
||||
concept.setDefinition(getJsonValue(definitionObj,
|
||||
"string"));
|
||||
}
|
||||
}
|
||||
conceptList.add(concept);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception ex ) {
|
||||
ex.printStackTrace();
|
||||
logger.error("Could not get concepts", ex);
|
||||
}
|
||||
return conceptList;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string from a json object or an empty string if there is no value for the given key
|
||||
* @param obj
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
protected String getJsonValue(JSONObject obj, String key) {
|
||||
if (obj.has(key)) {
|
||||
return obj.getString(key);
|
||||
} else {
|
||||
return new String("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected String getAvailableLangs(String concept_uri) {
|
||||
String result = new String();
|
||||
String serviceUrl = GemetWS_address + "getAvailableLanguages" +
|
||||
"?concept_uri=" + concept_uri;
|
||||
result = getGemetResults(serviceUrl);
|
||||
return result;
|
||||
}
|
||||
|
||||
protected String getConcept(String concept_uri) {
|
||||
String result = new String();
|
||||
String serviceUrl = GemetWS_address + "getConcept" +
|
||||
"?concept_uri=" + concept_uri +
|
||||
"&language=en";
|
||||
result = getGemetResults(serviceUrl);
|
||||
return result;
|
||||
}
|
||||
protected String getAllTranslationsForConcept(String concept_uri, String property) {
|
||||
String result = new String();
|
||||
String property_uri = new String();
|
||||
if (property.equals("definition")) {
|
||||
property_uri = definitionUri;
|
||||
} else if (property.equals("preferredLabel")) {
|
||||
property_uri = prefLabelUri;
|
||||
} else if (property.equals("scopeNote")) {
|
||||
property_uri = scopeNoteUri;
|
||||
} else if (property.equals("nonPreferredLabels")) {
|
||||
property_uri = altLabelUri;
|
||||
} else if (property.equals("example")) {
|
||||
property_uri = exampleUri;
|
||||
} else if (property.equals("acronymLabel")) {
|
||||
property_uri = acronymLabelUri;
|
||||
}
|
||||
|
||||
String serviceUrl = GemetWS_address + "getAllTranslationsForConcept" +
|
||||
"?concept_uri=" + concept_uri +
|
||||
"&property_uri=" + property_uri +
|
||||
"&language=en";
|
||||
result = getGemetResults(serviceUrl);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected String getRelatedConcepts(String concept_uri, String relation) {
|
||||
String result = new String();
|
||||
String relation_uri = new String();
|
||||
if (relation.equals("broader")) {
|
||||
relation_uri = broaderUri;
|
||||
} else if (relation.equals("narrower")) {
|
||||
relation_uri = narrowerUri;
|
||||
} else if (relation.equals("related")) {
|
||||
relation_uri = relatedUri;
|
||||
}
|
||||
String serviceUrl = GemetWS_address + "getRelatedConcepts" +
|
||||
"?concept_uri=" + concept_uri +
|
||||
"&relation_uri=" + relation_uri +
|
||||
"&language=en";
|
||||
result = getGemetResults(serviceUrl);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected String getConceptsMatchingKeyword(String keyword) {
|
||||
String result = new String();
|
||||
String serviceUrl = GemetWS_address + "getConceptsMatchingKeyword" +
|
||||
"?keyword=" + keyword +
|
||||
"&search_mode=0" +
|
||||
"&thesaurus_uri=http://www.eionet.europa.eu/gemet/concept/" +
|
||||
"&language=en";
|
||||
|
||||
result = getGemetResults(serviceUrl);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
protected String getGemetResults(String url) {
|
||||
String results = new String();
|
||||
//System.out.println("url: "+url);
|
||||
try {
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
URL serviceUrl = new URL(url);
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(serviceUrl.openStream()));
|
||||
String inputLine;
|
||||
while ((inputLine = in.readLine()) != null) {
|
||||
sw.write(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
results = sw.toString();
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error("error occurred in servlet", ex);
|
||||
return null;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,310 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.servlet;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.EditConfiguration;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.Field;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
||||
public class ProcessTerminologyController extends VitroHttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(ProcessTerminologyController.class);
|
||||
private static final String submissionUrl = "/edit/processRdfForm2.jsp";
|
||||
//Field names/variables names for n3 - these will have numbers added as suffix if more than one term
|
||||
private static String referencedBase = "referencedTerm";
|
||||
private static String entryBase = "entryTerm";
|
||||
private static String labelBase = "termLabel";
|
||||
private static String typeBase = "termType";
|
||||
//String datatype
|
||||
private static String xsdStringType = XSD.xstring.toString();
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
super.doPost(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
super.doGet(req, resp);
|
||||
VitroRequest vreq = new VitroRequest(req);
|
||||
|
||||
try{
|
||||
|
||||
|
||||
EditConfiguration editConfig = EditConfiguration.getConfigFromSession(req.getSession(), req);
|
||||
//For query parameters, check whether CUI
|
||||
String[] termsArray = new String[1];
|
||||
String referencedTerms = vreq.getParameter("referencedTerm");
|
||||
if(referencedTerms.indexOf(",") != -1) {
|
||||
termsArray = referencedTerms.split(",");
|
||||
}
|
||||
|
||||
int numberTerms = termsArray.length;
|
||||
log.debug("Number of terms included is " + numberTerms);
|
||||
//if multiple values then need to process this differently by adding additional
|
||||
//fields, assertions, etc. as well as changing the URL slightly
|
||||
String url = "/edit/processRdfForm2.jsp?" + vreq.getQueryString();
|
||||
if(numberTerms > 1) {
|
||||
//Add new resources, i.e. the additional terminology context nodes
|
||||
addNewResources(editConfig, vreq, numberTerms);
|
||||
//Add N3Required
|
||||
addN3Required(editConfig,vreq, numberTerms);
|
||||
//Add URIs on Form and Add Literals On Form
|
||||
addLiteralsAndUrisOnForm(editConfig, vreq, numberTerms);
|
||||
//Add fields
|
||||
addFields(editConfig, vreq, numberTerms);
|
||||
//Generate new url which will map input fields to value
|
||||
url = generateUrl(editConfig, vreq);
|
||||
}
|
||||
log.debug("Submitting to url using the following parameters " + url);
|
||||
RequestDispatcher dispatcher = req.getRequestDispatcher(url);
|
||||
dispatcher.forward(req, resp);
|
||||
|
||||
|
||||
} catch(Exception ex) {
|
||||
log.error("error occurred in servlet", ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String generateUrl(EditConfiguration editConfig, VitroRequest vreq) {
|
||||
|
||||
//Get original url and query string
|
||||
String newUrl = "/edit/processRdfForm2.jsp?" + vreq.getQueryString();
|
||||
//Iterate through the terms and include appropriate values
|
||||
Map <String,String[]> queryParameters = null;
|
||||
queryParameters = vreq.getParameterMap();
|
||||
//Use same query parameters to forward
|
||||
String termParam = vreq.getParameter("referencedTerm");
|
||||
String labelParam = vreq.getParameter("termLabel");
|
||||
String typeParam = vreq.getParameter("termType");
|
||||
if(!labelParam.contains(",")){
|
||||
log.error("Multiple labels are not being sent back, this is an error");
|
||||
}
|
||||
if(!typeParam.contains(",")) {
|
||||
log.error("Multiple types are not being sent back, this is an error");
|
||||
}
|
||||
|
||||
String[] termsArray = termParam.split(",");
|
||||
String[] termLabels = labelParam.split(",");
|
||||
String[] termTypes = typeParam.split(",");
|
||||
|
||||
int numberParameters = termsArray.length;
|
||||
int index;
|
||||
|
||||
//Should already include entry term so no need to include here
|
||||
//If that changes, then add entry term here
|
||||
//String entryTerm = vreq.getParameter("entryTerm");
|
||||
//newUrl += "&entryTerm=" + URLEncoder.encode(entryTerm);
|
||||
//Process values and generate url matching field name to value
|
||||
for(index = 1; index <= numberParameters; index++) {
|
||||
String referencedInputName = referencedBase + index;
|
||||
String termLabelInputName = labelBase + index;
|
||||
String termTypeInputName =typeBase + index;
|
||||
//array is set to start at 0, not 1
|
||||
String referencedTerm = termsArray[index - 1];
|
||||
String termLabel = termLabels[index - 1];
|
||||
String termType = termTypes[index - 1];
|
||||
newUrl += "&" + referencedInputName + "=" + URLEncoder.encode(referencedTerm);
|
||||
newUrl += "&" + termLabelInputName + "=" + URLEncoder.encode(termLabel);
|
||||
newUrl += "&" + termTypeInputName + "=" + URLEncoder.encode(termType);
|
||||
}
|
||||
return newUrl;
|
||||
}
|
||||
|
||||
private void addNewResources(EditConfiguration editConfig, VitroRequest vreq, int numberTerms) {
|
||||
Map<String, String> newResources = new HashMap<String, String>();
|
||||
//Based on number of terms, add new
|
||||
int n;
|
||||
String defaultNamespace = "";
|
||||
|
||||
String base = "terminologyContextNode";
|
||||
for(n = 1; n <= numberTerms; n++) {
|
||||
String newNode = base + n;
|
||||
newResources.put(newNode, defaultNamespace);
|
||||
}
|
||||
//TODO: Check if below is required as this is a reference
|
||||
editConfig.setNewResources(newResources);
|
||||
}
|
||||
|
||||
/*
|
||||
* "referencedTerm" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "UNDEFINED", //UNSURE WHAT TO KEEP HERE
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${n3ForTerminology}" ]
|
||||
},
|
||||
"entryTerm" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "${stringDatatypeUriJson}",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${n3ForTerminology}" ]
|
||||
},
|
||||
"termLabel" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "${stringDatatypeUriJson}",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${n3ForTerminology}" ]
|
||||
}
|
||||
,"termType" : {
|
||||
"newResource" : "false",
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "${stringDatatypeUriJson}",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${n3ForTerminology}" ]
|
||||
}
|
||||
*/
|
||||
|
||||
private void addFields(EditConfiguration editConfig, VitroRequest vreq, int numberTerms) {
|
||||
Map<String, Field> fieldMap = new HashMap<String, Field>();
|
||||
int index;
|
||||
|
||||
//Entry only needs to be added once
|
||||
fieldMap.put(entryBase, generateField(editConfig, xsdStringType));
|
||||
|
||||
//First one already included so add new ones here
|
||||
for(index = 1; index <= numberTerms; index++) {
|
||||
int suffix = index;
|
||||
String referencedTerm = referencedBase + suffix;
|
||||
String label = labelBase + suffix;
|
||||
String type = typeBase + suffix;
|
||||
//Generate Field for each
|
||||
fieldMap.put(referencedTerm, generateField(editConfig, null));
|
||||
fieldMap.put(label, generateField(editConfig, xsdStringType));
|
||||
fieldMap.put(type, generateField(editConfig, xsdStringType));
|
||||
}
|
||||
editConfig.setFields(fieldMap);
|
||||
}
|
||||
|
||||
/*
|
||||
"newResource" : "false",
|
||||
"validators" : [ "nonempty" ],
|
||||
"optionsType" : "UNDEFINED",
|
||||
"literalOptions" : [ ],
|
||||
"predicateUri" : "",
|
||||
"objectClassUri" : "",
|
||||
"rangeDatatypeUri" : "",
|
||||
"rangeLang" : "",
|
||||
"assertions" : [ "${n3ForTerminology}" ]*/
|
||||
private Field generateField(EditConfiguration editConfig, String dataType) {
|
||||
List<String> n3Required = editConfig.getN3Required();
|
||||
Field field = new Field();
|
||||
field.setNewResource(false);
|
||||
List<String> validators = new ArrayList<String>();
|
||||
validators.add("nonempty");
|
||||
field.setValidators(validators);
|
||||
field.setOptionsType("UNDEFINED");
|
||||
field.setLiteralOptions(new ArrayList<List<String>>());
|
||||
field.setPredicateUri("");
|
||||
field.setObjectClassUri("");
|
||||
if(dataType == null || dataType.isEmpty()) {
|
||||
field.setRangeLang("");
|
||||
field.setRangeDatatypeUri("");
|
||||
} else {
|
||||
field.setRangeDatatypeUri(dataType);
|
||||
}
|
||||
|
||||
field.setAssertions(n3Required);
|
||||
return field;
|
||||
}
|
||||
|
||||
//Original uris and literals included:
|
||||
/*
|
||||
* "urisOnForm" : [ "referencedTerm" ],
|
||||
"literalsOnForm" : [ "entryTerm", "termLabel" ],
|
||||
*/
|
||||
private void addLiteralsAndUrisOnForm(EditConfiguration editConfig,
|
||||
VitroRequest vreq, int numberTerms) {
|
||||
List<String> urisOnForm = new ArrayList<String>();
|
||||
List<String> literalsOnForm = new ArrayList<String>();
|
||||
|
||||
int index;
|
||||
//entry term needs to be added only once
|
||||
literalsOnForm.add(entryBase);
|
||||
|
||||
//First one already included so add new ones here
|
||||
for(index = 1; index <= numberTerms; index++) {
|
||||
int suffix = index;
|
||||
String referencedTerm = referencedBase + suffix;
|
||||
String label = labelBase + suffix;
|
||||
String type = typeBase + suffix;
|
||||
urisOnForm.add(referencedTerm);
|
||||
literalsOnForm.add(label);
|
||||
literalsOnForm.add(type);
|
||||
}
|
||||
editConfig.setUrisOnform(urisOnForm);
|
||||
editConfig.setLiteralsOnForm(literalsOnForm);
|
||||
}
|
||||
|
||||
//original n3 required is of this format
|
||||
/*@prefix core: <${vivoCore}> .
|
||||
?subject ?predicate ?terminologyContextNode .
|
||||
?terminologyContextNode core:referencedTerm ?referencedTerm .
|
||||
?terminologyContextNode core:entryTerm ?entryTerm .
|
||||
?terminologyContextNode core:termLabel ?termLabel .
|
||||
*/
|
||||
private void addN3Required(EditConfiguration editConfig, VitroRequest vreq, int numberTerms) {
|
||||
//List<String> n3Required = editConfig.getN3Required();
|
||||
List<String> n3Required = new ArrayList<String>();
|
||||
int index;
|
||||
String nodeBase = "?terminologyContextNode";
|
||||
String entryVar = "?" + entryBase;
|
||||
String referencedVar = "?" + referencedBase;
|
||||
String labelVar = "?" + labelBase;
|
||||
String typeVar = "?" + typeBase;
|
||||
String prefixStr = "@prefix core: <http://vivoweb.org/ontology/core#> .";
|
||||
//First one already included so add new ones here
|
||||
for(index = 1; index <= numberTerms; index++) {
|
||||
int suffix = index;
|
||||
String node = nodeBase + suffix;
|
||||
String referencedTerm = referencedVar + suffix;
|
||||
String label = labelVar + suffix;
|
||||
String type = typeVar + suffix;
|
||||
String n3String = prefixStr;
|
||||
n3String += "?subject ?predicate " + node + " . " +
|
||||
node + " core:entryTerm " + entryVar + " . " +
|
||||
node + " core:termLabel " + label + " . " +
|
||||
node + " core:termType " + type + " . " +
|
||||
node + " core:referencedTerm " + referencedTerm + " . ";
|
||||
n3Required.add(n3String);
|
||||
}
|
||||
editConfig.setN3Required(n3Required);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.servlet;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
||||
|
||||
public class UMLSTerminologyAnnotation extends VitroHttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final Log log = LogFactory.getLog(UMLSTerminologyAnnotation.class);
|
||||
private static final String submissionUrl = "http://link.informatics.stonybrook.edu/MeaningLookup/MlServiceServlet?";
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
super.doPost(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
super.doGet(req, resp);
|
||||
VitroRequest vreq = new VitroRequest(req);
|
||||
|
||||
try{
|
||||
//Get parameter
|
||||
String entryText = vreq.getParameter("searchTerm");
|
||||
log.debug("Executing UMLS term retrieval using " + entryText);
|
||||
String dataUrl = submissionUrl + "textToProcess=" + URLEncoder.encode(entryText) + "&format=json";
|
||||
try{
|
||||
ServletOutputStream sos = resp.getOutputStream();
|
||||
|
||||
resp.setCharacterEncoding("UTF-8");
|
||||
resp.setContentType("application/json;charset=UTF-8");
|
||||
URL rss = new URL(dataUrl);
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(rss.openStream()));
|
||||
String inputLine;
|
||||
while((inputLine = in.readLine()) != null) {
|
||||
sos.println(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
} catch(Exception ex) {
|
||||
log.error("error occurred in servlet", ex);
|
||||
}
|
||||
|
||||
}catch(Exception ex){
|
||||
log.warn(ex,ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.AddRoleToPersonTwoStageGenerator;
|
||||
|
||||
abstract public class AbstractConceptSearch implements ConceptSearchInterface{
|
||||
private Log log = LogFactory.getLog(AbstractConceptSearch.class);
|
||||
|
||||
public String doSearch(ServletContext context, VitroRequest vreq ) {
|
||||
String searchEntry = vreq.getParameter("searchTerm");
|
||||
String results = processResults(searchEntry);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
abstract public String processResults(String searchEntry);
|
||||
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public interface ConceptSearchInterface{
|
||||
String doSearch(ServletContext context, VitroRequest vreq );
|
||||
|
||||
String processResults(String searchEntry);
|
||||
}
|
|
@ -22,6 +22,8 @@ public class ConceptSearchServiceUtils {
|
|||
//TODO: Change this so retrieved from the system instead using a query
|
||||
private static final String UMLSVocabSource = "http://link.informatics.stonybrook.edu/umls";
|
||||
private static final String AgrovocVocabSource = "http://aims.fao.org/aos/agrovoc/agrovocScheme";
|
||||
private static final String GemetVocabSource = "http://www.eionet.europa.eu/gemet/gemetThesaurus";
|
||||
|
||||
//Get the class that corresponds to the appropriate search
|
||||
public static String getConceptSearchServiceClassName(String searchServiceName) {
|
||||
HashMap<String, String> map = getMapping();
|
||||
|
@ -36,7 +38,9 @@ public class ConceptSearchServiceUtils {
|
|||
public static HashMap<String, String> getVocabSources() {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put(UMLSVocabSource, "UMLS");
|
||||
map.put(AgrovocVocabSource, "Agrovoc");
|
||||
map.put(AgrovocVocabSource, "AGROVOC");
|
||||
map.put(GemetVocabSource, "GEMET");
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -47,7 +51,7 @@ public class ConceptSearchServiceUtils {
|
|||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
map.put(UMLSVocabSource, "edu.cornell.mannlib.semservices.service.impl.UMLSService");
|
||||
map.put(AgrovocVocabSource, "edu.cornell.mannlib.semservices.service.impl.AgrovocService");
|
||||
|
||||
map.put(GemetVocabSource, "edu.cornell.mannlib.semservices.service.impl.GemetService");
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
|
||||
|
||||
public class UMLSConceptSearch extends AbstractConceptSearch{
|
||||
private static final String submissionUrl = "http://link.informatics.stonybrook.edu/MeaningLookup/MlServiceServlet?";
|
||||
private static final Log log = LogFactory.getLog(UMLSConceptSearch.class);
|
||||
|
||||
public String processResults(String searchEntry) {
|
||||
|
||||
String dataUrl = submissionUrl + "textToProcess=" + URLEncoder.encode(searchEntry) + "&format=json";
|
||||
String results = null;
|
||||
try{
|
||||
StringWriter sw = new StringWriter();
|
||||
URL rss = new URL(dataUrl);
|
||||
|
||||
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(rss.openStream()));
|
||||
String inputLine;
|
||||
while((inputLine = in.readLine()) != null) {
|
||||
sw.write(inputLine);
|
||||
}
|
||||
in.close();
|
||||
|
||||
results = sw.toString();
|
||||
|
||||
} catch(Exception ex) {
|
||||
log.error("error occurred in servlet", ex);
|
||||
}
|
||||
|
||||
|
||||
results = processOutput(results);
|
||||
return results;
|
||||
}
|
||||
|
||||
//Returning string with
|
||||
private String processOutput(String results) {
|
||||
String newResults = null;
|
||||
try {
|
||||
JSONObject json = new JSONObject(results);
|
||||
//Return label and CUID of object
|
||||
if(json.has("All")) {
|
||||
|
||||
}
|
||||
|
||||
if(json.has("BestMatch")) {
|
||||
JSONArray bestMatchArray = json.getJSONArray("BestMatch");
|
||||
int len = bestMatchArray.length();
|
||||
int i;
|
||||
for(i = 0; i < len; i++) {
|
||||
JSONObject o = bestMatchArray.getJSONObject(i);
|
||||
String definition = o.getString("definition");
|
||||
String label = o.getString("label");
|
||||
String CUI = o.getString("CUI");
|
||||
String type = o.getString("type");
|
||||
}
|
||||
}
|
||||
} catch(Exception ex) {
|
||||
log.error("Error making json object out of output");
|
||||
}
|
||||
return newResults;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue