You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by lookman sanni <lo...@gmail.com> on 2016/08/04 03:36:39 UTC

Notation 3 Rule specification

Hi all,

I am beginning with Jena and I struggle with the specification of a rule
that would help infer new statements.

More concretely, I would like to know how to compare values of different
properties of a same resource in a rule file, following the n3 syntax.

E.g. [rule1: (?f pre:father ?a) (?u pre:brother ?f) -> (?u pre:uncle ?a)]

If we assume f and u have a property age and I would like to test whether
that property has the same value or not for both, how would I do it ?

Thanks, Lookman

Re: Notation 3 Rule specification

Posted by Dave Reynolds <da...@gmail.com>.
Note that Jena doesn't support N3 rules, I think this discussion is 
about Jena Rules.

On 04/08/16 06:54, lookman sanni wrote:
> Thanks Niels for the reply.
>
> [AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age) ->
> (?person1 ex:sameAge ?person2)] works fine for the purpose.
>
> Now let's assume that person1 has two properties: sonAge and daughterAge
> and I would like to infer a rule like person1 hasTwins. How would I write
> it ?

You have to first decide how you want to represent the concept of having 
twins. Then you write rules to implement that but your representation 
must come first.

For example, if you decided to use a class for this (someone with twins 
is a member of the class of people having twins) then you would write:

(?person eg:sonAge ?X) (?person eg:daughterAge ?X)
       -> (?person rdf:type eg:HasTwins)

I'm not saying using classes is a good representation, just an example.

Dave

> Thanks, Lookman
> Le 4 ao�t 2016 06:42, "Niels Andersen" <ni...@thinkiq.com> a �crit :
>
>> A general recommendation, please make sure that the properties that you
>> choose clearly describes the direction of the relationship. It is not clear
>> if ?f or ?a is the father.
>>
>> There are probably a million opinions about how to do this, my general
>> recommendation is to create properties that show the class to the left and
>> the relationship to the right, so ?a ex:person_Father ?b would mean that
>> ?a's father is ?b. It also makes it clear that the domain of
>> ex:person_Father is ex:Person and the range of ex:person_Father is
>> ex:Father.
>>
>> Not sure if I understand your question, but you could do the following to
>> compare ages
>> [AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age) ->
>> (?person1 ex:sameAge ?person2)]
>>
>> This rule would only trigger if both ?person1 and ?person2 are the same
>> age.
>>
>> More specifically you could say:
>>
>> [UncleRule: (?person experson_Father ?father) (?father ex:person_Brother
>> ?uncle) -> (?person ex:person_Uncle ?uncle)]
>> [UncleAgeRule: (?person1 ex:person_Uncle ?person2) (?person1 ex:person_Age
>> ?age) (?person2 ex:person_Age ?age) -> (?person1 ex:hasUncleWithSameAge
>> ?person2)]
>>
>> Not sure why you would do that, but it is just an example.
>>
>> Niels
>>
>>
>> -----Original Message-----
>> From: lookman sanni [mailto:lookouster@gmail.com]
>> Sent: Wednesday, August 3, 2016 20:37
>> To: users@jena.apache.org
>> Subject: Notation 3 Rule specification
>>
>> Hi all,
>>
>> I am beginning with Jena and I struggle with the specification of a rule
>> that would help infer new statements.
>>
>> More concretely, I would like to know how to compare values of different
>> properties of a same resource in a rule file, following the n3 syntax.
>>
>> E.g. [rule1: (?f pre:father ?a) (?u pre:brother ?f) -> (?u pre:uncle ?a)]
>>
>> If we assume f and u have a property age and I would like to test whether
>> that property has the same value or not for both, how would I do it ?
>>
>> Thanks, Lookman
>>
>

Re: Notation 3 Rule specification

Posted by Andy Seaborne <an...@apache.org>.
On 07/08/16 09:24, lookman sanni wrote:
> Thank you Niels, you made my day with the notEqual() function. The built-in
> primitives page that you suggested is a gold mine.
>
> @Dave: Jena does support N3 rules

