String Variable inside SWRL Head

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

String Variable inside SWRL Head

tomekldc
Hi,

I'm working in a project where I need to order participants that are in the
same group, in regards of some conditions.
I wrote this SWRL Rule :


My question is how can I put the individual name in the data-property
/hasForGroupOrder/ with the variables /?R1/ and /?R2/, as a string ?

Thank you for your time,




--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: String Variable inside SWRL Head

Martin O'Connor-2

I sounds to me like you are attempting to write a query, not a rule.

The SQWRL query language is documented here:


There is an example using ordering here:


Documentation for the SWRL language can be found here:


BTW, I am not sure what the forward slash notation means.

Martin

On Jul 16, 2019, at 5:28 AM, tomekldc <[hidden email]> wrote:

Hi,

I'm working in a project where I need to order participants that are in the
same group, in regards of some conditions.
I wrote this SWRL Rule :


My question is how can I put the individual name in the data-property
/hasForGroupOrder/ with the variables /?R1/ and /?R2/, as a string ?

Thank you for your time,




--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: String Variable inside SWRL Head

tomekldc
Hi,

The mailling list messed with my answer (the  and the / are in cause. And
there were no backslashes in my original question).
Here's the original SWRL syntax:

Robot(?R1) ^ Robot(?R2) ^ isDifferentFrom(?R1,?R2) ^
isCollaboratingWith(?R1,?R2) ^ isTheLeaderGroup(?R1,"true"^^xsd:boolean) ->
orderGroupIs(?R1,"?R1,?R2"^^xsd:string)

You may be right. I didn't though about writing a SQWRL Query at first
because I wanted to be part of the ontology as "knowledge" but I could go
this way if my goal of replace ?R1 variable by the xsd:string. Moreover the
sqwrl:select could do the work anyway. I'm just curious if we could replace
the variable as String Literal with simple SWRL.

I may forgot to say that the order expected is based on personal condition:
it's a particular order (it's not by alphabetical or numerical).



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: String Variable inside SWRL Head

Michael DeBellis-2
That rule may not do what you want. I may be misunderstanding but it seems what you ultimately want is a list with the lead robot at the front and all the other robots after it. So if you have R1, R2, and R3 and R2 is the leader you want the list: “R2, R1, R3”(?) 

If you only always have 2 robots collaborating then this would work (actually it might not there’s another issue I’ll discuss below) but if you have three robots collaborating you won’t get one string but 2. Rather than “R2, R1, R3” you will have two values for orderGroupIs: “R2, R1” and “R2, R3”. 

The other issue, and I’m not at my desktop so I can’t try this out to be sure, but I don’t think the kind of string coercion you are attempting to do here will work. Anything with a “?” Is of course a parameter that gets bound differently every time the rule fires. I don’t think you can just take those parameters and put them in strings. I think you would need to do something like get the name of the Robot and use that. 

Although IMO doing this with a string is not a great way to model it anyway. You lose the ability to reason about the actual objects in the list, you just have their names. 

I think what you want is probably a reusable list Vocabulary. If you look here you can find some: https://lov.linkeddata.es/dataset/lov/terms?q=List

Then you could have a rule to order the list based on the leader or other properties. You might want to check out my short SWRL tutorial. I don’t use a list but I do something similar to recursively compute things like the estimated time for a sequence of processes: https://symbolicshacker.blogspot.com/2017/06/swrl-process-modeling-tutorial.html

Michael

Sent from my iPad

On Jul 16, 2019, at 7:05 AM, tomekldc <[hidden email]> wrote:

Hi,

The mailling list messed with my answer (the  and the / are in cause. And
there were no backslashes in my original question).
Here's the original SWRL syntax:

Robot(?R1) ^ Robot(?R2) ^ isDifferentFrom(?R1,?R2) ^
isCollaboratingWith(?R1,?R2) ^ isTheLeaderGroup(?R1,"true"^^xsd:boolean) ->
orderGroupIs(?R1,"?R1,?R2"^^xsd:string)

You may be right. I didn't though about writing a SQWRL Query at first
because I wanted to be part of the ontology as "knowledge" but I could go
this way if my goal of replace ?R1 variable by the xsd:string. Moreover the
sqwrl:select could do the work anyway. I'm just curious if we could replace
the variable as String Literal with simple SWRL.

I may forgot to say that the order expected is based on personal condition:
it's a particular order (it's not by alphabetical or numerical).



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: String Variable inside SWRL Head

Lorenz Buehmann
In reply to this post by tomekldc

Hi,

The mailling list messed with my answer (the  and the / are in cause. And
there were no backslashes in my original question).
Here's the original SWRL syntax:

Robot(?R1) ^ Robot(?R2) ^ isDifferentFrom(?R1,?R2) ^
isCollaboratingWith(?R1,?R2) ^ isTheLeaderGroup(?R1,"true"^^xsd:boolean) ->
orderGroupIs(?R1,"?R1,?R2"^^xsd:string)

That rule should work with a string literal in the head, sure -

but: only if in your ontology you have explicitly defined that the robots are different from each other, ideally you can use pairwise distinct axiom, i.a. owl:AllDifferent with the list of robot individuals. Protege also provides a menu action to apply this for you


You may be right. I didn't though about writing a SQWRL Query at first
because I wanted to be part of the ontology as "knowledge" but I could go
this way if my goal of replace ?R1 variable by the xsd:string. Moreover the
sqwrl:select could do the work anyway. I'm just curious if we could replace
the variable as String Literal with simple SWRL.

I may forgot to say that the order expected is based on personal condition:
it's a particular order (it's not by alphabetical or numerical).



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: String Variable inside SWRL Head

Michael DeBellis-2
Lorenz, are you sure about that? The parameters are bound to the objects not to the name of the objects. I just tried an example rule in my Car test ontology: Car(?c) -> testStringProperty(?c, "?c"^^xsd:string)

Where testStringProperty has a range of xsd:string. The rule works but since the "?c" is inside a string it doesn't get interpreted and what I get is the one Car in the ontology (C1) has it's testStringProperty set to "?c" rather than "C1"  My guess is if the rule about the robots succeeded orderGroupIs would be set to the string "?R1,?R2" not to the names of the actual robots which is what I think the OP wanted. 

Michael

On Wed, Jul 17, 2019 at 12:25 AM Lorenz B. <[hidden email]> wrote:

Hi,

The mailling list messed with my answer (the  and the / are in cause. And
there were no backslashes in my original question).
Here's the original SWRL syntax:

Robot(?R1) ^ Robot(?R2) ^ isDifferentFrom(?R1,?R2) ^
isCollaboratingWith(?R1,?R2) ^ isTheLeaderGroup(?R1,"true"^^xsd:boolean) ->
orderGroupIs(?R1,"?R1,?R2"^^xsd:string)

That rule should work with a string literal in the head, sure -

but: only if in your ontology you have explicitly defined that the robots are different from each other, ideally you can use pairwise distinct axiom, i.a. owl:AllDifferent with the list of robot individuals. Protege also provides a menu action to apply this for you

You may be right. I didn't though about writing a SQWRL Query at first
because I wanted to be part of the ontology as "knowledge" but I could go
this way if my goal of replace ?R1 variable by the xsd:string. Moreover the
sqwrl:select could do the work anyway. I'm just curious if we could replace
the variable as String Literal with simple SWRL.

I may forgot to say that the order expected is based on personal condition:
it's a particular order (it's not by alphabetical or numerical).



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: String Variable inside SWRL Head

Igor Toujilov-2

Hi Tomek,

This rule should not work because you cannot treat names of OWL individuals as strings in SWRL. And I agree with Michael: this is not a right thing to do. The philosophy behind this: SWRL is for logical inference, not for formatting OWL entity names as strings.

I suggest to rethink what you try to achieve, and formulate it logically. For example, you can introduce object property "leads", and use an SWRL rule (in Rules tab, not in SWRLTab):

 

isCollaboratingWith(?R1,?R2), isTheLeaderGroup(?R1,"true"^^xsd:boolean) → leads(?R1,?R2)

 

Then you can run a DL Query for instances:

 

inverse(leads) value MyRobot

 

and the query will return all robots, which are led by MyRobot.

Also you can simplify your ontology: instead of data property isTheLeaderGroup, use class GroupLeader, and assert corresponding robots as members of this class.

 

I hope this helps.

 

Regards,

Igor

 

 
 
Sent: Wednesday, July 17, 2019 at 3:53 PM
From: "Michael DeBellis" <[hidden email]>
To: "User support for WebProtege and Protege Desktop" <[hidden email]>
Subject: Re: [protege-user] String Variable inside SWRL Head
Lorenz, are you sure about that? The parameters are bound to the objects not to the name of the objects. I just tried an example rule in my Car test ontology: Car(?c) -> testStringProperty(?c, "?c"^^xsd:string)
 
