Store output from sqwrl query

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

Store output from sqwrl query

Loveleen
Hello All,
Just a generic question:
Is there any way we can store the output from a sqwrl query in some local
variable within protege?
I understand that there is an option of saving the sqwrl query output in a
csv file. But can we store it in an owl class maybe wherein i can perform
further calculations on it.

Sample query given below, the query lists all patients on more than two
drugs.

 Patient(?p) ^ hasDrug(?p,?d) ˚
 sqwrl:makeSet(?s, ?d) ^ sqwrl:groupBy(?s, ?p) ˚
 sqwrl:size(?n, ?s) ^ swrlb:greaterThan(?n, 2)
 -> sqwrl:select(?p)

is there a way by which i can store the patients on more than two drugs in a
separate class?

Thanks in advance!
Loveleen



--
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: Store output from sqwrl query

Csongor Nyulas
Administrator
Hi Loveleen,

Yes , that is precisely what SWRL is good for. If you replace sqwrl:select(?p) (which is a SQWRL function) with, say, PatientWithMoreThanTwoDrugs(?p), all individuals that match the variable ?p the body (left hand side) of the rule, will become instances of the PatientWithMoreThanTwoDrugs class (or however you will end up calling it).

I didn't have an opportunity to try it out, but it should work.
Csongor


On 5/4/19 11:26 AM, Loveleen wrote:
Hello All,
Just a generic question: 
Is there any way we can store the output from a sqwrl query in some local
variable within protege?
I understand that there is an option of saving the sqwrl query output in a
csv file. But can we store it in an owl class maybe wherein i can perform
further calculations on it.

Sample query given below, the query lists all patients on more than two
drugs.

 Patient(?p) ^ hasDrug(?p,?d) ˚ 
 sqwrl:makeSet(?s, ?d) ^ sqwrl:groupBy(?s, ?p) ˚ 
 sqwrl:size(?n, ?s) ^ swrlb:greaterThan(?n, 2)
 -> sqwrl:select(?p)

is there a way by which i can store the patients on more than two drugs in a
separate class?

Thanks in advance!
Loveleen



--
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: Store output from sqwrl query

Michael DeBellis-2
I agree with what Csongor said but there is a caveat: there are some queries you can do in SQWRL that can only be queries and can't be asserted back into the ontology. And I think any of the queries involving making on the fly collections such as sqwrl:makeSet are of that type. See: https://github.com/protegeproject/swrlapi/wiki/SQWRLCollections  for more information. I think there may be a way to rewrite your SQWRL rule without using makeSet so that you could still find the appropriate individuals and make them instances of that class though, just don't use the makeSet operator. Something like the following might work: 

 Patient(?p) ^ hasDrug(?p,?d1)  ^ hasDrug(?p,?d2)  ^ hasDrug(?p,?d3) ^ differentFrom(?d1, ?d2) ^ differentFrom(?d2, ?d3) ^ differentFrom(?d1, ?d3) -> PatientWithMoreThanTwoDrugs(?p)

Or it might be possible (and IMO a bit more intuitive) to just make PatientWithMoreThanTwoDrugs a defined class with the appropriate cardinality axiom on the number of values for hasDrug. 

Michael


On Sat, May 4, 2019 at 10:34 PM Csongor Nyulas <[hidden email]> wrote:
Hi Loveleen,

Yes , that is precisely what SWRL is good for. If you replace sqwrl:select(?p) (which is a SQWRL function) with, say, PatientWithMoreThanTwoDrugs(?p), all individuals that match the variable ?p the body (left hand side) of the rule, will become instances of the PatientWithMoreThanTwoDrugs class (or however you will end up calling it).

I didn't have an opportunity to try it out, but it should work.
Csongor


On 5/4/19 11:26 AM, Loveleen wrote:
Hello All,
Just a generic question: 
Is there any way we can store the output from a sqwrl query in some local
variable within protege?
I understand that there is an option of saving the sqwrl query output in a
csv file. But can we store it in an owl class maybe wherein i can perform
further calculations on it.

Sample query given below, the query lists all patients on more than two
drugs.

 Patient(?p) ^ hasDrug(?p,?d) ˚ 
 sqwrl:makeSet(?s, ?d) ^ sqwrl:groupBy(?s, ?p) ˚ 
 sqwrl:size(?n, ?s) ^ swrlb:greaterThan(?n, 2)
 -> sqwrl:select(?p)

is there a way by which i can store the patients on more than two drugs in a
separate class?

Thanks in advance!
Loveleen



--
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

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

Re: Store output from sqwrl query

Michael DeBellis-2
In reply to this post by Loveleen
One more thing on the PatientWithMoreThanTwoDrugs class, assuming you have a class called Drug that all your drugs are instances of then the following axiom should work if you make  PatientWithMoreThanTwoDrugs   a defined class:

Patient and hasDrug min 3 Drug

Also, make sure that you make all your Drugs different individuals or this won't work. The default is that unless you explicitly state (or the reasoner can infer) that two individuals are different the reasoner won't assume that they are. I usually want all my individuals to be distinct so I just use the "Edit>Make all individuals different" option. If you do that keep in mind it only works for the individuals that exist in your ontology at the time you use the command. If you add new individuals you need to use that option again. There is also what I think is a new option to just select a specific class and then do "Edit>Make individuals different" and it will make all the instances of just the selected class distinct. 

Michael

On Sat, May 4, 2019 at 11:26 AM Loveleen <[hidden email]> wrote:
Hello All,
Just a generic question:
Is there any way we can store the output from a sqwrl query in some local
variable within protege?
I understand that there is an option of saving the sqwrl query output in a
csv file. But can we store it in an owl class maybe wherein i can perform
further calculations on it.

Sample query given below, the query lists all patients on more than two
drugs.

 Patient(?p) ^ hasDrug(?p,?d) ˚
 sqwrl:makeSet(?s, ?d) ^ sqwrl:groupBy(?s, ?p) ˚
 sqwrl:size(?n, ?s) ^ swrlb:greaterThan(?n, 2)
 -> sqwrl:select(?p)

is there a way by which i can store the patients on more than two drugs in a
separate class?

Thanks in advance!
Loveleen



--
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