Not really.  Jena rules and N3 have some similar capabilities but also 
differences.

N3 writes it's rules in extended RDF (N3 is itself extended RDF with 
nested structures called "formula").

Jena has a separate rules language, and own execution engine with both 
forward and backward rules.

Jena does parse N3 (at best, it treats it like Turtle from RDF 1.1 - 
that does not include formulae)

See
https://www.w3.org/2000/10/swap/doc/Processing

Their example: note combines data and rules in one file
----
@prefix : <uncle#>.
:Joe has :father :Fred.
:Fred has :brother :Bob.

@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@forAll :who1, :who2.
{ :who1 :father [ :brother :who2 ] } log:implies { :who1 :uncle :who2 }.
----

cwm - the original N3 interpreter - is a forward-chaining engine without 
RETE.

     Andy




Re: Notation 3 Rule specification

Posted by Dave Reynolds <da...@gmail.com>.
On 07/08/16 09:24, lookman sanni wrote:
> Thank you Niels, you made my day with the notEqual() function. The built-in
> primitives page that you suggested is a gold mine.
>
> @Dave: Jena does support N3 rules

Only if you use an external rules engine and I'm not aware of one.

I can assure you that Jena's GenericRules engine, as documented at:

https://jena.apache.org/documentation/inference/#rules

does not support N3 rules. There is some superficial similarity in that 
they are forward chaining rules which allow triple patterns in both left 
and right hand side. However, aside from the syntactic differences, the 
set of builtins is quite different. JenaRules does not, and probably 
could not, usefully support the metaprogramming stuff in N3 
(log:semantics, log:parsedAsN3 etc). The approaches to integrity 
checking rules is quite different as well.

Dave

