enable returning of related concepts in addition to best match results from GEMET service
This commit is contained in:
parent
f723e62c90
commit
0eafc20767
1 changed files with 23 additions and 7 deletions
|
@ -50,9 +50,7 @@ public class GemetService implements ExternalConceptService {
|
|||
private final String acronymLabelUri = "http://www.w3.org/2004/02/skos/core%23acronymLabel";
|
||||
|
||||
public List<Concept> processResults(String term) throws Exception {
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
String results = getConceptsMatchingKeyword(term);
|
||||
conceptList = processOutput(results);
|
||||
List<Concept> conceptList = processConceptsAndRelatedMatchingKeyword(term);
|
||||
return conceptList;
|
||||
|
||||
}
|
||||
|
@ -60,11 +58,15 @@ public class GemetService implements ExternalConceptService {
|
|||
/**
|
||||
* @param results
|
||||
* @return
|
||||
* By default, concepts set with best match = true
|
||||
*/
|
||||
private List<Concept> processOutput(String results) {
|
||||
return processOutput(results, "true");
|
||||
|
||||
}
|
||||
|
||||
private List<Concept> processOutput(String results, String bestMatch) {
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
|
||||
try {
|
||||
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON( results );
|
||||
|
||||
|
@ -72,7 +74,7 @@ public class GemetService implements ExternalConceptService {
|
|||
Concept concept = new Concept();
|
||||
concept
|
||||
.setDefinedBy("http://www.eionet.europa.eu/gemet/gemetThesaurus");
|
||||
concept.setBestMatch("true");
|
||||
concept.setBestMatch(bestMatch);
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
String uri = getJsonValue(json, "uri");
|
||||
|
||||
|
@ -103,7 +105,6 @@ public class GemetService implements ExternalConceptService {
|
|||
logger.error("Could not get concepts", ex);
|
||||
}
|
||||
return conceptList;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -196,6 +197,21 @@ public class GemetService implements ExternalConceptService {
|
|||
|
||||
}
|
||||
|
||||
//Get concepts matching keyword plus any related concepts
|
||||
protected List<Concept> processConceptsAndRelatedMatchingKeyword(String keyword) throws Exception {
|
||||
String result = getConceptsMatchingKeyword(keyword);
|
||||
//iterate through each of the concepts and add related concepts a well
|
||||
List<Concept> bestMatchConceptList = processOutput(result);
|
||||
List<Concept> relatedConceptList = new ArrayList<Concept>();
|
||||
for(Concept c: bestMatchConceptList) {
|
||||
String conceptUri = c.getUri();
|
||||
String resultsRelated = getRelatedConcepts(conceptUri, "related");
|
||||
relatedConceptList.addAll(processOutput(resultsRelated, "false"));
|
||||
}
|
||||
bestMatchConceptList.addAll(relatedConceptList);
|
||||
return bestMatchConceptList;
|
||||
}
|
||||
|
||||
protected String getGemetResults(String url) throws Exception {
|
||||
String results = new String();
|
||||
//System.out.println("url: "+url);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue