diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyInstanceDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyInstanceDaoJena.java index afb57d6e9..eaa24d3da 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyInstanceDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyInstanceDaoJena.java @@ -19,6 +19,13 @@ import com.hp.hpl.jena.ontology.OntClass; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntProperty; import com.hp.hpl.jena.ontology.Restriction; +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.query.Syntax; import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.ResIterator; import com.hp.hpl.jena.rdf.model.Resource; @@ -246,11 +253,17 @@ public class PropertyInstanceDaoJena extends JenaBaseDao implements } } + List propertyList = new ArrayList(); // find properties with class in domain ResIterator pit = ontModel.listSubjectsWithProperty( RDFS.domain, ontClass); while (pit.hasNext()) { Resource prop = pit.nextResource(); + propertyList.add(prop); + } + propertyList.addAll( + getPropertiesWithUnionDomainIncluding(VClassURI)); + for (Resource prop : propertyList) { if (prop.getNameSpace() != null && !NONUSER_NAMESPACES.contains( prop.getNameSpace()) ) { @@ -327,6 +340,38 @@ public class PropertyInstanceDaoJena extends JenaBaseDao implements return propInsts; } + + /** + * requires SPARQL 1.1 (or ARQ) property path support + * @param vclassURI + * @return list of property resources with union domains that include the vclass + */ + private List getPropertiesWithUnionDomainIncluding(String vclassURI) { + List propertyResList = new ArrayList(); + String queryStr = + "PREFIX rdf: \n" + + "PREFIX rdfs: \n" + + "PREFIX owl: \n\n " + + "SELECT ?p WHERE { \n" + + " ?f rdf:first <" + vclassURI + "> . \n" + + " ?u rdf:rest* ?f . \n" + + " ?d owl:unionOf ?u . \n" + + " ?p rdfs:domain ?d . \n" + + "}"; + Query q = QueryFactory.create(queryStr, Syntax.syntaxSPARQL_11); + QueryExecution qe = QueryExecutionFactory.create( + q, getOntModelSelector().getTBoxModel()); + try { + ResultSet rs = qe.execSelect(); + while (rs.hasNext()) { + QuerySolution qs = rs.nextSolution(); + propertyResList.add(qs.getResource("p")); + } + } finally { + qe.close(); + } + return propertyResList; + } private String getURIStr(Resource res) { String URIStr;