diff --git a/lib/agrovoc_ws.jar b/lib/agrovoc_ws.jar deleted file mode 100644 index d8eb97b0..00000000 Binary files a/lib/agrovoc_ws.jar and /dev/null differ diff --git a/lib/agrovocws-3.0.jar b/lib/agrovocws-3.0.jar new file mode 100644 index 00000000..5581be71 Binary files /dev/null and b/lib/agrovocws-3.0.jar differ diff --git a/lib/commons-beanutils.jar b/lib/commons-beanutils.jar deleted file mode 100644 index b1b89c9c..00000000 Binary files a/lib/commons-beanutils.jar and /dev/null differ diff --git a/lib/ehcache-spring-annotations-1.1.3.jar b/lib/ehcache-spring-annotations-1.1.3.jar new file mode 100644 index 00000000..be81cf7f Binary files /dev/null and b/lib/ehcache-spring-annotations-1.1.3.jar differ diff --git a/lib/ezmorph-1.0.4.jar b/lib/ezmorph-1.0.4.jar deleted file mode 100644 index 7625af67..00000000 Binary files a/lib/ezmorph-1.0.4.jar and /dev/null differ diff --git a/lib/htmlparser.jar b/lib/htmlparser.jar new file mode 100644 index 00000000..fad7a207 Binary files /dev/null and b/lib/htmlparser.jar differ diff --git a/lib/json-lib-2.2.2-jdk15.jar b/lib/json-lib-2.2.2-jdk15.jar deleted file mode 100644 index 27e7c7cc..00000000 Binary files a/lib/json-lib-2.2.2-jdk15.jar and /dev/null differ diff --git a/lib/owlapi-bin.jar b/lib/owlapi-bin.jar new file mode 100644 index 00000000..17ce372e Binary files /dev/null and b/lib/owlapi-bin.jar differ diff --git a/lib/skosapi-3-bin.jar b/lib/skosapi-3-bin.jar new file mode 100644 index 00000000..8a484059 Binary files /dev/null and b/lib/skosapi-3-bin.jar differ diff --git a/olddeploy.properties b/olddeploy.properties new file mode 100644 index 00000000..f4c7ed7d --- /dev/null +++ b/olddeploy.properties @@ -0,0 +1,162 @@ +# ----------------------------------------------------------------------------- +# +# VIVO deployment properties +# +# This file is provided as example.deploy.properties. +# +# Save a copy of this file as deploy.properties, and edit the properties as +# needed for your deployment. +# +# ----------------------------------------------------------------------------- + +# +# This namespace will be used when generating URIs for objects created in the +# editor. Change it to reflect your own domain. For example, Cornell's +# namespace is http://vivo.cornell.edu/individual/ +# +# Note: it is essential that this namespace end with a trailing slash. +# +Vitro.defaultNamespace = http://vivo.mannlib.cornell.edu/individual/ + +# +# Where is the Vitro core directory? +# In most deployments, this is set to ./vitro-core (It is not uncommon for this +# setting to point elsewhere in development environments). +# Examples: +# vitro.core.dir = ./vitro-core +# vitro.core.dir = ../vitro +# vitro.core.dir = /usr/local/vitro/trunk +vitro.core.dir = ../vivovitro + +# +# The base install directory for your Tomcat server. The VIVO application +# will be deployed in the /webapps directory below this base. +# +tomcat.home = C:/apache/apache-tomcat-7.0.40 + +# +# The name of the VIVO application. This will be used as the name of the +# subdirectory within your Tomcat server's /webapps directory. It also appears +# in the URL for the application. For example, http://my.vivo.server/vivo +# +webapp.name = vivo + +# +# The location where the VIVO application will store the data that it creates. +# This includes uploaded files (usually images) and the Lucene search index. +# +vitro.home.directory = C:/Users/hjk54/vivodata + +# +# SMTP host which the "Contact Us" form can use to send mail. If this is left +# empty, the "Contact Us" form will be disabled. +# +Vitro.smtpHost =appsmtp.mail.cornell.edu +#Added these per Jim's instructions, TO DO: try without smtpHost line +email.smtpHost = appsmtp.mail.cornell.edu +email.replyTo = hjk54@cornell.edu + +# +# The basic parameters for a database connection. Change the end of the +# URL to reflect your database name (if it is not "vitro"). Change the username +# and password to match the authorized database user you created. Increase the +# maximum size of the database connection pool if you need to serve a greater +# number of concurrent page requests. +# +#Test Empty database +#VitroConnection.DataSource.url = jdbc:mysql://localhost/testvivo + +VitroConnection.DataSource.url = jdbc:mysql://localhost/vivodb +VitroConnection.DataSource.username = vivouser +VitroConnection.DataSource.password = vivopass +#test migration +#VitroConnection.DataSource.url = jdbc:mysql://localhost/migratetest +#VitroConnection.DataSource.username = migrateuser +#VitroConnection.DataSource.password = migratepassword + +# +# The Jena triple store technology to use. SDB is Jena's SPARQL database; +# this setting allows RDF data to scale beyond the limits of the JVM heap. +# Set to RDB to use the older Jena RDB store with in-memory caching. +# +VitroConnection.DataSource.tripleStoreType = SDB + +# +# The maximum number of active connections in the database connection pool. +# Increase this value to support a greater number of concurrent page requests +# with SDB. It is not necessary to adjust this value when using the +# RDB configuration. +# +VitroConnection.DataSource.pool.maxActive = 40 + +# +# The maximum number of database connections that will be allowed +# to remain idle in the connection pool. Default is 25% +# of the maximum number of active connections. +# +VitroConnection.DataSource.pool.maxIdle = 10 + +# +# Parameters to change in order to use VIVO with a database other than +# MySQL. +# +VitroConnection.DataSource.dbtype = MySQL +VitroConnection.DataSource.driver = com.mysql.jdbc.Driver +VitroConnection.DataSource.validationQuery = SELECT 1 + +# +# The name of your first admin user for the VIVO application. The password +# for this user is initially set to "defaultAdmin", but you will be asked to +# change the password the first time you log in. +# +initialAdminUser = defaultAdmin +rootUser.emailAddress = hjk54@cornell.edu +# +# How is a logged-in user associated with a particular Individual? One way is +# for the Individual to have a property whose value is the username of the user. +# This value should be the URI for that property. +# +selfEditing.idMatchingProperty = http://vivo.mannlib.cornell.edu/ns#networkId + +# +# If an external authentication system like Shibboleth or CUWebAuth is to be +# used, these properties say how the login button should be labeled, and which +# HTTP header will contain the user ID from the authentication system. If such +# a system is not to be used, leave these commented out. Consult the +# installation instructions for more details. +# +#externalAuth.buttonText = Log in using BearCat Shibboleth +#externalAuth.netIdHeaderName = remote_userID + +# +# The temporal graph visualization can require extensive machine resources. +# This can have a particularly noticable impact on memory usage if +# - VIVO is configured to use Jena SDB, +# - The organization tree is deep, +# - The number of grants and publications is large. +# VIVO release 1.2 guards against this impact by disabling the temporal graph +# visualization unless the "visualization.temporal" flag is set to "enabled". +# +# visualization.temporal = enabled + +# +# The temporal graph visualization is used to compare different organizations/people +# within an organization on parameters like number of publications or grants. +# By default, the app will attempt to make its best guess at the top level +# organization in your instance. If you're unhappy with this selection, uncomment out +# the property below and set it to the URI of the organization individual you want to +# identify as the top level organization. It will be used as the default whenever the +# temporal graph visualization is rendered without being passed an explicit org. +# For example, to use "Ponce School of Medicine" as the top organization: +# visualization.topLevelOrg = http://vivo.psm.edu/individual/n2862 +# +# visualization.topLevelOrg = http://vivo.mydomain.edu/individual/topLevelOrgURI + +# +# Default type(s) for Google Refine Reconciliation Service +# The format for this property is id, name; id1, name1; id2, name2 etc. +# See Service Metadata from this page http://code.google.com/p/google-refine/wiki/ReconciliationServiceApi +# for more information. +Vitro.reconcile.defaultTypeList = http://vivoweb.org/ontology/core#Course, Course; http://vivoweb.org/ontology/core#Grant, Grant; http://aims.fao.org/aos/geopolitical.owl, Location; http://xmlns.com/foaf/0.1/Organization, Organization; http://xmlns.com/foaf/0.1/Person, Person; http://purl.org/ontology/bibo/Article, Publication +#solr +vitro.local.solr.url = http://localhost:8080/vivosolr \ No newline at end of file diff --git a/ontology/public/catalog-v001.xml b/ontology/public/catalog-v001.xml new file mode 100644 index 00000000..1b92b5e2 --- /dev/null +++ b/ontology/public/catalog-v001.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/productMods/templates/freemarker/body/partials/individual/individual-positions.ftl b/productMods/templates/freemarker/body/partials/individual/individual-positions.ftl index 01553334..c0816bba 100644 --- a/productMods/templates/freemarker/body/partials/individual/individual-positions.ftl +++ b/productMods/templates/freemarker/body/partials/individual/individual-positions.ftl @@ -1,6 +1,6 @@ <#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> -<#-- List of positions for the individual --> +<#-- List of positions for the individual -->