> On Thu, Aug 4, 2016 at 8:06 PM, Niels Andersen <ni...@thinkiq.com> wrote:
>
>> Here is how I would do it:
>>
>>
>>
>> [RuleMotherMutipleBirths: (?person rdf:Type ex:FemalePerson) (?parent
>> ex:person_Child ?Child1) (?parent ex:person_Child ?Child2)
>> notEqual(?Child1,?Child2) (?Child1 ex:person_Birthday ?ChildBirthday)
>> (?Child2 ex:person_ Birthday? ChildBirthday)
>>
>> -> (?parent ex:person_ChildrenType ex:HasMultipleBirth) (?Child1
>> ex:sameBirth ?Child2) (?Child2 ex: sameBirth ?Child1)]
>>
>>
>>
>> A couple of things to watch out for here:
>>
>> �         This rule will cover any multi berth situation (twins, triplets,
>> etc)
>>
>> �         The kids must come from the same birth, not just have the same
>> birthday or age. Therefore the parent must be a female.
>>
>> �         The rule will not work if the twins are born on two different
>> days.
>>
>> �         Not sure the word Birth is the right one, try to find a better
>> one.
>>
>>
>>
>> Look at https://jena.apache.org/documentation/inference/#
>> builtin-primitives for inspiration.
>>
>>
>>
>> Now you can write a rule that shows that a man has twins. I\u2019ll leave that
>> for you to try.
>>
>>
>>
>> Niels
>>
>>
>>
>>
>>
>> -----Original Message-----
>>
>> From: lookman sanni [mailto:lookouster@gmail.com]
>>
>> Sent: Wednesday, August 3, 2016 22:55
>>
>> To: users@jena.apache.org
>>
>> Subject: RE: Notation 3 Rule specification
>>
>>
>>
>> Thanks Niels for the reply.
>>
>>
>>
>> [AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age) ->
>>
>> (?person1 ex:sameAge ?person2)] works fine for the purpose.
>>
>>
>>
>> Now let's assume that person1 has two properties: sonAge and daughterAge
>> and I would like to infer a rule like person1 hasTwins. How would I write
>> it ?
>>
>>
>>
>> Thanks, Lookman
>>
>> Le 4 ao�t 2016 06:42, "Niels Andersen" <ni...@thinkiq.com> a �crit :
>>
>>
>>
>>> A general recommendation, please make sure that the properties that
>>
>>> you choose clearly describes the direction of the relationship. It is
>>
>>> not clear if ?f or ?a is the father.
>>
>>>
>>
>>> There are probably a million opinions about how to do this, my general
>>
>>> recommendation is to create properties that show the class to the left
>>
>>> and the relationship to the right, so ?a ex:person_Father ?b would
>>
>>> mean that ?a's father is ?b. It also makes it clear that the domain of
>>
>>> ex:person_Father is ex:Person and the range of ex:person_Father is
>>
>>> ex:Father.
>>
>>>
>>
>>> Not sure if I understand your question, but you could do the following
>>
>>> to compare ages
>>
>>> [AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age)
>>
>>> ->
>>
>>> (?person1 ex:sameAge ?person2)]
>>
>>>
>>
>>> This rule would only trigger if both ?person1 and ?person2 are the
>>
>>> same age.
>>
>>>
>>
>>> More specifically you could say:
>>
>>>
>>
>>> [UncleRule: (?person experson_Father ?father) (?father
>>
>>> ex:person_Brother
>>
>>> ?uncle) -> (?person ex:person_Uncle ?uncle)]
>>
>>> [UncleAgeRule: (?person1 ex:person_Uncle ?person2) (?person1
>>
>>> ex:person_Age
>>
>>> ?age) (?person2 ex:person_Age ?age) -> (?person1
>>
>>> ex:hasUncleWithSameAge ?person2)]
>>
>>>
>>
>>> Not sure why you would do that, but it is just an example.
>>
>>>
>>
>>> Niels
>>
>>>
>>
>>>
>>
>>> -----Original Message-----
>>
>>> From: lookman sanni [mailto:lookouster@gmail.com]
>>
>>> Sent: Wednesday, August 3, 2016 20:37
>>
>>> To: users@jena.apache.org
>>
>>> Subject: Notation 3 Rule specification
>>
>>>
>>
>>> Hi all,
>>
>>>
>>
>>> I am beginning with Jena and I struggle with the specification of a
>>
>>> rule that would help infer new statements.
>>
>>>
>>
>>> More concretely, I would like to know how to compare values of
>>
>>> different properties of a same resource in a rule file, following the n3
>> syntax.
>>
>>>
>>
>>> E.g. [rule1: (?f pre:father ?a) (?u pre:brother ?f) -> (?u pre:uncle
>>
>>> ?a)]
>>
>>>
>>
>>> If we assume f and u have a property age and I would like to test
>>
>>> whether that property has the same value or not for both, how would I do
>> it ?
>>
>>>
>>
>>> Thanks, Lookman
>>
>>>
>>
>
>
>


Re: Notation 3 Rule specification

Posted by lookman sanni <lo...@gmail.com>.
Thank you Niels, you made my day with the notEqual() function. The built-in
primitives page that you suggested is a gold mine.

@Dave: Jena does support N3 rules






On Thu, Aug 4, 2016 at 8:06 PM, Niels Andersen <ni...@thinkiq.com> wrote:

