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 getObjectPropertyByURIAndRangeURI(String objectPropertyURI, String rangeURI);
public List <ObjectProperty> getObjectPropertiesForObjectPropertyStatements(List /*of ObjectPropertyStatement */ objectPropertyStatements);
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);
}
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) {
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.ResultSet;
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.RDFNode;
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) {
if( objPropertyStmts == null || objPropertyStmts.size() < 1) return new ArrayList();
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.rdf.model.RDFNode;
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.StmtIterator;
import com.hp.hpl.jena.shared.Lock;
@ -711,14 +712,34 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
if (op == null) {
continue;
}
String domainURIStr = getURIStr(op.getDomain());
Resource[] foundRanges = applicableProperties.get(propertyURI);
Resource rangeRes = (foundRanges[0] != null)
? foundRanges[0]
: (op.getRange() == null && foundRanges[1] != null)
? foundRanges[1]
: op.getRange();
propInsts.add(getPropInstForPropertyAndRange(op, rangeRes, applicableProperties));
List<String> additionalFauxSubpropertyRangeURIs = getAdditionalFauxSubpropertyRangeURIsForPropertyURI(propertyURI);
for (String rangeURI : additionalFauxSubpropertyRangeURIs) {
if (getWebappDaoFactory().getVClassDao().isSubClassOf(rangeURI, rangeRes.getURI())) {
propInsts.add(getPropInstForPropertyAndRange(
op, ResourceFactory.createResource(rangeURI), applicableProperties));
}
}
}
} finally {
ontModel.leaveCriticalSection();
}
return propInsts;
}
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()) {
@ -753,14 +774,32 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao {
pi.setPropertyName(getLabelOrId(op)); // TODO
pi.setRangePublic(getLabelOrId(op));
pi.setDomainPublic(getLabelOrId(op));
propInsts.add(pi);
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 {
ontModel.leaveCriticalSection();
qe.close();
}
return propInsts;
return rangeURIs;
}
private String getURIStr(Resource res) {

View file

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

View file

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

View file

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