Positions!${core}personInPosition

<#assign positions = propertyGroups.pullProperty("${core}personInPosition")!> <#if positions?has_content> <#-- true when the property is in the list, even if not populated (when editing) --> <#assign localName = positions.localName> diff --git a/productMods/templates/freemarker/body/partials/individual/individual-researchAreas.ftl b/productMods/templates/freemarker/body/partials/individual/individual-researchAreas.ftl index a2c9dc9b..e01938d7 100644 --- a/productMods/templates/freemarker/body/partials/individual/individual-researchAreas.ftl +++ b/productMods/templates/freemarker/body/partials/individual/individual-researchAreas.ftl @@ -2,6 +2,9 @@ <#-- List of research areas for the individual --> <#assign researchAreas = propertyGroups.pullProperty("${core}hasResearchArea")!> +<#assign concepts = propertyGroups.pullProperty("${core}hasAssociatedConcept")!> +<#if concepts?has_content> concepts has content <#else> concepts dont have content +

RESEARCH AREAS: ${core}hasResearchArea

<#if researchAreas?has_content> <#-- true when the property is in the list, even if not populated (when editing) --> <#assign localName = researchAreas.localName>

@@ -11,5 +14,5 @@

+ <#else> Research areas does not have content diff --git a/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl b/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl index 4e40f816..5fca58d8 100644 --- a/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl +++ b/productMods/templates/freemarker/edit/forms/addAssociatedConcept.ftl @@ -96,6 +96,9 @@ + + +

