Hello, I could use some input on getting my first Jena rule working.
I have a simple test ontology here: http://mind-tap.net/kbswt/ruletest.ttl I apply this rule: @prefix : <http://mind-tap.net/kbswt/ruletest#>. [ chris1: (?s :isOutput ?p) -> (?s :meOutput ?p) ] And I run this SPARQL query PREFIX : <http://mind-tap.net/kbswt/ruletest#> select * where {?s :isOutput ?o. OPTIONAL {?s :meOutput ?x} } I was expecting to see a :meOutput value for ?x but I’m not. I have tried the different built in reasoners and in my test application I can see that the rules are applied to the reasoner that my SPARQL query is executing against. The application is basically following these steps #create my ontModel OntModelSpec ontModelSpec = new OntModelSpec( ModelFactory.createMemModelMaker(), null, RDFSRuleReasonerFactory.theInstance(), ProfileRegistry.OWL_DL_LANG); OntModel m = ModelFactory.createOntologyModel(ontModelSpec); m.read("http://mind-tap.net/kbswt/ruletest.ttl"); Then I use my ruleFromString class (a copy of the rulesFromURL updated to handle strings and show down below) to parse the rules and ontModel.getReasoner().setRules( [parsed rules list]) I next verify that the rules are applied to the reasoner by reading them back using a call to: reasoner.getRules(); and then I run my SPARQL on the ontModel. I have my code in the GUI and common folders in a GIT repository here: https://bitbucket.org/blackburnphd/ontometa/src. To use: 1) GUI has the main method. Run it 2) Setup the options on the Main tab and click init repository 3) Click the rule tab enter the rule and click “Replace” to clear the rules and add the rules listed in the rule text area 4) Click the SPARQL tab to enter and execute the SPARQL query. Hopefully it is simply a mis-understanding of how to create the rules. Any guidance would be appreciated. Thank you, Chris BTW, I think this class should be added to the Rule class. It took me a while to figure out that the Rule.parse(string) call did not handle prefixes. /** * Answer the list of rules parsed from the given string. * * @throws RulesetNotFoundException */ public static List<Rule> rulesFromString(String ruleInput) { BufferedReader br = null; try { StringReader sr = new StringReader(ruleInput); br = new BufferedReader(sr); return Rule.parseRules(Rule.rulesParserFromReader(br)); } finally { if (br != null) try { br.close(); } catch (IOException e2) { } } } Mindtap Inc Chris Snyder [email protected] 561-374-8772 4769 Pepper Bush Ln Boynton Beach, FL 33436