> Here is how I would do it:
>
>
>
> [RuleMotherMutipleBirths: (?person rdf:Type ex:FemalePerson) (?parent
> ex:person_Child ?Child1) (?parent ex:person_Child ?Child2)
> notEqual(?Child1,?Child2) (?Child1 ex:person_Birthday ?ChildBirthday)
> (?Child2 ex:person_ Birthday? ChildBirthday)
>
> -> (?parent ex:person_ChildrenType ex:HasMultipleBirth) (?Child1
> ex:sameBirth ?Child2) (?Child2 ex: sameBirth ?Child1)]
>
>
>
> A couple of things to watch out for here:
>
> ·         This rule will cover any multi berth situation (twins, triplets,
> etc)
>
> ·         The kids must come from the same birth, not just have the same
> birthday or age. Therefore the parent must be a female.
>
> ·         The rule will not work if the twins are born on two different
> days.
>
> ·         Not sure the word Birth is the right one, try to find a better
> one.
>
>
>
> Look at https://jena.apache.org/documentation/inference/#
> builtin-primitives for inspiration.
>
>
>
> Now you can write a rule that shows that a man has twins. I’ll leave that
> for you to try.
>
>
>
> Niels
>
>
>
>
>
> -----Original Message-----
>
> From: lookman sanni [mailto:lookouster@gmail.com]
>
> Sent: Wednesday, August 3, 2016 22:55
>
> To: users@jena.apache.org
>
> Subject: RE: Notation 3 Rule specification
>
>
>
> Thanks Niels for the reply.
>
>
>
> [AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age) ->
>
> (?person1 ex:sameAge ?person2)] works fine for the purpose.
>
>
>
> Now let's assume that person1 has two properties: sonAge and daughterAge
> and I would like to infer a rule like person1 hasTwins. How would I write
> it ?
>
>
>
> Thanks, Lookman
>
> Le 4 août 2016 06:42, "Niels Andersen" <ni...@thinkiq.com> a écrit :
>
>
>
> > A general recommendation, please make sure that the properties that
>
> > you choose clearly describes the direction of the relationship. It is
>
> > not clear if ?f or ?a is the father.
>
> >
>
> > There are probably a million opinions about how to do this, my general
>
> > recommendation is to create properties that show the class to the left
>
> > and the relationship to the right, so ?a ex:person_Father ?b would
>
> > mean that ?a's father is ?b. It also makes it clear that the domain of
>
> > ex:person_Father is ex:Person and the range of ex:person_Father is
>
> > ex:Father.
>
> >
>
> > Not sure if I understand your question, but you could do the following
>
> > to compare ages
>
> > [AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age)
>
> > ->
>
> > (?person1 ex:sameAge ?person2)]
>
> >
>
> > This rule would only trigger if both ?person1 and ?person2 are the
>
> > same age.
>
> >
>
> > More specifically you could say:
>
> >
>
> > [UncleRule: (?person experson_Father ?father) (?father
>
> > ex:person_Brother
>
> > ?uncle) -> (?person ex:person_Uncle ?uncle)]
>
> > [UncleAgeRule: (?person1 ex:person_Uncle ?person2) (?person1
>
> > ex:person_Age
>
> > ?age) (?person2 ex:person_Age ?age) -> (?person1
>
> > ex:hasUncleWithSameAge ?person2)]
>
> >
>
> > Not sure why you would do that, but it is just an example.
>
> >
>
> > Niels
>
> >
>
> >
>
> > -----Original Message-----
>
> > From: lookman sanni [mailto:lookouster@gmail.com]
>
> > Sent: Wednesday, August 3, 2016 20:37
>
> > To: users@jena.apache.org
>
> > Subject: Notation 3 Rule specification
>
> >
>
> > Hi all,
>
> >
>
> > I am beginning with Jena and I struggle with the specification of a
>
> > rule that would help infer new statements.
>
> >
>
> > More concretely, I would like to know how to compare values of
>
> > different properties of a same resource in a rule file, following the n3
> syntax.
>
> >
>
> > E.g. [rule1: (?f pre:father ?a) (?u pre:brother ?f) -> (?u pre:uncle
>
> > ?a)]
>
> >
>
> > If we assume f and u have a property age and I would like to test
>
> > whether that property has the same value or not for both, how would I do
> it ?
>
> >
>
> > Thanks, Lookman
>
> >
>



-- 
Best Regards

Lookman SANNI

RE: Notation 3 Rule specification

Posted by Niels Andersen <ni...@thinkiq.com>.
Here is how I would do it:



[RuleMotherMutipleBirths: (?person rdf:Type ex:FemalePerson) (?parent ex:person_Child ?Child1) (?parent ex:person_Child ?Child2) notEqual(?Child1,?Child2) (?Child1 ex:person_Birthday ?ChildBirthday) (?Child2 ex:person_ Birthday? ChildBirthday)

-> (?parent ex:person_ChildrenType ex:HasMultipleBirth) (?Child1 ex:sameBirth ?Child2) (?Child2 ex: sameBirth ?Child1)]



A couple of things to watch out for here:

·         This rule will cover any multi berth situation (twins, triplets, etc)

·         The kids must come from the same birth, not just have the same birthday or age. Therefore the parent must be a female.

·         The rule will not work if the twins are born on two different days.

·         Not sure the word Birth is the right one, try to find a better one.



Look at https://jena.apache.org/documentation/inference/#builtin-primitives for inspiration.



Now you can write a rule that shows that a man has twins. I’ll leave that for you to try.



Niels





-----Original Message-----

From: lookman sanni [mailto:lookouster@gmail.com]

Sent: Wednesday, August 3, 2016 22:55

To: users@jena.apache.org

Subject: RE: Notation 3 Rule specification



Thanks Niels for the reply.



[AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age) ->

(?person1 ex:sameAge ?person2)] works fine for the purpose.



Now let's assume that person1 has two properties: sonAge and daughterAge and I would like to infer a rule like person1 hasTwins. How would I write it ?



Thanks, Lookman

Le 4 août 2016 06:42, "Niels Andersen" <ni...@thinkiq.com> a écrit :



> A general recommendation, please make sure that the properties that

> you choose clearly describes the direction of the relationship. It is

> not clear if ?f or ?a is the father.

>

> There are probably a million opinions about how to do this, my general

> recommendation is to create properties that show the class to the left

> and the relationship to the right, so ?a ex:person_Father ?b would

> mean that ?a's father is ?b. It also makes it clear that the domain of

> ex:person_Father is ex:Person and the range of ex:person_Father is

> ex:Father.

>

> Not sure if I understand your question, but you could do the following

> to compare ages

> [AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age)

> ->

> (?person1 ex:sameAge ?person2)]

>

> This rule would only trigger if both ?person1 and ?person2 are the

> same age.

>

> More specifically you could say:

>

> [UncleRule: (?person experson_Father ?father) (?father

> ex:person_Brother

> ?uncle) -> (?person ex:person_Uncle ?uncle)]

> [UncleAgeRule: (?person1 ex:person_Uncle ?person2) (?person1

> ex:person_Age

> ?age) (?person2 ex:person_Age ?age) -> (?person1

> ex:hasUncleWithSameAge ?person2)]

>

> Not sure why you would do that, but it is just an example.

>

> Niels

>

>

> -----Original Message-----

> From: lookman sanni [mailto:lookouster@gmail.com]

> Sent: Wednesday, August 3, 2016 20:37

> To: users@jena.apache.org

> Subject: Notation 3 Rule specification

>

> Hi all,

>

> I am beginning with Jena and I struggle with the specification of a

> rule that would help infer new statements.

>

> More concretely, I would like to know how to compare values of

> different properties of a same resource in a rule file, following the n3 syntax.

>

> E.g. [rule1: (?f pre:father ?a) (?u pre:brother ?f) -> (?u pre:uncle

> ?a)]

>

> If we assume f and u have a property age and I would like to test

> whether that property has the same value or not for both, how would I do it ?

>

> Thanks, Lookman

>

RE: Notation 3 Rule specification

Posted by lookman sanni <lo...@gmail.com>.
Thanks Niels for the reply.

[AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age) ->
(?person1 ex:sameAge ?person2)] works fine for the purpose.

Now let's assume that person1 has two properties: sonAge and daughterAge
and I would like to infer a rule like person1 hasTwins. How would I write
it ?