diff --git a/productMods/templates/freemarker/edit/forms/js/addConcept.js b/productMods/templates/freemarker/edit/forms/js/addConcept.js index 5eb9318c..94411ff9 100644 --- a/productMods/templates/freemarker/edit/forms/js/addConcept.js +++ b/productMods/templates/freemarker/edit/forms/js/addConcept.js @@ -54,6 +54,7 @@ var addConceptForm = { this.externalConceptURI = $('#conceptNode'); this.externalConceptLabel = $('#conceptLabel'); this.externalConceptSource = $('#conceptSource'); + this.externalConceptSemanticTypeLabel = $("#conceptSemanticTypeLabel"); //remove links this.removeConceptLinks = $('a.remove'); this.errors = $('#errors'); @@ -236,23 +237,27 @@ var addConceptForm = { } var i; var len = checkedElements.length; - var checkedConcept, checkedConceptElement, conceptLabel, conceptSource; + var checkedConcept, checkedConceptElement, conceptLabel, conceptSource, conceptSemanticType; var conceptNodes = []; var conceptLabels = []; var conceptSources = []; + var conceptSemanticTypes = []; checkedElements.each(function() { checkedConceptElement = $(this); checkedConcept = checkedConceptElement.val(); conceptLabel = checkedConceptElement.attr("label"); conceptSource = checkedConceptElement.attr("conceptDefinedBy"); + conceptSemanticType = checkedConceptElement.attr("conceptType"); conceptNodes.push(checkedConcept); conceptLabels.push(conceptLabel); conceptSources.push(conceptSource); + conceptSemanticTypes.push(conceptSemanticType); }); this.externalConceptURI.val(conceptNodes); this.externalConceptLabel.val(conceptLabels); this.externalConceptSource.val(conceptSources); + this.externalConceptSemanticTypeLabel.val(conceptSemanticTypes); return true; }, generateIndividualConceptDisplay: function(cuiURI, label, definition, type, definedBy, isBestMatch) { diff --git a/src/edu/cornell/mannlib/semservices/bo/BaseObject.java b/src/edu/cornell/mannlib/semservices/bo/BaseObject.java new file mode 100644 index 00000000..f8f199b4 --- /dev/null +++ b/src/edu/cornell/mannlib/semservices/bo/BaseObject.java @@ -0,0 +1,27 @@ +package edu.cornell.mannlib.semservices.bo; + +public class BaseObject { + /** + * Simple JavaBean domain object with an id property. + * Used as a base class for objects needing this property. + * + * @author Ken Krebs + * @author Juergen Hoeller + */ + private Integer id; + + public void setId(Integer id) { + this.id = id; + } + + public Integer getId() { + return id; + } + + public boolean isNew() { + return (this.id == null); + } + + + +} diff --git a/src/edu/cornell/mannlib/semservices/bo/Concept.java b/src/edu/cornell/mannlib/semservices/bo/Concept.java index f78aaeb0..b2739a27 100644 --- a/src/edu/cornell/mannlib/semservices/bo/Concept.java +++ b/src/edu/cornell/mannlib/semservices/bo/Concept.java @@ -1,7 +1,8 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.bo; +import java.util.ArrayList; +import java.util.List; + public class Concept { private String definedBy; @@ -11,13 +12,22 @@ public class Concept { private String type; private String definition; private String uri; + private String schemeURI; + private List broaderURIList; + private List narrowerURIList; + private List exactMatchURIList; + private List closeMatchURIList; /** * default constructor */ public Concept() { - + this.broaderURIList = new ArrayList(); + this.narrowerURIList = new ArrayList(); + this.exactMatchURIList = new ArrayList(); + this.closeMatchURIList = new ArrayList(); } + /** * @return the conceptId */ @@ -90,6 +100,18 @@ public class Concept { public void setDefinedBy(String definedBy) { this.definedBy = definedBy; } + /** + * @return the schemeURI + */ + public String getSchemeURI() { + return schemeURI; + } + /** + * @param schemeURI the schemeURI to set + */ + public void setSchemeURI(String schemeURI) { + this.schemeURI = schemeURI; + } /** * @return the bestMatch */ @@ -102,5 +124,29 @@ public class Concept { public void setBestMatch(String bestMatch) { this.bestMatch = bestMatch; } +public List getBroaderURIList() { + return broaderURIList; +} +public void setBroaderURIList(List broaderURIList) { + this.broaderURIList = broaderURIList; +} +public List getNarrowerURIList() { + return narrowerURIList; +} +public void setNarrowerURIList(List narrowerURIList) { + this.narrowerURIList = narrowerURIList; +} +public List getExactMatchURIList() { + return exactMatchURIList; +} +public void setExactMatchURIList(List exactMatchURIList) { + this.exactMatchURIList = exactMatchURIList; +} +public List getCloseMatchURIList() { + return closeMatchURIList; +} +public void setCloseMatchURIList(List closeMatchURIList) { + this.closeMatchURIList = closeMatchURIList; +} } diff --git a/src/edu/cornell/mannlib/semservices/bo/ConceptInfo.java b/src/edu/cornell/mannlib/semservices/bo/ConceptInfo.java index 14aa22e0..4f111b3a 100644 --- a/src/edu/cornell/mannlib/semservices/bo/ConceptInfo.java +++ b/src/edu/cornell/mannlib/semservices/bo/ConceptInfo.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.bo; @@ -8,8 +6,7 @@ import java.util.List; public class ConceptInfo extends SemanticServicesInfoBase { - private List conceptList; - + private List conceptList; /** * */ @@ -18,17 +15,16 @@ public class ConceptInfo extends SemanticServicesInfoBase { } /** - * @return the vivoDepartmentList + * @return the conceptList */ - public List getConceptList() { + public List getConceptList() { return conceptList; } /** - * @param vivoDepartmentList the vivoDepartmentList to set + * @param conceptList the conceptList to set */ - public void setConceptList(List inputConceptList) { - this.conceptList = inputConceptList; + public void setConceptList(List conceptList) { + this.conceptList = conceptList; } - } diff --git a/src/edu/cornell/mannlib/semservices/bo/Day.java b/src/edu/cornell/mannlib/semservices/bo/Day.java index 1decc4e3..9c7bb998 100644 --- a/src/edu/cornell/mannlib/semservices/bo/Day.java +++ b/src/edu/cornell/mannlib/semservices/bo/Day.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.bo; import java.util.Calendar; diff --git a/src/edu/cornell/mannlib/semservices/bo/SemanticServicesError.java b/src/edu/cornell/mannlib/semservices/bo/SemanticServicesError.java index e6107e94..f6c903d4 100644 --- a/src/edu/cornell/mannlib/semservices/bo/SemanticServicesError.java +++ b/src/edu/cornell/mannlib/semservices/bo/SemanticServicesError.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.bo; public class SemanticServicesError { diff --git a/src/edu/cornell/mannlib/semservices/bo/SemanticServicesInfoBase.java b/src/edu/cornell/mannlib/semservices/bo/SemanticServicesInfoBase.java index d477f753..e434c594 100644 --- a/src/edu/cornell/mannlib/semservices/bo/SemanticServicesInfoBase.java +++ b/src/edu/cornell/mannlib/semservices/bo/SemanticServicesInfoBase.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.bo; public class SemanticServicesInfoBase { diff --git a/src/edu/cornell/mannlib/semservices/bo/SparqlFeed.java b/src/edu/cornell/mannlib/semservices/bo/SparqlFeed.java new file mode 100644 index 00000000..50858203 --- /dev/null +++ b/src/edu/cornell/mannlib/semservices/bo/SparqlFeed.java @@ -0,0 +1,208 @@ +package edu.cornell.mannlib.semservices.bo; + +import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; + +public class SparqlFeed extends BaseObject implements Serializable { + + + /** + * + */ + private static final long serialVersionUID = 6024170338796859330L; + private String name; + private String endpoint; + private String repository; + private String query; + private int mapperId; + private int fetcherId; + private Map parameterMap; + + /** + * Constructor + */ + public SparqlFeed() { + super(); + parameterMap = new HashMap(); + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the endpoint + */ + public String getEndpoint() { + return endpoint; + } + + /** + * @param endpoint the endpoint to set + */ + public void setEndpoint(String endpoint) { + this.endpoint = endpoint; + } + + /** + * @return the repository + */ + public String getRepository() { + return repository; + } + + /** + * @param repository the repository to set + */ + public void setRepository(String repository) { + this.repository = repository; + } + + /** + * @return the query + */ + public String getQuery() { + return query; + } + + /** + * @param query the query to set + */ + public void setQuery(String query) { + this.query = query; + } + + /** + * @return the mapperId + */ + public int getMapperId() { + return mapperId; + } + + /** + * @param mapperId the mapperId to set + */ + public void setMapperId(int mapperId) { + this.mapperId = mapperId; + } + + /** + * @return the fetcherId + */ + public int getFetcherId() { + return fetcherId; + } + + /** + * @param fetcherId the fetcherId to set + */ + public void setFetcherId(int fetcherId) { + this.fetcherId = fetcherId; + } + + /** + * @return the parameterMap + */ + public Map getParameterMap() { + return parameterMap; + } + + /** + * @param parameterMap the parameterMap to set + */ + public void setParameterMap(Map parameterMap) { + this.parameterMap = parameterMap; + } + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((endpoint == null) ? 0 : endpoint.hashCode()); + result = prime * result + fetcherId; + result = prime * result + mapperId; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + + ((parameterMap == null) ? 0 : parameterMap.hashCode()); + result = prime * result + ((query == null) ? 0 : query.hashCode()); + result = prime * result + + ((repository == null) ? 0 : repository.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + SparqlFeed other = (SparqlFeed) obj; + if (endpoint == null) { + if (other.endpoint != null) { + return false; + } + } else if (!endpoint.equals(other.endpoint)) { + return false; + } + if (fetcherId != other.fetcherId) { + return false; + } + if (mapperId != other.mapperId) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + if (parameterMap == null) { + if (other.parameterMap != null) { + return false; + } + } else if (!parameterMap.equals(other.parameterMap)) { + return false; + } + if (query == null) { + if (other.query != null) { + return false; + } + } else if (!query.equals(other.query)) { + return false; + } + if (repository == null) { + if (other.repository != null) { + return false; + } + } else if (!repository.equals(other.repository)) { + return false; + } + return true; + } + + + +} diff --git a/src/edu/cornell/mannlib/semservices/bo/SparqlFeedParam.java b/src/edu/cornell/mannlib/semservices/bo/SparqlFeedParam.java new file mode 100644 index 00000000..28cb8f4e --- /dev/null +++ b/src/edu/cornell/mannlib/semservices/bo/SparqlFeedParam.java @@ -0,0 +1,61 @@ +package edu.cornell.mannlib.semservices.bo; + +import java.io.Serializable; + +public class SparqlFeedParam extends BaseObject implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 4602167398212576479L; + private int sparqlFeedId; + private String param; + private String value; + + public SparqlFeedParam() { + // default constructor + } + + /** + * @return the sparqlFeedId + */ + public int getSparqlFeedId() { + return sparqlFeedId; + } + + /** + * @param sparqlFeedId the sparqlFeedId to set + */ + public void setSparqlFeedId(int sparqlFeedId) { + this.sparqlFeedId = sparqlFeedId; + } + + /** + * @return the param + */ + public String getParam() { + return param; + } + + /** + * @param param the param to set + */ + public void setParam(String param) { + this.param = param; + } + + /** + * @return the value + */ + public String getValue() { + return value; + } + + /** + * @param value the value to set + */ + public void setValue(String value) { + this.value = value; + } + +} diff --git a/src/edu/cornell/mannlib/semservices/bo/SparqlPlugin.java b/src/edu/cornell/mannlib/semservices/bo/SparqlPlugin.java new file mode 100644 index 00000000..bb6c74c5 --- /dev/null +++ b/src/edu/cornell/mannlib/semservices/bo/SparqlPlugin.java @@ -0,0 +1,54 @@ +package edu.cornell.mannlib.semservices.bo; + + +import java.util.HashMap; +import java.util.Map; + +public class SparqlPlugin extends BaseObject { + private String type; + private String name; + private String classname; + + /** + * + */ + public SparqlPlugin() { + super(); + } + /** + * @return the name + */ + public String getName() { + return name; + } + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + /** + * @return the type + */ + public String getType() { + return type; + } + /** + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + /** + * @return the classname + */ + public String getClassname() { + return classname; + } + /** + * @param classname the classname to set + */ + public void setClassname(String classname) { + this.classname = classname; + } +} diff --git a/src/edu/cornell/mannlib/semservices/bo/Time.java b/src/edu/cornell/mannlib/semservices/bo/Time.java index 546caa1a..6723947e 100644 --- a/src/edu/cornell/mannlib/semservices/bo/Time.java +++ b/src/edu/cornell/mannlib/semservices/bo/Time.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.bo; import java.util.Date; diff --git a/src/edu/cornell/mannlib/semservices/exceptions/ConceptsNotFoundException.java b/src/edu/cornell/mannlib/semservices/exceptions/ConceptsNotFoundException.java new file mode 100644 index 00000000..c57f49a6 --- /dev/null +++ b/src/edu/cornell/mannlib/semservices/exceptions/ConceptsNotFoundException.java @@ -0,0 +1,13 @@ +package edu.cornell.mannlib.semservices.exceptions; + +public class ConceptsNotFoundException extends Exception { + /** + * An exception that indicates a service could not find a Concept + */ + private static final long serialVersionUID = -4729465393290022840L; + public ConceptsNotFoundException() { } + public ConceptsNotFoundException(String message) { super(message); } + public ConceptsNotFoundException(Throwable cause) { super(cause); } + public ConceptsNotFoundException(String message, Throwable cause) { super(message, cause); } + +} diff --git a/src/edu/cornell/mannlib/semservices/service/ExternalConceptService.java b/src/edu/cornell/mannlib/semservices/service/ExternalConceptService.java index 891ee322..69f70f9b 100644 --- a/src/edu/cornell/mannlib/semservices/service/ExternalConceptService.java +++ b/src/edu/cornell/mannlib/semservices/service/ExternalConceptService.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.service; import java.util.List; @@ -7,7 +5,24 @@ import java.util.List; import edu.cornell.mannlib.semservices.bo.Concept; public interface ExternalConceptService { - // this is the only method that needs to be exposed - List processResults(String term) throws Exception; + + /** + * @param term + * @return + */ + List processResults(String term) throws Exception; + + /** + * @param term + * @return + * @throws Exception + */ + List getConcepts(String term) throws Exception; + + /** + * @param uri + * @return + */ + List getConceptsByURIWithSparql(String uri) throws Exception; } diff --git a/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java b/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java index 50ac9092..93de713e 100644 --- a/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java +++ b/src/edu/cornell/mannlib/semservices/service/impl/AgrovocService.java @@ -8,18 +8,30 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.StringWriter; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.rmi.RemoteException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; import java.util.List; - import javax.xml.parsers.ParserConfigurationException; import javax.xml.rpc.ServiceException; + +import org.apache.commons.lang.StringUtils; 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.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; @@ -27,95 +39,190 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; +import com.hp.hpl.jena.query.Query; +import com.hp.hpl.jena.query.QueryExecution; +import com.hp.hpl.jena.query.QueryExecutionFactory; +import com.hp.hpl.jena.query.QueryFactory; +import com.hp.hpl.jena.query.QuerySolution; +import com.hp.hpl.jena.query.ResultSet; +import com.hp.hpl.jena.rdf.model.Literal; +import com.hp.hpl.jena.rdf.model.RDFNode; +import com.hp.hpl.jena.rdf.model.Resource; + import edu.cornell.mannlib.semservices.bo.Concept; import edu.cornell.mannlib.semservices.service.ExternalConceptService; import edu.cornell.mannlib.semservices.util.XMLUtils; public class AgrovocService implements ExternalConceptService { + protected final Log logger = LogFactory.getLog(getClass()); - private java.lang.String AgrovocWS_address = "http://www.fao.org/webservices/AgrovocWS"; + 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"; + + + + @Override + public List getConcepts(String term) throws Exception { + List conceptList = new ArrayList(); + //System.out.println("Searching for term: "+ term); + String result = getURIByTermAndLangXML(this.ontologyName, term, this.searchMode, this.format, this.lang); + // return empty conceptList if conceptUri is empty + if (StringUtils.isEmpty(result)) { + return conceptList; + } + + // First create a new SKOSManager + String conceptUri = getConceptURIFromRDF(result); + SKOSManager manager = new SKOSManager(); + + // return empty conceptList if conceptUri is empty + if (StringUtils.isEmpty(conceptUri)) { + return conceptList; + } + URI uri = null; + try { + uri = new URI(conceptUri); + } catch (URISyntaxException e) { + e.printStackTrace(); + return conceptList; + } + + 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()); + concept.setUri(skosConcept.getURI().toString()); + concept.setConceptId(stripConceptId(skosConcept.getURI().toString())); + concept.setBestMatch("true"); + concept.setDefinedBy(this.schemeUri); + concept.setSchemeURI(this.schemeUri); + concept.setType(""); + String lang = ""; + + for (SKOSLiteral literal : skosConcept.getSKOSRelatedConstantByProperty(dataset, manager.getSKOSDataFactory().getSKOSPrefLabelProperty())) { + + if (!literal.isTyped()) { + // if it has language + SKOSUntypedLiteral untypedLiteral = literal.getAsSKOSUntypedLiteral(); + if (untypedLiteral.hasLang()) { + lang = untypedLiteral.getLang(); + } else { + lang = ""; + } + } + if (lang.equals("en")) { + //System.out.println("prefLabel: " + literal.getLiteral()); + + concept.setLabel(literal.getLiteral()); + } + } + + // get the broader property URI + List broaderURIList = new ArrayList(); + for (SKOSAnnotation annotation: skosConcept.getSKOSAnnotationsByURI(dataset, manager.getSKOSDataFactory().getSKOSBroaderProperty().getURI())) { + String value = new String(); + if (annotation.isAnnotationByConstant()) { + SKOSLiteral literal = annotation.getAnnotationValueAsConstant(); + value = literal.getLiteral(); + //System.out.println("broder uri: "+ value); + } else { + // annotation is some resource + SKOSEntity entity = annotation.getAnnotationValue(); + value = entity.getURI().toString(); + } + //System.out.println("broader uri: "+value); + broaderURIList.add(value); + } + concept.setBroaderURIList(broaderURIList); + + // get the narrower property URI + List narrowerURIList = new ArrayList(); + for (SKOSAnnotation annotation: skosConcept.getSKOSAnnotationsByURI(dataset, manager.getSKOSDataFactory().getSKOSNarrowerProperty().getURI())) { + String value = new String(); + if (annotation.isAnnotationByConstant()) { + SKOSLiteral literal = annotation.getAnnotationValueAsConstant(); + value = literal.getLiteral(); + //System.out.println("narrower uri: "+ value); + } else { + // annotation is some resource + SKOSEntity entity = annotation.getAnnotationValue(); + value = entity.getURI().toString(); + } + //System.out.println("narrower uri: "+value); + narrowerURIList.add(value); + } + concept.setNarrowerURIList(narrowerURIList); + + // exact match + List exactMatchURIList = new ArrayList(); + for (SKOSAnnotation annotation: skosConcept.getSKOSAnnotationsByURI(dataset, manager.getSKOSDataFactory().getSKOSExactMatchProperty().getURI())) { + String value = new String(); + if (annotation.isAnnotationByConstant()) { + SKOSLiteral literal = annotation.getAnnotationValueAsConstant(); + value = literal.getLiteral(); + //System.out.println("exact match: "+ value); + } else { + // annotation is some resource + SKOSEntity entity = annotation.getAnnotationValue(); + value = entity.getURI().toString(); + } + //System.out.println("exact match: "+value); + exactMatchURIList.add(value); + } + concept.setExactMatchURIList(exactMatchURIList); + + // close match + List closeMatchURIList = new ArrayList(); + for (SKOSAnnotation annotation: skosConcept.getSKOSAnnotationsByURI(dataset, manager.getSKOSDataFactory().getSKOSCloseMatchProperty().getURI())) { + String value = new String(); + if (annotation.isAnnotationByConstant()) { + SKOSLiteral literal = annotation.getAnnotationValueAsConstant(); + value = literal.getLiteral(); + //System.out.println("close match: "+ value); + } else { + // annotation is some resource + SKOSEntity entity = annotation.getAnnotationValue(); + value = entity.getURI().toString(); + } + //System.out.println("close match: "+value); + closeMatchURIList.add(value); + if (value.startsWith("http://dbpedia.org")) { + String description = getDbpediaDescription(value); + //System.out.println("description: "+ description); + concept.setDefinition(description); + } + } + concept.setCloseMatchURIList(closeMatchURIList); + + conceptList.add(concept); + + + } + return conceptList; + } public List processResults(String term) throws Exception { - List conceptList = new ArrayList(); - - String termcode; - try { - termcode = getTermcodeByTerm(term); - } catch (Exception e1) { - logger.error("Could not get termcode from service", e1); - throw e1; - } - - String format = "SKOS"; - // if the termcode is null it means that either the service is not responding - // or there was not a match for the string - //System.out.println("Got termcode: "+termcode); - - String results = getConceptInfoByTermcodeXML(termcode, format); - - //XMLUtils.prettyPrint(results); - - try { - Document doc = XMLUtils.parse(results); - String prefLabelQuery = "child::*[@xml:lang='EN']"; - NodeList nodes = doc.getElementsByTagName("skos:Concept"); - //System.out.println("Found this many nodes: "+ nodes.getLength()); - for (int i=0; i < nodes.getLength(); i++) { - - Node node = nodes.item(i); - //XMLUtils.serializeNode(node); System.out.println(); - - Concept concept = new Concept(); - concept.setDefinedBy("http://aims.fao.org/aos/agrovoc/agrovocScheme"); - concept.setConceptId(termcode); - - NamedNodeMap attrs = node.getAttributes(); - Attr idAttr = (Attr) attrs.getNamedItem("rdf:about"); - String conceptUri = idAttr.getTextContent(); - concept.setUri(conceptUri); - - Node prefLabelNode = XMLUtils.getNodeWithXpath(node, prefLabelQuery); - if (prefLabelNode != null) { - String prefLabel = prefLabelNode.getTextContent(); - concept.setLabel(prefLabel); - } - conceptList.add(concept); - } - } catch (IOException e) { - e.printStackTrace(); - } catch (SAXException e) { - e.printStackTrace(); - } catch (ParserConfigurationException e) { - e.printStackTrace(); - } - return conceptList; + return getConcepts(term); } - - - protected String getAgrovocLanguages() { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getAgrovocLanguages(); - } catch (ServiceException e) { - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - + + + + @Deprecated protected String getTermcodeByTerm(String term) throws Exception { String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); + ACSWWebServiceServiceLocator locator = new ACSWWebServiceServiceLocator(); try { URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); + ACSWWebService agrovoc_service = locator.getACSWWebService(url); result = agrovoc_service.getTermcodeByTerm(term); } catch (ServiceException e) { logger.error("service exception", e); @@ -130,275 +237,58 @@ public class AgrovocService implements ExternalConceptService { return result; } - protected String getTermcodeByTermXML(String term, String format) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getTermcodeByTermXML(term, format); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - return result; - } + + + protected String getTermCodeByTermAndLangXML(String ontologyName, String searchString, String lang, String codeName, String format) { + String result = new String(); + ACSWWebServiceServiceLocator locator = new ACSWWebServiceServiceLocator(); + try { + URL url = new URL(AgrovocWS_address); + ACSWWebService agrovoc_service = locator.getACSWWebService(url); + result = agrovoc_service.getTermCodeByTermAndLangXML(ontologyName, searchString, lang, codeName, format); + } catch (ServiceException e) { + logger.error("service exception", e); + e.printStackTrace(); + } catch (RemoteException e) { + e.printStackTrace(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } + return result; + } - protected String getTermByLanguage(int termcode, String language) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getTermByLanguage(termcode, language); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - return result; - } + - protected String getTermByLanguageXML(int termcode, String language, String format) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getTermByLanguageXML(termcode, language, format); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } + protected String getURIByTermAndLangXML(String ontologyName, String term, + String searchMode, String format, String lang) { + String result = new String(); + ACSWWebServiceServiceLocator locator = new ACSWWebServiceServiceLocator(); + try { + URL url = new URL(AgrovocWS_address); + ACSWWebService agrovoc_service = locator.getACSWWebService(url); + result = agrovoc_service.getURIByTermAndLangXML(ontologyName, term, + searchMode, format, lang); + } catch (ServiceException e) { + e.printStackTrace(); + } catch (RemoteException e) { + e.printStackTrace(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } - return result; - } + return result; + } - protected String getTermsListByLanguage2(String termcodes, String language, String sep) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getTermsListByLanguage2(termcodes, language, sep); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - return result; - } - - protected String getTermsListByLanguageXML(String termcodes, String language, String format) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getTermsListByLanguageXML(termcodes, language, format); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String getAllLabelsByTermcode2(int termcode, String sep) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getAllLabelsByTermcode2(termcode, sep); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String getAllLabelsByTermcodeXML(int termcode, String format) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getAllLabelsByTermcodeXML(termcode, format); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String simpleSearchByMode2(String term, String mode, String sep ) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.simpleSearchByMode2(term, mode, sep); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String simpleSearchByModeXML(String term, String mode, String format) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.simpleSearchByModeXML(term, mode, format); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String searchByTerm2(String term, String sep) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.searchByTerm2(term, sep); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String searchByTermXML(String term, String format) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.searchByTermXML(term, format); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String searchCategoryByMode(String term, String lang, String schemeid, String mode, String sep) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.searchCategoryByMode(term, lang, schemeid, mode, sep); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String searchCategoryByModeXML(String term, String mode, String schemeid, String lang, String format) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.searchCategoryByModeXML(term, mode, schemeid, lang, format); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String[] getConceptInfoByTermcode(String termcode) { - String result[] = null; - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getConceptInfoByTermcode(termcode); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } + + + protected String getConceptInfoByTermcodeXML(String termcode, String format) { String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); + ACSWWebServiceServiceLocator locator = new ACSWWebServiceServiceLocator(); try { URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); + ACSWWebService agrovoc_service = locator.getACSWWebService(url); result = agrovoc_service.getConceptInfoByTermcodeXML(termcode, format); } catch (ServiceException e) { logger.error("service exception", e); @@ -411,70 +301,34 @@ public class AgrovocService implements ExternalConceptService { return result; } + + protected String getConceptByKeyword(String ontologyName, String searchString, String format, String searchMode, String lang) { + String result = new String(); + ACSWWebServiceServiceLocator locator = new ACSWWebServiceServiceLocator(); + try { + URL url = new URL(AgrovocWS_address); + ACSWWebService agrovoc_service = locator.getACSWWebService(url); + result = agrovoc_service.getConceptByKeyword(ontologyName, searchString, format, searchMode, lang); + } catch (ServiceException e) { + logger.error("service exception", e); + e.printStackTrace(); + } catch (RemoteException e) { + e.printStackTrace(); + } catch (MalformedURLException e) { + e.printStackTrace(); + } - protected String[] getDefinitions(int termcode, String lang) { - String[] result = null; - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getDefinitions(termcode, lang); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String getDefinitionsXML(int termcode, String lang, String format) { - String result = null; - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getDefinitionsXML(termcode, lang, format); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } - - protected String getTermExpansion(String aQuery, String langugage) { - String result = new String(); - AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); - try { - URL url = new URL(AgrovocWS_address); - AgrovocWS agrovoc_service = locator.getAgrovocWS(url); - result = agrovoc_service.getTermExpansion(aQuery, langugage); - } catch (ServiceException e) { - logger.error("service exception", e); - e.printStackTrace(); - } catch (RemoteException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - - return result; - } + return result; + } + + protected String getWsdl() { String result = new String(); try { StringWriter sw = new StringWriter(); - URL rss = new URL(AgrovocWS_address + "?wsdl"); + URL rss = new URL(this.AgrovocWS_address + "?wsdl"); BufferedReader in = new BufferedReader(new InputStreamReader(rss.openStream())); String inputLine; @@ -490,4 +344,139 @@ public class AgrovocService implements ExternalConceptService { } return result; } + + + public List getConceptsByURIWithSparql(String uri) throws Exception { + //John Ferreira's original code has implementation + List newConceptList = new ArrayList(); + return newConceptList; + } + + protected String getAgrovocTermCode(String rdf) throws Exception { + String termcode = new String(); + try { + Document doc = XMLUtils.parse(rdf); + NodeList nodes = doc.getElementsByTagName("hasCodeAgrovoc"); + if (nodes.item(0) != null) { + Node node = nodes.item(0); + termcode = node.getTextContent(); + } + + } catch (SAXException e) { + //e.printStackTrace(); + throw e; + } catch (ParserConfigurationException e) { + //e.printStackTrace(); + throw e; + } catch (IOException e) { + //e.printStackTrace(); + throw e; + } + return termcode; + } + + protected String getConceptURIFromRDF(String rdf) { + String conceptUri = new String(); + try { + Document doc = XMLUtils.parse(rdf); + NodeList nodes = doc.getElementsByTagName("skos:Concept"); + Node node = nodes.item(0); + + NamedNodeMap attrs = node.getAttributes(); + Attr idAttr = (Attr) attrs.getNamedItem("rdf:about"); + conceptUri = idAttr.getTextContent(); + } catch (IOException e) { + e.printStackTrace(); + System.err.println("rdf: "+rdf); + } catch (SAXException e) { + e.printStackTrace(); + System.err.println("rdf: "+rdf); + } catch (ParserConfigurationException e) { + e.printStackTrace(); + System.err.println("rdf: "+rdf); + } + return conceptUri; + + } + + protected String getDbpediaDescription(String uri) throws Exception{ + String description = new String(); + String qs = "" + + "PREFIX rdfs: \n" + + "PREFIX rdf: \n" + + "PREFIX foaf: \n" + + "PREFIX dbpedia-owl: \n" + + "SELECT DISTINCT ?description WHERE { \n" + "<" + uri + + "> rdfs:comment ?description . \n" + + "FILTER (LANG(?description)='en' ) \n" + "}"; + //System.out.println(qs); + List resultList = new ArrayList(); + QueryExecution qexec = null; + try { + + Query query = QueryFactory.create(qs); + qexec = QueryExecutionFactory.sparqlService(this.dbpedia_endpoint, + query); + resultList = new ArrayList(); + ResultSet resultSet = qexec.execSelect(); + int resultSetSize = 0; + while (resultSet.hasNext()) { + resultSetSize++; + QuerySolution solution = resultSet.nextSolution(); + Iterator varnames = solution.varNames(); + HashMap hm = new HashMap(); + while (varnames.hasNext()) { + String name = (String) varnames.next(); + RDFNode rdfnode = solution.get(name); + // logger.info("rdf node name, type: "+ name + // +", "+getRDFNodeType(rdfnode)); + if (rdfnode.isLiteral()) { + Literal literal = rdfnode.asLiteral(); + String nodeval = literal.getString(); + hm.put(name, nodeval); + } else if (rdfnode.isResource()) { + Resource resource = rdfnode.asResource(); + String nodeval = resource.toString(); + hm.put(name, nodeval); + } + } + resultList.add(hm); + } + description = ""; + for (HashMap map : resultList) { + if (map.containsKey("description")) { + description = (String) map.get("description"); + } + } + } catch (Exception ex) { + throw ex; + } + return description; + } + + /** + * @param uri + * @return + */ + protected String stripConceptId(String uri) { + String conceptId = new String(); + int lastslash = uri.lastIndexOf('/'); + conceptId = uri.substring(lastslash + 1, uri.length()); + return conceptId; + } + + /** + * @param str + * @return + */ + protected String extractConceptId(String str) { + try { + return str.substring(1, str.length() - 1); + } catch (Exception ex) { + return ""; + } + } + + + } diff --git a/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java b/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java index e71b6a0d..495aee66 100644 --- a/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java +++ b/src/edu/cornell/mannlib/semservices/service/impl/GemetService.java @@ -1,41 +1,23 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - 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.exceptions.ConceptsNotFoundException; import edu.cornell.mannlib.semservices.service.ExternalConceptService; -import edu.cornell.mannlib.semservices.util.XMLUtils; -import edu.cornell.mannlib.vitro.webapp.web.URLEncoder; public class GemetService implements ExternalConceptService { protected final Log logger = LogFactory.getLog(getClass()); @@ -49,63 +31,112 @@ public class GemetService implements ExternalConceptService { 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"; + private final String endpoint = "http://cr.eionet.europa.eu/sparql"; + private final String schemeURI = "http://www.eionet.europa.eu/gemet/gemetThesaurus"; + + + + @Override + public List getConcepts(String term) throws Exception { + List conceptList = new ArrayList(); + try { + String results = getConceptsMatchingKeyword(term); + //System.out.println(results); + conceptList = processOutput(results); + + } catch (Exception ex) { + return new ArrayList(); + //ex.printStackTrace(); + //throw ex; + } + return conceptList; + } public List processResults(String term) throws Exception { - List conceptList = processConceptsAndRelatedMatchingKeyword(term); + List conceptList = new ArrayList(); + try { + String results = getConceptsMatchingKeyword(term); + conceptList = processOutput(results); + } catch (Exception ex) { + //ex.printStackTrace(); + throw ex; + } return conceptList; } + public List getConceptsByURIWithSparql(String uri) throws Exception { + //John Ferreira's original code has implementation + List newConceptList = new ArrayList(); + return newConceptList; + } + /** * @param results * @return - * By default, concepts set with best match = true */ - private List processOutput(String results) { - return processOutput(results, "true"); + private List processOutput(String results) throws Exception { + + List conceptList = new ArrayList(); - } - - private List processOutput(String results, String bestMatch) { - List conceptList = new ArrayList(); 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(bestMatch); - JSONObject json = jsonArray.getJSONObject(i); - String uri = getJsonValue(json, "uri"); + if (jsonArray.size() == 0) { + throw new ConceptsNotFoundException(); + } - 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); + for (int i = 0; i < jsonArray.size(); i++) { + Concept concept = new Concept(); + concept.setDefinedBy(this.schemeURI); + concept.setBestMatch("true"); + JSONObject json = jsonArray.getJSONObject(i); + String uri = getJsonValue(json, "uri"); - } - + concept.setUri(uri); + concept.setConceptId(stripConceptId(uri)); + concept.setSchemeURI(schemeURI); + 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")); + } + } + + String narrower = getRelatedConcepts(uri, "narrower"); + List narrowerURIList = getRelatedUris(narrower); + concept.setNarrowerURIList(narrowerURIList); + + String broader = getRelatedConcepts(uri, "broader"); + List broaderURIList = getRelatedUris(broader); + concept.setBroaderURIList(broaderURIList); + + /*String related = getRelatedConcepts(uri, "related"); + List relatedURIList = getRelatedUris(related); + for (String s: relatedURIList) { + System.out.println("related uri: "+s); + }*/ + + + conceptList.add(concept); + + } } catch (Exception ex ) { - ex.printStackTrace(); + //ex.printStackTrace(); logger.error("Could not get concepts", ex); + throw ex; } return conceptList; + } /** @@ -123,23 +154,50 @@ public class GemetService implements ExternalConceptService { } + /** + * @param concept_uri + * @return + * @throws Exception + */ protected String getAvailableLangs(String concept_uri) throws Exception { String result = new String(); String serviceUrl = GemetWS_address + "getAvailableLanguages" + "?concept_uri=" + concept_uri; - result = getGemetResults(serviceUrl); + try { + result = getGemetResults(serviceUrl); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } return result; } + /** + * @param concept_uri + * @return + * @throws Exception + */ protected String getConcept(String concept_uri) throws Exception { String result = new String(); String serviceUrl = GemetWS_address + "getConcept" + "?concept_uri=" + concept_uri + "&language=en"; - result = getGemetResults(serviceUrl); + try { + result = getGemetResults(serviceUrl); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } return result; } - protected String getAllTranslationsForConcept(String concept_uri, String property) throws Exception { + + /** + * @param concept_uri + * @param property + * @return + * @throws Exception + */ + protected String getAllTranslationsForConcept(String concept_uri, String property) throws Exception { String result = new String(); String property_uri = new String(); if (property.equals("definition")) { @@ -160,11 +218,23 @@ public class GemetService implements ExternalConceptService { "?concept_uri=" + concept_uri + "&property_uri=" + property_uri + "&language=en"; - result = getGemetResults(serviceUrl); + + try { + result = getGemetResults(serviceUrl); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } return result; } + /** + * @param concept_uri + * @param relation + * @return + * @throws Exception + */ protected String getRelatedConcepts(String concept_uri, String relation) throws Exception { String result = new String(); String relation_uri = new String(); @@ -179,41 +249,43 @@ public class GemetService implements ExternalConceptService { "?concept_uri=" + concept_uri + "&relation_uri=" + relation_uri + "&language=en"; - result = getGemetResults(serviceUrl); + try { + result = getGemetResults(serviceUrl); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } return result; } + /** + * @param keyword + * @return + * @throws Exception + */ protected String getConceptsMatchingKeyword(String keyword) throws Exception { String result = new String(); String serviceUrl = GemetWS_address + "getConceptsMatchingKeyword" + - "?keyword=" + URLEncoder.encode(keyword) + + "?keyword=" + keyword + "&search_mode=0" + "&thesaurus_uri=http://www.eionet.europa.eu/gemet/concept/" + "&language=en"; - - result = getGemetResults(serviceUrl); + try { + result = getGemetResults(serviceUrl); + } catch (Exception ex) { + throw ex; + } 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 { + /** + * @param url + * @return + */ + protected String getGemetResults(String url) throws Exception { String results = new String(); //System.out.println("url: "+url); try { @@ -232,9 +304,36 @@ public class GemetService implements ExternalConceptService { } catch (Exception ex) { logger.error("error occurred in servlet", ex); + ex.printStackTrace(); throw ex; } return results; } + + protected List getRelatedUris(String json) { + List uriList = new ArrayList(); + String uri = new String(); + JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON( json ); + if (jsonArray.size() == 0) { + return new ArrayList(); + } + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObj = jsonArray.getJSONObject(i); + uri = getJsonValue(jsonObj, "uri"); + uriList.add(uri); + } + + return uriList; + + } + + protected String stripConceptId(String uri) { + String conceptId = new String(); + int lastslash = uri.lastIndexOf('/'); + conceptId = uri.substring(lastslash + 1, uri.length()); + return conceptId; + } + + } diff --git a/src/edu/cornell/mannlib/semservices/service/impl/UMLSService.java b/src/edu/cornell/mannlib/semservices/service/impl/UMLSService.java index b39b094c..21c83edd 100644 --- a/src/edu/cornell/mannlib/semservices/service/impl/UMLSService.java +++ b/src/edu/cornell/mannlib/semservices/service/impl/UMLSService.java @@ -1,11 +1,10 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.service.impl; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.StringWriter; import java.net.URL; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; @@ -17,8 +16,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.semservices.bo.Concept; +import edu.cornell.mannlib.semservices.exceptions.ConceptsNotFoundException; import edu.cornell.mannlib.semservices.service.ExternalConceptService; -import edu.cornell.mannlib.vitro.webapp.web.URLEncoder; /** * @author jaf30 @@ -28,11 +27,48 @@ public class UMLSService implements ExternalConceptService { protected final Log logger = LogFactory.getLog(getClass()); private static final String submissionUrl = "http://link.informatics.stonybrook.edu/MeaningLookup/MlServiceServlet?"; 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"; - public List processResults(String term) throws Exception{ + + @Override + public List getConcepts(String term) throws Exception { + List conceptList = new ArrayList(); + + 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"; + + 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(); + //System.out.println("results before processing: "+results); + conceptList = processOutput(results); + return conceptList; + + } catch (Exception ex) { + logger.error("error occurred in servlet", ex); + return null; + } + } + + public List processResults(String term) throws Exception { String results = null; String dataUrl = submissionUrl + "textToProcess=" - + URLEncoder.encode(term) + "&format=json"; + + URLEncoder.encode(term, "UTF-8") + "&format=json"; try { @@ -47,41 +83,57 @@ public class UMLSService implements ExternalConceptService { in.close(); results = sw.toString(); + //System.out.println("results before processing: "+results); + List conceptList = processOutput(results); + return conceptList; } catch (Exception ex) { logger.error("error occurred in servlet", ex); - throw ex; + return null; } - List conceptList = processOutput(results); - return conceptList; + + } + + /** + * @param uri + * @return + */ + public List getConceptsByURIWithSparql(String uri) throws Exception { + //John Ferreira's original code has implementation + List newConceptList = new ArrayList(); + return newConceptList; } /** * @param results * @return */ - private List processOutput(String results) { + private List processOutput(String results) throws Exception { List conceptList = new ArrayList(); List bestMatchIdList = new ArrayList(); String bestMatchId = new String(); + boolean bestMatchFound = false; + boolean allFound = false; + try { JSONObject json = (JSONObject) JSONSerializer.toJSON( results ); - + //System.out.println(json.toString()); if (json.has("Best Match")) { + bestMatchFound = true; //System.out.println("Best Match"); JSONArray bestMatchArray = json.getJSONArray("Best Match"); int len = bestMatchArray.size(); if (len > 1) { - System.out.println("Found this many best matches: "+ len); + logger.debug("Found this many best matches: "+ len); } int i; for (i = 0; i < len; i++) { JSONObject o = bestMatchArray.getJSONObject(i); //System.out.println(o.toString()); Concept concept = new Concept(); - concept.setDefinedBy("http://link.informatics.stonybrook.edu/umls"); + concept.setDefinedBy(schemeURI); concept.setBestMatch("true"); String cui = getJsonValue(o, "CUI"); bestMatchIdList.add(cui); @@ -91,11 +143,12 @@ public class UMLSService implements ExternalConceptService { concept.setType(getJsonValue(o, "type")); concept.setDefinition(getJsonValue(o, "definition")); concept.setUri(baseUri + cui); + concept.setSchemeURI(schemeURI); conceptList.add(concept); } } if (json.has("All")) { - + allFound = true; JSONArray allArray = json.getJSONArray("All"); int len = allArray.size(); //System.out.println("size of best match array: "+ len); @@ -104,7 +157,7 @@ public class UMLSService implements ExternalConceptService { JSONObject o = allArray.getJSONObject(i); //System.out.println(o.toString()); Concept concept = new Concept(); - concept.setDefinedBy("http://link.informatics.stonybrook.edu/umls"); + concept.setDefinedBy(schemeURI); String cui = getJsonValue(o, "CUI"); concept.setConceptId(cui); @@ -112,6 +165,7 @@ public class UMLSService implements ExternalConceptService { concept.setType(getJsonValue(o, "type")); concept.setDefinition(getJsonValue(o, "definition")); concept.setUri(baseUri + cui); + concept.setSchemeURI(schemeURI); // prevent duplicate concepts in list if (! bestMatchIdList.contains(cui)) { concept.setBestMatch("false"); @@ -122,20 +176,18 @@ public class UMLSService implements ExternalConceptService { } catch (Exception ex ) { ex.printStackTrace(); logger.error("Could not get concepts", ex); + throw ex; } + if (! bestMatchFound && !allFound) { + // we did not get a bestMatch or All element + throw new ConceptsNotFoundException(); + } + + // return conceptList; - // - // now serialize the list of Concepts to a JSON String - // - //JSONObject jsonObject = null; - //jsonObject = BeanToJsonSerializer.serializeToJsonObject(conceptList); - //System.out.println(jsonObject.toString()); - //return jsonObject.toString(); - } - /** * Get a string from a json object or an empty string if there is no value for the given key * @param obj @@ -150,4 +202,13 @@ public class UMLSService implements ExternalConceptService { } } + + + protected String stripConceptId(String uri) { + String conceptId = new String(); + int lastslash = uri.lastIndexOf('/'); + conceptId = uri.substring(lastslash + 1, uri.length()); + return conceptId; + } + } diff --git a/src/edu/cornell/mannlib/semservices/util/ClassUtils.java b/src/edu/cornell/mannlib/semservices/util/ClassUtils.java index c71e3d22..457734c2 100644 --- a/src/edu/cornell/mannlib/semservices/util/ClassUtils.java +++ b/src/edu/cornell/mannlib/semservices/util/ClassUtils.java @@ -1,7 +1,4 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - /* - * $Id$ * CONFIDENTIAL AND PROPRIETARY. ? 2007 Revolution Health Group LLC. All rights reserved. * This source code may not be disclosed to others, used or reproduced without the written permission of Revolution Health Group. diff --git a/src/edu/cornell/mannlib/semservices/util/DateConverter.java b/src/edu/cornell/mannlib/semservices/util/DateConverter.java index d91d371a..9c1980f2 100644 --- a/src/edu/cornell/mannlib/semservices/util/DateConverter.java +++ b/src/edu/cornell/mannlib/semservices/util/DateConverter.java @@ -1,7 +1,4 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - /* - * $Id: DateConverter.java 50408 2007-03-28 19:14:46Z jdamick $ * * Copyright 2006- Revolution Health Group. All rights reserved. diff --git a/src/edu/cornell/mannlib/semservices/util/DateUtils.java b/src/edu/cornell/mannlib/semservices/util/DateUtils.java index 7e18b736..42a54874 100644 --- a/src/edu/cornell/mannlib/semservices/util/DateUtils.java +++ b/src/edu/cornell/mannlib/semservices/util/DateUtils.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.util; import java.text.ParsePosition; diff --git a/src/edu/cornell/mannlib/semservices/util/DayConverter.java b/src/edu/cornell/mannlib/semservices/util/DayConverter.java index f21edefa..c8ba9f2b 100644 --- a/src/edu/cornell/mannlib/semservices/util/DayConverter.java +++ b/src/edu/cornell/mannlib/semservices/util/DayConverter.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.util; diff --git a/src/edu/cornell/mannlib/semservices/util/MetadataNamespaceContext.java b/src/edu/cornell/mannlib/semservices/util/MetadataNamespaceContext.java index 298b16b1..8c177eea 100644 --- a/src/edu/cornell/mannlib/semservices/util/MetadataNamespaceContext.java +++ b/src/edu/cornell/mannlib/semservices/util/MetadataNamespaceContext.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.util; import java.util.Iterator; import javax.xml.XMLConstants; diff --git a/src/edu/cornell/mannlib/semservices/util/ObjectUtils.java b/src/edu/cornell/mannlib/semservices/util/ObjectUtils.java index 9cea3a73..b79eb200 100644 --- a/src/edu/cornell/mannlib/semservices/util/ObjectUtils.java +++ b/src/edu/cornell/mannlib/semservices/util/ObjectUtils.java @@ -264,5 +264,10 @@ public class ObjectUtils { } } + public static String nl2br(String text) { + return text.replaceAll("\n\n", "

").replaceAll("\n", "
"); + } + + } diff --git a/src/edu/cornell/mannlib/semservices/util/TimeConverter.java b/src/edu/cornell/mannlib/semservices/util/TimeConverter.java index ccd6147c..41a04448 100644 --- a/src/edu/cornell/mannlib/semservices/util/TimeConverter.java +++ b/src/edu/cornell/mannlib/semservices/util/TimeConverter.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.util; import edu.cornell.mannlib.semservices.bo.Time; import java.util.Date; diff --git a/src/edu/cornell/mannlib/semservices/util/TimestampConverter.java b/src/edu/cornell/mannlib/semservices/util/TimestampConverter.java index c4f3baa8..8c015ee3 100644 --- a/src/edu/cornell/mannlib/semservices/util/TimestampConverter.java +++ b/src/edu/cornell/mannlib/semservices/util/TimestampConverter.java @@ -1,5 +1,3 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.util; import java.sql.Timestamp; import java.text.SimpleDateFormat; diff --git a/src/edu/cornell/mannlib/semservices/util/XMLGregorianCalendarConverter.java b/src/edu/cornell/mannlib/semservices/util/XMLGregorianCalendarConverter.java index 180bd4f9..69d23eb9 100644 --- a/src/edu/cornell/mannlib/semservices/util/XMLGregorianCalendarConverter.java +++ b/src/edu/cornell/mannlib/semservices/util/XMLGregorianCalendarConverter.java @@ -1,5 +1,4 @@ /* - * $Id: XMLGregorianCalendarConverter.java 28642 2006-10-25 13:41:54Z jdamick $ * * Copyright 2006- Revolution Health Group. All rights reserved. diff --git a/src/edu/cornell/mannlib/semservices/util/XMLUtils.java b/src/edu/cornell/mannlib/semservices/util/XMLUtils.java index 82fafd9c..5c6407c0 100644 --- a/src/edu/cornell/mannlib/semservices/util/XMLUtils.java +++ b/src/edu/cornell/mannlib/semservices/util/XMLUtils.java @@ -1,8 +1,7 @@ -/* $This file is distributed under the terms of the license in /doc/license.txt$ */ - package edu.cornell.mannlib.semservices.util; import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; @@ -81,7 +80,7 @@ public class XMLUtils { public synchronized static Document parse(String xmlString) throws IOException, SAXException, ParserConfigurationException { StringReader reader = new StringReader(xmlString); - InputSource inputSource = new InputSource(reader); + InputSource inputSource = new InputSource(reader); return getDocumentBuilder().parse(inputSource); } @@ -122,6 +121,15 @@ public class XMLUtils { serializer.serialize(doc); } + public static String serializeDoctoString(Document doc) throws IOException { + XMLSerializer serializer = new XMLSerializer(); + ByteArrayOutputStream bout = new ByteArrayOutputStream(); + + serializer.setOutputByteStream(bout); + serializer.serialize(doc); + return bout.toString(); + } + /** * @param xml */ @@ -152,6 +160,36 @@ public class XMLUtils { } + /** + * @param xml + */ + public static String prettyPrintToString(String xml) { + Source xmlInput = new StreamSource(new StringReader(xml)); + StreamResult xmlOutput = new StreamResult(new StringWriter()); + Transformer transformer = null; + try { + transformer = TransformerFactory.newInstance().newTransformer(); + } catch (TransformerConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (TransformerFactoryConfigurationError e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + //transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "testing.dtd"); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); + try { + transformer.transform(xmlInput, xmlOutput); + } catch (TransformerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String formattedxml=xmlOutput.getWriter().toString(); + return formattedxml; + + } + /** * @param node */ diff --git a/src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/BeanToJsonSerializer.java b/src/edu/cornell/mannlib/semservices/view/BeanToJsonSerializer.java similarity index 93% rename from src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/BeanToJsonSerializer.java rename to src/edu/cornell/mannlib/semservices/view/BeanToJsonSerializer.java index 8c26e5d4..ddc58286 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/BeanToJsonSerializer.java +++ b/src/edu/cornell/mannlib/semservices/view/BeanToJsonSerializer.java @@ -1,4 +1,16 @@ -package edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService; +/* + * $Id: BeanToJsonSerializer.java 66350 2007-08-20 21:11:41Z xluan $ + * + * Copyright 2006- Revolution Health Group. All rights reserved. + * + * This software is the confidential and proprietary information + * of Revolution Health Group. (Confidential Information). + * You shall not disclose such Confidential Information and shall + * use it only in accordance with the terms of the license + * agreement you entered into with Revolution Health Group. + * + */ +package edu.cornell.mannlib.semservices.view; import java.beans.PropertyDescriptor; import java.lang.reflect.InvocationTargetException; diff --git a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddAssociatedConceptGenerator.java b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddAssociatedConceptGenerator.java index a51c32f9..02f7efc0 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddAssociatedConceptGenerator.java +++ b/src/edu/cornell/mannlib/vitro/webapp/edit/n3editing/configuration/generators/AddAssociatedConceptGenerator.java @@ -46,7 +46,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements private Log log = LogFactory.getLog(AddAssociatedConceptGenerator.class); private String template = "addAssociatedConcept.ftl"; private static String SKOSConceptType = "http://www.w3.org/2004/02/skos/core#Concept"; - + //TODO: Set this to a dynamic mechanism + private static String VIVOCore = "http://vivoweb.org/ontology/core#"; @Override public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) { @@ -168,10 +169,13 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements return n3Required; } - //Don't think there's any n3 optional here + //Optional N3, includes possibility of semantic type which may or may not be included + //label and source are independent of semantic type private List generateN3Optional() { return list("?conceptNode <" + RDFS.label.getURI() + "> ?conceptLabel .\n" + - "?conceptNode <" + RDFS.isDefinedBy.getURI() + "> ?conceptSource ." + "?conceptNode <" + RDFS.isDefinedBy.getURI() + "> ?conceptSource .", + "?conceptNode <" + VIVOCore + "conceptSemanticType> ?conceptSemanticTypeURI ." + + "?conceptSemanticTypeURI <" + RDFS.label.getURI() + "> ?conceptSemanticTypeLabel ." ); } @@ -185,6 +189,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements HashMap newResources = new HashMap(); //There are no new resources here, the concept node uri doesn't //get created but already exists, and vocab uri should already exist as well + //Adding concept semantic type uri just to test - note this isn't really on the form at all + newResources.put("conceptSemanticTypeURI", null); return newResources; } @@ -233,9 +239,12 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements //The URI of the node that defines the concept urisOnForm.add("conceptNode"); urisOnForm.add("conceptSource"); + urisOnForm.add("conceptSemanticTypeURI"); editConfiguration.setUrisOnform(urisOnForm); //Also need to add the label of the concept literalsOnForm.add("conceptLabel"); + literalsOnForm.add("conceptSemanticTypeLabel"); + editConfiguration.setLiteralsOnForm(literalsOnForm); } @@ -263,6 +272,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements setConceptNodeField(editConfiguration, vreq); setConceptLabelField(editConfiguration, vreq); setVocabURIField(editConfiguration, vreq); + setConceptSemanticTypeURIField(editConfiguration,vreq); + setConceptSemanticTypeLabelField(editConfiguration,vreq); } //this field will be hidden and include the concept node URI @@ -290,6 +301,22 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements setRangeDatatypeUri(XSD.xstring.toString()) ); } + + //This will also be a URI + private void setConceptSemanticTypeURIField(EditConfigurationVTwo editConfiguration, + VitroRequest vreq) { + editConfiguration.addField(new FieldVTwo(). + setName("conceptSemanticTypeURI") + ); + } + + private void setConceptSemanticTypeLabelField(EditConfigurationVTwo editConfiguration, + VitroRequest vreq) { + editConfiguration.addField(new FieldVTwo(). + setName("conceptSemanticTypeLabel"). + setRangeDatatypeUri(XSD.xstring.toString()) + ); + } //Add preprocessor @@ -357,6 +384,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements boolean isSKOSConcept = false; String conceptUri = conceptIndividual.getURI(); String conceptLabel = conceptIndividual.getName(); + //Check if SKOS Concept type List osl = conceptIndividual.getObjectPropertyStatements(RDF.type.getURI()); for(ObjectPropertyStatement os: osl) { @@ -367,7 +395,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements } if(isSKOSConcept) { - info.add(new AssociatedConceptInfo(conceptLabel, conceptUri, null, null, SKOSConceptType)); + //if the concept in question is skos - which would imply a user generated concept + info.add(new AssociatedConceptInfo(conceptLabel, conceptUri, null, null, SKOSConceptType, null, null)); } else { //Get the vocab source and vocab label List vocabList = conceptIndividual.getObjectPropertyStatements(RDFS.isDefinedBy.getURI()); @@ -379,7 +408,19 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements //Assuming name will get label vocabLabel = sourceIndividual.getName(); } - info.add(new AssociatedConceptInfo(conceptLabel, conceptUri, vocabSource, vocabLabel, null)); + String conceptSemanticTypeURI = null; + String conceptSemanticTypeLabel = null; + //Can a concept have multiple semantic types? Currently we are only returning the first one + List semanticTypeStatements = conceptIndividual.getObjectPropertyStatements(VIVOCore + "conceptSemanticType"); + if(semanticTypeStatements.size() > 0) { + conceptSemanticTypeURI = semanticTypeStatements.get(0).getObjectURI(); + Individual conceptSemanticTypeIndividual = EditConfigurationUtils.getIndividual(vreq, conceptSemanticTypeURI); + conceptSemanticTypeLabel = conceptSemanticTypeIndividual.getName(); + } + //get label + + //Assuming this is from an external vocabulary source + info.add(new AssociatedConceptInfo(conceptLabel, conceptUri, vocabSource, vocabLabel, null, conceptSemanticTypeURI, conceptSemanticTypeLabel)); } } @@ -392,12 +433,16 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements private String vocabURI; private String vocabLabel; private String type; //In case of SKOS concept, will have skos concept type - public AssociatedConceptInfo(String inputLabel, String inputURI, String inputVocabURI, String inputVocabLabel, String inputType) { + private String conceptSemanticTypeURI; //For some services, such as UMLS, we have a semantic type associated + private String conceptSemanticTypeLabel; + public AssociatedConceptInfo(String inputLabel, String inputURI, String inputVocabURI, String inputVocabLabel, String inputType, String inputConceptSemanticTypeURI, String inputConceptSemanticTypeLabel) { this.conceptLabel = inputLabel; this.conceptURI = inputURI; this.vocabURI = inputVocabURI; this.vocabLabel = inputVocabLabel; this.type = inputType; + this.conceptSemanticTypeURI = inputConceptSemanticTypeURI; + this.conceptSemanticTypeLabel = inputConceptSemanticTypeLabel; } //Getters @@ -421,6 +466,14 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements return type; } + public String getConceptSemanticTypeURI(){ + return conceptSemanticTypeURI; + } + + public String getConceptSemanticTypeLabel(){ + return conceptSemanticTypeLabel; + } + } public class AssociatedConceptInfoComparator implements Comparator{ diff --git a/src/edu/cornell/mannlib/vitro/webapp/servlet/ConceptSearchServlet.java b/src/edu/cornell/mannlib/vitro/webapp/servlet/ConceptSearchServlet.java index deca950d..9d47efb2 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/servlet/ConceptSearchServlet.java +++ b/src/edu/cornell/mannlib/vitro/webapp/servlet/ConceptSearchServlet.java @@ -20,9 +20,9 @@ import org.apache.commons.logging.LogFactory; import edu.cornell.mannlib.semservices.bo.Concept; import edu.cornell.mannlib.semservices.bo.ConceptInfo; import edu.cornell.mannlib.semservices.bo.SemanticServicesError; +import edu.cornell.mannlib.semservices.view.BeanToJsonSerializer; import edu.cornell.mannlib.vitro.webapp.controller.VitroHttpServlet; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; -import edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService.BeanToJsonSerializer; import edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService.ConceptSearchServiceUtils; public class ConceptSearchServlet extends VitroHttpServlet { diff --git a/src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java b/src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java index c0521e0b..d232e875 100644 --- a/src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java +++ b/src/edu/cornell/mannlib/vitro/webapp/utils/ConceptSearchService/ConceptSearchServiceUtils.java @@ -39,7 +39,7 @@ public class ConceptSearchServiceUtils { HashMap map = new HashMap(); map.put(UMLSVocabSource, new VocabSourceDescription("UMLS", UMLSVocabSource, "http://www.nlm.nih.gov/research/umls/", "Unified Medical Language System")); //Commenting out agrovoc for now until implementation is updated - // map.put(AgrovocVocabSource, new VocabSourceDescription("AGROVOC", AgrovocVocabSource, "http://www.fao.org/agrovoc/", "Agricultural Vocabulary")); + map.put(AgrovocVocabSource, new VocabSourceDescription("AGROVOC", AgrovocVocabSource, "http://www.fao.org/agrovoc/", "Agricultural Vocabulary")); map.put(GemetVocabSource, new VocabSourceDescription("GEMET", GemetVocabSource, "http://www.eionet.europa.eu/gemet", "GEneral Multilingual Environmental Thesaurus")); return map; } @@ -82,7 +82,7 @@ public class ConceptSearchServiceUtils { //Get search String searchTerm = getSearchTerm(vreq); - List conceptResults = conceptServiceClass.processResults(searchTerm); + List conceptResults = conceptServiceClass.getConcepts(searchTerm); return conceptResults; }