updates for semantic services, temporarily commenting out concept semantic type which is still in progress

This commit is contained in:
hudajkhan 2013-08-12 13:09:04 -04:00
parent a728d53c22
commit ad0ae3c09a
7 changed files with 165 additions and 40 deletions

View file

@ -95,9 +95,9 @@
</p><span id="createOwnOne"> ${i18n().or} &nbsp;<a href="${userDefinedConceptUrl}" title="${i18n().create_own_concept}">${i18n().create_own_concept}&nbsp;</a></span> </p><span id="createOwnOne"> ${i18n().or} &nbsp;<a href="${userDefinedConceptUrl}" title="${i18n().create_own_concept}">${i18n().create_own_concept}&nbsp;</a></span>
<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="conceptSemanticTypeURI" name="conceptSemanticTypeURI" value="" /> <!-- Field value populated by JavaScript -->
<input type="hidden" id="conceptSemanticTypeLabel" name="conceptSemanticTypeLabel" 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">

View file

@ -17,6 +17,7 @@ public class Concept {
private List<String> narrowerURIList; private List<String> narrowerURIList;
private List<String> exactMatchURIList; private List<String> exactMatchURIList;
private List<String> closeMatchURIList; private List<String> closeMatchURIList;
private List<String> altLabelList;
/** /**
* default constructor * default constructor
@ -149,4 +150,12 @@ public void setCloseMatchURIList(List<String> closeMatchURIList) {
this.closeMatchURIList = closeMatchURIList; this.closeMatchURIList = closeMatchURIList;
} }
public List<String> getAltLabelList() {
return altLabelList;
}
public void setAltLabelList(List<String> altLabelList) {
this.altLabelList = altLabelList;
}
} }

View file

@ -67,7 +67,6 @@ public class AgrovocService implements ExternalConceptService {
protected final String dbpedia_endpoint = " http://dbpedia.org/sparql"; protected final String dbpedia_endpoint = " http://dbpedia.org/sparql";
@Override @Override
public List<Concept> getConcepts(String term) throws Exception { public List<Concept> getConcepts(String term) throws Exception {
List<Concept> conceptList = new ArrayList<Concept>(); List<Concept> conceptList = new ArrayList<Concept>();
@ -94,16 +93,16 @@ public class AgrovocService implements ExternalConceptService {
return conceptList; return conceptList;
} }
System.out.println("uri: "+uri); //System.out.println("uri: "+uri);
SKOSDataset dataset = manager.loadDataset(uri); SKOSDataset dataset = manager.loadDataset(uri);
for (SKOSConcept skosConcept : dataset.getSKOSConcepts()) { for (SKOSConcept skosConcept : dataset.getSKOSConcepts()) {
Concept concept = new Concept(); Concept concept = new Concept();
System.out.println("Concept: " + skosConcept.getURI()); //System.out.println("Concept: " + skosConcept.getURI());
concept.setUri(skosConcept.getURI().toString()); concept.setUri(skosConcept.getURI().toString());
concept.setConceptId(stripConceptId(skosConcept.getURI().toString())); concept.setConceptId(stripConceptId(skosConcept.getURI().toString()));
concept.setBestMatch("true"); concept.setBestMatch("true");
concept.setDefinedBy(this.schemeUri); concept.setDefinedBy(schemeUri);
concept.setSchemeURI(this.schemeUri); concept.setSchemeURI(this.schemeUri);
concept.setType(""); concept.setType("");
String lang = ""; 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 // get the broader property URI
List<String> broaderURIList = new ArrayList<String>(); List<String> broaderURIList = new ArrayList<String>();
for (SKOSAnnotation annotation: skosConcept.getSKOSAnnotationsByURI(dataset, manager.getSKOSDataFactory().getSKOSBroaderProperty().getURI())) { 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 { public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception {
//John Ferreira's original code has implementation // deprecating this method...just return an empty list
List<Concept> newConceptList = new ArrayList<Concept>(); List<Concept> conceptList = new ArrayList<Concept>();
return newConceptList; return conceptList;
} }
protected String getAgrovocTermCode(String rdf) throws Exception { protected String getAgrovocTermCode(String rdf) throws Exception {

View file

@ -35,7 +35,6 @@ public class GemetService implements ExternalConceptService {
private final String schemeURI = "http://www.eionet.europa.eu/gemet/gemetThesaurus"; private final String schemeURI = "http://www.eionet.europa.eu/gemet/gemetThesaurus";
@Override @Override
public List<Concept> getConcepts(String term) throws Exception { public List<Concept> getConcepts(String term) throws Exception {
List<Concept> conceptList = new ArrayList<Concept>(); List<Concept> conceptList = new ArrayList<Concept>();
@ -65,11 +64,12 @@ public class GemetService implements ExternalConceptService {
} }
public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception { public List<Concept> getConceptsByURIWithSparql(String uri)
//John Ferreira's original code has implementation throws Exception {
List<Concept> newConceptList = new ArrayList<Concept>(); // deprecating this method...just return an empty list
return newConceptList; List<Concept> conceptList = new ArrayList<Concept>();
} return conceptList;
}
/** /**
* @param results * @param results
@ -87,7 +87,7 @@ public class GemetService implements ExternalConceptService {
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.setDefinedBy(this.schemeURI); concept.setDefinedBy(schemeURI);
concept.setBestMatch("true"); concept.setBestMatch("true");
JSONObject json = jsonArray.getJSONObject(i); JSONObject json = jsonArray.getJSONObject(i);
String uri = getJsonValue(json, "uri"); String uri = getJsonValue(json, "uri");
@ -124,7 +124,7 @@ public class GemetService implements ExternalConceptService {
for (String s: relatedURIList) { for (String s: relatedURIList) {
System.out.println("related uri: "+s); System.out.println("related uri: "+s);
}*/ }*/
//String altLabels = getAllTranslationsForConcept(uri, "nonPreferredLabels");
conceptList.add(concept); conceptList.add(concept);
@ -218,9 +218,10 @@ 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";
try { try {
result = getGemetResults(serviceUrl); result = getGemetResults(serviceUrl);
List<String> props = getPropertyFromJson(result);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
throw e; throw e;
@ -310,6 +311,7 @@ public class GemetService implements ExternalConceptService {
return results; return results;
} }
protected List<String> getRelatedUris(String json) { protected List<String> getRelatedUris(String json) {
List<String> uriList = new ArrayList<String>(); List<String> uriList = new ArrayList<String>();
String uri = new 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) { protected String stripConceptId(String uri) {
String conceptId = new String(); String conceptId = new String();
int lastslash = uri.lastIndexOf('/'); int lastslash = uri.lastIndexOf('/');

View file

@ -31,12 +31,12 @@ public class UMLSService implements ExternalConceptService {
private static final String schemeURI = "http://link.informatics.stonybrook.edu/umls"; private static final String schemeURI = "http://link.informatics.stonybrook.edu/umls";
@Override @Override
public List<Concept> getConcepts(String term) throws Exception { public List<Concept> getConcepts(String term) throws Exception {
List<Concept> conceptList = new ArrayList<Concept>(); List<Concept> conceptList = new ArrayList<Concept>();
String results = null; String results = null;
//Format in rdf/xml is possible but would require separate processing method
String dataUrl = submissionUrl + "textToProcess=" String dataUrl = submissionUrl + "textToProcess="
+ URLEncoder.encode(term, "UTF-8") + URLEncoder.encode(term, "UTF-8")
+ "&format=json"; + "&format=json";
@ -98,11 +98,12 @@ public class UMLSService implements ExternalConceptService {
* @param uri * @param uri
* @return * @return
*/ */
public List<Concept> getConceptsByURIWithSparql(String uri) throws Exception { public List<Concept> getConceptsByURIWithSparql(String uri)
//John Ferreira's original code has implementation throws Exception {
List<Concept> newConceptList = new ArrayList<Concept>(); // deprecating this method...just return an empty list
return newConceptList; List<Concept> conceptList = new ArrayList<Concept>();
} return conceptList;
}
/** /**
* @param results * @param results

View file

@ -190,7 +190,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
//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 //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; return newResources;
} }
@ -239,11 +239,11 @@ 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"); // 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"); // literalsOnForm.add("conceptSemanticTypeLabel");
editConfiguration.setLiteralsOnForm(literalsOnForm); editConfiguration.setLiteralsOnForm(literalsOnForm);
} }
@ -272,8 +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); //setConceptSemanticTypeURIField(editConfiguration,vreq);
setConceptSemanticTypeLabelField(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
@ -325,7 +325,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
//An Edit submission preprocessor for enabling addition of multiple terms for a single search //An Edit submission preprocessor for enabling addition of multiple terms for a single search
editConfiguration.addEditSubmissionPreprocessor( editConfiguration.addEditSubmissionPreprocessor(
new AddAssociatedConceptsPreprocessor(editConfiguration)); new AddAssociatedConceptsPreprocessor(editConfiguration, wadf));
} }
@ -411,12 +411,13 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
String conceptSemanticTypeURI = null; String conceptSemanticTypeURI = null;
String conceptSemanticTypeLabel = null; String conceptSemanticTypeLabel = null;
//Can a concept have multiple semantic types? Currently we are only returning the first one //Can a concept have multiple semantic types? Currently we are only returning the first one
/*
List<ObjectPropertyStatement> semanticTypeStatements = conceptIndividual.getObjectPropertyStatements(VIVOCore + "conceptSemanticType"); List<ObjectPropertyStatement> semanticTypeStatements = conceptIndividual.getObjectPropertyStatements(VIVOCore + "conceptSemanticType");
if(semanticTypeStatements.size() > 0) { if(semanticTypeStatements.size() > 0) {
conceptSemanticTypeURI = semanticTypeStatements.get(0).getObjectURI(); conceptSemanticTypeURI = semanticTypeStatements.get(0).getObjectURI();
Individual conceptSemanticTypeIndividual = EditConfigurationUtils.getIndividual(vreq, conceptSemanticTypeURI); Individual conceptSemanticTypeIndividual = EditConfigurationUtils.getIndividual(vreq, conceptSemanticTypeURI);
conceptSemanticTypeLabel = conceptSemanticTypeIndividual.getName(); conceptSemanticTypeLabel = conceptSemanticTypeIndividual.getName();
} }*/
//get label //get label
//Assuming this is from an external vocabulary source //Assuming this is from an external vocabulary source
@ -441,8 +442,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
this.vocabURI = inputVocabURI; this.vocabURI = inputVocabURI;
this.vocabLabel = inputVocabLabel; this.vocabLabel = inputVocabLabel;
this.type = inputType; this.type = inputType;
this.conceptSemanticTypeURI = inputConceptSemanticTypeURI; //this.conceptSemanticTypeURI = inputConceptSemanticTypeURI;
this.conceptSemanticTypeLabel = inputConceptSemanticTypeLabel; //this.conceptSemanticTypeLabel = inputConceptSemanticTypeLabel;
} }
//Getters //Getters

View file

@ -13,6 +13,9 @@ import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.vocabulary.XSD; 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.BaseEditSubmissionPreprocessorVTwo;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils;
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo; import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
@ -24,6 +27,7 @@ public class AddAssociatedConceptsPreprocessor extends
protected static final Log log = LogFactory protected static final Log log = LogFactory
.getLog(AddAssociatedConceptsPreprocessor.class.getName()); .getLog(AddAssociatedConceptsPreprocessor.class.getName());
protected WebappDaoFactory wadf = null;
// Field names/variables names for n3 - these will have numbers added as // Field names/variables names for n3 - these will have numbers added as
// suffix if more than one term // suffix if more than one term
@ -34,14 +38,17 @@ public class AddAssociatedConceptsPreprocessor extends
private static String conceptNodeValues = null; private static String conceptNodeValues = null;
private static String conceptLabelValues = null; private static String conceptLabelValues = null;
private static String conceptSourceValues = null; private static String conceptSourceValues = null;
private static String conceptSemanticTypeLabelValues = null;
private static String conceptSemanticTypeURIValues = null;
private static MultiValueEditSubmission submission = null; private static MultiValueEditSubmission submission = null;
// String datatype // String datatype
// Will be editing the edit configuration as well as edit submission here // Will be editing the edit configuration as well as edit submission here
public AddAssociatedConceptsPreprocessor(EditConfigurationVTwo editConfig) { public AddAssociatedConceptsPreprocessor(EditConfigurationVTwo editConfig, WebappDaoFactory wadf) {
super(editConfig); super(editConfig);
this.wadf = wadf;
} }
public void preprocess(MultiValueEditSubmission inputSubmission) { public void preprocess(MultiValueEditSubmission inputSubmission) {
@ -50,7 +57,9 @@ public class AddAssociatedConceptsPreprocessor extends
// as vocab uri (which is based on thge // as vocab uri (which is based on thge
// For query parameters, check whether CUI // For query parameters, check whether CUI
copySubmissionValues(); 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) { if (conceptNodeValues != null) {
String[] conceptNodes = convertDelimitedStringToArray(conceptNodeValues); String[] conceptNodes = convertDelimitedStringToArray(conceptNodeValues);
int numberConcepts = conceptNodes.length; int numberConcepts = conceptNodes.length;
@ -71,8 +80,26 @@ public class AddAssociatedConceptsPreprocessor extends
conceptLabelValues = getConceptLabelValues(); conceptLabelValues = getConceptLabelValues();
conceptNodeValues = getConceptNodeValues(); conceptNodeValues = getConceptNodeValues();
conceptSourceValues = getConceptSourceValues(); 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) { private void processConceptNodes(int numberConcepts) {
//There are no "new" resources b/c the concept nodes are URIs from external vocabularies //There are no "new" resources b/c the concept nodes are URIs from external vocabularies
// Add N3Required // Add N3Required
@ -98,6 +125,9 @@ public class AddAssociatedConceptsPreprocessor extends
addConceptNodeInputs(numberConcepts); addConceptNodeInputs(numberConcepts);
addConceptSourceInputs(numberConcepts); addConceptSourceInputs(numberConcepts);
addConceptLabelInputs(numberConcepts); addConceptLabelInputs(numberConcepts);
//for concept semantic type labels and uris where they exist
//addConceptSemanticTypeLabelInputs(numberConcepts);
//addConceptSemanticTypeURIInputs(numberConcepts);
} }
@ -168,6 +198,15 @@ public class AddAssociatedConceptsPreprocessor extends
} }
} }
private void addConceptSemanticTypeLabelInputs(int numberConcepts) {
}
private void addConceptSemanticTypeURIInputs(int numberConcepts) {
}
//Fields
private void addFields(int numberConcepts) { private void addFields(int numberConcepts) {
//Clear out all fields in edit configuration first //Clear out all fields in edit configuration first
@ -290,6 +329,7 @@ public class AddAssociatedConceptsPreprocessor extends
} }
//Get values from submission
private String getConceptNodeValues() { private String getConceptNodeValues() {
Map<String, List<String>> urisFromForm = submission.getUrisFromForm(); Map<String, List<String>> urisFromForm = submission.getUrisFromForm();
List<String> conceptNodes = urisFromForm.get("conceptNode"); 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) { private Object getFirstElement(List inputList) {
if(inputList == null || inputList.size() == 0) if(inputList == null || inputList.size() == 0)
return null; return null;