Stardog returns reasoning results even if the database is empty

Hi Stephen,

Glad that my problem can help reproduce the bug. :slight_smile:

Yes, I was using DL reasoning. I have switched to SL reasoning, and the expected correct results are produced! It worked like a charm. You rock!

However, my application also requires to use reasoning explanation, which doesn’t work under SL. Let me show you my code with reasoning explanation.

SIBenchMini.java

package com.sibench.mini;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.openrdf.model.Model;
import org.openrdf.model.Statement;
import org.openrdf.query.BindingSet;
import org.openrdf.query.TupleQueryResult;
import org.openrdf.rio.RDFFormat;

import com.complexible.common.openrdf.model.Models2;
import com.complexible.common.rdf.model.Values;
import com.complexible.stardog.reasoning.Proof;
import com.complexible.stardog.reasoning.ProofType;
import com.complexible.common.rdf.model.StardogValueFactory.RDF;

public class SIBenchMini {
	
	public static void main(String[] args) throws IOException {
		String query = "PREFIX ub: <http://swat.cse.lehigh.edu/onto/univ-bench.owl#> SELECT ?s WHERE { ?s rdf:type ub:Chair . }";
		SnarlClient client = new SnarlClient();
		client.loadData("./file/ontology/univ-bench.owl", RDFFormat.RDFXML);
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("./file/data/data.rdfstream"))));
		String aDataLine = "";
		int counter = 1;
		while((aDataLine = br.readLine()) != null) {
			Pattern pattern = Pattern.compile("<([:.\\/\\-#A-Za-z\\d]+)>\\s<([:.\\/\\-#A-Za-z\\d]+)>\\s[<\"]?([@:.\\/\\-#A-Za-z\\d]+)[>\"]?\\s<([:.\\/\\-#A-Za-z\\d]+)>\\s(\\d+:[\\d.:]+)\\s?(\\d+:[\\d.:]+)?\\s?([\\d.]+)?");
			Matcher match = pattern.matcher(aDataLine);
			if(match.find()) {
				String s = match.group(1);
				String p = match.group(2);
				String o = match.group(3);
				String g = match.group(4);
				// create model
				Model dataModel = null;
				if(o.contains("http")) { dataModel = Models2.newModel(Values.statement(Values.iri(s),Values.iri(p),Values.iri(o))); }
				else { dataModel = Models2.newModel(Values.statement(Values.iri(s),Values.iri(p),Values.literal(o))); }
				client.addModel(dataModel, g);
			}
			if(counter % 303 == 0) { // load 303 triples each time
				System.out.println("iteration " + counter / 303);
				TupleQueryResult result = client.query(query, true);
				while(result.hasNext()) {
					BindingSet bs = result.next();
					// newly added code --> explain the results using SL reasoning in database. 
					Iterator<Proof> proof_itr = client.explain(Values.statement(Values.iri(bs.getValue("s").stringValue()), RDF.TYPE, Values.iri("http://swat.cse.lehigh.edu/onto/univ-bench.owl#Chair")));
					while(proof_itr.hasNext()) {
						Proof aproof = proof_itr.next();
						aproof.getExpressions(ProofType.ASSERTED).forEach((e)->{
							Iterator<Statement> e_itr = e.iterator();
							e_itr.forEachRemaining((itr)->{
								System.out.println(itr.toString());
							});
						}); 
					}					
				}
				result.close();
				client.clearAllGraphs();
			}
			counter++;
		}
		br.close();		
	}
}

I have received the following error with SL reasoning explanation:

[Stardog INFO]connected to http://localhost:5820/db
[Stardog INFO]database cleaned
[Stardog INFO]database initialized
[Stardog INFO]data loaded from ./file/ontology/univ-bench.owl
iteration 1
Exception in thread "main" com.complexible.stardog.StardogException: Error getting content in response to inference explanation
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection.toProof(HttpReasoningConnection.java:301)
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection.getExplainResult(HttpReasoningConnection.java:277)
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection.executeExplain(HttpReasoningConnection.java:255)
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection.access$100(HttpReasoningConnection.java:77)
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection$1.proofs(HttpReasoningConnection.java:115)
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection$1.proofs(HttpReasoningConnection.java:112)
	at com.complexible.stardog.reasoning.AbstractStardogExplainer.proofs(AbstractStardogExplainer.java:62)
	at com.sibench.mini.SnarlClient.explain(SnarlClient.java:81)
	at com.sibench.mini.SIBenchMini.main(SIBenchMini.java:53)