Where testStringProperty has a range of xsd:string. The rule works but since the "?c" is inside a string it doesn't get interpreted and what I get is the one Car in the ontology (C1) has it's testStringProperty set to "?c" rather than "C1"  My guess is if the rule about the robots succeeded orderGroupIs would be set to the string "?R1,?R2" not to the names of the actual robots which is what I think the OP wanted. 
 
Michael
 
On Wed, Jul 17, 2019 at 12:25 AM Lorenz B. <[hidden email]> wrote:
 
Hi,

The mailling list messed with my answer (the  and the / are in cause. And
there were no backslashes in my original question).
Here's the original SWRL syntax:

Robot(?R1) ^ Robot(?R2) ^ isDifferentFrom(?R1,?R2) ^
isCollaboratingWith(?R1,?R2) ^ isTheLeaderGroup(?R1,"true"^^xsd:boolean) ->
orderGroupIs(?R1,"?R1,?R2"^^xsd:string)

That rule should work with a string literal in the head, sure -

but: only if in your ontology you have explicitly defined that the robots are different from each other, ideally you can use pairwise distinct axiom, i.a. owl:AllDifferent with the list of robot individuals. Protege also provides a menu action to apply this for you

You may be right. I didn't though about writing a SQWRL Query at first
because I wanted to be part of the ontology as "knowledge" but I could go
this way if my goal of replace ?R1 variable by the xsd:string. Moreover the
sqwrl:select could do the work anyway. I'm just curious if we could replace
the variable as String Literal with simple SWRL.

I may forgot to say that the order expected is based on personal condition:
it's a particular order (it's not by alphabetical or numerical).



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
_______________________________________________ protege-user mailing list [hidden email] https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: String Variable inside SWRL Head

tomekldc
Hi everyone,

Thank you all for your answers.
You've come with very good ideas.

I will follow Igor's approach with the:

Igor Toujilov-2 wrote
> I suggest to rethink what you try to achieve, and formulate it logically.
> For example, you can introduce object property &quot;leads&quot;, and use
> an SWRL rule (in Rules tab, not in SWRLTab):
> isCollaboratingWith(?R1,?R2),
> isTheLeaderGroup(?R1,&quot;true&quot;^^xsd:boolean) &rarr; leads(?R1,?R2)
> Then you can run a DL Query for instances:
> inverse(leads) value MyRobot
> and the query will return all robots, which are led by MyRobot.

Thank you all for your time,
Cheers

Tomek



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: String Variable inside SWRL Head

Lorenz Buehmann
In reply to this post by Michael DeBellis-2

Well, no ... you're of course right - I didn't read carefully enough, just though about using an arbitrary string literal in the head. Of course, this here doesn't work, no String interpolation is done in SWRL.

Cheers,

Lorenz

On 17.07.19 16:53, Michael DeBellis wrote:
Lorenz, are you sure about that? The parameters are bound to the objects not to the name of the objects. I just tried an example rule in my Car test ontology: Car(?c) -> testStringProperty(?c, "?c"^^xsd:string)

Where testStringProperty has a range of xsd:string. The rule works but since the "?c" is inside a string it doesn't get interpreted and what I get is the one Car in the ontology (C1) has it's testStringProperty set to "?c" rather than "C1"  My guess is if the rule about the robots succeeded orderGroupIs would be set to the string "?R1,?R2" not to the names of the actual robots which is what I think the OP wanted. 

Michael

On Wed, Jul 17, 2019 at 12:25 AM Lorenz B. <[hidden email]> wrote:

Hi,

The mailling list messed with my answer (the  and the / are in cause. And
there were no backslashes in my original question).
Here's the original SWRL syntax:

Robot(?R1) ^ Robot(?R2) ^ isDifferentFrom(?R1,?R2) ^
isCollaboratingWith(?R1,?R2) ^ isTheLeaderGroup(?R1,"true"^^xsd:boolean) ->
orderGroupIs(?R1,"?R1,?R2"^^xsd:string)

That rule should work with a string literal in the head, sure -

but: only if in your ontology you have explicitly defined that the robots are different from each other, ideally you can use pairwise distinct axiom, i.a. owl:AllDifferent with the list of robot individuals. Protege also provides a menu action to apply this for you

You may be right. I didn't though about writing a SQWRL Query at first
because I wanted to be part of the ontology as "knowledge" but I could go
this way if my goal of replace ?R1 variable by the xsd:string. Moreover the
sqwrl:select could do the work anyway. I'm just curious if we could replace
the variable as String Literal with simple SWRL.

I may forgot to say that the order expected is based on personal condition:
it's a particular order (it's not by alphabetical or numerical).



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user