diff --git a/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java b/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java index 146a93da..3ae27c0f 100644 --- a/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java +++ b/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java @@ -50,9 +50,7 @@ public class GemetService implements ExternalConceptService { private final String acronymLabelUri = "http://www.w3.org/2004/02/skos/core%23acronymLabel"; public List processResults(String term) throws Exception { - List conceptList = new ArrayList(); - String results = getConceptsMatchingKeyword(term); - conceptList = processOutput(results); + List 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 processOutput(String results) { + return processOutput(results, "true"); - List conceptList = new ArrayList(); - + } + + private List processOutput(String results, String bestMatch) { + List conceptList = new ArrayList(); 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; - } /** @@ -195,6 +196,21 @@ public class GemetService implements ExternalConceptService { return result; } + + //Get concepts matching keyword plus any related concepts + protected List processConceptsAndRelatedMatchingKeyword(String keyword) throws Exception { + String result = getConceptsMatchingKeyword(keyword); + //iterate through each of the concepts and add related concepts a well + List bestMatchConceptList = processOutput(result); + List relatedConceptList = new ArrayList(); + 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();