Caused by: java.lang.NullPointerException
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection$ProofListDeserializer.toProofNode(HttpReasoningConnection.java:341)
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection$ProofListDeserializer.toProofNodes(HttpReasoningConnection.java:318)
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection$ProofListDeserializer.deserialize(HttpReasoningConnection.java:310)
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection$ProofListDeserializer.deserialize(HttpReasoningConnection.java:305)
	at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)
	at com.google.gson.Gson.fromJson(Gson.java:795)
	at com.complexible.stardog.protocols.http.reasoning.client.HttpReasoningConnection.toProof(HttpReasoningConnection.java:298)
	... 8 more

However, DL reasoning will return explanation as follows:

[Stardog INFO]connected to http://localhost:5820/db
[Stardog INFO]database cleaned
[Stardog INFO]database initialized
[Stardog INFO]data loaded from ./file/ontology/univ-bench.owl
iteration 1
(http://www.Department0.University0.edu, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://swat.cse.lehigh.edu/onto/univ-bench.owl#Department) [null]
(http://www.Department0.University0.edu/FullProfessor7, http://swat.cse.lehigh.edu/onto/univ-bench.owl#headOf, http://www.Department0.University0.edu) [null]
(http://swat.cse.lehigh.edu/onto/univ-bench.owl#publicationAuthor, http://www.w3.org/2000/01/rdf-schema#range, http://swat.cse.lehigh.edu/onto/univ-bench.owl#Person) [null]
(http://www.Department0.University0.edu/FullProfessor7/Publication7, http://swat.cse.lehigh.edu/onto/univ-bench.owl#publicationAuthor, http://www.Department0.University0.edu/FullProfessor7) [null]
(_:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_398, http://www.w3.org/2002/07/owl#intersectionOf, _:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_399) [null]
(http://swat.cse.lehigh.edu/onto/univ-bench.owl#Chair, http://www.w3.org/2002/07/owl#equivalentClass, _:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_398) [null]
(_:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_400, http://www.w3.org/1999/02/22-rdf-syntax-ns#rest, http://www.w3.org/1999/02/22-rdf-syntax-ns#nil) [null]
(_:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_400, http://www.w3.org/1999/02/22-rdf-syntax-ns#first, http://swat.cse.lehigh.edu/onto/univ-bench.owl#Person) [null]
(_:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_399, http://www.w3.org/1999/02/22-rdf-syntax-ns#rest, _:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_400) [null]
(_:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_398, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#Class) [null]
(_:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_399, http://www.w3.org/1999/02/22-rdf-syntax-ns#first, http://swat.cse.lehigh.edu/onto/univ-bench.owl#DepartmentHead) [null]
(http://swat.cse.lehigh.edu/onto/univ-bench.owl#DepartmentHead, http://www.w3.org/2002/07/owl#equivalentClass, _:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_401) [null]
(_:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_401, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#Restriction) [null]
(_:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_401, http://www.w3.org/2002/07/owl#onProperty, http://swat.cse.lehigh.edu/onto/univ-bench.owl#headOf) [null]
(_:bnode_773b6d6d_cc0e_4ae8_85e9_9f4d7d9359cb_401, http://www.w3.org/2002/07/owl#someValuesFrom, http://swat.cse.lehigh.edu/onto/univ-bench.owl#Department) [null]

So my situation:
using DL won’t produce correct results, but reasoning explanation works
using SL will produce correct results, but reasoning explanation doesn’t work.

Might this be also related to the bug that you mentioned?

Thank you,
Robert