updates to remove errant file and updates for adding concept
This commit is contained in:
parent
4b52ccd687
commit
0511404a47
5 changed files with 258 additions and 60 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@
|
||||||
/deploy.properties
|
/deploy.properties
|
||||||
/build.properties
|
/build.properties
|
||||||
/runtime.properties
|
/runtime.properties
|
||||||
|
/ontology/public/catalog-v0001.xml
|
|
@ -1,5 +0,0 @@
|
||||||
<?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>
|
|
47
productMods/WEB-INF/filegraph/tbox/ConceptSemanticType.owl
Normal file
47
productMods/WEB-INF/filegraph/tbox/ConceptSemanticType.owl
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
<rdf:RDF
|
||||||
|
xmlns:vitro-public="http://vitro.mannlib.cornell.edu/ns/vitro/public#"
|
||||||
|
xmlns:c4o="http://purl.org/spar/c4o/"
|
||||||
|
xmlns:ero="http://purl.obolibrary.org/obo/"
|
||||||
|
xmlns:pvs="http://vivoweb.org/ontology/provenance-support#"
|
||||||
|
xmlns:owl2="http://www.w3.org/2006/12/owl2-xml#"
|
||||||
|
xmlns:scirr="http://vivoweb.org/ontology/scientific-research-resource#"
|
||||||
|
xmlns:vivo="http://vivoweb.org/ontology/core#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:bibo="http://purl.org/ontology/bibo/"
|
||||||
|
xmlns:afn="http://jena.hpl.hp.com/ARQ/function#"
|
||||||
|
xmlns:foaf="http://xmlns.com/foaf/0.1/"
|
||||||
|
xmlns:scires="http://vivoweb.org/ontology/scientific-research#"
|
||||||
|
xmlns:dcterms="http://purl.org/dc/terms/"
|
||||||
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
|
||||||
|
xmlns:geo="http://aims.fao.org/aos/geopolitical.owl#"
|
||||||
|
xmlns:skco="http://www.w3.org/2004/02/skos/core#"
|
||||||
|
xmlns:event="http://purl.org/NET/c4dm/event.owl#"
|
||||||
|
xmlns:dcelem="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:vitro="http://vitro.mannlib.cornell.edu/ns/vitro/0.7#"
|
||||||
|
xmlns:vann="http://purl.org/vocab/vann/"
|
||||||
|
xmlns:skos="http://www.w3.org/2008/05/skos#"
|
||||||
|
xmlns:swvs="http://www.w3.org/2003/06/sw-vocab-status/ns#"
|
||||||
|
xmlns:owl="http://www.w3.org/2002/07/owl#"
|
||||||
|
xmlns:fabio="http://purl.org/spar/fabio/"
|
||||||
|
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
|
||||||
|
|
||||||
|
<owl:versionInfo rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal"
|
||||||
|
>0.7</owl:versionInfo>
|
||||||
|
|
||||||
|
|
||||||
|
<owl:Class rdf:about="http://vivoweb.org/ontology/core#ConceptSemanticType">
|
||||||
|
<vitro:exampleAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
|
||||||
|
>Semantic Type for given concept, for example UMLS's type returned for concepts</vitro:exampleAnnot>
|
||||||
|
<vitro:descriptionAnnot rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
|
||||||
|
>Semantic Type for given concept, for example UMLS's type returned for concepts.</vitro:descriptionAnnot>
|
||||||
|
|
||||||
|
<vitro:shortDef rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
|
||||||
|
>Concept Semantic Type</vitro:shortDef>
|
||||||
|
</owl:Class>
|
||||||
|
|
||||||
|
<owl:ObjectProperty rdf:about="http://vivoweb.org/ontology/core#hasConceptSemanticType">
|
||||||
|
<rdfs:range rdf:resource="http://vivoweb.org/ontology/core#ConceptSemanticType"/>
|
||||||
|
<owl:inverseOf rdf:resource="http://vivoweb.org/ontology/core#isConceptSemanticTypeOf"/>
|
||||||
|
</owl:ObjectProperty>
|
||||||
|
|
||||||
|
</rdf:RDF>
|
|
@ -16,6 +16,7 @@ import javax.servlet.http.HttpSession;
|
||||||
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 com.hp.hpl.jena.ontology.OntModel;
|
||||||
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.vocabulary.RDF;
|
import com.hp.hpl.jena.vocabulary.RDF;
|
||||||
|
@ -27,6 +28,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
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;
|
||||||
|
@ -85,7 +87,7 @@ 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, vreq.getWebappDaoFactory());
|
addPreprocessors(editConfiguration, ModelAccess.on(vreq).getJenaOntModel());
|
||||||
// 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
|
||||||
|
@ -174,8 +176,10 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
||||||
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 ." +
|
"?conceptNode <" + VIVOCore + "hasConceptSemanticType> ?conceptSemanticTypeURI ." +
|
||||||
"?conceptSemanticTypeURI <" + RDFS.label.getURI() + "> ?conceptSemanticTypeLabel ."
|
"?conceptSemanticTypeURI <" + VIVOCore + "isConceptSemanticTypeOf> ?conceptNode ." +
|
||||||
|
"?conceptSemanticTypeURI <" + RDFS.label.getURI() + "> ?conceptSemanticTypeLabel ." +
|
||||||
|
"?conceptSemanticTypeURI <" + RDF.type.getURI() + "> <" + VIVOCore + "ConceptSemanticType> ."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +194,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 +243,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 +276,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
|
||||||
|
@ -321,12 +325,14 @@ public class AddAssociatedConceptGenerator extends VivoBaseGenerator implements
|
||||||
|
|
||||||
//Add preprocessor
|
//Add preprocessor
|
||||||
|
|
||||||
private void addPreprocessors(EditConfigurationVTwo editConfiguration, WebappDaoFactory wadf) {
|
private void addPreprocessors(EditConfigurationVTwo editConfiguration, OntModel ontModel) {
|
||||||
//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
|
||||||
|
|
||||||
|
//Passing model to check for any URIs that are present
|
||||||
|
|
||||||
editConfiguration.addEditSubmissionPreprocessor(
|
editConfiguration.addEditSubmissionPreprocessor(
|
||||||
new AddAssociatedConceptsPreprocessor(editConfiguration, wadf));
|
new AddAssociatedConceptsPreprocessor(editConfiguration, ontModel));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,13 +418,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 + "hasConceptSemanticType");
|
||||||
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
|
||||||
|
@ -443,8 +449,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
|
||||||
|
|
|
@ -4,18 +4,27 @@ package edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.preprocess
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
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 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.Resource;
|
||||||
|
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;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -27,13 +36,18 @@ 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;
|
//TODO: Check if better way to do this?
|
||||||
|
protected OntModel ontModel = 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
|
||||||
private static String conceptNodeBase = "conceptNode";
|
private static String conceptNodeBase = "conceptNode";
|
||||||
private static String sourceBase = "conceptSource";
|
private static String sourceBase = "conceptSource";
|
||||||
private static String labelBase = "conceptLabel";
|
private static String labelBase = "conceptLabel";
|
||||||
|
private static String conceptSemanticTypeLabelBase = "conceptSemanticTypeLabel";
|
||||||
|
private static String conceptSemanticTypeURIBase = "conceptSemanticTypeURI";
|
||||||
|
//keyed off label variable, specifies which uri variable should be used, useful if same label repeated twice
|
||||||
|
private HashMap<String, String> labelVarToUriVarHash = null;
|
||||||
|
|
||||||
//Also storing submission values
|
//Also storing submission values
|
||||||
private static String conceptNodeValues = null;
|
private static String conceptNodeValues = null;
|
||||||
private static String conceptLabelValues = null;
|
private static String conceptLabelValues = null;
|
||||||
|
@ -46,9 +60,10 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
|
|
||||||
// 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, WebappDaoFactory wadf) {
|
public AddAssociatedConceptsPreprocessor(EditConfigurationVTwo editConfig, OntModel ontModel) {
|
||||||
super(editConfig);
|
super(editConfig);
|
||||||
this.wadf = wadf;
|
this.ontModel = ontModel;
|
||||||
|
this.labelVarToUriVarHash = new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void preprocess(MultiValueEditSubmission inputSubmission) {
|
public void preprocess(MultiValueEditSubmission inputSubmission) {
|
||||||
|
@ -57,12 +72,14 @@ 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;
|
||||||
|
//This will put the URI value in scope for the first semantic type label
|
||||||
|
//and generate the rest if need be
|
||||||
|
processConceptSemanticValues();
|
||||||
if (numberConcepts > 1) {
|
if (numberConcepts > 1) {
|
||||||
processConceptNodes(numberConcepts);
|
processConceptNodes(numberConcepts);
|
||||||
}
|
}
|
||||||
|
@ -80,6 +97,7 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
conceptLabelValues = getConceptLabelValues();
|
conceptLabelValues = getConceptLabelValues();
|
||||||
conceptNodeValues = getConceptNodeValues();
|
conceptNodeValues = getConceptNodeValues();
|
||||||
conceptSourceValues = getConceptSourceValues();
|
conceptSourceValues = getConceptSourceValues();
|
||||||
|
log.debug("concept label values are " + conceptLabelValues);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,14 +112,11 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//This is for additional concept nodes (i.e. if user selects more than one concept)
|
//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
|
||||||
|
//New resources for concept semantic type uris
|
||||||
|
addNewResources(numberConcepts);
|
||||||
// Add N3Required
|
// Add N3Required
|
||||||
addN3Required(numberConcepts);
|
addN3Required(numberConcepts);
|
||||||
//Add N3 Optional as well
|
//Add N3 Optional as well
|
||||||
|
@ -115,6 +130,31 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//This is specifically for concept semantic type URIs which may need to be generated
|
||||||
|
private void addNewResources(int numberConcepts) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
addConceptSemanticTypeURIResources(numberConcepts);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addConceptSemanticTypeURIResources(int numberConcepts) {
|
||||||
|
String[] conceptSemanticTypeURIs= convertDelimitedStringToArray(conceptSemanticTypeURIValues);
|
||||||
|
//the number of existing values may not match up, or at least existing populated ones
|
||||||
|
if(conceptSemanticTypeURIs != null && conceptSemanticTypeURIs.length == numberConcepts) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < numberConcepts; i++) {
|
||||||
|
int suffix = i + 1;
|
||||||
|
String newResourceName = conceptSemanticTypeURIBase + suffix;
|
||||||
|
editConfiguration.addNewResource(newResourceName, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else if(conceptSemanticTypeURIs != null && conceptSemanticTypeURIs.length != numberConcepts){
|
||||||
|
log.error("Number of concept semantic type uris does not match the number of concepts");
|
||||||
|
} else{
|
||||||
|
log.error("Concept semantic type uris returned as null");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//This is where the actual values will be submitted as if they were separate input fields
|
//This is where the actual values will be submitted as if they were separate input fields
|
||||||
//Each field name will correspond to the names of the fileds/uris on form/literals on form
|
//Each field name will correspond to the names of the fileds/uris on form/literals on form
|
||||||
//generated here
|
//generated here
|
||||||
|
@ -126,8 +166,8 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
addConceptSourceInputs(numberConcepts);
|
addConceptSourceInputs(numberConcepts);
|
||||||
addConceptLabelInputs(numberConcepts);
|
addConceptLabelInputs(numberConcepts);
|
||||||
//for concept semantic type labels and uris where they exist
|
//for concept semantic type labels and uris where they exist
|
||||||
//addConceptSemanticTypeLabelInputs(numberConcepts);
|
addConceptSemanticTypeLabelInputs(numberConcepts);
|
||||||
//addConceptSemanticTypeURIInputs(numberConcepts);
|
addConceptSemanticTypeURIInputs(numberConcepts);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,11 +239,51 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addConceptSemanticTypeLabelInputs(int numberConcepts) {
|
private void addConceptSemanticTypeLabelInputs(int numberConcepts) {
|
||||||
|
String[] labels = convertDelimitedStringToArray(conceptSemanticTypeLabelValues);
|
||||||
|
if(labels != null && labels.length == numberConcepts) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < numberConcepts; i++) {
|
||||||
|
int suffix = i + 1;
|
||||||
|
String labelInputName = conceptSemanticTypeLabelBase + suffix;
|
||||||
|
String[] labelValues = new String[1];
|
||||||
|
labelValues[0] = labels[i];
|
||||||
|
//TODO: Check if there are no funky typed information also stored
|
||||||
|
//At this point the field should already have been added to edit configuration
|
||||||
|
FieldVTwo labelField = editConfiguration.getField(labelInputName);
|
||||||
|
//TODO: Also check to see whether the label is actually populate or will n3 editing take care of that?
|
||||||
|
if(labelField != null) {
|
||||||
|
submission.addLiteralToForm(editConfiguration, labelField, labelInputName, labelValues);
|
||||||
|
} else {
|
||||||
|
log.error("Corresponding field for " + labelInputName + " was not added to edit configuration");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else if(labels != null && labels.length != numberConcepts){
|
||||||
|
log.error("Number of concept semantic type labels did not match the number of concepts to be added");
|
||||||
|
} else{
|
||||||
|
log.error("Concept labels returned were null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void addConceptSemanticTypeURIInputs(int numberConcepts) {
|
private void addConceptSemanticTypeURIInputs(int numberConcepts) {
|
||||||
|
String[] conceptSemanticTypeURIs= convertDelimitedStringToArray(conceptSemanticTypeURIValues);
|
||||||
|
//the number of existing values may not match up, or at least existing populated ones
|
||||||
|
if(conceptSemanticTypeURIs != null && conceptSemanticTypeURIs.length == numberConcepts) {
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < numberConcepts; i++) {
|
||||||
|
int suffix = i + 1;
|
||||||
|
String conceptInputName = conceptSemanticTypeURIBase + suffix;
|
||||||
|
String[] uriValues = new String[1];
|
||||||
|
uriValues[0] = conceptSemanticTypeURIs[i];
|
||||||
|
//Add value for uri to form
|
||||||
|
//TODO: Check if value is empty in which case don't add to submission
|
||||||
|
submission.addUriToForm(editConfiguration, conceptInputName, uriValues);
|
||||||
|
}
|
||||||
|
} else if(conceptSemanticTypeURIs != null && conceptSemanticTypeURIs.length != numberConcepts){
|
||||||
|
log.error("Number of concept nodes did not match the number of concepts to be added");
|
||||||
|
} else{
|
||||||
|
log.error("Concept nodes returned were null");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Fields
|
//Fields
|
||||||
|
@ -218,10 +298,16 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
String conceptNode = conceptNodeBase + suffix;
|
String conceptNode = conceptNodeBase + suffix;
|
||||||
String label = labelBase + suffix;
|
String label = labelBase + suffix;
|
||||||
String source = sourceBase + suffix;
|
String source = sourceBase + suffix;
|
||||||
|
String conceptSemanticTypeLabel = conceptSemanticTypeLabelBase + suffix;
|
||||||
|
String conceptSemanticTypeURI = conceptSemanticTypeURIBase + suffix;
|
||||||
|
|
||||||
addConceptNodeField(conceptNode);
|
addConceptNodeField(conceptNode);
|
||||||
addLabelField(label);
|
addLabelField(label);
|
||||||
addSourceField(source);
|
addSourceField(source);
|
||||||
|
//Also add fields for concept semantic type label
|
||||||
|
addConceptSemanticTypeLabelField(conceptSemanticTypeLabel);
|
||||||
|
//and concept semantic type URI
|
||||||
|
addConceptSemanticTypeURIField(conceptSemanticTypeURI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +333,21 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Will need to check whether or not semantic type label even exists though?
|
||||||
|
private void addConceptSemanticTypeLabelField(String label) {
|
||||||
|
editConfiguration.addField(new FieldVTwo().
|
||||||
|
setName(label).
|
||||||
|
setRangeDatatypeUri(XSD.xstring.toString())
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addConceptSemanticTypeURIField(String conceptSemanticTypeURI) {
|
||||||
|
editConfiguration.addField(new FieldVTwo().
|
||||||
|
setName(conceptSemanticTypeURI));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//original literals on form: label, uris on form: conceptNode and conceptSource
|
//original literals on form: label, uris on form: conceptNode and conceptSource
|
||||||
//This will overwrite the original values in the edit configuration
|
//This will overwrite the original values in the edit configuration
|
||||||
private void addLiteralsAndUrisOnForm(int numberTerms) {
|
private void addLiteralsAndUrisOnForm(int numberTerms) {
|
||||||
|
@ -261,9 +362,13 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
String conceptNode = conceptNodeBase + suffix;
|
String conceptNode = conceptNodeBase + suffix;
|
||||||
String label = labelBase + suffix;
|
String label = labelBase + suffix;
|
||||||
String source = sourceBase + suffix;
|
String source = sourceBase + suffix;
|
||||||
|
String conceptSemanticTypeLabel = conceptSemanticTypeLabelBase + suffix;
|
||||||
|
String conceptSemanticTypeURI = conceptSemanticTypeURIBase + suffix;
|
||||||
urisOnForm.add(conceptNode);
|
urisOnForm.add(conceptNode);
|
||||||
urisOnForm.add(source);
|
urisOnForm.add(source);
|
||||||
|
urisOnForm.add(conceptSemanticTypeURI);
|
||||||
literalsOnForm.add(label);
|
literalsOnForm.add(label);
|
||||||
|
literalsOnForm.add(conceptSemanticTypeLabel);
|
||||||
}
|
}
|
||||||
editConfiguration.setUrisOnform(urisOnForm);
|
editConfiguration.setUrisOnform(urisOnForm);
|
||||||
editConfiguration.setLiteralsOnForm(literalsOnForm);
|
editConfiguration.setLiteralsOnForm(literalsOnForm);
|
||||||
|
@ -279,8 +384,7 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
List<String> n3Required = new ArrayList<String>();
|
List<String> n3Required = new ArrayList<String>();
|
||||||
int index;
|
int index;
|
||||||
String nodeBase = "?" + conceptNodeBase;
|
String nodeBase = "?" + conceptNodeBase;
|
||||||
String labelVar = "?" + labelBase;
|
|
||||||
String sourceVar = "?" + sourceBase;
|
|
||||||
String prefixStr = "@prefix core: <http://vivoweb.org/ontology/core#> .";
|
String prefixStr = "@prefix core: <http://vivoweb.org/ontology/core#> .";
|
||||||
// First one already included so add new ones here
|
// First one already included so add new ones here
|
||||||
for (index = 1; index <= numberConcepts; index++) {
|
for (index = 1; index <= numberConcepts; index++) {
|
||||||
|
@ -293,23 +397,30 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
editConfiguration.setN3Required(n3Required);
|
editConfiguration.setN3Required(n3Required);
|
||||||
}
|
}
|
||||||
//Add n3 optional
|
//Add n3 optional
|
||||||
|
//TODO: Rewrite optional N3
|
||||||
private void addN3Optional(int numberConcepts) {
|
private void addN3Optional(int numberConcepts) {
|
||||||
List<String> n3Optional = new ArrayList<String>();
|
List<String> n3Optional = new ArrayList<String>();
|
||||||
int index;
|
int index;
|
||||||
String nodeBase = "?" + conceptNodeBase;
|
String nodeBase = "?" + conceptNodeBase;
|
||||||
String labelVar = "?" + labelBase;
|
|
||||||
String sourceVar = "?" + sourceBase;
|
String conceptSemanticTypeLabelVar = "?" + conceptSemanticTypeLabelBase;
|
||||||
|
String conceptSemanticTypeURIVar = "?" + conceptSemanticTypeURIBase;
|
||||||
String prefixStr = "@prefix core: <http://vivoweb.org/ontology/core#> .";
|
String prefixStr = "@prefix core: <http://vivoweb.org/ontology/core#> .";
|
||||||
// First one already included so add new ones here
|
// First one already included so add new ones here
|
||||||
for (index = 1; index <= numberConcepts; index++) {
|
for (index = 1; index <= numberConcepts; index++) {
|
||||||
int suffix = index;
|
int suffix = index;
|
||||||
String node = nodeBase + suffix;
|
String node = nodeBase + suffix;
|
||||||
String label = labelVar + suffix;
|
|
||||||
String source = sourceVar + suffix;
|
String conceptSemanticTypeLabel = conceptSemanticTypeLabelVar + suffix;
|
||||||
|
String conceptSemanticTypeURI = conceptSemanticTypeURIVar + suffix;
|
||||||
String n3String = prefixStr;
|
String n3String = prefixStr;
|
||||||
n3String += node + " <" + RDFS.label.getURI() + "> " + label + " .\n" +
|
|
||||||
node + " <" + RDFS.isDefinedBy.getURI() + "> " + source + " .";
|
|
||||||
|
n3String += node + " core:hasConceptSemanticType " + conceptSemanticTypeURI + " ." +
|
||||||
|
conceptSemanticTypeURI + " core:isConceptSemanticTypeOf " + node + ". " +
|
||||||
|
conceptSemanticTypeURI + " <" + RDFS.label.getURI() + "> " + conceptSemanticTypeLabel + " .\n" +
|
||||||
|
conceptSemanticTypeURI + " <" + RDF.type.getURI() + "> core:ConceptSemanticType .\n" ;
|
||||||
|
|
||||||
n3Optional.add(n3String);
|
n3Optional.add(n3String);
|
||||||
}
|
}
|
||||||
//Already have n3 required so need to add to that
|
//Already have n3 required so need to add to that
|
||||||
|
@ -357,33 +468,71 @@ public class AddAssociatedConceptsPreprocessor extends
|
||||||
//This will either generate or retrieve URIs for the concept semantic type labels if they exist
|
//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
|
//We will then update the submission to include this
|
||||||
private String getConceptSemanticTypeURIValues() {
|
private String getConceptSemanticTypeURIValues() {
|
||||||
List<String> conceptSemanticTypeURIs = new ArrayList<String>();
|
|
||||||
String[] conceptSemanticTypeLabels = convertDelimitedStringToArray(conceptSemanticTypeLabelValues);
|
String[] conceptSemanticTypeLabels = convertDelimitedStringToArray(conceptSemanticTypeLabelValues);
|
||||||
|
//keep track of unique labels
|
||||||
|
HashSet<String> allSemanticTypeLabels = new HashSet<String>();
|
||||||
int numberLabels = conceptSemanticTypeLabels.length;
|
int numberLabels = conceptSemanticTypeLabels.length;
|
||||||
|
String pseudoInputString = "";
|
||||||
for(int i = 0; i < numberLabels; i++) {
|
for(int i = 0; i < numberLabels; i++) {
|
||||||
String label = conceptSemanticTypeLabels[i];
|
String label = conceptSemanticTypeLabels[i];
|
||||||
|
//if label not already in the hash, then create key
|
||||||
|
if(!allSemanticTypeLabels.contains(label)) {
|
||||||
|
|
||||||
|
}
|
||||||
//Make or retrieve URI for this label
|
//Make or retrieve URI for this label
|
||||||
String uri = getURIForSemanticTypeLabel(label);
|
String uri = getURIForSemanticTypeLabel(label);
|
||||||
conceptSemanticTypeURIs.add(uri);
|
if(i != 0) {
|
||||||
|
pseudoInputString += ",";
|
||||||
|
}
|
||||||
|
pseudoInputString += uri;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set uris as string
|
String[] urisToAdd = new String[1];
|
||||||
//Essentially this will allow the URI to be put in scope
|
urisToAdd[0] = pseudoInputString;
|
||||||
return conceptSemanticTypeURIs.toString();
|
log.debug("uris to add" + pseudoInputString);
|
||||||
|
submission.addUriToForm(this.editConfiguration, "conceptSemanticTypeURI", urisToAdd);
|
||||||
|
return pseudoInputString;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getURIForSemanticTypeLabel(String label) {
|
private String getURIForSemanticTypeLabel(String label) {
|
||||||
//Check if system has an individual with this URI
|
String existingURI = this.getExistingSemanticTypeURI(label);
|
||||||
//
|
if(existingURI != null) {
|
||||||
List<Individual> individualsWithLabel = this.wadf.getIndividualDao().getIndividualsByDataProperty(RDFS.label.getURI(), label);
|
return existingURI;
|
||||||
//We are only interested in semantic type objects and this may return multiple elements (perhaps too many?
|
}
|
||||||
//getting the model requires servlet and context and we don't want to pass that here do we//Return all semantic type objects with this label
|
//if we leave this as null, we should be able to generate a new resource
|
||||||
//this.modelSelector.
|
//empty string because there may be more than one value returned for labels
|
||||||
return null;
|
else return "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getExistingSemanticTypeURI(String label) {
|
||||||
|
String queryStr = "SELECT ?semanticType WHERE { ?semanticType <" + RDF.type.getURI() + "> <http://vivoweb.org/ontology/core#ConceptSemanticType> . " +
|
||||||
|
"?semanticType <" + RDFS.label.getURI() + "> \"" + label + "\"^^<http://www.w3.org/2001/XMLSchema#string> . }";
|
||||||
|
QueryExecution qe = null;
|
||||||
|
try{
|
||||||
|
Query query = QueryFactory.create(queryStr);
|
||||||
|
qe = QueryExecutionFactory.create(query, this.ontModel);
|
||||||
|
ResultSet results = null;
|
||||||
|
results = qe.execSelect();
|
||||||
|
|
||||||
|
while( results.hasNext()){
|
||||||
|
QuerySolution qs = results.nextSolution();
|
||||||
|
if(qs.get("semanticType") != null) {
|
||||||
|
Resource semanticTypeURI = qs.getResource("semanticType");
|
||||||
|
log.debug("Semantic Type URI returned " + semanticTypeURI.getURI());
|
||||||
|
return semanticTypeURI.getURI();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}catch(Exception ex){
|
||||||
|
throw new Error("Error in executing query string: \n" + queryStr + '\n' + ex.getMessage());
|
||||||
|
}finally{
|
||||||
|
if( qe != null)
|
||||||
|
qe.close();
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
|
Loading…
Add table
Reference in a new issue