External vocabulary service and integration of Agrovoc with work beginning for applying concept semantic type to UMLS concepts.

This commit is contained in:
hudajkhan 2013-08-07 16:08:11 -04:00
parent 9fda9d2922
commit 2ea474b6ef
44 changed files with 1387 additions and 557 deletions

Binary file not shown.

BIN
lib/agrovocws-3.0.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/htmlparser.jar Normal file

Binary file not shown.

Binary file not shown.

BIN
lib/owlapi-bin.jar Normal file

Binary file not shown.

BIN
lib/skosapi-3-bin.jar Normal file

Binary file not shown.

162
olddeploy.properties Normal file
View file

@ -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

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog prefer="public" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<uri id="User Entered Import Resolution" name="http://vivoweb.org/ontology/core/vivo-c4o-public-1.5.owl" uri="vivo-core-public-1.5.owl"/>
<group id="Folder Repository, directory=, recursive=true, Auto-Update=true, version=2" prefer="public" xml:base=""/>
</catalog>

View file

@ -1,6 +1,6 @@
<#-- $This file is distributed under the terms of the license in /doc/license.txt$ --> <#-- $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 --> <h3>Positions!${core}personInPosition</h3>
<#assign positions = propertyGroups.pullProperty("${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) --> <#if positions?has_content> <#-- true when the property is in the list, even if not populated (when editing) -->
<#assign localName = positions.localName> <#assign localName = positions.localName>

View file

@ -2,6 +2,9 @@
<#-- List of research areas for the individual --> <#-- List of research areas for the individual -->
<#assign researchAreas = propertyGroups.pullProperty("${core}hasResearchArea")!> <#assign researchAreas = propertyGroups.pullProperty("${core}hasResearchArea")!>
<#assign concepts = propertyGroups.pullProperty("${core}hasAssociatedConcept")!>
<#if concepts?has_content> concepts has content <#else> concepts dont have content</#if>
<h2>RESEARCH AREAS: ${core}hasResearchArea</h2>
<#if researchAreas?has_content> <#-- true when the property is in the list, even if not populated (when editing) --> <#if researchAreas?has_content> <#-- true when the property is in the list, even if not populated (when editing) -->
<#assign localName = researchAreas.localName> <#assign localName = researchAreas.localName>
<h2 id="${localName}" class="mainPropGroup"> <h2 id="${localName}" class="mainPropGroup">
@ -11,5 +14,5 @@
</h2> </h2>
<ul id="individual-${localName}" role="list" > <ul id="individual-${localName}" role="list" >
<@p.objectProperty researchAreas editable /> <@p.objectProperty researchAreas editable />
</ul> </ul> <#else> Research areas does not have content
</#if> </#if>

View file

@ -96,6 +96,9 @@
<input type="hidden" id="conceptNode" name="conceptNode" value=""/> <!-- Field value populated by JavaScript --> <input type="hidden" id="conceptNode" name="conceptNode" value=""/> <!-- Field value populated by JavaScript -->
<input type="hidden" id="conceptLabel" name="conceptLabel" value="" /> <!-- Field value populated by JavaScript --> <input type="hidden" id="conceptLabel" name="conceptLabel" value="" /> <!-- Field value populated by JavaScript -->
<input type="hidden" id="conceptSource" name="conceptSource" value="" /> <!-- Field value populated by JavaScript --> <input type="hidden" id="conceptSource" name="conceptSource" value="" /> <!-- Field value populated by JavaScript -->
<input type="hidden" id="conceptSemanticTypeURI" name="conceptSemanticTypeURI" value="" /> <!-- Field value populated by JavaScript -->
<input type="hidden" id="conceptSemanticTypeLabel" name="conceptSemanticTypeLabel" value="" /> <!-- Field value populated by JavaScript -->
<div id="selectedConcept" name="selectedConcept" class="acSelection"> <div id="selectedConcept" name="selectedConcept" class="acSelection">
<p class="inline"> <p class="inline">
</p> </p>

View file

@ -54,6 +54,7 @@ var addConceptForm = {
this.externalConceptURI = $('#conceptNode'); this.externalConceptURI = $('#conceptNode');
this.externalConceptLabel = $('#conceptLabel'); this.externalConceptLabel = $('#conceptLabel');
this.externalConceptSource = $('#conceptSource'); this.externalConceptSource = $('#conceptSource');
this.externalConceptSemanticTypeLabel = $("#conceptSemanticTypeLabel");
//remove links //remove links
this.removeConceptLinks = $('a.remove'); this.removeConceptLinks = $('a.remove');
this.errors = $('#errors'); this.errors = $('#errors');
@ -236,23 +237,27 @@ var addConceptForm = {
} }
var i; var i;
var len = checkedElements.length; var len = checkedElements.length;
var checkedConcept, checkedConceptElement, conceptLabel, conceptSource; var checkedConcept, checkedConceptElement, conceptLabel, conceptSource, conceptSemanticType;
var conceptNodes = []; var conceptNodes = [];
var conceptLabels = []; var conceptLabels = [];
var conceptSources = []; var conceptSources = [];
var conceptSemanticTypes = [];
checkedElements.each(function() { checkedElements.each(function() {
checkedConceptElement = $(this); checkedConceptElement = $(this);
checkedConcept = checkedConceptElement.val(); checkedConcept = checkedConceptElement.val();
conceptLabel = checkedConceptElement.attr("label"); conceptLabel = checkedConceptElement.attr("label");
conceptSource = checkedConceptElement.attr("conceptDefinedBy"); conceptSource = checkedConceptElement.attr("conceptDefinedBy");
conceptSemanticType = checkedConceptElement.attr("conceptType");
conceptNodes.push(checkedConcept); conceptNodes.push(checkedConcept);
conceptLabels.push(conceptLabel); conceptLabels.push(conceptLabel);
conceptSources.push(conceptSource); conceptSources.push(conceptSource);
conceptSemanticTypes.push(conceptSemanticType);
}); });
this.externalConceptURI.val(conceptNodes); this.externalConceptURI.val(conceptNodes);
this.externalConceptLabel.val(conceptLabels); this.externalConceptLabel.val(conceptLabels);
this.externalConceptSource.val(conceptSources); this.externalConceptSource.val(conceptSources);
this.externalConceptSemanticTypeLabel.val(conceptSemanticTypes);
return true; return true;
}, },
generateIndividualConceptDisplay: function(cuiURI, label, definition, type, definedBy, isBestMatch) { generateIndividualConceptDisplay: function(cuiURI, label, definition, type, definedBy, isBestMatch) {

View file

@ -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);
}
}

