I'm trying to run SPARQL queries on my self-made ontology in protege, I have stored the data in TDB persistent storage and so far I assume that data is being successfully stored in it. I have run several SPARQL queries of the same ontology file in Jena Fuseki and all of them are working, but unfortunately, whenever I try to run the same SPARQL queries over this dataset it shows me the null value error as shown in the question above. I would really appreciate if anyone helps me in this matter and be very specific as I'm relatively new and very inexperienced in the field of semantic web. following is the code of my TDB file.
package jena;
import java.util.Iterator;
import org.apache.jena.query.Dataset;
import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.query.ResultSetFormatter;
import org.apache.jena.rdf.model.*;
import org.apache.jena.tdb.TDB;
import org.apache.jena.util.FileManager;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.tdb.TDBFactory;
//import com.hp.hpl.jena.util.FileManager;
public class tdb {
public static void main(String[] args)
{
new tdb().storetdbdata();
new tdb().loadtdbdata();
new tdb().viasparql();
}
public void storetdbdata()
{
String directory = "c:/users/shahrukh/databases";
Dataset dataset = TDBFactory.createDataset(directory);
Model tdb = dataset.getDefaultModel();
//Model tdb = dataset.getNamedGraph( "graph42" );
String source ="e:/university work/fyp/sdd folder/my sdd/university.owl";
FileManager.get().loadModel(source);
//FileManager.get().readModel( tdb, source);
//dataset.commit();
TDB.sync(dataset);
tdb.close();
dataset.close();
}
public void loadtdbdata()
{
String directory = "c:/users/shahrukh/databases";
Dataset dataset = TDBFactory.createDataset(directory) ;
Iterator<String> graphNames = dataset.listNames();
while (graphNames.hasNext()) {
String graphName = graphNames.next();
System.out.println(graphName);
}
}
public void viasparql()
{
String directory = "c:/users/shahrukh/databases" ;
Dataset dataset = TDBFactory.createDataset(directory) ;
String sparqlQueryString = "SELECT (count(*) AS ?count) { ?s ?p ?o }" ;
/*String sparqlQueryString="PREFIX st: <http://www.semanticweb.org/shahrukh/ontologies/2017/4/university.owl#>"+
"PREFIX foaf: <http://www.semanticweb.org/shahrukh/ontologies/2017/4/university.owl#>"+
"PREFIX rdf: <http://www.semanticweb.org/shahrukh/ontologies/2017/4/university.owl#>" +
"SELECT ?y WHERE { <http://www.semanticweb.org/shahrukh/ontologies/2017/4/university.owl#JawadMirza> rdf:first_name ?y. }";*/
//String sparqlQueryString="SELECT *";
//String sparqlQueryString="SELECT * { GRAPH ?g {} }";
String s2="PREFIX st: <http://www.semanticweb.org/shahrukh/ontologies/2017/4/university.owl#>" +
"SELECT ?first_name ?last_name WHERE { ?x st:first_name ?first_name ."
+ "?x st:last_name ?last_name" + "}";
String s="prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
"prefix owl: <http://www.w3.org/2002/07/owl#>" +
"prefix xsd: <http://www.w3.org/2001/XMLSchema#>" +
"SELECT ?s ?p ?o WHERE { ?s ?p ?o }";
String s3="SELECT ?s ?p ?o WHERE {?s HAS+ ?o FILTER ( ?s = <ID_6> )} ";
Query query = QueryFactory.create(s) ;
QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
QueryExecution qExe = QueryExecutionFactory.sparqlService( "http://10.0.2.2:3030/dataset.html?tab=upload&ds=/FYP", query );
ResultSet results = qexec.execSelect() ;
/*while (results.hasNext()) {
QuerySolution soln = (QuerySolution) results.nextSolution();
}*/
/*org.apache.jena.query.QuerySolution soln=results.nextSolution();
Literal first_name=(Literal) soln.getLiteral("?s");
System.out.println(first_name);*/
ResultSetFormatter.out(System.out,results,query) ;
}
}
Following are the exceptions I have been receiving:
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
WARN [main] (Log.java:80) - Binding.add: null value - ignored
-------------
| s | p | o |
=============
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
-------------