updates for semantic services, temporarily commenting out concept semantic type which is still in progress
This commit is contained in:
parent
a728d53c22
commit
ad0ae3c09a
7 changed files with 165 additions and 40 deletions
|
@ -17,7 +17,8 @@ public class Concept {
|
|||
private List<String> narrowerURIList;
|
||||
private List<String> exactMatchURIList;
|
||||
private List<String> closeMatchURIList;
|
||||
|
||||
private List<String> altLabelList;
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
*/
|
||||
|
@ -149,4 +150,12 @@ public void setCloseMatchURIList(List<String> closeMatchURIList) {
|
|||
this.closeMatchURIList = closeMatchURIList;
|
||||
}
|
||||
|
||||
public List<String> getAltLabelList() {
|
||||
return altLabelList;
|
||||
}
|
||||
|
||||
public void setAltLabelList(List<String> altLabelList) {
|
||||
this.altLabelList = altLabelList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ public class AgrovocService implements ExternalConceptService {
|
|||
private final String codeName = "hasCodeAgrovoc";
|
||||
private final String searchMode = "Exact Match";
|
||||
protected final String dbpedia_endpoint = " http://dbpedia.org/sparql";
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -94,16 +93,16 @@ public class AgrovocService implements ExternalConceptService {
|
|||
return conceptList;
|
||||
}
|
||||
|
||||
System.out.println("uri: "+uri);
|
||||
//System.out.println("uri: "+uri);
|
||||
SKOSDataset dataset = manager.loadDataset(uri);
|
||||
|
||||
for (SKOSConcept skosConcept : dataset.getSKOSConcepts()) {
|
||||
Concept concept = new Concept();
|
||||
System.out.println("Concept: " + skosConcept.getURI());
|
||||
//System.out.println("Concept: " + skosConcept.getURI());
|
||||
concept.setUri(skosConcept.getURI().toString());
|
||||
concept.setConceptId(stripConceptId(skosConcept.getURI().toString()));
|
||||
concept.setBestMatch("true");
|
||||
concept.setDefinedBy(this.schemeUri);
|
||||
concept.setDefinedBy(schemeUri);
|
||||
concept.setSchemeURI(this.schemeUri);
|
||||
concept.setType("");
|
||||
String lang = "";
|
||||
|
@ -126,6 +125,32 @@ public class AgrovocService implements ExternalConceptService {
|
|||
}
|
||||
}
|
||||
|
||||
// get altLabels
|
||||
List<String> altLabelList = new ArrayList<String>();
|
||||
for (SKOSLiteral literal : skosConcept
|
||||
.getSKOSRelatedConstantByProperty(dataset, manager
|
||||
.getSKOSDataFactory().getSKOSAltLabelProperty())) {
|
||||
|
||||
if (!literal.isTyped()) {
|
||||
// if it has language
|
||||
SKOSUntypedLiteral untypedLiteral = literal
|
||||
.getAsSKOSUntypedLiteral();
|
||||
if (untypedLiteral.hasLang()) {
|
||||
lang = untypedLiteral.getLang();
|
||||
} else {
|
||||
lang = "";
|
||||
}
|
||||
}
|
||||
//System.out.println("literal: "+ literal.getLiteral());
|
||||
if (lang.equals("en")) {
|
||||
//System.out.println("altLabel: " + literal.getLiteral());
|
||||
altLabelList.add(literal.getLiteral());
|
||||
}
|
||||
}
|
||||
concept.setAltLabelList(altLabelList);
|
||||
|
||||
|
||||
|
||||
// get the broader property URI
|
||||
List<String> broaderURIList = new ArrayList<String>();
|
||||
for (SKOSAnnotation annotation: skosConcept.getSKOSAnnotationsByURI(dataset, manager.getSKOSDataFactory().getSKOSBroaderProperty().getURI())) {
|
||||
|
@ -347,9 +372,9 @@ public class AgrovocService implements ExternalConceptService {
|
|||
|
||||
|
||||
public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception {
|
||||
//John Ferreira's original code has implementation
|
||||
List<Concept> newConceptList = new ArrayList<Concept>();
|
||||
return newConceptList;
|
||||
// deprecating this method...just return an empty list
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
return conceptList;
|
||||
}
|
||||
|
||||
protected String getAgrovocTermCode(String rdf) throws Exception {
|
||||
|
|
|
@ -34,8 +34,7 @@ public class GemetService implements ExternalConceptService {
|
|||
private final String endpoint = "http://cr.eionet.europa.eu/sparql";
|
||||
private final String schemeURI = "http://www.eionet.europa.eu/gemet/gemetThesaurus";
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<Concept> getConcepts(String term) throws Exception {
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
|
@ -65,11 +64,12 @@ public class GemetService implements ExternalConceptService {
|
|||
|
||||
}
|
||||
|
||||
public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception {
|
||||
//John Ferreira's original code has implementation
|
||||
List<Concept> newConceptList = new ArrayList<Concept>();
|
||||
return newConceptList;
|
||||
}
|
||||
public List<Concept> getConceptsByURIWithSparql(String uri)
|
||||
throws Exception {
|
||||
// deprecating this method...just return an empty list
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
return conceptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param results
|
||||
|
@ -87,7 +87,7 @@ public class GemetService implements ExternalConceptService {
|
|||
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
Concept concept = new Concept();
|
||||
concept.setDefinedBy(this.schemeURI);
|
||||
concept.setDefinedBy(schemeURI);
|
||||
concept.setBestMatch("true");
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
String uri = getJsonValue(json, "uri");
|
||||
|
@ -124,7 +124,7 @@ public class GemetService implements ExternalConceptService {
|
|||
for (String s: relatedURIList) {
|
||||
System.out.println("related uri: "+s);
|
||||
}*/
|
||||
|
||||
//String altLabels = getAllTranslationsForConcept(uri, "nonPreferredLabels");
|
||||
|
||||
conceptList.add(concept);
|
||||
|
||||
|
@ -218,9 +218,10 @@ public class GemetService implements ExternalConceptService {
|
|||
"?concept_uri=" + concept_uri +
|
||||
"&property_uri=" + property_uri +
|
||||
"&language=en";
|
||||
|
||||
try {
|
||||
result = getGemetResults(serviceUrl);
|
||||
List<String> props = getPropertyFromJson(result);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
|
@ -310,6 +311,7 @@ public class GemetService implements ExternalConceptService {
|
|||
return results;
|
||||
}
|
||||
|
||||
|
||||
protected List<String> getRelatedUris(String json) {
|
||||
List<String> uriList = new ArrayList<String>();
|
||||
String uri = new String();
|
||||
|
@ -327,6 +329,19 @@ public class GemetService implements ExternalConceptService {
|
|||
|
||||
}
|
||||
|
||||
protected List<String> getPropertyFromJson(String json) {
|
||||
List<String> props = new ArrayList<String>();
|
||||
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON(json);
|
||||
if (jsonArray.size() == 0) {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
JSONObject jsonObj = jsonArray.getJSONObject(i);
|
||||
System.out.println(jsonObj.toString());
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
protected String stripConceptId(String uri) {
|
||||
String conceptId = new String();
|
||||
int lastslash = uri.lastIndexOf('/');
|
||||
|
|
|
@ -29,14 +29,14 @@ public class UMLSService implements ExternalConceptService {
|
|||
private static final String baseUri = "http://link.informatics.stonybrook.edu/umls/CUI/";
|
||||
private static final String endpoint = "http://link.informatics.stonybrook.edu/sparql/";
|
||||
private static final String schemeURI = "http://link.informatics.stonybrook.edu/umls";
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<Concept> getConcepts(String term) throws Exception {
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
|
||||
String results = null;
|
||||
//Format in rdf/xml is possible but would require separate processing method
|
||||
String dataUrl = submissionUrl + "textToProcess="
|
||||
+ URLEncoder.encode(term, "UTF-8")
|
||||
+ "&format=json";
|
||||
|
@ -98,11 +98,12 @@ public class UMLSService implements ExternalConceptService {
|
|||
* @param uri
|
||||
* @return
|
||||
*/
|
||||
public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception {
|
||||
//John Ferreira's original code has implementation
|
||||
List<Concept> newConceptList = new ArrayList<Concept>();
|
||||
return newConceptList;
|
||||
}
|
||||
public List<Concept> getConceptsByURIWithSparql(String uri)
|
||||
throws Exception {
|
||||
// deprecating this method...just return an empty list
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
return conceptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param results
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue