You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Marco Knietzsch <ar...@hotmail.com> on 2012/11/17 19:32:23 UTC

Custom rule file - prefix to local file?

Hi, I want to have a custom reasoner that uses a local file to make inferences, without having to set up a server. Is this possible?I thought something like this would work:@prefix this: <file:///C:/myontologgy.rdf#>
But it doesnt. Can someone help?ThxMarco 		 	   		  

RE: Custom rule file - prefix to local file?

Posted by Marco Knietzsch <ar...@hotmail.com>.


> Date: Sat, 17 Nov 2012 21:36:53 +0000
> From: dave.e.reynolds@gmail.com
> To: users@jena.apache.org
> Subject: Re: Custom rule file - prefix to local file?
> 
> On 17/11/12 19:23, Marco Knietzsch wrote:
> >
> >> Date: Sat, 17 Nov 2012 19:09:17 +0000
> >> From: dave.e.reynolds@gmail.com
> >> To: users@jena.apache.org
> >> Subject: Re: Custom rule file - prefix to local file?
> >>
> >> On 17/11/12 18:32, Marco Knietzsch wrote:
> >>>
> >>> Hi, I want to have a custom reasoner that uses a local file to make inferences, without having to set up a server. Is this possible?I thought something like this would work:@prefix this: <file:///C:/myontologgy.rdf#>
> >>> But it doesnt. Can someone help?ThxMarco 		 	   		
> >>
> >> Sorry but it is hard to understand your question. In particular I've no
> >> idea *where* you are putting that @prefix declaration, and what you are
> >> expecting it to do.
> >>
> >> If by "customer reasoner" you mean the GenericRuleReasoner and by "uses
> >> a local file" you mean a file containing Jena Rules then sure that's
> >> possible.
> >>
> >> If you are doing all this in Java then when you create the reasoner
> >> instance you do something like:
> >>
> >>           List<Rule> rules = Rule.rulesFromURL("file:myrules.rules");
> >>           GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
> >>
> >> If you are doing this in an assembler definition then that is possible
> >> and should be described in the assembler documentation.
> >>
> >> Dave
> >>
> > OK, I try to make myself clearer. I define my reasoner like this:FileReader f = new FileReader (ruleFile);BufferedReader b = new BufferedReader (f);Rule.Parser p = Rule.rulesParserFromReader (b);java.util.List rules = Rule.parseRules (p);Reasoner reasoner = new GenericRuleReasoner (rules);OntModelSpec s = new OntModelSpec (OntModelSpec.OWL_MEM);s.setReasoner (reasoner);
> > So it gets the rules from "ruleFile". The file looks like this:@prefix this: <file:///C:/trpg.rdf#>@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#>
> > [inverse: (?x owl:inverseOf ?y) (?a ?x ?b) -> (?b ?y ?a)] <-- works![rule: (?x this:property ?y) -> something] <-- doesnt work
> > In the rules I want to access properties from "this", but it doesnt work. It works fine for owl and the others. Hope thats clear enough.
> > Marco 		 	   		
> >
> 
> Probably a mismatch in definition of this. Without seeing your data, how 
> you are reading your data and your rule file (the above has no white 
> spaces and is missing terminators and so won't parse) it to say more 
> than that.
> 
> General advice is to avoid using things like file: for namespaces. 
> Invent a base URI for your data, declare that in your data file and in 
> your rule file. The data doesn't have to physically be at that URI for 
> the reasoner to work.
> 
> Dave
> 

Thanks, that helped! 		 	   		  

Re: Custom rule file - prefix to local file?

Posted by Dave Reynolds <da...@gmail.com>.
On 17/11/12 19:23, Marco Knietzsch wrote:
>
>> Date: Sat, 17 Nov 2012 19:09:17 +0000
>> From: dave.e.reynolds@gmail.com
>> To: users@jena.apache.org
>> Subject: Re: Custom rule file - prefix to local file?
>>
>> On 17/11/12 18:32, Marco Knietzsch wrote:
>>>
>>> Hi, I want to have a custom reasoner that uses a local file to make inferences, without having to set up a server. Is this possible?I thought something like this would work:@prefix this: <file:///C:/myontologgy.rdf#>
>>> But it doesnt. Can someone help?ThxMarco 		 	   		
>>
>> Sorry but it is hard to understand your question. In particular I've no
>> idea *where* you are putting that @prefix declaration, and what you are
>> expecting it to do.
>>
>> If by "customer reasoner" you mean the GenericRuleReasoner and by "uses
>> a local file" you mean a file containing Jena Rules then sure that's
>> possible.
>>
>> If you are doing all this in Java then when you create the reasoner
>> instance you do something like:
>>
>>           List<Rule> rules = Rule.rulesFromURL("file:myrules.rules");
>>           GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
>>
>> If you are doing this in an assembler definition then that is possible
>> and should be described in the assembler documentation.
>>
>> Dave
>>
> OK, I try to make myself clearer. I define my reasoner like this:FileReader f = new FileReader (ruleFile);BufferedReader b = new BufferedReader (f);Rule.Parser p = Rule.rulesParserFromReader (b);java.util.List rules = Rule.parseRules (p);Reasoner reasoner = new GenericRuleReasoner (rules);OntModelSpec s = new OntModelSpec (OntModelSpec.OWL_MEM);s.setReasoner (reasoner);
> So it gets the rules from "ruleFile". The file looks like this:@prefix this: <file:///C:/trpg.rdf#>@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#>
> [inverse: (?x owl:inverseOf ?y) (?a ?x ?b) -> (?b ?y ?a)] <-- works![rule: (?x this:property ?y) -> something] <-- doesnt work
> In the rules I want to access properties from "this", but it doesnt work. It works fine for owl and the others. Hope thats clear enough.
> Marco 		 	   		
>

Probably a mismatch in definition of this. Without seeing your data, how 
you are reading your data and your rule file (the above has no white 
spaces and is missing terminators and so won't parse) it to say more 
than that.

General advice is to avoid using things like file: for namespaces. 
Invent a base URI for your data, declare that in your data file and in 
your rule file. The data doesn't have to physically be at that URI for 
the reasoner to work.

Dave


RE: Custom rule file - prefix to local file?

Posted by Marco Knietzsch <ar...@hotmail.com>.
> Date: Sat, 17 Nov 2012 19:09:17 +0000
> From: dave.e.reynolds@gmail.com
> To: users@jena.apache.org
> Subject: Re: Custom rule file - prefix to local file?
> 
> On 17/11/12 18:32, Marco Knietzsch wrote:
> >
> > Hi, I want to have a custom reasoner that uses a local file to make inferences, without having to set up a server. Is this possible?I thought something like this would work:@prefix this: <file:///C:/myontologgy.rdf#>
> > But it doesnt. Can someone help?ThxMarco 		 	   		
> 
> Sorry but it is hard to understand your question. In particular I've no 
> idea *where* you are putting that @prefix declaration, and what you are 
> expecting it to do.
> 
> If by "customer reasoner" you mean the GenericRuleReasoner and by "uses 
> a local file" you mean a file containing Jena Rules then sure that's 
> possible.
> 
> If you are doing all this in Java then when you create the reasoner 
> instance you do something like:
> 
>          List<Rule> rules = Rule.rulesFromURL("file:myrules.rules");
>          GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
> 
> If you are doing this in an assembler definition then that is possible 
> and should be described in the assembler documentation.
> 
> Dave
> 
OK, I try to make myself clearer. I define my reasoner like this:FileReader f = new FileReader (ruleFile);BufferedReader b = new BufferedReader (f);Rule.Parser p = Rule.rulesParserFromReader (b);java.util.List rules = Rule.parseRules (p);Reasoner reasoner = new GenericRuleReasoner (rules);OntModelSpec s = new OntModelSpec (OntModelSpec.OWL_MEM);s.setReasoner (reasoner);
So it gets the rules from "ruleFile". The file looks like this:@prefix this: <file:///C:/trpg.rdf#>@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#>
[inverse: (?x owl:inverseOf ?y) (?a ?x ?b) -> (?b ?y ?a)] <-- works![rule: (?x this:property ?y) -> something] <-- doesnt work
In the rules I want to access properties from "this", but it doesnt work. It works fine for owl and the others. Hope thats clear enough.
Marco 		 	   		  

Re: Custom rule file - prefix to local file?

Posted by Dave Reynolds <da...@gmail.com>.
On 17/11/12 18:32, Marco Knietzsch wrote:
>
> Hi, I want to have a custom reasoner that uses a local file to make inferences, without having to set up a server. Is this possible?I thought something like this would work:@prefix this: <file:///C:/myontologgy.rdf#>
> But it doesnt. Can someone help?ThxMarco 		 	   		

Sorry but it is hard to understand your question. In particular I've no 
idea *where* you are putting that @prefix declaration, and what you are 
expecting it to do.

If by "customer reasoner" you mean the GenericRuleReasoner and by "uses 
a local file" you mean a file containing Jena Rules then sure that's 
possible.

If you are doing all this in Java then when you create the reasoner 
instance you do something like:

         List<Rule> rules = Rule.rulesFromURL("file:myrules.rules");
         GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);

If you are doing this in an assembler definition then that is possible 
and should be described in the assembler documentation.

Dave