View file

@ -1,7 +1,8 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.bo; package edu.cornell.mannlib.semservices.bo;
import java.util.ArrayList;
import java.util.List;
public class Concept { public class Concept {
private String definedBy; private String definedBy;
@ -11,13 +12,22 @@ public class Concept {
private String type; private String type;
private String definition; private String definition;
private String uri; private String uri;
private String schemeURI;
private List<String> broaderURIList;
private List<String> narrowerURIList;
private List<String> exactMatchURIList;
private List<String> closeMatchURIList;
/** /**
* default constructor * default constructor
*/ */
public Concept() { public Concept() {
this.broaderURIList = new ArrayList<String>();
this.narrowerURIList = new ArrayList<String>();
this.exactMatchURIList = new ArrayList<String>();
this.closeMatchURIList = new ArrayList<String>();
} }
/** /**
* @return the conceptId * @return the conceptId
*/ */
@ -90,6 +100,18 @@ public class Concept {
public void setDefinedBy(String definedBy) { public void setDefinedBy(String definedBy) {
this.definedBy = 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 * @return the bestMatch
*/ */
@ -102,5 +124,29 @@ public class Concept {
public void setBestMatch(String bestMatch) { public void setBestMatch(String bestMatch) {
this.bestMatch = bestMatch; this.bestMatch = bestMatch;
} }
public List<String> getBroaderURIList() {
return broaderURIList;
}
public void setBroaderURIList(List<String> broaderURIList) {
this.broaderURIList = broaderURIList;
}
public List<String> getNarrowerURIList() {
return narrowerURIList;
}
public void setNarrowerURIList(List<String> narrowerURIList) {
this.narrowerURIList = narrowerURIList;
}
public List<String> getExactMatchURIList() {
return exactMatchURIList;
}
public void setExactMatchURIList(List<String> exactMatchURIList) {
this.exactMatchURIList = exactMatchURIList;
}
public List<String> getCloseMatchURIList() {
return closeMatchURIList;
}
public void setCloseMatchURIList(List<String> closeMatchURIList) {
this.closeMatchURIList = closeMatchURIList;
}
} }

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.bo; package edu.cornell.mannlib.semservices.bo;
@ -8,8 +6,7 @@ import java.util.List;
public class ConceptInfo extends SemanticServicesInfoBase { public class ConceptInfo extends SemanticServicesInfoBase {
private List<Concept> conceptList; private List<?> conceptList;
/** /**
* *
*/ */
@ -18,17 +15,16 @@ public class ConceptInfo extends SemanticServicesInfoBase {
} }
/** /**
* @return the vivoDepartmentList * @return the conceptList
*/ */
public List<Concept> getConceptList() { public List<?> getConceptList() {
return conceptList; return conceptList;
} }
/** /**
* @param vivoDepartmentList the vivoDepartmentList to set * @param conceptList the conceptList to set
*/ */
public void setConceptList(List<Concept> inputConceptList) { public void setConceptList(List<?> conceptList) {
this.conceptList = inputConceptList; this.conceptList = conceptList;
} }
} }

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.bo; package edu.cornell.mannlib.semservices.bo;
import java.util.Calendar; import java.util.Calendar;

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.bo; package edu.cornell.mannlib.semservices.bo;
public class SemanticServicesError { public class SemanticServicesError {

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.bo; package edu.cornell.mannlib.semservices.bo;
public class SemanticServicesInfoBase { public class SemanticServicesInfoBase {

View file

@ -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<String, String> parameterMap;
/**
* Constructor
*/
public SparqlFeed() {
super();
parameterMap = new HashMap<String, String>();
}
/**
* @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<String, String> getParameterMap() {
return parameterMap;
}
/**
* @param parameterMap the parameterMap to set
*/
public void setParameterMap(Map<String, String> 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;
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.bo; package edu.cornell.mannlib.semservices.bo;
import java.util.Date; import java.util.Date;

View file

@ -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); }
}

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.service; package edu.cornell.mannlib.semservices.service;
import java.util.List; import java.util.List;
@ -7,7 +5,24 @@ import java.util.List;
import edu.cornell.mannlib.semservices.bo.Concept; import edu.cornell.mannlib.semservices.bo.Concept;
public interface ExternalConceptService { public interface ExternalConceptService {
// this is the only method that needs to be exposed
List<Concept> processResults(String term) throws Exception; /**
* @param term
* @return
*/
List<Concept> processResults(String term) throws Exception;
/**
* @param term
* @return
* @throws Exception
*/
List<Concept> getConcepts(String term) throws Exception;
/**
* @param uri
* @return
*/
List<Concept> getConceptsByURIWithSparql(String uri) throws Exception;
} }

View file

@ -8,18 +8,30 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.ParserConfigurationException;
import javax.xml.rpc.ServiceException; import javax.xml.rpc.ServiceException;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.fao.gilw.aims.webservices.AgrovocWS; import org.fao.www.webservices.AgrovocWS.ACSWWebService;
import org.fao.gilw.aims.webservices.AgrovocWSServiceLocator; 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.Attr;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap; import org.w3c.dom.NamedNodeMap;
@ -27,95 +39,190 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList; import org.w3c.dom.NodeList;
import org.xml.sax.SAXException; 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.bo.Concept;
import edu.cornell.mannlib.semservices.service.ExternalConceptService; import edu.cornell.mannlib.semservices.service.ExternalConceptService;
import edu.cornell.mannlib.semservices.util.XMLUtils; import edu.cornell.mannlib.semservices.util.XMLUtils;
public class AgrovocService implements ExternalConceptService { public class AgrovocService implements ExternalConceptService {
protected final Log logger = LogFactory.getLog(getClass()); 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<Concept> getConcepts(String term) throws Exception {
List<Concept> conceptList = new ArrayList<Concept>();
//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<String> broaderURIList = new ArrayList<String>();
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<String> narrowerURIList = new ArrayList<String>();
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<String> exactMatchURIList = new ArrayList<String>();
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<String> closeMatchURIList = new ArrayList<String>();
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<Concept> processResults(String term) throws Exception { public List<Concept> processResults(String term) throws Exception {
List<Concept> conceptList = new ArrayList<Concept>(); return getConcepts(term);
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;
} }
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 { protected String getTermcodeByTerm(String term) throws Exception {
String result = new String(); String result = new String();
AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); ACSWWebServiceServiceLocator locator = new ACSWWebServiceServiceLocator();
try { try {
URL url = new URL(AgrovocWS_address); URL url = new URL(AgrovocWS_address);
AgrovocWS agrovoc_service = locator.getAgrovocWS(url); ACSWWebService agrovoc_service = locator.getACSWWebService(url);
result = agrovoc_service.getTermcodeByTerm(term); result = agrovoc_service.getTermcodeByTerm(term);
} catch (ServiceException e) { } catch (ServiceException e) {
logger.error("service exception", e); logger.error("service exception", e);
@ -130,275 +237,58 @@ public class AgrovocService implements ExternalConceptService {
return result; 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 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) { protected String getTermCodeByTermAndLangXML(String ontologyName, String searchString, String lang, String codeName, String format) {
String result = new String(); String result = new String();
AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); ACSWWebServiceServiceLocator locator = new ACSWWebServiceServiceLocator();
try { try {
URL url = new URL(AgrovocWS_address); URL url = new URL(AgrovocWS_address);
AgrovocWS agrovoc_service = locator.getAgrovocWS(url); ACSWWebService agrovoc_service = locator.getACSWWebService(url);
result = agrovoc_service.getTermByLanguageXML(termcode, language, format); result = agrovoc_service.getTermCodeByTermAndLangXML(ontologyName, searchString, lang, codeName, format);
} catch (ServiceException e) { } catch (ServiceException e) {
logger.error("service exception", e); logger.error("service exception", e);
e.printStackTrace(); e.printStackTrace();
} catch (RemoteException e) { } catch (RemoteException e) {
e.printStackTrace(); e.printStackTrace();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); 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) { protected String getURIByTermAndLangXML(String ontologyName, String term,
String result = new String(); String searchMode, String format, String lang) {
AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); String result = new String();
try { ACSWWebServiceServiceLocator locator = new ACSWWebServiceServiceLocator();
URL url = new URL(AgrovocWS_address); try {
AgrovocWS agrovoc_service = locator.getAgrovocWS(url); URL url = new URL(AgrovocWS_address);
result = agrovoc_service.getTermsListByLanguageXML(termcodes, language, format); ACSWWebService agrovoc_service = locator.getACSWWebService(url);
} catch (ServiceException e) { result = agrovoc_service.getURIByTermAndLangXML(ontologyName, term,
logger.error("service exception", e); searchMode, format, lang);
e.printStackTrace(); } catch (ServiceException e) {
} catch (RemoteException e) { e.printStackTrace();
e.printStackTrace(); } catch (RemoteException e) {
} catch (MalformedURLException e) { e.printStackTrace();
e.printStackTrace(); } catch (MalformedURLException e) {
} e.printStackTrace();
}
return result; 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) { protected String getConceptInfoByTermcodeXML(String termcode, String format) {
String result = new String(); String result = new String();
AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); ACSWWebServiceServiceLocator locator = new ACSWWebServiceServiceLocator();
try { try {
URL url = new URL(AgrovocWS_address); URL url = new URL(AgrovocWS_address);
AgrovocWS agrovoc_service = locator.getAgrovocWS(url); ACSWWebService agrovoc_service = locator.getACSWWebService(url);
result = agrovoc_service.getConceptInfoByTermcodeXML(termcode, format); result = agrovoc_service.getConceptInfoByTermcodeXML(termcode, format);
} catch (ServiceException e) { } catch (ServiceException e) {
logger.error("service exception", e); logger.error("service exception", e);
@ -412,69 +302,33 @@ public class AgrovocService implements ExternalConceptService {
return result; return result;
} }
protected String[] getDefinitions(int termcode, String lang) { protected String getConceptByKeyword(String ontologyName, String searchString, String format, String searchMode, String lang) {
String[] result = null; String result = new String();
AgrovocWSServiceLocator locator = new AgrovocWSServiceLocator(); ACSWWebServiceServiceLocator locator = new ACSWWebServiceServiceLocator();
try { try {
URL url = new URL(AgrovocWS_address); URL url = new URL(AgrovocWS_address);
AgrovocWS agrovoc_service = locator.getAgrovocWS(url); ACSWWebService agrovoc_service = locator.getACSWWebService(url);
result = agrovoc_service.getDefinitions(termcode, lang); result = agrovoc_service.getConceptByKeyword(ontologyName, searchString, format, searchMode, lang);
} catch (ServiceException e) { } catch (ServiceException e) {
logger.error("service exception", e); logger.error("service exception", e);
e.printStackTrace(); e.printStackTrace();
} catch (RemoteException e) { } catch (RemoteException e) {
e.printStackTrace(); e.printStackTrace();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
e.printStackTrace(); e.printStackTrace();
} }
return result; 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;
}
protected String getWsdl() { protected String getWsdl() {
String result = new String(); String result = new String();
try { try {
StringWriter sw = new StringWriter(); 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())); BufferedReader in = new BufferedReader(new InputStreamReader(rss.openStream()));
String inputLine; String inputLine;
@ -490,4 +344,139 @@ public class AgrovocService implements ExternalConceptService {
} }
return result; return result;
} }
public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception {
//John Ferreira's original code has implementation
List<Concept> newConceptList = new ArrayList<Concept>();
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: <http://www.w3.org/2000/01/rdf-schema#> \n"
+ "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n"
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n"
+ "PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>\n"
+ "SELECT DISTINCT ?description WHERE { \n" + "<" + uri
+ "> rdfs:comment ?description . \n"
+ "FILTER (LANG(?description)='en' ) \n" + "}";
//System.out.println(qs);
List<HashMap> resultList = new ArrayList<HashMap>();
QueryExecution qexec = null;
try {
Query query = QueryFactory.create(qs);
qexec = QueryExecutionFactory.sparqlService(this.dbpedia_endpoint,
query);
resultList = new ArrayList<HashMap>();
ResultSet resultSet = qexec.execSelect();
int resultSetSize = 0;
while (resultSet.hasNext()) {
resultSetSize++;
QuerySolution solution = resultSet.nextSolution();
Iterator varnames = solution.varNames();
HashMap<String, String> hm = new HashMap<String, String>();
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 "";
}
}
} }

View file

@ -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; package edu.cornell.mannlib.semservices.service.impl;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.rmi.RemoteException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.rpc.ServiceException;
import net.sf.json.JSONArray; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer; import net.sf.json.JSONSerializer;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; 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.bo.Concept;
import edu.cornell.mannlib.semservices.exceptions.ConceptsNotFoundException;
import edu.cornell.mannlib.semservices.service.ExternalConceptService; 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 { public class GemetService implements ExternalConceptService {
protected final Log logger = LogFactory.getLog(getClass()); 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 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 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 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<Concept> getConcepts(String term) throws Exception {
List<Concept> conceptList = new ArrayList<Concept>();
try {
String results = getConceptsMatchingKeyword(term);
//System.out.println(results);
conceptList = processOutput(results);
} catch (Exception ex) {
return new ArrayList<Concept>();
//ex.printStackTrace();
//throw ex;
}
return conceptList;
}
public List<Concept> processResults(String term) throws Exception { public List<Concept> processResults(String term) throws Exception {
List<Concept> conceptList = processConceptsAndRelatedMatchingKeyword(term); List<Concept> conceptList = new ArrayList<Concept>();
try {
String results = getConceptsMatchingKeyword(term);
conceptList = processOutput(results);
} catch (Exception ex) {
//ex.printStackTrace();
throw ex;
}
return conceptList; return conceptList;
} }
public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception {
//John Ferreira's original code has implementation
List<Concept> newConceptList = new ArrayList<Concept>();
return newConceptList;
}
/** /**
* @param results * @param results
* @return * @return
* By default, concepts set with best match = true
*/ */
private List<Concept> processOutput(String results) { private List<Concept> processOutput(String results) throws Exception {
return processOutput(results, "true");
} List<Concept> conceptList = new ArrayList<Concept>();
private List<Concept> processOutput(String results, String bestMatch) {
List<Concept> conceptList = new ArrayList<Concept>();
try { try {
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON( results ); JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON( results );
if (jsonArray.size() == 0) {
throw new ConceptsNotFoundException();
}
for (int i = 0; i < jsonArray.size(); i++) { for (int i = 0; i < jsonArray.size(); i++) {
Concept concept = new Concept(); Concept concept = new Concept();
concept concept.setDefinedBy(this.schemeURI);
.setDefinedBy("http://www.eionet.europa.eu/gemet/gemetThesaurus"); concept.setBestMatch("true");
concept.setBestMatch(bestMatch); JSONObject json = jsonArray.getJSONObject(i);
JSONObject json = jsonArray.getJSONObject(i); String uri = getJsonValue(json, "uri");
String uri = getJsonValue(json, "uri");
concept.setUri(uri); concept.setUri(uri);
concept.setConceptId(uri); concept.setConceptId(stripConceptId(uri));
if (json.has("preferredLabel")) { concept.setSchemeURI(schemeURI);
JSONObject preferredLabelObj = json if (json.has("preferredLabel")) {
.getJSONObject("preferredLabel"); JSONObject preferredLabelObj = json
if (preferredLabelObj.has("string")) { .getJSONObject("preferredLabel");
concept.setLabel(getJsonValue(preferredLabelObj, if (preferredLabelObj.has("string")) {
"string")); concept.setLabel(getJsonValue(preferredLabelObj,
} "string"));
} }
if (json.has("definition")) { }
JSONObject definitionObj = json.getJSONObject("definition"); if (json.has("definition")) {
if (definitionObj.has("string")) { JSONObject definitionObj = json.getJSONObject("definition");
concept.setDefinition(getJsonValue(definitionObj, if (definitionObj.has("string")) {
"string")); concept.setDefinition(getJsonValue(definitionObj,
} "string"));
} }
conceptList.add(concept); }
} String narrower = getRelatedConcepts(uri, "narrower");
List<String> narrowerURIList = getRelatedUris(narrower);
concept.setNarrowerURIList(narrowerURIList);
String broader = getRelatedConcepts(uri, "broader");
List<String> broaderURIList = getRelatedUris(broader);
concept.setBroaderURIList(broaderURIList);
/*String related = getRelatedConcepts(uri, "related");
List<String> relatedURIList = getRelatedUris(related);
for (String s: relatedURIList) {
System.out.println("related uri: "+s);
}*/
conceptList.add(concept);
}
} catch (Exception ex ) { } catch (Exception ex ) {
ex.printStackTrace(); //ex.printStackTrace();
logger.error("Could not get concepts", ex); logger.error("Could not get concepts", ex);
throw ex;
} }
return conceptList; 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 { protected String getAvailableLangs(String concept_uri) throws Exception {
String result = new String(); String result = new String();
String serviceUrl = GemetWS_address + "getAvailableLanguages" + String serviceUrl = GemetWS_address + "getAvailableLanguages" +
"?concept_uri=" + concept_uri; "?concept_uri=" + concept_uri;
result = getGemetResults(serviceUrl); try {
result = getGemetResults(serviceUrl);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return result; return result;
} }
/**
* @param concept_uri
* @return
* @throws Exception
*/
protected String getConcept(String concept_uri) throws Exception { protected String getConcept(String concept_uri) throws Exception {
String result = new String(); String result = new String();
String serviceUrl = GemetWS_address + "getConcept" + String serviceUrl = GemetWS_address + "getConcept" +
"?concept_uri=" + concept_uri + "?concept_uri=" + concept_uri +
"&language=en"; "&language=en";
result = getGemetResults(serviceUrl); try {
result = getGemetResults(serviceUrl);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return result; 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 result = new String();
String property_uri = new String(); String property_uri = new String();
if (property.equals("definition")) { if (property.equals("definition")) {
@ -160,11 +218,23 @@ public class GemetService implements ExternalConceptService {
"?concept_uri=" + concept_uri + "?concept_uri=" + concept_uri +
"&property_uri=" + property_uri + "&property_uri=" + property_uri +
"&language=en"; "&language=en";
result = getGemetResults(serviceUrl);
try {
result = getGemetResults(serviceUrl);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return result; return result;
} }
/**
* @param concept_uri
* @param relation
* @return
* @throws Exception
*/
protected String getRelatedConcepts(String concept_uri, String relation) throws Exception { protected String getRelatedConcepts(String concept_uri, String relation) throws Exception {
String result = new String(); String result = new String();
String relation_uri = new String(); String relation_uri = new String();
@ -179,41 +249,43 @@ public class GemetService implements ExternalConceptService {
"?concept_uri=" + concept_uri + "?concept_uri=" + concept_uri +
"&relation_uri=" + relation_uri + "&relation_uri=" + relation_uri +
"&language=en"; "&language=en";
result = getGemetResults(serviceUrl); try {
result = getGemetResults(serviceUrl);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
return result; return result;
} }
/**
* @param keyword
* @return
* @throws Exception
*/
protected String getConceptsMatchingKeyword(String keyword) throws Exception { protected String getConceptsMatchingKeyword(String keyword) throws Exception {
String result = new String(); String result = new String();
String serviceUrl = GemetWS_address + "getConceptsMatchingKeyword" + String serviceUrl = GemetWS_address + "getConceptsMatchingKeyword" +
"?keyword=" + URLEncoder.encode(keyword) + "?keyword=" + keyword +
"&search_mode=0" + "&search_mode=0" +
"&thesaurus_uri=http://www.eionet.europa.eu/gemet/concept/" + "&thesaurus_uri=http://www.eionet.europa.eu/gemet/concept/" +
"&language=en"; "&language=en";
try {
result = getGemetResults(serviceUrl); result = getGemetResults(serviceUrl);
} catch (Exception ex) {
throw ex;
}
return result; return result;
} }
//Get concepts matching keyword plus any related concepts /**
protected List<Concept> processConceptsAndRelatedMatchingKeyword(String keyword) throws Exception { * @param url
String result = getConceptsMatchingKeyword(keyword); * @return
//iterate through each of the concepts and add related concepts a well */
List<Concept> bestMatchConceptList = processOutput(result); protected String getGemetResults(String url) throws Exception {
List<Concept> relatedConceptList = new ArrayList<Concept>();
for(Concept c: bestMatchConceptList) {
String conceptUri = c.getUri();
String resultsRelated = getRelatedConcepts(conceptUri, "related");
relatedConceptList.addAll(processOutput(resultsRelated, "false"));
}
bestMatchConceptList.addAll(relatedConceptList);
return bestMatchConceptList;
}
protected String getGemetResults(String url) throws Exception {
String results = new String(); String results = new String();
//System.out.println("url: "+url); //System.out.println("url: "+url);
try { try {
@ -232,9 +304,36 @@ public class GemetService implements ExternalConceptService {
} catch (Exception ex) { } catch (Exception ex) {
logger.error("error occurred in servlet", ex); logger.error("error occurred in servlet", ex);
ex.printStackTrace();
throw ex; throw ex;
} }
return results; return results;
} }
protected List<String> getRelatedUris(String json) {
List<String> uriList = new ArrayList<String>();
String uri = new String();
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON( json );
if (jsonArray.size() == 0) {
return new ArrayList<String>();
}
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObj = jsonArray.getJSONObject(i);
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;
}
} }

View file

@ -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; package edu.cornell.mannlib.semservices.service.impl;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -17,8 +16,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.semservices.bo.Concept; 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.service.ExternalConceptService;
import edu.cornell.mannlib.vitro.webapp.web.URLEncoder;
/** /**
* @author jaf30 * @author jaf30
@ -28,11 +27,48 @@ public class UMLSService implements ExternalConceptService {
protected final Log logger = LogFactory.getLog(getClass()); protected final Log logger = LogFactory.getLog(getClass());
private static final String submissionUrl = "http://link.informatics.stonybrook.edu/MeaningLookup/MlServiceServlet?"; 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 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<Concept> processResults(String term) throws Exception{
@Override
public List<Concept> getConcepts(String term) throws Exception {
List<Concept> conceptList = new ArrayList<Concept>();
String results = null;
//Format in rdf/xml is possible but would require separate processing method
String dataUrl = submissionUrl + "textToProcess="
+ URLEncoder.encode(term, "UTF-8")
+ "&format=json";
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<Concept> processResults(String term) throws Exception {
String results = null; String results = null;
String dataUrl = submissionUrl + "textToProcess=" String dataUrl = submissionUrl + "textToProcess="
+ URLEncoder.encode(term) + "&format=json"; + URLEncoder.encode(term, "UTF-8") + "&format=json";
try { try {
@ -47,41 +83,57 @@ public class UMLSService implements ExternalConceptService {
in.close(); in.close();
results = sw.toString(); results = sw.toString();
//System.out.println("results before processing: "+results);
List<Concept> conceptList = processOutput(results);
return conceptList;
} catch (Exception ex) { } catch (Exception ex) {
logger.error("error occurred in servlet", ex); logger.error("error occurred in servlet", ex);
throw ex; return null;
} }
List<Concept> conceptList = processOutput(results);
return conceptList; }
/**
* @param uri
* @return
*/
public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception {
//John Ferreira's original code has implementation
List<Concept> newConceptList = new ArrayList<Concept>();
return newConceptList;
} }
/** /**
* @param results * @param results
* @return * @return
*/ */
private List<Concept> processOutput(String results) { private List<Concept> processOutput(String results) throws Exception {
List<Concept> conceptList = new ArrayList<Concept>(); List<Concept> conceptList = new ArrayList<Concept>();
List<String> bestMatchIdList = new ArrayList<String>(); List<String> bestMatchIdList = new ArrayList<String>();
String bestMatchId = new String(); String bestMatchId = new String();
boolean bestMatchFound = false;
boolean allFound = false;
try { try {
JSONObject json = (JSONObject) JSONSerializer.toJSON( results ); JSONObject json = (JSONObject) JSONSerializer.toJSON( results );
//System.out.println(json.toString());
if (json.has("Best Match")) { if (json.has("Best Match")) {
bestMatchFound = true;
//System.out.println("Best Match"); //System.out.println("Best Match");
JSONArray bestMatchArray = json.getJSONArray("Best Match"); JSONArray bestMatchArray = json.getJSONArray("Best Match");
int len = bestMatchArray.size(); int len = bestMatchArray.size();
if (len > 1) { if (len > 1) {
System.out.println("Found this many best matches: "+ len); logger.debug("Found this many best matches: "+ len);
} }
int i; int i;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
JSONObject o = bestMatchArray.getJSONObject(i); JSONObject o = bestMatchArray.getJSONObject(i);
//System.out.println(o.toString()); //System.out.println(o.toString());
Concept concept = new Concept(); Concept concept = new Concept();
concept.setDefinedBy("http://link.informatics.stonybrook.edu/umls"); concept.setDefinedBy(schemeURI);
concept.setBestMatch("true"); concept.setBestMatch("true");
String cui = getJsonValue(o, "CUI"); String cui = getJsonValue(o, "CUI");
bestMatchIdList.add(cui); bestMatchIdList.add(cui);
@ -91,11 +143,12 @@ public class UMLSService implements ExternalConceptService {
concept.setType(getJsonValue(o, "type")); concept.setType(getJsonValue(o, "type"));
concept.setDefinition(getJsonValue(o, "definition")); concept.setDefinition(getJsonValue(o, "definition"));
concept.setUri(baseUri + cui); concept.setUri(baseUri + cui);
concept.setSchemeURI(schemeURI);
conceptList.add(concept); conceptList.add(concept);
} }
} }
if (json.has("All")) { if (json.has("All")) {
allFound = true;
JSONArray allArray = json.getJSONArray("All"); JSONArray allArray = json.getJSONArray("All");
int len = allArray.size(); int len = allArray.size();
//System.out.println("size of best match array: "+ len); //System.out.println("size of best match array: "+ len);
@ -104,7 +157,7 @@ public class UMLSService implements ExternalConceptService {
JSONObject o = allArray.getJSONObject(i); JSONObject o = allArray.getJSONObject(i);
//System.out.println(o.toString()); //System.out.println(o.toString());
Concept concept = new Concept(); Concept concept = new Concept();
concept.setDefinedBy("http://link.informatics.stonybrook.edu/umls"); concept.setDefinedBy(schemeURI);
String cui = getJsonValue(o, "CUI"); String cui = getJsonValue(o, "CUI");
concept.setConceptId(cui); concept.setConceptId(cui);
@ -112,6 +165,7 @@ public class UMLSService implements ExternalConceptService {
concept.setType(getJsonValue(o, "type")); concept.setType(getJsonValue(o, "type"));
concept.setDefinition(getJsonValue(o, "definition")); concept.setDefinition(getJsonValue(o, "definition"));
concept.setUri(baseUri + cui); concept.setUri(baseUri + cui);
concept.setSchemeURI(schemeURI);
// prevent duplicate concepts in list // prevent duplicate concepts in list
if (! bestMatchIdList.contains(cui)) { if (! bestMatchIdList.contains(cui)) {
concept.setBestMatch("false"); concept.setBestMatch("false");
@ -122,20 +176,18 @@ public class UMLSService implements ExternalConceptService {
} catch (Exception ex ) { } catch (Exception ex ) {
ex.printStackTrace(); ex.printStackTrace();
logger.error("Could not get concepts", ex); 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; 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 * Get a string from a json object or an empty string if there is no value for the given key
* @param obj * @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;
}
} }

View file

@ -1,7 +1,4 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
/* /*
* $Id$ * $Id$
* CONFIDENTIAL AND PROPRIETARY. ? 2007 Revolution Health Group LLC. All rights reserved. * 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. * This source code may not be disclosed to others, used or reproduced without the written permission of Revolution Health Group.

View file

@ -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 $ * $Id: DateConverter.java 50408 2007-03-28 19:14:46Z jdamick $
* *
* Copyright 2006- Revolution Health Group. All rights reserved. * Copyright 2006- Revolution Health Group. All rights reserved.

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.util; package edu.cornell.mannlib.semservices.util;
import java.text.ParsePosition; import java.text.ParsePosition;

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.util; package edu.cornell.mannlib.semservices.util;

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.util; package edu.cornell.mannlib.semservices.util;
import java.util.Iterator; import java.util.Iterator;
import javax.xml.XMLConstants; import javax.xml.XMLConstants;

View file

@ -264,5 +264,10 @@ public class ObjectUtils {
} }
} }
public static String nl2br(String text) {
return text.replaceAll("\n\n", "<p>").replaceAll("\n", "<br>");
}
} }

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.util; package edu.cornell.mannlib.semservices.util;
import edu.cornell.mannlib.semservices.bo.Time; import edu.cornell.mannlib.semservices.bo.Time;
import java.util.Date; import java.util.Date;

View file

@ -1,5 +1,3 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.util; package edu.cornell.mannlib.semservices.util;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;

View file

@ -1,5 +1,4 @@
/* /*
* $Id: XMLGregorianCalendarConverter.java 28642 2006-10-25 13:41:54Z jdamick $ * $Id: XMLGregorianCalendarConverter.java 28642 2006-10-25 13:41:54Z jdamick $
* *
* Copyright 2006- Revolution Health Group. All rights reserved. * Copyright 2006- Revolution Health Group. All rights reserved.

View file

@ -1,8 +1,7 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.semservices.util; package edu.cornell.mannlib.semservices.util;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
@ -122,6 +121,15 @@ public class XMLUtils {
serializer.serialize(doc); 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 * @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 * @param node
*/ */

View file

@ -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.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;

View file

@ -46,7 +46,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
private Log log = LogFactory.getLog(AddAssociatedConceptGenerator.class); private Log log = LogFactory.getLog(AddAssociatedConceptGenerator.class);
private String template = "addAssociatedConcept.ftl"; private String template = "addAssociatedConcept.ftl";
private static String SKOSConceptType = "http://www.w3.org/2004/02/skos/core#Concept"; 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 @Override
public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) { public EditConfigurationVTwo getEditConfiguration(VitroRequest vreq, HttpSession session) {
@ -168,10 +169,13 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
return n3Required; 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<String> generateN3Optional() { private List<String> generateN3Optional() {
return list("?conceptNode <" + RDFS.label.getURI() + "> ?conceptLabel .\n" + 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<String, String> newResources = new HashMap<String, String>(); HashMap<String, String> newResources = new HashMap<String, String>();
//There are no new resources here, the concept node uri doesn't //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 //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; return newResources;
} }
@ -233,9 +239,12 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
//The URI of the node that defines the concept //The URI of the node that defines the concept
urisOnForm.add("conceptNode"); urisOnForm.add("conceptNode");
urisOnForm.add("conceptSource"); urisOnForm.add("conceptSource");
urisOnForm.add("conceptSemanticTypeURI");
editConfiguration.setUrisOnform(urisOnForm); editConfiguration.setUrisOnform(urisOnForm);
//Also need to add the label of the concept //Also need to add the label of the concept
literalsOnForm.add("conceptLabel"); literalsOnForm.add("conceptLabel");
literalsOnForm.add("conceptSemanticTypeLabel");
editConfiguration.setLiteralsOnForm(literalsOnForm); editConfiguration.setLiteralsOnForm(literalsOnForm);
} }
@ -263,6 +272,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
setConceptNodeField(editConfiguration, vreq); setConceptNodeField(editConfiguration, vreq);
setConceptLabelField(editConfiguration, vreq); setConceptLabelField(editConfiguration, vreq);
setVocabURIField(editConfiguration, vreq); setVocabURIField(editConfiguration, vreq);
setConceptSemanticTypeURIField(editConfiguration,vreq);
setConceptSemanticTypeLabelField(editConfiguration,vreq);
} }
//this field will be hidden and include the concept node URI //this field will be hidden and include the concept node URI
@ -291,6 +302,22 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
); );
} }
//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 //Add preprocessor
@ -357,6 +384,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
boolean isSKOSConcept = false; boolean isSKOSConcept = false;
String conceptUri = conceptIndividual.getURI(); String conceptUri = conceptIndividual.getURI();
String conceptLabel = conceptIndividual.getName(); String conceptLabel = conceptIndividual.getName();
//Check if SKOS Concept type //Check if SKOS Concept type
List<ObjectPropertyStatement> osl = conceptIndividual.getObjectPropertyStatements(RDF.type.getURI()); List<ObjectPropertyStatement> osl = conceptIndividual.getObjectPropertyStatements(RDF.type.getURI());
for(ObjectPropertyStatement os: osl) { for(ObjectPropertyStatement os: osl) {
@ -367,7 +395,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
} }
if(isSKOSConcept) { 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 { } else {
//Get the vocab source and vocab label //Get the vocab source and vocab label
List<ObjectPropertyStatement> vocabList = conceptIndividual.getObjectPropertyStatements(RDFS.isDefinedBy.getURI()); List<ObjectPropertyStatement> vocabList = conceptIndividual.getObjectPropertyStatements(RDFS.isDefinedBy.getURI());
@ -379,7 +408,19 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
//Assuming name will get label //Assuming name will get label
vocabLabel = sourceIndividual.getName(); 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<ObjectPropertyStatement> 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 vocabURI;
private String vocabLabel; private String vocabLabel;
private String type; //In case of SKOS concept, will have skos concept type 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.conceptLabel = inputLabel;
this.conceptURI = inputURI; this.conceptURI = inputURI;
this.vocabURI = inputVocabURI; this.vocabURI = inputVocabURI;
this.vocabLabel = inputVocabLabel; this.vocabLabel = inputVocabLabel;
this.type = inputType; this.type = inputType;
this.conceptSemanticTypeURI = inputConceptSemanticTypeURI;
this.conceptSemanticTypeLabel = inputConceptSemanticTypeLabel;
} }
//Getters //Getters
@ -421,6 +466,14 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
return type; return type;
} }
public String getConceptSemanticTypeURI(){
return conceptSemanticTypeURI;
}
public String getConceptSemanticTypeLabel(){
return conceptSemanticTypeLabel;
}
} }
public class AssociatedConceptInfoComparator implements Comparator<AssociatedConceptInfo>{ public class AssociatedConceptInfoComparator implements Comparator<AssociatedConceptInfo>{

View file

@ -20,9 +20,9 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.semservices.bo.Concept; import edu.cornell.mannlib.semservices.bo.Concept;
import edu.cornell.mannlib.semservices.bo.ConceptInfo; import edu.cornell.mannlib.semservices.bo.ConceptInfo;
import edu.cornell.mannlib.semservices.bo.SemanticServicesError; 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.VitroHttpServlet;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; 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; import edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService.ConceptSearchServiceUtils;
public class ConceptSearchServlet extends VitroHttpServlet { public class ConceptSearchServlet extends VitroHttpServlet {

View file

@ -39,7 +39,7 @@ public class ConceptSearchServiceUtils {
HashMap<String, VocabSourceDescription> map = new HashMap<String, VocabSourceDescription>(); HashMap<String, VocabSourceDescription> map = new HashMap<String, VocabSourceDescription>();
map.put(UMLSVocabSource, new VocabSourceDescription("UMLS", UMLSVocabSource, "http://www.nlm.nih.gov/research/umls/", "Unified Medical Language System")); 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 //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")); map.put(GemetVocabSource, new VocabSourceDescription("GEMET", GemetVocabSource, "http://www.eionet.europa.eu/gemet", "GEneral Multilingual Environmental Thesaurus"));
return map; return map;
} }
@ -82,7 +82,7 @@ public class ConceptSearchServiceUtils {
//Get search //Get search
String searchTerm = getSearchTerm(vreq); String searchTerm = getSearchTerm(vreq);
List<Concept> conceptResults = conceptServiceClass.processResults(searchTerm); List<Concept> conceptResults = conceptServiceClass.getConcepts(searchTerm);
return conceptResults; return conceptResults;
} }