updates for concept semantic type in external vocab search
This commit is contained in:
parent
508f88a7c5
commit
14ddc38177
2 changed files with 66 additions and 14 deletions
|
@ -17,8 +17,16 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import com.hp.hpl.jena.ontology.OntModel;
|
import com.hp.hpl.jena.ontology.OntModel;
|
||||||
|
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.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.Model;
|
import com.hp.hpl.jena.rdf.model.Model;
|
||||||
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
import com.hp.hpl.jena.vocabulary.RDF;
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
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;
|
||||||
|
@ -34,6 +42,7 @@ import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUti
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.fields.FieldVTwo;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.AddAssociatedConceptsPreprocessor;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.AddAssociatedConceptsPreprocessor;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors.ConceptSemanticTypesPreprocessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
import edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.validators.AntiXssValidation;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService.ConceptSearchServiceUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.ConceptSearchService.ConceptSearchServiceUtils;
|
||||||
/**
|
/**
|
||||||
|
@ -86,7 +95,9 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
||||||
setTemplate(editConfiguration, vreq);
|
setTemplate(editConfiguration, vreq);
|
||||||
// No validators required here
|
// No validators required here
|
||||||
// Add preprocessors
|
// Add preprocessors
|
||||||
addPreprocessors(editConfiguration, ModelAccess.on(vreq).getJenaOntModel());
|
addPreprocessors(editConfiguration,
|
||||||
|
ModelAccess.on(vreq).getJenaOntModel(),
|
||||||
|
ModelAccess.on(vreq).getOntModelSelector().getTBoxModel());
|
||||||
// Adding additional data, specifically edit mode
|
// Adding additional data, specifically edit mode
|
||||||
addFormSpecificData(editConfiguration, vreq);
|
addFormSpecificData(editConfiguration, vreq);
|
||||||
// One override for basic functionality, changing url pattern
|
// One override for basic functionality, changing url pattern
|
||||||
|
@ -324,7 +335,7 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
||||||
|
|
||||||
//Add preprocessor
|
//Add preprocessor
|
||||||
|
|
||||||
private void addPreprocessors(EditConfigurationVTwo editConfiguration, OntModel ontModel) {
|
private void addPreprocessors(EditConfigurationVTwo editConfiguration, OntModel ontModel, OntModel modelChangeModel) {
|
||||||
//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
|
||||||
//TODO: Check if this is the appropriate way of getting model
|
//TODO: Check if this is the appropriate way of getting model
|
||||||
|
|
||||||
|
@ -332,6 +343,8 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
||||||
|
|
||||||
editConfiguration.addEditSubmissionPreprocessor(
|
editConfiguration.addEditSubmissionPreprocessor(
|
||||||
new AddAssociatedConceptsPreprocessor(editConfiguration, ontModel));
|
new AddAssociatedConceptsPreprocessor(editConfiguration, ontModel));
|
||||||
|
editConfiguration.addModelChangePreprocessor(new ConceptSemanticTypesPreprocessor(
|
||||||
|
modelChangeModel));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,14 +430,15 @@ 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
|
||||||
|
//TODO: Change this into a sparql query that returns all types for the concept that are subclasses of SKOS concepts
|
||||||
|
HashMap<String, String> typeAndLabel = this.getConceptSemanticTypeQueryResults(conceptIndividual.getURI(), ModelAccess.on(vreq).getJenaOntModel());
|
||||||
|
if(typeAndLabel.containsKey("semanticTypeURI")) {
|
||||||
|
conceptSemanticTypeURI = typeAndLabel.get("semanticTypeURI");
|
||||||
|
}
|
||||||
|
if(typeAndLabel.containsKey("semanticTypeLabel")) {
|
||||||
|
conceptSemanticTypeLabel = typeAndLabel.get("semanticTypeLabel");
|
||||||
|
}
|
||||||
|
|
||||||
List<ObjectPropertyStatement> semanticTypeStatements = conceptIndividual.getObjectPropertyStatements(VIVOCore + "hasConceptSemanticType");
|
|
||||||
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
|
//Assuming this is from an external vocabulary source
|
||||||
info.add(new AssociatedConceptInfo(conceptLabel, conceptUri, vocabSource, vocabLabel, null, conceptSemanticTypeURI, conceptSemanticTypeLabel));
|
info.add(new AssociatedConceptInfo(conceptLabel, conceptUri, vocabSource, vocabLabel, null, conceptSemanticTypeURI, conceptSemanticTypeLabel));
|
||||||
|
@ -434,6 +448,44 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashMap<String, String> getConceptSemanticTypeQueryResults(String conceptURI, OntModel ontModel) {
|
||||||
|
HashMap<String, String> typeAndLabel = new HashMap<String, String>();
|
||||||
|
String queryStr = "SELECT ?semanticTypeURI ?semanticTypeLabel WHERE { " +
|
||||||
|
"<" + conceptURI + "> <" + RDF.type.getURI() + "> ?semanticTypeURI . " +
|
||||||
|
"?semanticTypeURI <" + RDFS.subClassOf.getURI() + "> <" + this.SKOSConceptType + ">. " +
|
||||||
|
"?semanticTypeURI <" + RDFS.label.getURI() + "> ?semanticTypeLabel ." +
|
||||||
|
"}";
|
||||||
|
QueryExecution qe = null;
|
||||||
|
try{
|
||||||
|
Query query = QueryFactory.create(queryStr);
|
||||||
|
qe = QueryExecutionFactory.create(query, ontModel);
|
||||||
|
ResultSet results = null;
|
||||||
|
results = qe.execSelect();
|
||||||
|
|
||||||
|
while( results.hasNext()){
|
||||||
|
QuerySolution qs = results.nextSolution();
|
||||||
|
if(qs.get("semanticTypeURI") != null) {
|
||||||
|
Resource semanticTypeURI = qs.getResource("semanticTypeURI");
|
||||||
|
log.debug("Semantic Type URI returned " + semanticTypeURI.getURI());
|
||||||
|
typeAndLabel.put("semanticTypeURI", semanticTypeURI.getURI());
|
||||||
|
}
|
||||||
|
if(qs.get("semanticTypeLabel") != null) {
|
||||||
|
Literal semanticTypeLabel = qs.getLiteral("semanticTypeLabel");
|
||||||
|
log.debug("Semantic Type label returned " + semanticTypeLabel.getString());
|
||||||
|
typeAndLabel.put("semanticTypeLabel", semanticTypeLabel.getString());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}catch(Exception ex){
|
||||||
|
throw new Error("Error in executing query string: \n" + queryStr + '\n' + ex.getMessage());
|
||||||
|
}finally{
|
||||||
|
if( qe != null)
|
||||||
|
qe.close();
|
||||||
|
}
|
||||||
|
return typeAndLabel;
|
||||||
|
}
|
||||||
|
|
||||||
public class AssociatedConceptInfo {
|
public class AssociatedConceptInfo {
|
||||||
private String conceptLabel;
|
private String conceptLabel;
|
||||||
private String conceptURI;
|
private String conceptURI;
|
||||||
|
|
|
@ -21,6 +21,7 @@ import com.hp.hpl.jena.query.QuerySolution;
|
||||||
import com.hp.hpl.jena.query.ResultSet;
|
import com.hp.hpl.jena.query.ResultSet;
|
||||||
import com.hp.hpl.jena.rdf.model.Literal;
|
import com.hp.hpl.jena.rdf.model.Literal;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
import com.hp.hpl.jena.vocabulary.RDF;
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
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;
|
||||||
|
@ -469,10 +470,9 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
n3String += node + " <" + RDFS.label.getURI() + "> " + label + " .\n" +
|
n3String += node + " <" + RDFS.label.getURI() + "> " + label + " .\n" +
|
||||||
node + " <" + RDFS.isDefinedBy.getURI() + "> " + source + " .";
|
node + " <" + RDFS.isDefinedBy.getURI() + "> " + source + " .";
|
||||||
String n3ConceptTypeString = prefixStr;
|
String n3ConceptTypeString = prefixStr;
|
||||||
n3ConceptTypeString += node + " core:hasConceptSemanticType " + conceptSemanticTypeURI + " ." +
|
n3ConceptTypeString += node + " <" + RDF.type.getURI() + "> " + conceptSemanticTypeURI + " ." +
|
||||||
conceptSemanticTypeURI + " core:isConceptSemanticTypeOf " + node + ". " +
|
conceptSemanticTypeURI + " <" + RDFS.label.getURI() + "> " + conceptSemanticTypeLabel + " .\n" +
|
||||||
conceptSemanticTypeURI + " <" + RDFS.label.getURI() + "> " + conceptSemanticTypeLabel + " .\n" +
|
conceptSemanticTypeURI + " <" + RDFS.subClassOf.getURI() + "> <http://www.w3.org/2004/02/skos/core#Concept> .\n" ;
|
||||||
conceptSemanticTypeURI + " <" + RDF.type.getURI() + "> core:ConceptSemanticType .\n" ;
|
|
||||||
|
|
||||||
n3Optional.add(n3String);
|
n3Optional.add(n3String);
|
||||||
//adding separately so their resolution does not depend on each other
|
//adding separately so their resolution does not depend on each other
|
||||||
|
@ -630,7 +630,7 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getExistingSemanticTypeURI(String label) {
|
private String getExistingSemanticTypeURI(String label) {
|
||||||
String queryStr = "SELECT ?semanticType WHERE { ?semanticType <" + RDF.type.getURI() + "> <http://vivoweb.org/ontology/core#ConceptSemanticType> . " +
|
String queryStr = "SELECT ?semanticType WHERE { ?semanticType <" + RDF.type.getURI() + "> <" + OWL.Class.getURI() + "> . " +
|
||||||
"?semanticType <" + RDFS.label.getURI() + "> \"" + label + "\"^^<http://www.w3.org/2001/XMLSchema#string> . }";
|
"?semanticType <" + RDFS.label.getURI() + "> \"" + label + "\"^^<http://www.w3.org/2001/XMLSchema#string> . }";
|
||||||
QueryExecution qe = null;
|
QueryExecution qe = null;
|
||||||
try{
|
try{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue