diff --git a/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java b/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java index 1c61bbc8..4cfe65e1 100644 --- a/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java +++ b/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java @@ -25,13 +25,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.fao.www.webservices.AgrovocWS.ACSWWebService; import org.fao.www.webservices.AgrovocWS.ACSWWebServiceServiceLocator; -import org.semanticweb.skos.SKOSAnnotation; -import org.semanticweb.skos.SKOSConcept; -import org.semanticweb.skos.SKOSDataset; -import org.semanticweb.skos.SKOSEntity; -import org.semanticweb.skos.SKOSLiteral; -import org.semanticweb.skos.SKOSUntypedLiteral; -import org.semanticweb.skosapibinding.SKOSManager; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.NamedNodeMap; @@ -53,20 +46,20 @@ import edu.cornell.mannlib.semservices.bo.Concept; import edu.cornell.mannlib.semservices.service.ExternalConceptService; import edu.cornell.mannlib.semservices.util.SKOSUtils; import edu.cornell.mannlib.semservices.util.XMLUtils; +import edu.cornell.mannlib.vitro.webapp.web.URLEncoder; public class AgrovocService implements ExternalConceptService { protected final Log logger = LogFactory.getLog(getClass()); private java.lang.String AgrovocWS_address = "http://agrovoc.fao.org/axis/services/SKOSWS"; private final String schemeUri = "http://aims.fao.org/aos/agrovoc/agrovocScheme"; - private final String baseUri = "http://aims.fao.org/aos/agrovoc/"; private final String ontologyName = "agrovoc"; private final String format = "SKOS"; private final String lang = "en"; - private final String codeName = "hasCodeAgrovoc"; private final String searchMode = "Exact Match"; protected final String dbpedia_endpoint = " http://dbpedia.org/sparql"; - + //URL to get all the information for a concept + protected final String conceptSkosMosURL = "http://aims.fao.org/skosmos/rest/v1/agrovoc/data?"; @Override public List getConcepts(String term) throws Exception { @@ -94,25 +87,25 @@ public class AgrovocService implements ExternalConceptService { } //Returns concept information in the format specified, which is currently XML - //This will return - String conceptInfo = this.getConceptInfoByURI(this.ontologyName, conceptUri, this.format); - if(StringUtils.isNotEmpty(conceptInfo)) { - Concept c = this.createConcept("true", conceptUri, conceptInfo); - if(c != null) { - //Get definition from dbpedia references stored in the close Match list - List closeMatches = c.getCloseMatchURIList(); - for(String closeMatch: closeMatches) { - - if (closeMatch.startsWith("http://dbpedia.org")) { - String description = getDbpediaDescription(closeMatch); - //System.out.println("description: "+ description); - c.setDefinition(description); - } - } - conceptList.add(c); + //Utilizing Agrovoc's getConceptInfo returns alternate and preferred labels but + //none of the exact match or close match descriptions + + Concept c = this.createConcept("true", conceptUri); + if(c != null) { + //Get definition from dbpedia references stored in the close Match list + List closeMatches = c.getCloseMatchURIList(); + for(String closeMatch: closeMatches) { + + if (closeMatch.startsWith("http://dbpedia.org")) { + String description = getDbpediaDescription(closeMatch); + //System.out.println("description: "+ description); + c.setDefinition(description); + } } - + conceptList.add(c); } + + //Get the concept itself using Agrovoc's own service or OWL ontology manager @@ -191,7 +184,7 @@ public class AgrovocService implements ExternalConceptService { } - public Concept createConcept(String bestMatch, String skosConceptURI, String results) { + public Concept createConcept(String bestMatch, String skosConceptURI) { Concept concept = new Concept(); //System.out.println("Concept: " + skosConcept.getURI()); @@ -201,12 +194,15 @@ public class AgrovocService implements ExternalConceptService { concept.setDefinedBy(schemeUri); concept.setSchemeURI(this.schemeUri); concept.setType(""); - String lang = ""; - //Will need to get the language attribute + + String encodedURI = URLEncoder.encode(skosConceptURI); + String encodedFormat = URLEncoder.encode("application/rdf+xml"); + String url = conceptSkosMosURL + "uri=" + encodedURI + "&format="+ encodedFormat; //Utilize the XML directly instead of the SKOS API try { - concept = SKOSUtils.createConceptUsingXML(concept, results, "xmlns", "en"); + + concept = SKOSUtils.createConceptUsingXMLFromURI(concept, url, "abbreviated", "en"); } catch(Exception ex) { logger.debug("Error occurred for creating concept " + skosConceptURI, ex); diff --git a/src/edu/cornell/mannlib/semservices/service/impl/LCSHService.java b/src/edu/cornell/mannlib/semservices/service/impl/LCSHService.java index 8b682ead..39b8b94e 100644 --- a/src/edu/cornell/mannlib/semservices/service/impl/LCSHService.java +++ b/src/edu/cornell/mannlib/semservices/service/impl/LCSHService.java @@ -149,7 +149,8 @@ public class LCSHService implements ExternalConceptService { //Utilize the XML directly instead of the SKOS API try { - concept = SKOSUtils.createConceptUsingXMLFromURI(concept, skosConceptURI, "abbreviated"); + //LCSH doesn't need a language tag right now as results in english + concept = SKOSUtils.createConceptUsingXMLFromURI(concept, skosConceptURI, "abbreviated", null); } catch(Exception ex) { log.debug("Error occurred for annotation retrieval for skos concept " + skosConceptURI, ex); diff --git a/src/edu/cornell/mannlib/semservices/util/SKOSUtils.java b/src/edu/cornell/mannlib/semservices/util/SKOSUtils.java index 11b7f6b0..615ab250 100644 --- a/src/edu/cornell/mannlib/semservices/util/SKOSUtils.java +++ b/src/edu/cornell/mannlib/semservices/util/SKOSUtils.java @@ -71,12 +71,12 @@ public class SKOSUtils { // Downloading the XML from the URI itself //No language tag support here but can be specified if need be at this level as well public static Concept createConceptUsingXMLFromURI(Concept concept, - String conceptUriString, String relationshipScheme) { + String conceptUriString, String relationshipScheme, String langTagValue) { String results = getConceptXML(conceptUriString); if (StringUtils.isEmpty(results)) { return null; } - return createConceptUsingXML(concept, results, relationshipScheme, null); + return createConceptUsingXML(concept, results, relationshipScheme, langTagValue); } @@ -169,6 +169,10 @@ public class SKOSUtils { // Attribute name returns the value for the attribute on the node // MatchAttributeValue: returns NODE values that MATCH this value for // attributeName + //Extending this based on specific SKOSMos search for Agrovoc, sometimes + //results in format , other times in format .. + //closeMatch and exactMatch use these patterns + //broader and narrower may be either rdf:resource pattern above or ...etc. public static List getValuesFromXML(NodeList nodes, String attributeName, String matchAttributeValue) { int len = nodes.getLength(); @@ -265,4 +269,15 @@ public class SKOSUtils { return relationshipHash.get("narrower"); } + + //Custom cases for Agrovoc and/or similar patterns if they exist + //get about URI from - returns "x" + public static String getTagNestedAbout(Node n) { + return null; + } + + //get about URI from , returns "x" + public static String getTagNestedSKOSConceptAbout(Node n) { + return null; + } } \ No newline at end of file