updates for semantic services, temporarily commenting out concept semantic type which is still in progress
This commit is contained in:
parent
a728d53c22
commit
ad0ae3c09a
7 changed files with 165 additions and 40 deletions
|
@ -17,7 +17,8 @@ public class Concept {
|
|||
private List<String> narrowerURIList;
|
||||
private List<String> exactMatchURIList;
|
||||
private List<String> closeMatchURIList;
|
||||
|
||||
private List<String> altLabelList;
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
*/
|
||||
|
@ -149,4 +150,12 @@ public void setCloseMatchURIList(List<String> closeMatchURIList) {
|
|||
this.closeMatchURIList = closeMatchURIList;
|
||||
}
|
||||
|
||||
public List<String> getAltLabelList() {
|
||||
return altLabelList;
|
||||
}
|
||||
|
||||
public void setAltLabelList(List<String> altLabelList) {
|
||||
this.altLabelList = altLabelList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ public class AgrovocService implements ExternalConceptService {
|
|||
private final String codeName = "hasCodeAgrovoc";
|
||||
private final String searchMode = "Exact Match";
|
||||
protected final String dbpedia_endpoint = " http://dbpedia.org/sparql";
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -94,16 +93,16 @@ public class AgrovocService implements ExternalConceptService {
|
|||
return conceptList;
|
||||
}
|
||||
|
||||
System.out.println("uri: "+uri);
|
||||
//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());
|
||||
//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.setDefinedBy(schemeUri);
|
||||
concept.setSchemeURI(this.schemeUri);
|
||||
concept.setType("");
|
||||
String lang = "";
|
||||
|
@ -126,6 +125,32 @@ public class AgrovocService implements ExternalConceptService {
|
|||
}
|
||||
}
|
||||
|
||||
// get altLabels
|
||||
List<String> altLabelList = new ArrayList<String>();
|
||||
for (SKOSLiteral literal : skosConcept
|
||||
.getSKOSRelatedConstantByProperty(dataset, manager
|
||||
.getSKOSDataFactory().getSKOSAltLabelProperty())) {
|
||||
|
||||
if (!literal.isTyped()) {
|
||||
// if it has language
|
||||
SKOSUntypedLiteral untypedLiteral = literal
|
||||
.getAsSKOSUntypedLiteral();
|
||||
if (untypedLiteral.hasLang()) {
|
||||
lang = untypedLiteral.getLang();
|
||||
} else {
|
||||
lang = "";
|
||||
}
|
||||
}
|
||||
//System.out.println("literal: "+ literal.getLiteral());
|
||||
if (lang.equals("en")) {
|
||||
//System.out.println("altLabel: " + literal.getLiteral());
|
||||
altLabelList.add(literal.getLiteral());
|
||||
}
|
||||
}
|
||||
concept.setAltLabelList(altLabelList);
|
||||
|
||||
|
||||
|
||||
// get the broader property URI
|
||||
List<String> broaderURIList = new ArrayList<String>();
|
||||
for (SKOSAnnotation annotation: skosConcept.getSKOSAnnotationsByURI(dataset, manager.getSKOSDataFactory().getSKOSBroaderProperty().getURI())) {
|
||||
|
@ -347,9 +372,9 @@ public class AgrovocService implements ExternalConceptService {
|
|||
|
||||
|
||||
public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception {
|
||||
//John Ferreira's original code has implementation
|
||||
List<Concept> newConceptList = new ArrayList<Concept>();
|
||||
return newConceptList;
|
||||
// deprecating this method...just return an empty list
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
return conceptList;
|
||||
}
|
||||
|
||||
protected String getAgrovocTermCode(String rdf) throws Exception {
|
||||
|
|
|
@ -34,8 +34,7 @@ public class GemetService implements ExternalConceptService {
|
|||
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>();
|
||||
|
@ -65,11 +64,12 @@ public class GemetService implements ExternalConceptService {
|
|||
|
||||
}
|
||||
|
||||
public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception {
|
||||
//John Ferreira's original code has implementation
|
||||
List<Concept> newConceptList = new ArrayList<Concept>();
|
||||
return newConceptList;
|
||||
}
|
||||
public List<Concept> getConceptsByURIWithSparql(String uri)
|
||||
throws Exception {
|
||||
// deprecating this method...just return an empty list
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
return conceptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param results
|
||||
|
@ -87,7 +87,7 @@ public class GemetService implements ExternalConceptService {
|
|||
|
||||
for (int i = 0; i < jsonArray.size(); i++) {
|
||||
Concept concept = new Concept();
|
||||
concept.setDefinedBy(this.schemeURI);
|
||||
concept.setDefinedBy(schemeURI);
|
||||
concept.setBestMatch("true");
|
||||
JSONObject json = jsonArray.getJSONObject(i);
|
||||
String uri = getJsonValue(json, "uri");
|
||||
|
@ -124,7 +124,7 @@ public class GemetService implements ExternalConceptService {
|
|||
for (String s: relatedURIList) {
|
||||
System.out.println("related uri: "+s);
|
||||
}*/
|
||||
|
||||
//String altLabels = getAllTranslationsForConcept(uri, "nonPreferredLabels");
|
||||
|
||||
conceptList.add(concept);
|
||||
|
||||
|
@ -218,9 +218,10 @@ public class GemetService implements ExternalConceptService {
|
|||
"?concept_uri=" + concept_uri +
|
||||
"&property_uri=" + property_uri +
|
||||
"&language=en";
|
||||
|
||||
try {
|
||||
result = getGemetResults(serviceUrl);
|
||||
List<String> props = getPropertyFromJson(result);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
|
@ -310,6 +311,7 @@ public class GemetService implements ExternalConceptService {
|
|||
return results;
|
||||
}
|
||||
|
||||
|
||||
protected List<String> getRelatedUris(String json) {
|
||||
List<String> uriList = new ArrayList<String>();
|
||||
String uri = new String();
|
||||
|
@ -327,6 +329,19 @@ public class GemetService implements ExternalConceptService {
|
|||
|
||||
}
|
||||
|
||||
protected List<String> getPropertyFromJson(String json) {
|
||||
List<String> props = new ArrayList<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);
|
||||
System.out.println(jsonObj.toString());
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
protected String stripConceptId(String uri) {
|
||||
String conceptId = new String();
|
||||
int lastslash = uri.lastIndexOf('/');
|
||||
|
|
|
@ -29,14 +29,14 @@ public class UMLSService implements ExternalConceptService {
|
|||
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";
|
||||
|
||||
|
||||
|
||||
|
||||
@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";
|
||||
|
@ -98,11 +98,12 @@ public class UMLSService implements ExternalConceptService {
|
|||
* @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;
|
||||
}
|
||||
public List<Concept> getConceptsByURIWithSparql(String uri)
|
||||
throws Exception {
|
||||
// deprecating this method...just return an empty list
|
||||
List<Concept> conceptList = new ArrayList<Concept>();
|
||||
return conceptList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param results
|
||||
|
|
|
@ -190,7 +190,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
//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);
|
||||
//newResources.put("conceptSemanticTypeURI", null);
|
||||
return newResources;
|
||||
}
|
||||
|
||||
|
@ -239,11 +239,11 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
//The URI of the node that defines the concept
|
||||
urisOnForm.add("conceptNode");
|
||||
urisOnForm.add("conceptSource");
|
||||
urisOnForm.add("conceptSemanticTypeURI");
|
||||
// urisOnForm.add("conceptSemanticTypeURI");
|
||||
editConfiguration.setUrisOnform(urisOnForm);
|
||||
//Also need to add the label of the concept
|
||||
literalsOnForm.add("conceptLabel");
|
||||
literalsOnForm.add("conceptSemanticTypeLabel");
|
||||
// literalsOnForm.add("conceptSemanticTypeLabel");
|
||||
|
||||
editConfiguration.setLiteralsOnForm(literalsOnForm);
|
||||
}
|
||||
|
@ -272,8 +272,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
setConceptNodeField(editConfiguration, vreq);
|
||||
setConceptLabelField(editConfiguration, vreq);
|
||||
setVocabURIField(editConfiguration, vreq);
|
||||
setConceptSemanticTypeURIField(editConfiguration,vreq);
|
||||
setConceptSemanticTypeLabelField(editConfiguration,vreq);
|
||||
//setConceptSemanticTypeURIField(editConfiguration,vreq);
|
||||
//setConceptSemanticTypeLabelField(editConfiguration,vreq);
|
||||
}
|
||||
|
||||
//this field will be hidden and include the concept node URI
|
||||
|
@ -325,7 +325,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
//An Edit submission preprocessor for enabling addition of multiple terms for a single search
|
||||
|
||||
editConfiguration.addEditSubmissionPreprocessor(
|
||||
new AddAssociatedConceptsPreprocessor(editConfiguration));
|
||||
new AddAssociatedConceptsPreprocessor(editConfiguration, wadf));
|
||||
|
||||
}
|
||||
|
||||
|
@ -411,12 +411,13 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
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
|
||||
|
@ -441,8 +442,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
|||
this.vocabURI = inputVocabURI;
|
||||
this.vocabLabel = inputVocabLabel;
|
||||
this.type = inputType;
|
||||
this.conceptSemanticTypeURI = inputConceptSemanticTypeURI;
|
||||
this.conceptSemanticTypeLabel = inputConceptSemanticTypeLabel;
|
||||
//this.conceptSemanticTypeURI = inputConceptSemanticTypeURI;
|
||||
//this.conceptSemanticTypeLabel = inputConceptSemanticTypeLabel;
|
||||
}
|
||||
|
||||
//Getters
|
||||
|
|
|
@ -13,6 +13,9 @@ import org.apache.commons.logging.LogFactory;
|
|||
import com.hp.hpl.jena.rdf.model.Literal;
|
||||
import com.hp.hpl.jena.vocabulary.RDFS;
|
||||
import com.hp.hpl.jena.vocabulary.XSD;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.BaseEditSubmissionPreprocessorVTwo;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||
|
@ -24,6 +27,7 @@ public class AddAssociatedConceptsPreprocessor extends
|
|||
|
||||
protected static final Log log = LogFactory
|
||||
.getLog(AddAssociatedConceptsPreprocessor.class.getName());
|
||||
protected WebappDaoFactory wadf = null;
|
||||
|
||||
// Field names/variables names for n3 - these will have numbers added as
|
||||
// suffix if more than one term
|
||||
|
@ -34,14 +38,17 @@ public class AddAssociatedConceptsPreprocessor extends
|
|||
private static String conceptNodeValues = null;
|
||||
private static String conceptLabelValues = null;
|
||||
private static String conceptSourceValues = null;
|
||||
private static String conceptSemanticTypeLabelValues = null;
|
||||
private static String conceptSemanticTypeURIValues = null;
|
||||
private static MultiValueEditSubmission submission = null;
|
||||
|
||||
// String datatype
|
||||
|
||||
// Will be editing the edit configuration as well as edit submission here
|
||||
|
||||
public AddAssociatedConceptsPreprocessor(EditConfigurationVTwo editConfig) {
|
||||
public AddAssociatedConceptsPreprocessor(EditConfigurationVTwo editConfig, WebappDaoFactory wadf) {
|
||||
super(editConfig);
|
||||
this.wadf = wadf;
|
||||
}
|
||||
|
||||
public void preprocess(MultiValueEditSubmission inputSubmission) {
|
||||
|
@ -50,7 +57,9 @@ public class AddAssociatedConceptsPreprocessor extends
|
|||
// as vocab uri (which is based on thge
|
||||
// For query parameters, check whether CUI
|
||||
copySubmissionValues();
|
||||
|
||||
//This will put the URI value in scope for the first semantic type label
|
||||
//and generate the rest if need be
|
||||
//processConceptSemanticValues();
|
||||
if (conceptNodeValues != null) {
|
||||
String[] conceptNodes = convertDelimitedStringToArray(conceptNodeValues);
|
||||
int numberConcepts = conceptNodes.length;
|
||||
|
@ -71,8 +80,26 @@ public class AddAssociatedConceptsPreprocessor extends
|
|||
conceptLabelValues = getConceptLabelValues();
|
||||
conceptNodeValues = getConceptNodeValues();
|
||||
conceptSourceValues = getConceptSourceValues();
|
||||
|
||||
}
|
||||
|
||||
//
|
||||
private void processConceptSemanticValues() {
|
||||
conceptSemanticTypeLabelValues = getConceptSemanticTypeLabelValues();
|
||||
conceptSemanticTypeURIValues = getConceptSemanticTypeURIValues();
|
||||
|
||||
//We are first going to handle the single value case and then handle additional values
|
||||
//where the rest of the additional values are handled
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//This is for additional concept nodes (i.e. if user selects more than one concept)
|
||||
private void processConceptNodes(int numberConcepts) {
|
||||
//There are no "new" resources b/c the concept nodes are URIs from external vocabularies
|
||||
// Add N3Required
|
||||
|
@ -98,6 +125,9 @@ public class AddAssociatedConceptsPreprocessor extends
|
|||
addConceptNodeInputs(numberConcepts);
|
||||
addConceptSourceInputs(numberConcepts);
|
||||
addConceptLabelInputs(numberConcepts);
|
||||
//for concept semantic type labels and uris where they exist
|
||||
//addConceptSemanticTypeLabelInputs(numberConcepts);
|
||||
//addConceptSemanticTypeURIInputs(numberConcepts);
|
||||
|
||||
}
|
||||
|
||||
|
@ -167,8 +197,17 @@ public class AddAssociatedConceptsPreprocessor extends
|
|||
log.error("Concept labels returned were null");
|
||||
}
|
||||
}
|
||||
|
||||
private void addConceptSemanticTypeLabelInputs(int numberConcepts) {
|
||||
|
||||
}
|
||||
|
||||
private void addConceptSemanticTypeURIInputs(int numberConcepts) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Fields
|
||||
|
||||
private void addFields(int numberConcepts) {
|
||||
//Clear out all fields in edit configuration first
|
||||
editConfiguration.setFields(new HashMap<String, FieldVTwo>());
|
||||
|
@ -290,6 +329,7 @@ public class AddAssociatedConceptsPreprocessor extends
|
|||
}
|
||||
|
||||
|
||||
//Get values from submission
|
||||
private String getConceptNodeValues() {
|
||||
Map<String, List<String>> urisFromForm = submission.getUrisFromForm();
|
||||
List<String> conceptNodes = urisFromForm.get("conceptNode");
|
||||
|
@ -308,6 +348,40 @@ public class AddAssociatedConceptsPreprocessor extends
|
|||
|
||||
}
|
||||
|
||||
private String getConceptSemanticTypeLabelValues() {
|
||||
Map<String, List<Literal>> literalsFromForm = submission.getLiteralsFromForm();
|
||||
Map<String, List<String>> transformed = EditConfigurationUtils.transformLiteralMap(literalsFromForm);
|
||||
return (String) getFirstElement(transformed.get("conceptSemanticTypeLabel"));
|
||||
}
|
||||
|
||||
//This will either generate or retrieve URIs for the concept semantic type labels if they exist
|
||||
//We will then update the submission to include this
|
||||
private String getConceptSemanticTypeURIValues() {
|
||||
List<String> conceptSemanticTypeURIs = new ArrayList<String>();
|
||||
String[] conceptSemanticTypeLabels = convertDelimitedStringToArray(conceptSemanticTypeLabelValues);
|
||||
int numberLabels = conceptSemanticTypeLabels.length;
|
||||
|
||||
for(int i = 0; i < numberLabels; i++) {
|
||||
String label = conceptSemanticTypeLabels[i];
|
||||
//Make or retrieve URI for this label
|
||||
String uri = getURIForSemanticTypeLabel(label);
|
||||
conceptSemanticTypeURIs.add(uri);
|
||||
}
|
||||
|
||||
//Set uris as string
|
||||
//Essentially this will allow the URI to be put in scope
|
||||
return conceptSemanticTypeURIs.toString();
|
||||
}
|
||||
|
||||
private String getURIForSemanticTypeLabel(String label) {
|
||||
//Check if system has an individual with this URI
|
||||
//
|
||||
List<Individual> individualsWithLabel = this.wadf.getIndividualDao().getIndividualsByDataProperty(RDFS.label.getURI(), label);
|
||||
//We are only interested in concepts
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
private Object getFirstElement(List inputList) {
|
||||
if(inputList == null || inputList.size() == 0)
|
||||
return null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue