What I am trying to do is list all the classes using the following query in an owl file which I created using Protege 5 and has "foaf" as imported ontology.
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT DISTINCT ?subject ?label ?comment
WHERE
{
?subject a owl:Class
OPTIONAL { ?subject a rdfs:Class }
OPTIONAL { ?subject rdfs:label ?label }
OPTIONAL { ?subject rdfs:comment ?comment}
}
Problem is, when I run this query in SPARQL tab of Protege I get all the classes defined in "foaf" namespace but when I try to run the same query using dotnetrdf api in c# I don't get the same result.
Following is my code in c#
var g = new Graph();
g.LoadFromFile(owlFile, new TurtleParser());
ISparqlDataset ds = new InMemoryDataset(g);
LeviathanQueryProcessor processor = new LeviathanQueryProcessor(ds);
var queryParser = new SparqlQueryParser();
var parmeterizedString = new SparqlParameterizedString(query);
parmeterizedString.SetLiteral("value", searchQuery);
return processor.ProcessQuery(queryParser.ParseFromString(parmeterizedString.ToString())) as SparqlResultSet;
What am i doing wrong ?
Just parsing a file does not cause owl:imports statements to be followed. The query engine is not OWL-sensitive.
g.LoadFromFile(owlFile, new TurtleParser());
https://github.com/dotnetrdf/dotnetrdf/wiki/HowTo-Load-OWL
While dotNetRDF does not support OWL in terms of axioms, OWL ontologies and reasoning
LoadFromFile
reads the RDF statements that encode the ontology. There is no OWL-level processing, and that includes processing owl:imports
.
You can simulate this by finding owl:imports statement and reading the link into g
. This is not perfect but, from the original description, may be what is wanted.