continuing work on VIVO-60 application ontology support for property/class combinations

This commit is contained in:
brianjlowe 2013-06-21 16:47:42 -04:00
parent 4341d72ec4
commit e3fe0ac52b
7 changed files with 167 additions and 54 deletions

View file

@ -15,6 +15,8 @@ public interface ObjectPropertyDao extends PropertyDao {
public ObjectProperty getObjectPropertyByURI(String objectPropertyURI); public ObjectProperty getObjectPropertyByURI(String objectPropertyURI);
public ObjectProperty getObjectPropertyByURIAndRangeURI(String objectPropertyURI, String rangeURI);
public List <ObjectProperty> getObjectPropertiesForObjectPropertyStatements(List /*of ObjectPropertyStatement */ objectPropertyStatements); public List <ObjectProperty> getObjectPropertiesForObjectPropertyStatements(List /*of ObjectPropertyStatement */ objectPropertyStatements);
public List<String> getSuperPropertyURIs(String objectPropertyURI, boolean direct); public List<String> getSuperPropertyURIs(String objectPropertyURI, boolean direct);

View file

@ -49,6 +49,11 @@ class ObjectPropertyDaoFiltering extends BaseFiltering implements ObjectProperty
return (newOprop == null) ? null : new ObjectPropertyFiltering(newOprop, filters); return (newOprop == null) ? null : new ObjectPropertyFiltering(newOprop, filters);
} }
public ObjectProperty getObjectPropertyByURIAndRangeURI(String objectPropertyURI, String rangeURI) {
ObjectProperty newOprop=innerObjectPropertyDao.getObjectPropertyByURIAndRangeURI(objectPropertyURI, rangeURI);
return (newOprop == null) ? null : new ObjectPropertyFiltering(newOprop, filters);
}
public List<ObjectPropertyStatement> getStatementsUsingObjectProperty(ObjectProperty op) { public List<ObjectPropertyStatement> getStatementsUsingObjectProperty(ObjectProperty op) {
return ObjectPropertyStatementDaoFiltering.filterAndWrapList(innerObjectPropertyDao.getStatementsUsingObjectProperty(op),filters); return ObjectPropertyStatementDaoFiltering.filterAndWrapList(innerObjectPropertyDao.getStatementsUsingObjectProperty(op),filters);
} }

View file

