@@ -55,26 +55,26 @@ public VerySimpleRdfsBackwardsChainingConnection(SailConnection wrappedCon,
5555 public boolean hasStatement (Resource subj , IRI pred , Value obj , boolean includeInferred , Resource ... contexts )
5656 throws SailException {
5757
58- if (rdfsSubClassOfReasoner == null && includeInferredStatements ) {
59- return super .hasStatement (subj , pred , obj , includeInferred , contexts );
58+ boolean includeBaseInferred = includeInferredStatements && includeInferred ;
59+ if (rdfsSubClassOfReasoner == null ) {
60+ return super .hasStatement (subj , pred , obj , includeBaseInferred , contexts );
6061 }
6162
62- boolean hasStatement = super .hasStatement (subj , pred , obj , false , contexts );
63+ boolean hasStatement = super .hasStatement (subj , pred , obj , includeBaseInferred , contexts );
6364
6465 if (hasStatement ) {
6566 return true ;
6667 }
6768
68- if (rdfsSubClassOfReasoner != null && includeInferred && obj != null && obj .isResource ()
69- && RDF .TYPE .equals (pred )) {
69+ if (obj != null && obj .isResource () && RDF .TYPE .equals (pred )) {
7070
7171 Set <Resource > types = rdfsSubClassOfReasoner .backwardsChain ((Resource ) obj );
7272 if (types .size () == 1 ) {
7373 return hasStatement ;
7474 }
7575 if (types .size () > 10 ) {
7676 try (CloseableIteration <? extends Statement > statements = super .getStatements (subj ,
77- RDF .TYPE , null , false , contexts )) {
77+ RDF .TYPE , null , includeBaseInferred , contexts )) {
7878 return statements .stream ()
7979 .map (Statement ::getObject )
8080 .filter (Value ::isResource )
@@ -84,7 +84,7 @@ public boolean hasStatement(Resource subj, IRI pred, Value obj, boolean includeI
8484 } else {
8585 return types
8686 .stream ()
87- .anyMatch (type -> super .hasStatement (subj , pred , type , false , contexts ));
87+ .anyMatch (type -> super .hasStatement (subj , pred , type , includeBaseInferred , contexts ));
8888 }
8989
9090 }
@@ -96,13 +96,14 @@ public boolean hasStatement(Resource subj, IRI pred, Value obj, boolean includeI
9696 public CloseableIteration <? extends Statement > getStatements (Resource subj , IRI pred , Value obj ,
9797 boolean includeInferred , Resource ... contexts ) throws SailException {
9898
99- if (rdfsSubClassOfReasoner != null && includeInferred && obj != null && obj .isResource ()
99+ boolean includeBaseInferred = includeInferredStatements && includeInferred ;
100+ if (rdfsSubClassOfReasoner != null && obj != null && obj .isResource ()
100101 && RDF .TYPE .equals (pred )) {
101102 Set <Resource > inferredTypes = rdfsSubClassOfReasoner .backwardsChain ((Resource ) obj );
102103 if (inferredTypes .size () > 1 ) {
103104
104105 CloseableIteration <Statement >[] statementsMatchingInferredTypes = inferredTypes .stream ()
105- .map (r -> super .getStatements (subj , pred , r , false , contexts ))
106+ .map (r -> super .getStatements (subj , pred , r , includeBaseInferred , contexts ))
106107 .toArray (CloseableIteration []::new );
107108
108109 return new LookAheadIteration <>() {
@@ -154,6 +155,6 @@ protected void handleClose() throws SailException {
154155 }
155156 }
156157
157- return super .getStatements (subj , pred , obj , includeInferred , contexts );
158+ return super .getStatements (subj , pred , obj , includeBaseInferred , contexts );
158159 }
159160}
0 commit comments