Thanks, Lookman
Le 4 août 2016 06:42, "Niels Andersen" <ni...@thinkiq.com> a écrit :

> A general recommendation, please make sure that the properties that you
> choose clearly describes the direction of the relationship. It is not clear
> if ?f or ?a is the father.
>
> There are probably a million opinions about how to do this, my general
> recommendation is to create properties that show the class to the left and
> the relationship to the right, so ?a ex:person_Father ?b would mean that
> ?a's father is ?b. It also makes it clear that the domain of
> ex:person_Father is ex:Person and the range of ex:person_Father is
> ex:Father.
>
> Not sure if I understand your question, but you could do the following to
> compare ages
> [AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age) ->
> (?person1 ex:sameAge ?person2)]
>
> This rule would only trigger if both ?person1 and ?person2 are the same
> age.
>
> More specifically you could say:
>
> [UncleRule: (?person experson_Father ?father) (?father ex:person_Brother
> ?uncle) -> (?person ex:person_Uncle ?uncle)]
> [UncleAgeRule: (?person1 ex:person_Uncle ?person2) (?person1 ex:person_Age
> ?age) (?person2 ex:person_Age ?age) -> (?person1 ex:hasUncleWithSameAge
> ?person2)]
>
> Not sure why you would do that, but it is just an example.
>
> Niels
>
>
> -----Original Message-----
> From: lookman sanni [mailto:lookouster@gmail.com]
> Sent: Wednesday, August 3, 2016 20:37
> To: users@jena.apache.org
> Subject: Notation 3 Rule specification
>
> Hi all,
>
> I am beginning with Jena and I struggle with the specification of a rule
> that would help infer new statements.
>
> More concretely, I would like to know how to compare values of different
> properties of a same resource in a rule file, following the n3 syntax.
>
> E.g. [rule1: (?f pre:father ?a) (?u pre:brother ?f) -> (?u pre:uncle ?a)]
>
> If we assume f and u have a property age and I would like to test whether
> that property has the same value or not for both, how would I do it ?
>
> Thanks, Lookman
>

RE: Notation 3 Rule specification

Posted by Niels Andersen <ni...@thinkiq.com>.
A general recommendation, please make sure that the properties that you choose clearly describes the direction of the relationship. It is not clear if ?f or ?a is the father. 

There are probably a million opinions about how to do this, my general recommendation is to create properties that show the class to the left and the relationship to the right, so ?a ex:person_Father ?b would mean that ?a's father is ?b. It also makes it clear that the domain of ex:person_Father is ex:Person and the range of ex:person_Father is ex:Father.

Not sure if I understand your question, but you could do the following to compare ages
[AgeRule: (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age) -> (?person1 ex:sameAge ?person2)] 

This rule would only trigger if both ?person1 and ?person2 are the same age.

More specifically you could say:

[UncleRule: (?person experson_Father ?father) (?father ex:person_Brother ?uncle) -> (?person ex:person_Uncle ?uncle)]
[UncleAgeRule: (?person1 ex:person_Uncle ?person2) (?person1 ex:person_Age ?age) (?person2 ex:person_Age ?age) -> (?person1 ex:hasUncleWithSameAge ?person2)]

Not sure why you would do that, but it is just an example.

Niels


-----Original Message-----
From: lookman sanni [mailto:lookouster@gmail.com] 
Sent: Wednesday, August 3, 2016 20:37
To: users@jena.apache.org
Subject: Notation 3 Rule specification

Hi all,

I am beginning with Jena and I struggle with the specification of a rule that would help infer new statements.

More concretely, I would like to know how to compare values of different properties of a same resource in a rule file, following the n3 syntax.

E.g. [rule1: (?f pre:father ?a) (?u pre:brother ?f) -> (?u pre:uncle ?a)]

If we assume f and u have a property age and I would like to test whether that property has the same value or not for both, how would I do it ?

Thanks, Lookman