@ -28,6 +28,8 @@ import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution; 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.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
@ -282,6 +284,65 @@ public class ObjectPropertyDaoJena extends PropertyDaoJena implements ObjectProp
} }
} }
public ObjectProperty getObjectPropertyByURIAndRangeURI(String propertyURI, String rangeURI) {
ObjectProperty op = getObjectPropertyByURI(propertyURI);
if (op == null) {
return op;
}
op.setRangeVClassURI(rangeURI);
String propQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
"PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" +
"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" +
"SELECT ?range ?label ?group ?customForm ?displayLevel ?updateLevel WHERE { \n" +
" ?context config:configContextFor <" + propertyURI + "> . \n" +
" ?context config:qualifiedBy <" + rangeURI + "> . \n" +
" ?context config:hasConfiguration ?configuration . \n" +
" OPTIONAL { ?configuration config:propertyGroup ?group } \n" +
" OPTIONAL { ?configuration config:displayName ?label } \n" +
" OPTIONAL { ?configuration vitro:customEntryFormAnnot ?customForm } \n" +
" OPTIONAL { ?configuration vitro:hiddenFromDisplayBelowRoleLevelAnnot ?displayLevel } \n" +
" OPTIONAL { ?configuration vitro:prohibitedFromUpdateBelowRoleLevelAnnot ?updateLevel } \n" +
"}";
Query q = QueryFactory.create(propQuery);
QueryExecution qe = QueryExecutionFactory.create(q, getOntModelSelector().getDisplayModel());
try {
ResultSet rs = qe.execSelect();
if (rs.hasNext()) {
QuerySolution qsoln = rs.nextSolution();
log.debug(qsoln);
Resource groupRes = qsoln.getResource("group");
if (groupRes != null) {
op.setGroupURI(groupRes.getURI());
}
Resource displayLevelRes = qsoln.getResource("displayLevel");
if (displayLevelRes != null) {
op.setHiddenFromDisplayBelowRoleLevel(
BaseResourceBean.RoleLevel.getRoleByUri(
displayLevelRes.getURI()));
}
Resource updateLevelRes = qsoln.getResource("updateLevel");
if (updateLevelRes != null) {
op.setProhibitedFromUpdateBelowRoleLevel(
BaseResourceBean.RoleLevel.getRoleByUri(
updateLevelRes.getURI()));
}
Literal labelLit = qsoln.getLiteral("label");
if (labelLit != null) {
op.setDomainPublic(labelLit.getLexicalForm());
}
Literal customFormLit = qsoln.getLiteral("customForm");
if (customFormLit != null) {
op.setCustomEntryForm(customFormLit.getLexicalForm());
}
}
} finally {
qe.close();
}
return op;
}
public List<ObjectProperty> getObjectPropertiesForObjectPropertyStatements(List objPropertyStmts) { public List<ObjectProperty> getObjectPropertiesForObjectPropertyStatements(List objPropertyStmts) {
if( objPropertyStmts == null || objPropertyStmts.size() < 1) return new ArrayList(); if( objPropertyStmts == null || objPropertyStmts.size() < 1) return new ArrayList();
HashMap<String,ObjectProperty> hash = new HashMap<String,ObjectProperty>(); HashMap<String,ObjectProperty> hash = new HashMap<String,ObjectProperty>();

View file

@ -30,6 +30,7 @@ import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.Syntax; import com.hp.hpl.jena.query.Syntax;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource; 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.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.shared.Lock;
@ -706,55 +707,27 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
// make the PropertyInstance objects // make the PropertyInstance objects
for (String propertyURI : applicableProperties.keySet()) { for (String propertyURI : applicableProperties.keySet()) {
OntProperty op = ontModel OntProperty op = ontModel
.getOntProperty(propertyURI); .getOntProperty(propertyURI);
if (op == null) { if (op == null) {
continue; continue;
} }
String domainURIStr = getURIStr(op.getDomain()); Resource[] foundRanges = applicableProperties.get(propertyURI);
Resource[] foundRanges = applicableProperties.get(propertyURI); Resource rangeRes = (foundRanges[0] != null)
Resource rangeRes = (foundRanges[0] != null) ? foundRanges[0]
? foundRanges[0] : (op.getRange() == null && foundRanges[1] != null)
: (op.getRange() == null && foundRanges[1] != null) ? foundRanges[1]
? foundRanges[1] : op.getRange();
: op.getRange(); propInsts.add(getPropInstForPropertyAndRange(op, rangeRes, applicableProperties));
PropertyInstance pi = new PropertyInstance(); List<String> additionalFauxSubpropertyRangeURIs = getAdditionalFauxSubpropertyRangeURIsForPropertyURI(propertyURI);
if (rangeRes != null) { for (String rangeURI : additionalFauxSubpropertyRangeURIs) {
String rangeClassURI; if (getWebappDaoFactory().getVClassDao().isSubClassOf(rangeURI, rangeRes.getURI())) {
if (rangeRes.isAnon()) { propInsts.add(getPropInstForPropertyAndRange(
rangeClassURI = PSEUDO_BNODE_NS + rangeRes.getId() op, ResourceFactory.createResource(rangeURI), applicableProperties));
.toString(); }
} else { }
rangeClassURI = rangeRes.getURI();
}
pi.setRangeClassURI(rangeClassURI);
VClass range = getWebappDaoFactory().getVClassDao()
.getVClassByURI(rangeClassURI);
if (range == null) {
range = new VClass();
range.setURI(rangeClassURI);
range.setName(range.getLocalName());
}
pi.setRangeClassName(range.getName());
} else {
pi.setRangeClassURI(OWL.Thing.getURI()); // TODO see above
}
pi.setDomainClassURI(domainURIStr);
VClass domain = getWebappDaoFactory().getVClassDao()
.getVClassByURI(domainURIStr);
if (domain == null) {
domain = new VClass();
domain.setURI(domainURIStr);
domain.setName(domain.getLocalName());
}
pi.setDomainClassName(domain.getName());
pi.setSubjectSide(true);
pi.setPropertyURI(op.getURI());
pi.setPropertyName(getLabelOrId(op)); // TODO
pi.setRangePublic(getLabelOrId(op));
pi.setDomainPublic(getLabelOrId(op));
propInsts.add(pi);
} }
} finally { } finally {
ontModel.leaveCriticalSection(); ontModel.leaveCriticalSection();
} }
@ -763,6 +736,72 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
} }
private PropertyInstance getPropInstForPropertyAndRange(OntProperty op, Resource rangeRes,
Map<String, Resource[]> applicableProperties) {
PropertyInstance pi = new PropertyInstance();
String domainURIStr = getURIStr(op.getDomain());
if (rangeRes != null) {
String rangeClassURI;
if (rangeRes.isAnon()) {
rangeClassURI = PSEUDO_BNODE_NS + rangeRes.getId()
.toString();
} else {
rangeClassURI = rangeRes.getURI();
}
pi.setRangeClassURI(rangeClassURI);
VClass range = getWebappDaoFactory().getVClassDao()
.getVClassByURI(rangeClassURI);
if (range == null) {
range = new VClass();
range.setURI(rangeClassURI);
range.setName(range.getLocalName());
}
pi.setRangeClassName(range.getName());
} else {
pi.setRangeClassURI(OWL.Thing.getURI()); // TODO see above
}
pi.setDomainClassURI(domainURIStr);
VClass domain = getWebappDaoFactory().getVClassDao()
.getVClassByURI(domainURIStr);
if (domain == null) {
domain = new VClass();
domain.setURI(domainURIStr);
domain.setName(domain.getLocalName());
}
pi.setDomainClassName(domain.getName());
pi.setSubjectSide(true);
pi.setPropertyURI(op.getURI());
pi.setPropertyName(getLabelOrId(op)); // TODO
pi.setRangePublic(getLabelOrId(op));
pi.setDomainPublic(getLabelOrId(op));
return pi;
}
private List<String> getAdditionalFauxSubpropertyRangeURIsForPropertyURI(String propertyURI) {
List<String> rangeURIs = new ArrayList<String>();
String propQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
"PREFIX config: <http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationConfiguration#> \n" +
"PREFIX vitro: <http://vitro.mannlib.cornell.edu/ns/vitro/0.7#> \n" +
"SELECT ?range WHERE { \n" +
" ?context config:configContextFor <" + propertyURI + "> . \n" +
" ?context config:qualifiedBy ?range . \n" +
"}";
Query q = QueryFactory.create(propQuery);
QueryExecution qe = QueryExecutionFactory.create(q, getOntModelSelector().getDisplayModel());
try {
ResultSet rs = qe.execSelect();
while (rs.hasNext()) {
QuerySolution qsoln = rs.nextSolution();
Resource rangeRes = qsoln.getResource("range");
rangeURIs.add(rangeRes.getURI());
}
} finally {
qe.close();
}
return rangeURIs;
}
private String getURIStr(Resource res) { private String getURIStr(Resource res) {
String URIStr; String URIStr;
if (res == null) { if (res == null) {

View file

@ -47,6 +47,7 @@ public class SimpleOntModelSelector implements OntModelSelector {
this.applicationMetadataModel = ontModel; this.applicationMetadataModel = ontModel;
this.tboxModel = ontModel; this.tboxModel = ontModel;
this.userAccountsModel = ontModel; this.userAccountsModel = ontModel;
this.displayModel = ontModel;
} }
public void setABoxModel(OntModel m) { public void setABoxModel(OntModel m) {

View file

@ -183,7 +183,7 @@ public class GroupedPropertyList extends BaseTemplateModel {
if (pi != null) { if (pi != null) {
if (!alreadyOnObjectPropertyList( if (!alreadyOnObjectPropertyList(
populatedObjectPropertyList, pi)) { populatedObjectPropertyList, pi)) {
addObjectPropertyToPropertyList(pi.getPropertyURI(), addObjectPropertyToPropertyList(pi.getPropertyURI(), pi.getRangeClassURI(),
propertyList); propertyList);
} }
} else { } else {
@ -199,7 +199,7 @@ public class GroupedPropertyList extends BaseTemplateModel {
// constitute a special case (i.e., included in piDao.getAllPossiblePropInstForIndividual()). // constitute a special case (i.e., included in piDao.getAllPossiblePropInstForIndividual()).
for (String propertyUri : VITRO_PROPS_TO_ADD_TO_LIST) { for (String propertyUri : VITRO_PROPS_TO_ADD_TO_LIST) {
if (!alreadyOnPropertyList(propertyList, propertyUri)) { if (!alreadyOnPropertyList(propertyList, propertyUri)) {
addObjectPropertyToPropertyList(propertyUri, propertyList); addObjectPropertyToPropertyList(propertyUri, null, propertyList);
} }
} }
} }
@ -217,10 +217,10 @@ public class GroupedPropertyList extends BaseTemplateModel {
return false; return false;
} }
private void addObjectPropertyToPropertyList(String propertyUri, private void addObjectPropertyToPropertyList(String propertyUri, String rangeUri,
List<Property> propertyList) { List<Property> propertyList) {
ObjectPropertyDao opDao = wdf.getObjectPropertyDao(); ObjectPropertyDao opDao = wdf.getObjectPropertyDao();
ObjectProperty op = opDao.getObjectPropertyByURI(propertyUri); ObjectProperty op = opDao.getObjectPropertyByURIAndRangeURI(propertyUri, rangeUri);
if (op == null) { if (op == null) {
log.error("ObjectProperty op returned null from opDao.getObjectPropertyByURI(" + propertyUri + ")"); log.error("ObjectProperty op returned null from opDao.getObjectPropertyByURI(" + propertyUri + ")");
} else if (op.getURI() == null) { } else if (op.getURI() == null) {

View file

@ -66,6 +66,11 @@ public class ObjectPropertyDaoStub implements ObjectPropertyDao {
return opMap.get(objectPropertyURI); return opMap.get(objectPropertyURI);
} }
@Override
public ObjectProperty getObjectPropertyByURIAndRangeURI(String objectPropertyURI, String rangeURI) {
return getObjectPropertyByURI(objectPropertyURI);
}
@Override @Override
public String getCustomListViewConfigFileName(ObjectProperty objectProperty) { public String getCustomListViewConfigFileName(ObjectProperty objectProperty) {
if (objectProperty == null) { if (objectProperty == null) {