diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java index 05c224030..81e3fe9d5 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java @@ -2,6 +2,8 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena; +import static edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY; + import java.io.InputStream; import java.sql.Timestamp; import java.text.Collator; @@ -817,8 +819,8 @@ public class IndividualSDB extends IndividualImpl implements Individual { } @Override - public List getVClasses(boolean direct) { - if (direct) { + public List getVClasses(boolean assertedOnly) { + if (assertedOnly) { if (directVClasses != null) { return directVClasses; } else { @@ -835,34 +837,19 @@ public class IndividualSDB extends IndividualImpl implements Individual { } } - private List getMyVClasses(boolean direct) { + private List getMyVClasses(boolean assertedOnly) { List vClassList = new ArrayList(); Model tempModel = null; if (ind.getModel().contains((Resource) null, RDF.type, (RDFNode) null)){ tempModel = ind.getModel(); } else { - String[] graphVars = { "?g" }; - String getTypes = - "CONSTRUCT{ <" + this.individualURI + "> <" + RDF.type + - "> ?types }\n" + - "WHERE{ { GRAPH ?g" - + " { <" + this.individualURI +"> <" +RDF.type+ "> ?types } \n" - + WebappDaoFactorySDB.getFilterBlock( - graphVars, (direct - ? WebappDaoFactorySDB.SDBDatasetMode - .ASSERTIONS_ONLY - : datasetMode)) - + "} \n" - // GRAPH-less pattern to support retrieving inferred types - // from the unnamed base graph, as in Sesame and OWLIM - + ((datasetMode.equals(WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY)) - ? "" : "UNION { <" + this.individualURI +"> <" +RDF.type+ "> ?types }" ) - + "} \n"; + String getTypesQuery = buildMyVClassesQuery(assertedOnly); + RDFService service = webappDaoFactory.getRDFService(); try { tempModel = RDFServiceUtils.parseModel( service.sparqlConstructQuery( - getTypes, RDFService.ModelSerializationFormat.N3), + getTypesQuery, RDFService.ModelSerializationFormat.N3), RDFService.ModelSerializationFormat.N3); } catch (RDFServiceException e) { throw new RuntimeException(e); @@ -884,7 +871,7 @@ public class IndividualSDB extends IndividualImpl implements Individual { ArrayList done = new ArrayList(); /* Loop for comparing starts here */ - if(direct){ + if(assertedOnly){ while(!directTypes){ itr = list.listIterator(); @@ -943,6 +930,36 @@ public class IndividualSDB extends IndividualImpl implements Individual { return vClassList; } + + /** + * If we are restricting to asserted types, either by request or by dataset + * mode, then filter by graph and include a UNION clause to support + * retrieving inferred types from the unnamed base graph, as in Sesame and + * OWLIM. + */ + private String buildMyVClassesQuery(boolean assertedOnly) { + SDBDatasetMode queryMode = assertedOnly ? ASSERTIONS_ONLY : datasetMode; + + String filterBlock = WebappDaoFactorySDB.getFilterBlock(new String[] { "?g" }, queryMode); + + if (filterBlock.isEmpty()) { + return + "CONSTRUCT { <" + this.individualURI + "> " + "<" + RDF.type + "> ?types }\n" + + "WHERE { <" + this.individualURI +"> <" +RDF.type+ "> ?types } \n"; + } else { + String unionBlock = (queryMode.equals(ASSERTIONS_ONLY)) ? + "" : + "UNION { <" + this.individualURI +"> <" +RDF.type+ "> ?types }"; + return + "CONSTRUCT{ <" + this.individualURI + "> " + "<" + RDF.type + "> ?types }\n" + + "WHERE{ { GRAPH ?g" + + " { <" + this.individualURI +"> <" +RDF.type+ "> ?types } \n" + + filterBlock + + "} \n" + + unionBlock + + "} \n"; + } + } /** * The base method in {@link IndividualImpl} is adequate if the reasoner is diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java index c7d6197ee..eeba74a12 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java @@ -129,12 +129,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { .append("&& ").append(graphVars[i]).append(" != <") .append(ModelNames.TBOX_INFERENCES) .append(">") - .append("&& ").append(graphVars[i]).append(" != <") - .append(SimpleReasonerSetup.JENA_INF_MODEL_REBUILD) - .append(">") - .append("&& ").append(graphVars[i]).append(" != <") - .append(SimpleReasonerSetup.JENA_INF_MODEL_SCRATCHPAD) - .append(">") .append(") ) \n"); break; case INFERENCES_ONLY : diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/exclusions/ExcludeBasedOnType.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/exclusions/ExcludeBasedOnType.java index 15eda7f25..d5abfdce1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/exclusions/ExcludeBasedOnType.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/searchindex/exclusions/ExcludeBasedOnType.java @@ -12,11 +12,8 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property; /** - * Exclude individual from search index if it is a member of any of the the - * types. - * - * @author bdc34 - * + * Exclude individual from search index if it is a member of any of the + * excluding types. */ public class ExcludeBasedOnType implements SearchIndexExcluder { @@ -34,13 +31,10 @@ public class ExcludeBasedOnType implements SearchIndexExcluder { if (ind == null) { return DONT_EXCLUDE; } - if (typeURIinExcludeList(ind.getVClass())) { - return SKIP_MSG + ind.getVClass(); - } List vclasses = new ArrayList<>(); + vclasses.add(ind.getVClass()); addToList(vclasses, ind.getVClasses()); - addToList(vclasses, ind.getVClasses(true)); for (VClass vclz : vclasses) { if (typeURIinExcludeList(vclz)) diff --git a/webapp/test/edu/cornell/mannlib/vitro/webapp/searchindex/exclusions/ExcludeBasedOnTypeTest.java b/webapp/test/edu/cornell/mannlib/vitro/webapp/searchindex/exclusions/ExcludeBasedOnTypeTest.java index 052cd246c..9c031e735 100644 --- a/webapp/test/edu/cornell/mannlib/vitro/webapp/searchindex/exclusions/ExcludeBasedOnTypeTest.java +++ b/webapp/test/edu/cornell/mannlib/vitro/webapp/searchindex/exclusions/ExcludeBasedOnTypeTest.java @@ -44,7 +44,7 @@ public class ExcludeBasedOnTypeTest { vClassList.add( new VClass("http://example.com/Robot")); vClassList.add( new VClass("http://example.com/KillerRobot")); vClassList.add( new VClass("http://example.com/Droid")); - ind.setVClasses(vClassList, true); + ind.setVClasses(vClassList, false); String excludeResult = ebot.checkForExclusion(ind); assertNotNull( excludeResult ); @@ -79,7 +79,7 @@ public class ExcludeBasedOnTypeTest { vClassList.add( new VClass("http://example.com/Robot")); vClassList.add( new VClass("http://example.com/KillerRobot")); vClassList.add( new VClass("http://example.com/Droid")); - ind.setVClasses(vClassList, true); + ind.setVClasses(vClassList, false); String excludeResult = ebot.checkForExclusion(ind); assertNull( excludeResult );