Reputation: 123
I am working with Jena SPARQL API, and I want to execute queries on my RDF files after applying inference rules. I created a .rul
file that contains all my rules; now I want to run those rules and execute my queries. When I used OWL, I proceeded this way:
OntModel model1 = ModelFactory.createOntologyModel( OntModelSpec..OWL_MEM_MICRO_RULE_INF);
// read the RDF/XML file
model1.read( "./files/ontology.owl", "RDF/XML" );
model1.read( "./files/data.rdf", "RDF/XML" );
// Create a new query
String queryString =
".....my query";
Query query = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(query, model1);
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query);
I want to do the same thing with inferences rules, i.e., load my .rul
file like this:
model1.read( "./files/rules.rul", "RDF/XML" );
This didn't work with .rul
files, the rules are not executed. Any ideas how to load a .rul
file? Thanks in advance.
Upvotes: 0
Views: 305
Reputation: 16700
Jena rules aren't RDF, and you don't read them into a model.
RDFS is RDF, and it is implemented internally using rules.
To build an inference model:
Model baseData = ...
List<Rule> rules = Rule.rulesFromURL("file:YourRulesFile") ;
Reasoner reasoner = new GenericRuleReasoner(rules);
Model infModel = ModelFactory.createInfModel(reasoner, baseData) ;
See ModelFactory
for other ways to build models (e.g., RDFS inference) directly.
Upvotes: 1