updates for concept search and label management

This commit is contained in:
hudajkhan 2013-09-05 15:45:49 -04:00
parent 14ddc38177
commit a9ebf8f94b
13 changed files with 171 additions and 76 deletions

View file

@ -396,37 +396,38 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
}
//To determine whether or not a concept is a user generated or one from an external vocab source.
//we cannot rely on whether or not it is a skos concept because incorporating UMLS semantic network classes as
//SKOS concept subclasses means that even concepts from an external vocab source might be considered SKOS concepts
//Instead, we will simply determine whether a concept is defined by an external vocabulary source and use that
//as the primary indicator of whether a concept is from an external vocabulary source or a user generated concept
private List<AssociatedConceptInfo> getAssociatedConceptInfo(
List<Individual> concepts, VitroRequest vreq) {
List<AssociatedConceptInfo> info = new ArrayList<AssociatedConceptInfo>();
for ( Individual conceptIndividual : concepts ) {
boolean isSKOSConcept = false;
boolean userGenerated = true;
//Note that this isn't technically
String conceptUri = conceptIndividual.getURI();
String conceptLabel = conceptIndividual.getName();
//Check if SKOS Concept type
List<ObjectPropertyStatement> osl = conceptIndividual.getObjectPropertyStatements(RDF.type.getURI());
for(ObjectPropertyStatement os: osl) {
if(os.getObjectURI().equals(SKOSConceptType)) {
isSKOSConcept = true;
break;
}
}
//Check if defined by an external vocabulary source
List<ObjectPropertyStatement> vocabList = conceptIndividual.getObjectPropertyStatements(RDFS.isDefinedBy.getURI());
String vocabSource = null;
String vocabLabel = null;
if(vocabList != null && vocabList.size() > 0) {
userGenerated = false;
vocabSource = vocabList.get(0).getObjectURI();
Individual sourceIndividual = EditConfigurationUtils.getIndividual(vreq, vocabSource);
//Assuming name will get label
vocabLabel = sourceIndividual.getName();
}
if(isSKOSConcept) {
if(userGenerated) {
//if the concept in question is skos - which would imply a user generated concept
info.add(new AssociatedConceptInfo(conceptLabel, conceptUri, null, null, SKOSConceptType, null, null));
} else {
//Get the vocab source and vocab label
List<ObjectPropertyStatement> vocabList = conceptIndividual.getObjectPropertyStatements(RDFS.isDefinedBy.getURI());
String vocabSource = null;
String vocabLabel = null;
if(vocabList != null && vocabList.size() > 0) {
vocabSource = vocabList.get(0).getObjectURI();
Individual sourceIndividual = EditConfigurationUtils.getIndividual(vreq, vocabSource);
//Assuming name will get label
vocabLabel = sourceIndividual.getName();
}
String conceptSemanticTypeURI = null;
String conceptSemanticTypeLabel = null;
//Can a concept have multiple semantic types? Currently we are only returning the first one
@ -438,7 +439,6 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
if(typeAndLabel.containsKey("semanticTypeLabel")) {
conceptSemanticTypeLabel = typeAndLabel.get("semanticTypeLabel");
}
//Assuming this is from an external vocabulary source
info.add(new AssociatedConceptInfo(conceptLabel, conceptUri, vocabSource, vocabLabel, null, conceptSemanticTypeURI, conceptSemanticTypeLabel));

View file

@ -84,6 +84,8 @@ public class AddAssociatedConceptsPreprocessor extends
//This will put the URI value in scope for the first semantic type label
//and generate the rest if need be
processConceptSemanticValues();
//Also need to see if any broader or narrower uris for the concepts that already exist in the system
//and set up the appropriate relationships between this concept and the broader/narrower uri
if (numberConcepts > 1) {
processConceptNodes(numberConcepts);
}

View file

@ -0,0 +1,125 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocessors;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.query.Dataset;
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.QuerySolutionMap;
import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapperFactory;
//We are representing semantic types from the UMLS Semantic Network as OWL Classes
//and this preprocessor will add the appropriate class information to the TBox
public class ConceptSemanticTypesPreprocessor implements ModelChangePreprocessor {
private static String VIVOCore = "http://vivoweb.org/ontology/core#";
private static String SKOSConceptType = "http://www.w3.org/2004/02/skos/core#Concept";
private Log log = LogFactory.getLog(ConceptSemanticTypesPreprocessor.class);
private OntModel toUpdateModel = null;
//Custom constructor
public ConceptSemanticTypesPreprocessor(OntModel updateModel) {
this.toUpdateModel = updateModel;
}
@Override
public void preprocess(Model retractionsModel, Model additionsModel,
HttpServletRequest request) {
//Run a construct query against the additions model
String prefixes = "PREFIX rdfs:<" + RDFS.getURI() + "> " +
"PREFIX owl:<http://www.w3.org/2002/07/owl#> " +
"PREFIX rdf:<" + RDF.getURI() + ">" +
"PREFIX skos:<http://www.w3.org/2004/02/skos/core#>";
String constructQuery = prefixes + " CONSTRUCT { " +
"?semanticType rdf:type owl:Class. " +
"?semanticType rdfs:subClassOf skos:Concept . " +
"?semanticType rdfs:label ?label. " +
"} WHERE { " +
"?concept rdf:type ?semanticType. " +
"?semanticType rdfs:label ?label . " +
"?semanticType rdfs:subClassOf skos:Concept . " +
"}";
//Execute construct query
Model constructedModel = ModelFactory.createDefaultModel();
log.debug("CONSTRUCT query string " + constructQuery);
Query query = null;
try {
query = QueryFactory.create(constructQuery, Syntax.syntaxARQ);
} catch(Throwable th){
log.error("Could not create CONSTRUCT SPARQL query for query " +
"string. " + th.getMessage());
log.error(constructQuery);
return;
}
additionsModel.getLock().enterCriticalSection(Lock.READ);
QueryExecution qe = null;
try {
qe = QueryExecutionFactory.create(
query, additionsModel);
qe.execConstruct(constructedModel);
} catch (Exception e) {
log.error("Error getting constructed model for query string " + constructQuery);
} finally {
if (qe != null) {
qe.close();
}
additionsModel.getLock().leaveCriticalSection();
}
//Add constructed model to the designated update model
toUpdateModel.enterCriticalSection(Lock.WRITE);
try {
toUpdateModel.add(constructedModel);
} catch (Exception e) {
log.error("Error adding statements to update model for " + constructQuery);
} finally {
toUpdateModel.leaveCriticalSection();
}
//Take this constructed model and remove from the additions model
additionsModel.enterCriticalSection(Lock.WRITE);
try {
additionsModel.remove(constructedModel.listStatements().toList());
} catch (Exception e) {
log.error("Error removing statements from additions model for " + constructQuery);
} finally {
additionsModel.leaveCriticalSection();
}
}
}