我已经对pizza本体上的SPARQL查询进行了测试,该查询工作正常。问题是当我尝试使用dotNetRDF在相同的本体文件上运行相同的查询时。该查询返回正确数量的结果,但它们似乎都为空。
有人可以指出这里的问题吗?
使用Protege查询结果
使用dotNetRDF查询结果:
这是我在C#中的代码:
OntologyGraph ontGraph = new OntologyGraph();
FileLoader.Load(ontGraph, "PizzaOntology.owl");
ontGraph.BaseUri = null;
#region SPARQL query
SparqlParameterizedString queryString = new SparqlParameterizedString();
queryString.Namespaces.AddNamespace("rdf", new Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#"));
queryString.Namespaces.AddNamespace("owl", new Uri("http://www.w3.org/2002/07/owl#"));
queryString.Namespaces.AddNamespace("rdfs", new Uri("http://www.w3.org/2000/01/rdf-schema#"));
queryString.Namespaces.AddNamespace("xsd", new Uri("http://www.w3.org/2001/XMLSchema#"));
queryString.Namespaces.AddNamespace("ont", new Uri("http://www.semanticweb.org/ontologies/pizza.owl#"));
queryString.CommandText = "SELECT ?subject";
queryString.CommandText += "WHERE { ?subject rdfs:subClassOf ont:PizzaBase }";
SparqlQueryParser parser = new SparqlQueryParser();
SparqlQuery query = parser.ParseFromString(queryString);
#endregion
#region Query Processor
TripleStore store = new TripleStore();
store.Add(ontGraph);
InMemoryDataset ds = new InMemoryDataset(store, true);
ISparqlQueryProcessor processor = new LeviathanQueryProcessor(ds);
object results = processor.ProcessQuery(query);
if (results is SparqlResultSet)
{
//Print out the Results
SparqlResultSet rset = (SparqlResultSet)results;
foreach (SparqlResult result in rset)
{
Console.WriteLine(result.ToString());
}
}
#endregion