simple addition

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

simple addition

Luis Enrique Ramos García
dear friends

I am trying to perform a simple addition operation with protege and swrl as follows:

I have 2 concepts c1 and c2, every concept has a hasValue datatype property, that is

c1 hasValue v1

c2 hasValue v2

c1 and c2 have resultSum datatype as well 


I want to make a simple addition of v1 and v2, and put the result in the sum datatype property, with the rule:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)


when I apply the rule, I do not obtain the result of the sum, but the value of one of the concepts only. That means v1 or v2, but never the sum of both. What I am doing wrong.


I am working with the latest Protege 5.5 and 2.0.6 version of the SWRLTab plugin



Bets regards



Luis Ramos.





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

Re: simple addition

Michael DeBellis-2
Luis, First I think there may have been  typos in your rule or if not there is an obvious reason it's not working. You wrote:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)

If that is indeed the rule then ?ov1 and ?ov2 aren't going to be bound to any data and so the add function will fail and the rule won't fire. Also, I think you left out a few "^".  I'm going to assume that the rule is really:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  ^  resultSum(?c2, ?sum)  

If that is the rule, there are a few issues that I can think of. 

First, remember that OWL and SWRL don't assume that two individuals are necessarily distinct. I'm not sure if that would cause problems here but I've seen it cause issues with some of my rules in the past. One thing I typically do is to use the Protege command: Edit>Make all individuals different. There are of course times you don't want that assumption but often you do. Also, remember that this command only works for the individuals in your ontology when you run the command. If you add more individuals you need to run the command again. 

What might be a bigger issue though is that even if this rule works I have a feeling it won't be doing what you want it to due to the fact that SWRL doesn't support non-monotonic reasoning. Non-monotonic reasoning is the standard semantics for almost all programming languages. You can have a variable X that is set to 0 then your program can add 1 to X and then it can add 1 to X again resulting in X being 2. With OWL and SWRL you are in the domain of logic and proof though, where things are deduced to have values. You can't have a proof that says X = 0 and then later in the proof say X =1 In proof theory if you have some variable equal to 2 different values you have a contradiction and your proof is invalid and the same is true for OWL/SWRL. 

Forget about the second resultSum (I actually don't think you need it anyway) in your rule consequent and let's just consider if the rule is:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  

Assume that you have 4 instances (C1, C2, C3, and C4) of the concept class that are all different, and that each of them have hasValue set to 1. What you might expect is that the rule will fire for each permutation of ?c1 and ?c2. That is correct the rule will fire 16 times. You might also expect that resultSum will be set to 4. E.g., resultSum will get set to 2 the first time for each instance then 3 and then 4. That is incorrect. Instead what will happen is that resultSum will get set to 2 when the rule fires for C1 and C2. Then when the rule fires for C1 and C3 the consequent will be that resultSum should be 2 which it already is and the reasoner will say "Okay fine" and continue on it's merry way. 

Now however, assume that instead hasValue is 1 for C1, 2 for C2, 3 for C3 and 4 for C4. Again, what you might assume is that result sum will end up being 10 for each individual. But that is not what will happen. Instead you will end up with resultSum having 5 different values.  For C1 they will be 1, 2, 3, 4, and 5. For C2 the values will be 2, 3, 4, 5, and 6 and so on. If you define resultSum as a functional data property (as many numeric data properties are) you will end up with a contradiction because you have five different values for each instance. 

If you want to see examples of the rule firing write and run the SQWRL rule: 

Concept(?c1) ^ Concept(?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> sqwrl:select(?c1, ?c2, ?v1, ?v2, ?sum)

I hope that makes sense. I know that was a long winded answer but this can be confusing to new users because it's so different from most other languages so I wanted to try and make it clear. 

The way around this is to use a language like Java and a Java library like Apache Jena to make Java objects out of the individuals in your ontology and then you can just use Java code to manipulate their values just as you would for any Java instance. Or you can use SPARQL which is more or less to OWL as SQL is to relational databases. It can also do traditional non-monotonic reasoning.   

Michael







On Thu, Aug 1, 2019 at 3:02 AM Luis Enrique Ramos García <[hidden email]> wrote:
dear friends

I am trying to perform a simple addition operation with protege and swrl as follows:

I have 2 concepts c1 and c2, every concept has a hasValue datatype property, that is

c1 hasValue v1

c2 hasValue v2

c1 and c2 have resultSum datatype as well 


I want to make a simple addition of v1 and v2, and put the result in the sum datatype property, with the rule:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)


when I apply the rule, I do not obtain the result of the sum, but the value of one of the concepts only. That means v1 or v2, but never the sum of both. What I am doing wrong.


I am working with the latest Protege 5.5 and 2.0.6 version of the SWRLTab plugin



Bets regards



Luis Ramos.




_______________________________________________
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: simple addition

Michael DeBellis-2
Slight correction. In the second example, I should have said they will have 4 values not 5 and that C1 will be 2,3,4, and 5; C2 will be 3,4,5, and 6, etc. Note: in the rule as I revised it (but I think this would be the case for yours as well) ?c1 and ?c2 will get bound to the same individual as well as to the other instances of concept. If you don't want the behavior you need to add the SWRL expression: swrlb:differentFrom(?c1, ?c2) to the left hand side of your rule. 

Michael


On Thu, Aug 1, 2019 at 7:59 PM Michael DeBellis <[hidden email]> wrote:
Luis, First I think there may have been  typos in your rule or if not there is an obvious reason it's not working. You wrote:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)

If that is indeed the rule then ?ov1 and ?ov2 aren't going to be bound to any data and so the add function will fail and the rule won't fire. Also, I think you left out a few "^".  I'm going to assume that the rule is really:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  ^  resultSum(?c2, ?sum)  

If that is the rule, there are a few issues that I can think of. 

First, remember that OWL and SWRL don't assume that two individuals are necessarily distinct. I'm not sure if that would cause problems here but I've seen it cause issues with some of my rules in the past. One thing I typically do is to use the Protege command: Edit>Make all individuals different. There are of course times you don't want that assumption but often you do. Also, remember that this command only works for the individuals in your ontology when you run the command. If you add more individuals you need to run the command again. 

What might be a bigger issue though is that even if this rule works I have a feeling it won't be doing what you want it to due to the fact that SWRL doesn't support non-monotonic reasoning. Non-monotonic reasoning is the standard semantics for almost all programming languages. You can have a variable X that is set to 0 then your program can add 1 to X and then it can add 1 to X again resulting in X being 2. With OWL and SWRL you are in the domain of logic and proof though, where things are deduced to have values. You can't have a proof that says X = 0 and then later in the proof say X =1 In proof theory if you have some variable equal to 2 different values you have a contradiction and your proof is invalid and the same is true for OWL/SWRL. 

Forget about the second resultSum (I actually don't think you need it anyway) in your rule consequent and let's just consider if the rule is:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  

Assume that you have 4 instances (C1, C2, C3, and C4) of the concept class that are all different, and that each of them have hasValue set to 1. What you might expect is that the rule will fire for each permutation of ?c1 and ?c2. That is correct the rule will fire 16 times. You might also expect that resultSum will be set to 4. E.g., resultSum will get set to 2 the first time for each instance then 3 and then 4. That is incorrect. Instead what will happen is that resultSum will get set to 2 when the rule fires for C1 and C2. Then when the rule fires for C1 and C3 the consequent will be that resultSum should be 2 which it already is and the reasoner will say "Okay fine" and continue on it's merry way. 

Now however, assume that instead hasValue is 1 for C1, 2 for C2, 3 for C3 and 4 for C4. Again, what you might assume is that result sum will end up being 10 for each individual. But that is not what will happen. Instead you will end up with resultSum having 5 different values.  For C1 they will be 1, 2, 3, 4, and 5. For C2 the values will be 2, 3, 4, 5, and 6 and so on. If you define resultSum as a functional data property (as many numeric data properties are) you will end up with a contradiction because you have five different values for each instance. 

If you want to see examples of the rule firing write and run the SQWRL rule: 

Concept(?c1) ^ Concept(?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> sqwrl:select(?c1, ?c2, ?v1, ?v2, ?sum)

I hope that makes sense. I know that was a long winded answer but this can be confusing to new users because it's so different from most other languages so I wanted to try and make it clear. 

The way around this is to use a language like Java and a Java library like Apache Jena to make Java objects out of the individuals in your ontology and then you can just use Java code to manipulate their values just as you would for any Java instance. Or you can use SPARQL which is more or less to OWL as SQL is to relational databases. It can also do traditional non-monotonic reasoning.   

Michael







On Thu, Aug 1, 2019 at 3:02 AM Luis Enrique Ramos García <[hidden email]> wrote:
dear friends

I am trying to perform a simple addition operation with protege and swrl as follows:

I have 2 concepts c1 and c2, every concept has a hasValue datatype property, that is

c1 hasValue v1

c2 hasValue v2

c1 and c2 have resultSum datatype as well 


I want to make a simple addition of v1 and v2, and put the result in the sum datatype property, with the rule:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)


when I apply the rule, I do not obtain the result of the sum, but the value of one of the concepts only. That means v1 or v2, but never the sum of both. What I am doing wrong.


I am working with the latest Protege 5.5 and 2.0.6 version of the SWRLTab plugin



Bets regards



Luis Ramos.




_______________________________________________
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: simple addition

Luis Enrique Ramos García
Hi Michael, 

Thanks for the support, and invested time.


You are right in the sense of the mistaken rule writing, the current rule is:

concept(?c1) ^ concept(?c2) ^ differentFrom(?c1, ?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> hasSum(?c1, ?sum) hasSum(?c2, ?sum)

I have experience as developer with Jena and OWL API, only that I wanted to show a prototiping, where according the monotonic logic assumption, we should see two values, and get an inconsistency. 


I attach the three states in protege 5, before and after running the rules, without diff and with diff, ther we can see the behavior you explained. 


The question, is there a way to avoid this in protege?



Luis Ramos















El vie., 2 ago. 2019 a las 5:15, Michael DeBellis (<[hidden email]>) escribió:
Slight correction. In the second example, I should have said they will have 4 values not 5 and that C1 will be 2,3,4, and 5; C2 will be 3,4,5, and 6, etc. Note: in the rule as I revised it (but I think this would be the case for yours as well) ?c1 and ?c2 will get bound to the same individual as well as to the other instances of concept. If you don't want the behavior you need to add the SWRL expression: swrlb:differentFrom(?c1, ?c2) to the left hand side of your rule. 

Michael


On Thu, Aug 1, 2019 at 7:59 PM Michael DeBellis <[hidden email]> wrote:
Luis, First I think there may have been  typos in your rule or if not there is an obvious reason it's not working. You wrote:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)

If that is indeed the rule then ?ov1 and ?ov2 aren't going to be bound to any data and so the add function will fail and the rule won't fire. Also, I think you left out a few "^".  I'm going to assume that the rule is really:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  ^  resultSum(?c2, ?sum)  

If that is the rule, there are a few issues that I can think of. 

First, remember that OWL and SWRL don't assume that two individuals are necessarily distinct. I'm not sure if that would cause problems here but I've seen it cause issues with some of my rules in the past. One thing I typically do is to use the Protege command: Edit>Make all individuals different. There are of course times you don't want that assumption but often you do. Also, remember that this command only works for the individuals in your ontology when you run the command. If you add more individuals you need to run the command again. 

What might be a bigger issue though is that even if this rule works I have a feeling it won't be doing what you want it to due to the fact that SWRL doesn't support non-monotonic reasoning. Non-monotonic reasoning is the standard semantics for almost all programming languages. You can have a variable X that is set to 0 then your program can add 1 to X and then it can add 1 to X again resulting in X being 2. With OWL and SWRL you are in the domain of logic and proof though, where things are deduced to have values. You can't have a proof that says X = 0 and then later in the proof say X =1 In proof theory if you have some variable equal to 2 different values you have a contradiction and your proof is invalid and the same is true for OWL/SWRL. 

Forget about the second resultSum (I actually don't think you need it anyway) in your rule consequent and let's just consider if the rule is:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  

Assume that you have 4 instances (C1, C2, C3, and C4) of the concept class that are all different, and that each of them have hasValue set to 1. What you might expect is that the rule will fire for each permutation of ?c1 and ?c2. That is correct the rule will fire 16 times. You might also expect that resultSum will be set to 4. E.g., resultSum will get set to 2 the first time for each instance then 3 and then 4. That is incorrect. Instead what will happen is that resultSum will get set to 2 when the rule fires for C1 and C2. Then when the rule fires for C1 and C3 the consequent will be that resultSum should be 2 which it already is and the reasoner will say "Okay fine" and continue on it's merry way. 

Now however, assume that instead hasValue is 1 for C1, 2 for C2, 3 for C3 and 4 for C4. Again, what you might assume is that result sum will end up being 10 for each individual. But that is not what will happen. Instead you will end up with resultSum having 5 different values.  For C1 they will be 1, 2, 3, 4, and 5. For C2 the values will be 2, 3, 4, 5, and 6 and so on. If you define resultSum as a functional data property (as many numeric data properties are) you will end up with a contradiction because you have five different values for each instance. 

If you want to see examples of the rule firing write and run the SQWRL rule: 

Concept(?c1) ^ Concept(?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> sqwrl:select(?c1, ?c2, ?v1, ?v2, ?sum)

I hope that makes sense. I know that was a long winded answer but this can be confusing to new users because it's so different from most other languages so I wanted to try and make it clear. 

The way around this is to use a language like Java and a Java library like Apache Jena to make Java objects out of the individuals in your ontology and then you can just use Java code to manipulate their values just as you would for any Java instance. Or you can use SPARQL which is more or less to OWL as SQL is to relational databases. It can also do traditional non-monotonic reasoning.   

Michael







On Thu, Aug 1, 2019 at 3:02 AM Luis Enrique Ramos García <[hidden email]> wrote:
dear friends

I am trying to perform a simple addition operation with protege and swrl as follows:

I have 2 concepts c1 and c2, every concept has a hasValue datatype property, that is

c1 hasValue v1

c2 hasValue v2

c1 and c2 have resultSum datatype as well 


I want to make a simple addition of v1 and v2, and put the result in the sum datatype property, with the rule:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)


when I apply the rule, I do not obtain the result of the sum, but the value of one of the concepts only. That means v1 or v2, but never the sum of both. What I am doing wrong.


I am working with the latest Protege 5.5 and 2.0.6 version of the SWRLTab plugin



Bets regards



Luis Ramos.




_______________________________________________
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

state1.png (117K) Download Attachment
state3.png (122K) Download Attachment
satat2.png (122K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: simple addition

Lorenz Buehmann

You want to avoid what?


And it's difficult to understand your screenshots as it's not clear which does show what, especially since you once showed concept1 and once concept2.

On 02.08.19 07:50, Luis Enrique Ramos García wrote:
Hi Michael, 

Thanks for the support, and invested time.


You are right in the sense of the mistaken rule writing, the current rule is:

concept(?c1) ^ concept(?c2) ^ differentFrom(?c1, ?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> hasSum(?c1, ?sum) hasSum(?c2, ?sum)

I have experience as developer with Jena and OWL API, only that I wanted to show a prototiping, where according the monotonic logic assumption, we should see two values, and get an inconsistency. 


I attach the three states in protege 5, before and after running the rules, without diff and with diff, ther we can see the behavior you explained. 


The question, is there a way to avoid this in protege?



Luis Ramos















El vie., 2 ago. 2019 a las 5:15, Michael DeBellis (<[hidden email]>) escribió:
Slight correction. In the second example, I should have said they will have 4 values not 5 and that C1 will be 2,3,4, and 5; C2 will be 3,4,5, and 6, etc. Note: in the rule as I revised it (but I think this would be the case for yours as well) ?c1 and ?c2 will get bound to the same individual as well as to the other instances of concept. If you don't want the behavior you need to add the SWRL expression: swrlb:differentFrom(?c1, ?c2) to the left hand side of your rule. 

Michael


On Thu, Aug 1, 2019 at 7:59 PM Michael DeBellis <[hidden email]> wrote:
Luis, First I think there may have been  typos in your rule or if not there is an obvious reason it's not working. You wrote:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)

If that is indeed the rule then ?ov1 and ?ov2 aren't going to be bound to any data and so the add function will fail and the rule won't fire. Also, I think you left out a few "^".  I'm going to assume that the rule is really:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  ^  resultSum(?c2, ?sum)  

If that is the rule, there are a few issues that I can think of. 

First, remember that OWL and SWRL don't assume that two individuals are necessarily distinct. I'm not sure if that would cause problems here but I've seen it cause issues with some of my rules in the past. One thing I typically do is to use the Protege command: Edit>Make all individuals different. There are of course times you don't want that assumption but often you do. Also, remember that this command only works for the individuals in your ontology when you run the command. If you add more individuals you need to run the command again. 

What might be a bigger issue though is that even if this rule works I have a feeling it won't be doing what you want it to due to the fact that SWRL doesn't support non-monotonic reasoning. Non-monotonic reasoning is the standard semantics for almost all programming languages. You can have a variable X that is set to 0 then your program can add 1 to X and then it can add 1 to X again resulting in X being 2. With OWL and SWRL you are in the domain of logic and proof though, where things are deduced to have values. You can't have a proof that says X = 0 and then later in the proof say X =1 In proof theory if you have some variable equal to 2 different values you have a contradiction and your proof is invalid and the same is true for OWL/SWRL. 

Forget about the second resultSum (I actually don't think you need it anyway) in your rule consequent and let's just consider if the rule is:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  

Assume that you have 4 instances (C1, C2, C3, and C4) of the concept class that are all different, and that each of them have hasValue set to 1. What you might expect is that the rule will fire for each permutation of ?c1 and ?c2. That is correct the rule will fire 16 times. You might also expect that resultSum will be set to 4. E.g., resultSum will get set to 2 the first time for each instance then 3 and then 4. That is incorrect. Instead what will happen is that resultSum will get set to 2 when the rule fires for C1 and C2. Then when the rule fires for C1 and C3 the consequent will be that resultSum should be 2 which it already is and the reasoner will say "Okay fine" and continue on it's merry way. 

Now however, assume that instead hasValue is 1 for C1, 2 for C2, 3 for C3 and 4 for C4. Again, what you might assume is that result sum will end up being 10 for each individual. But that is not what will happen. Instead you will end up with resultSum having 5 different values.  For C1 they will be 1, 2, 3, 4, and 5. For C2 the values will be 2, 3, 4, 5, and 6 and so on. If you define resultSum as a functional data property (as many numeric data properties are) you will end up with a contradiction because you have five different values for each instance. 

If you want to see examples of the rule firing write and run the SQWRL rule: 

Concept(?c1) ^ Concept(?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> sqwrl:select(?c1, ?c2, ?v1, ?v2, ?sum)

I hope that makes sense. I know that was a long winded answer but this can be confusing to new users because it's so different from most other languages so I wanted to try and make it clear. 

The way around this is to use a language like Java and a Java library like Apache Jena to make Java objects out of the individuals in your ontology and then you can just use Java code to manipulate their values just as you would for any Java instance. Or you can use SPARQL which is more or less to OWL as SQL is to relational databases. It can also do traditional non-monotonic reasoning.   

Michael







On Thu, Aug 1, 2019 at 3:02 AM Luis Enrique Ramos García <[hidden email]> wrote:
dear friends

I am trying to perform a simple addition operation with protege and swrl as follows:

I have 2 concepts c1 and c2, every concept has a hasValue datatype property, that is

c1 hasValue v1

c2 hasValue v2

c1 and c2 have resultSum datatype as well 


I want to make a simple addition of v1 and v2, and put the result in the sum datatype property, with the rule:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)


when I apply the rule, I do not obtain the result of the sum, but the value of one of the concepts only. That means v1 or v2, but never the sum of both. What I am doing wrong.


I am working with the latest Protege 5.5 and 2.0.6 version of the SWRLTab plugin



Bets regards



Luis Ramos.




_______________________________________________
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

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

Re: simple addition

Michael DeBellis-2
In reply to this post by Luis Enrique Ramos García
I agree with Lorenz, I'm not sure what you want to avoid unless you are just asking is there a way to get SWRL to support non-monotonic reasoning in which case the answer is no. 

On Thu, Aug 1, 2019 at 10:51 PM Luis Enrique Ramos García <[hidden email]> wrote:
Hi Michael, 

Thanks for the support, and invested time.


You are right in the sense of the mistaken rule writing, the current rule is:

concept(?c1) ^ concept(?c2) ^ differentFrom(?c1, ?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> hasSum(?c1, ?sum) hasSum(?c2, ?sum)

I have experience as developer with Jena and OWL API, only that I wanted to show a prototiping, where according the monotonic logic assumption, we should see two values, and get an inconsistency. 


I attach the three states in protege 5, before and after running the rules, without diff and with diff, ther we can see the behavior you explained. 


The question, is there a way to avoid this in protege?



Luis Ramos















El vie., 2 ago. 2019 a las 5:15, Michael DeBellis (<[hidden email]>) escribió:
Slight correction. In the second example, I should have said they will have 4 values not 5 and that C1 will be 2,3,4, and 5; C2 will be 3,4,5, and 6, etc. Note: in the rule as I revised it (but I think this would be the case for yours as well) ?c1 and ?c2 will get bound to the same individual as well as to the other instances of concept. If you don't want the behavior you need to add the SWRL expression: swrlb:differentFrom(?c1, ?c2) to the left hand side of your rule. 

Michael


On Thu, Aug 1, 2019 at 7:59 PM Michael DeBellis <[hidden email]> wrote:
Luis, First I think there may have been  typos in your rule or if not there is an obvious reason it's not working. You wrote:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)

If that is indeed the rule then ?ov1 and ?ov2 aren't going to be bound to any data and so the add function will fail and the rule won't fire. Also, I think you left out a few "^".  I'm going to assume that the rule is really:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  ^  resultSum(?c2, ?sum)  

If that is the rule, there are a few issues that I can think of. 

First, remember that OWL and SWRL don't assume that two individuals are necessarily distinct. I'm not sure if that would cause problems here but I've seen it cause issues with some of my rules in the past. One thing I typically do is to use the Protege command: Edit>Make all individuals different. There are of course times you don't want that assumption but often you do. Also, remember that this command only works for the individuals in your ontology when you run the command. If you add more individuals you need to run the command again. 

What might be a bigger issue though is that even if this rule works I have a feeling it won't be doing what you want it to due to the fact that SWRL doesn't support non-monotonic reasoning. Non-monotonic reasoning is the standard semantics for almost all programming languages. You can have a variable X that is set to 0 then your program can add 1 to X and then it can add 1 to X again resulting in X being 2. With OWL and SWRL you are in the domain of logic and proof though, where things are deduced to have values. You can't have a proof that says X = 0 and then later in the proof say X =1 In proof theory if you have some variable equal to 2 different values you have a contradiction and your proof is invalid and the same is true for OWL/SWRL. 

Forget about the second resultSum (I actually don't think you need it anyway) in your rule consequent and let's just consider if the rule is:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  

Assume that you have 4 instances (C1, C2, C3, and C4) of the concept class that are all different, and that each of them have hasValue set to 1. What you might expect is that the rule will fire for each permutation of ?c1 and ?c2. That is correct the rule will fire 16 times. You might also expect that resultSum will be set to 4. E.g., resultSum will get set to 2 the first time for each instance then 3 and then 4. That is incorrect. Instead what will happen is that resultSum will get set to 2 when the rule fires for C1 and C2. Then when the rule fires for C1 and C3 the consequent will be that resultSum should be 2 which it already is and the reasoner will say "Okay fine" and continue on it's merry way. 

Now however, assume that instead hasValue is 1 for C1, 2 for C2, 3 for C3 and 4 for C4. Again, what you might assume is that result sum will end up being 10 for each individual. But that is not what will happen. Instead you will end up with resultSum having 5 different values.  For C1 they will be 1, 2, 3, 4, and 5. For C2 the values will be 2, 3, 4, 5, and 6 and so on. If you define resultSum as a functional data property (as many numeric data properties are) you will end up with a contradiction because you have five different values for each instance. 

If you want to see examples of the rule firing write and run the SQWRL rule: 

Concept(?c1) ^ Concept(?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> sqwrl:select(?c1, ?c2, ?v1, ?v2, ?sum)

I hope that makes sense. I know that was a long winded answer but this can be confusing to new users because it's so different from most other languages so I wanted to try and make it clear. 

The way around this is to use a language like Java and a Java library like Apache Jena to make Java objects out of the individuals in your ontology and then you can just use Java code to manipulate their values just as you would for any Java instance. Or you can use SPARQL which is more or less to OWL as SQL is to relational databases. It can also do traditional non-monotonic reasoning.   

Michael







On Thu, Aug 1, 2019 at 3:02 AM Luis Enrique Ramos García <[hidden email]> wrote:
dear friends

I am trying to perform a simple addition operation with protege and swrl as follows:

I have 2 concepts c1 and c2, every concept has a hasValue datatype property, that is

c1 hasValue v1

c2 hasValue v2

c1 and c2 have resultSum datatype as well 


I want to make a simple addition of v1 and v2, and put the result in the sum datatype property, with the rule:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)


when I apply the rule, I do not obtain the result of the sum, but the value of one of the concepts only. That means v1 or v2, but never the sum of both. What I am doing wrong.


I am working with the latest Protege 5.5 and 2.0.6 version of the SWRLTab plugin



Bets regards



Luis Ramos.




_______________________________________________
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

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

Re: simple addition

Luis Enrique Ramos García
Hi Lorenz and Michael, 

Thank for the time invested to talk about this, 

Michael, my concern is not because of the monotonic feature of description logic, I know how to deal with it. I mean, I should see two values in hasSum after triggering the rule, should have two values, hasSum 0 and hasSum 30, because for c1 hasValue is set to 10, and for c2 hasValue is set to 20, thus swrlb:add(?sum, ?ov1, ?ov2) , should give me 30 as value of sum. however it shows the behavior you described at the beginning, and continues adding, that is my concern. Is it possible to avoid these many additions, and obtain the real result of the sum?. I think it should be triggered only one time with the real values of the variables. 

Lorenz, I added a more detailed screen shot, I hope this helps more. 


Luis 





El vie., 2 ago. 2019 a las 16:14, Michael DeBellis (<[hidden email]>) escribió:
I agree with Lorenz, I'm not sure what you want to avoid unless you are just asking is there a way to get SWRL to support non-monotonic reasoning in which case the answer is no. 

On Thu, Aug 1, 2019 at 10:51 PM Luis Enrique Ramos García <[hidden email]> wrote:
Hi Michael, 

Thanks for the support, and invested time.


You are right in the sense of the mistaken rule writing, the current rule is:

concept(?c1) ^ concept(?c2) ^ differentFrom(?c1, ?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> hasSum(?c1, ?sum) hasSum(?c2, ?sum)

I have experience as developer with Jena and OWL API, only that I wanted to show a prototiping, where according the monotonic logic assumption, we should see two values, and get an inconsistency. 


I attach the three states in protege 5, before and after running the rules, without diff and with diff, ther we can see the behavior you explained. 


The question, is there a way to avoid this in protege?



Luis Ramos















El vie., 2 ago. 2019 a las 5:15, Michael DeBellis (<[hidden email]>) escribió:
Slight correction. In the second example, I should have said they will have 4 values not 5 and that C1 will be 2,3,4, and 5; C2 will be 3,4,5, and 6, etc. Note: in the rule as I revised it (but I think this would be the case for yours as well) ?c1 and ?c2 will get bound to the same individual as well as to the other instances of concept. If you don't want the behavior you need to add the SWRL expression: swrlb:differentFrom(?c1, ?c2) to the left hand side of your rule. 

Michael


On Thu, Aug 1, 2019 at 7:59 PM Michael DeBellis <[hidden email]> wrote:
Luis, First I think there may have been  typos in your rule or if not there is an obvious reason it's not working. You wrote:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)

If that is indeed the rule then ?ov1 and ?ov2 aren't going to be bound to any data and so the add function will fail and the rule won't fire. Also, I think you left out a few "^".  I'm going to assume that the rule is really:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  ^  resultSum(?c2, ?sum)  

If that is the rule, there are a few issues that I can think of. 

First, remember that OWL and SWRL don't assume that two individuals are necessarily distinct. I'm not sure if that would cause problems here but I've seen it cause issues with some of my rules in the past. One thing I typically do is to use the Protege command: Edit>Make all individuals different. There are of course times you don't want that assumption but often you do. Also, remember that this command only works for the individuals in your ontology when you run the command. If you add more individuals you need to run the command again. 

What might be a bigger issue though is that even if this rule works I have a feeling it won't be doing what you want it to due to the fact that SWRL doesn't support non-monotonic reasoning. Non-monotonic reasoning is the standard semantics for almost all programming languages. You can have a variable X that is set to 0 then your program can add 1 to X and then it can add 1 to X again resulting in X being 2. With OWL and SWRL you are in the domain of logic and proof though, where things are deduced to have values. You can't have a proof that says X = 0 and then later in the proof say X =1 In proof theory if you have some variable equal to 2 different values you have a contradiction and your proof is invalid and the same is true for OWL/SWRL. 

Forget about the second resultSum (I actually don't think you need it anyway) in your rule consequent and let's just consider if the rule is:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  

Assume that you have 4 instances (C1, C2, C3, and C4) of the concept class that are all different, and that each of them have hasValue set to 1. What you might expect is that the rule will fire for each permutation of ?c1 and ?c2. That is correct the rule will fire 16 times. You might also expect that resultSum will be set to 4. E.g., resultSum will get set to 2 the first time for each instance then 3 and then 4. That is incorrect. Instead what will happen is that resultSum will get set to 2 when the rule fires for C1 and C2. Then when the rule fires for C1 and C3 the consequent will be that resultSum should be 2 which it already is and the reasoner will say "Okay fine" and continue on it's merry way. 

Now however, assume that instead hasValue is 1 for C1, 2 for C2, 3 for C3 and 4 for C4. Again, what you might assume is that result sum will end up being 10 for each individual. But that is not what will happen. Instead you will end up with resultSum having 5 different values.  For C1 they will be 1, 2, 3, 4, and 5. For C2 the values will be 2, 3, 4, 5, and 6 and so on. If you define resultSum as a functional data property (as many numeric data properties are) you will end up with a contradiction because you have five different values for each instance. 

If you want to see examples of the rule firing write and run the SQWRL rule: 

Concept(?c1) ^ Concept(?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> sqwrl:select(?c1, ?c2, ?v1, ?v2, ?sum)

I hope that makes sense. I know that was a long winded answer but this can be confusing to new users because it's so different from most other languages so I wanted to try and make it clear. 

The way around this is to use a language like Java and a Java library like Apache Jena to make Java objects out of the individuals in your ontology and then you can just use Java code to manipulate their values just as you would for any Java instance. Or you can use SPARQL which is more or less to OWL as SQL is to relational databases. It can also do traditional non-monotonic reasoning.   

Michael







On Thu, Aug 1, 2019 at 3:02 AM Luis Enrique Ramos García <[hidden email]> wrote:
dear friends

I am trying to perform a simple addition operation with protege and swrl as follows:

I have 2 concepts c1 and c2, every concept has a hasValue datatype property, that is

c1 hasValue v1

c2 hasValue v2

c1 and c2 have resultSum datatype as well 


I want to make a simple addition of v1 and v2, and put the result in the sum datatype property, with the rule:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)


when I apply the rule, I do not obtain the result of the sum, but the value of one of the concepts only. That means v1 or v2, but never the sum of both. What I am doing wrong.


I am working with the latest Protege 5.5 and 2.0.6 version of the SWRLTab plugin



Bets regards



Luis Ramos.




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

initialvalue.png (23K) Download Attachment
addition.png (32K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: simple addition

samsontu
You should post your ontology. I can’t make any sense out of your screenshots.

If concept1 hasValue 10 and concept2 hasValue 20, **in the absence of any other individuals**, running your rule should result in concept1 and concept2 having sum of 30, and that’s exactly what I got when I ran the rule. The screenshot shows the results derived in Pellet (SWRLTab gave the same result):


I strongly recommend that you use the Pellet reasoner instead of SWRLTab when you don’t need specific capabilities of the SWRLTab. Unlike SWRLTab, where you need to write back the inferred axioms as asserted statement to see the results of firing rules, Pellet clearly shows what are inferred and what are asserted. 

When you add a third individual, then you get multiple sum values as Michael suggested. However, with your rule, you don’t get the sum of the values in the 3 Concept individuals, only pairwise sums. 

With best regards,
Samson



On Aug 2, 2019, at 9:54 PM, Luis Enrique Ramos García <[hidden email]> wrote:

Hi Lorenz and Michael, 

Thank for the time invested to talk about this, 

Michael, my concern is not because of the monotonic feature of description logic, I know how to deal with it. I mean, I should see two values in hasSum after triggering the rule, should have two values, hasSum 0 and hasSum 30, because for c1 hasValue is set to 10, and for c2 hasValue is set to 20, thus swrlb:add(?sum, ?ov1, ?ov2) , should give me 30 as value of sum. however it shows the behavior you described at the beginning, and continues adding, that is my concern. Is it possible to avoid these many additions, and obtain the real result of the sum?. I think it should be triggered only one time with the real values of the variables. 

Lorenz, I added a more detailed screen shot, I hope this helps more. 


Luis 





El vie., 2 ago. 2019 a las 16:14, Michael DeBellis (<[hidden email]>) escribió:
I agree with Lorenz, I'm not sure what you want to avoid unless you are just asking is there a way to get SWRL to support non-monotonic reasoning in which case the answer is no. 

On Thu, Aug 1, 2019 at 10:51 PM Luis Enrique Ramos García <[hidden email]> wrote:
Hi Michael, 

Thanks for the support, and invested time.


You are right in the sense of the mistaken rule writing, the current rule is:

concept(?c1) ^ concept(?c2) ^ differentFrom(?c1, ?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> hasSum(?c1, ?sum) hasSum(?c2, ?sum)

I have experience as developer with Jena and OWL API, only that I wanted to show a prototiping, where according the monotonic logic assumption, we should see two values, and get an inconsistency. 


I attach the three states in protege 5, before and after running the rules, without diff and with diff, ther we can see the behavior you explained. 


The question, is there a way to avoid this in protege?



Luis Ramos















El vie., 2 ago. 2019 a las 5:15, Michael DeBellis (<[hidden email]>) escribió:
Slight correction. In the second example, I should have said they will have 4 values not 5 and that C1 will be 2,3,4, and 5; C2 will be 3,4,5, and 6, etc. Note: in the rule as I revised it (but I think this would be the case for yours as well) ?c1 and ?c2 will get bound to the same individual as well as to the other instances of concept. If you don't want the behavior you need to add the SWRL expression: swrlb:differentFrom(?c1, ?c2) to the left hand side of your rule. 

Michael


On Thu, Aug 1, 2019 at 7:59 PM Michael DeBellis <[hidden email]> wrote:
Luis, First I think there may have been  typos in your rule or if not there is an obvious reason it's not working. You wrote:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)

If that is indeed the rule then ?ov1 and ?ov2 aren't going to be bound to any data and so the add function will fail and the rule won't fire. Also, I think you left out a few "^".  I'm going to assume that the rule is really:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  ^  resultSum(?c2, ?sum)  

If that is the rule, there are a few issues that I can think of. 

First, remember that OWL and SWRL don't assume that two individuals are necessarily distinct. I'm not sure if that would cause problems here but I've seen it cause issues with some of my rules in the past. One thing I typically do is to use the Protege command: Edit>Make all individuals different. There are of course times you don't want that assumption but often you do. Also, remember that this command only works for the individuals in your ontology when you run the command. If you add more individuals you need to run the command again. 

What might be a bigger issue though is that even if this rule works I have a feeling it won't be doing what you want it to due to the fact that SWRL doesn't support non-monotonic reasoning. Non-monotonic reasoning is the standard semantics for almost all programming languages. You can have a variable X that is set to 0 then your program can add 1 to X and then it can add 1 to X again resulting in X being 2. With OWL and SWRL you are in the domain of logic and proof though, where things are deduced to have values. You can't have a proof that says X = 0 and then later in the proof say X =1 In proof theory if you have some variable equal to 2 different values you have a contradiction and your proof is invalid and the same is true for OWL/SWRL. 

Forget about the second resultSum (I actually don't think you need it anyway) in your rule consequent and let's just consider if the rule is:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  

Assume that you have 4 instances (C1, C2, C3, and C4) of the concept class that are all different, and that each of them have hasValue set to 1. What you might expect is that the rule will fire for each permutation of ?c1 and ?c2. That is correct the rule will fire 16 times. You might also expect that resultSum will be set to 4. E.g., resultSum will get set to 2 the first time for each instance then 3 and then 4. That is incorrect. Instead what will happen is that resultSum will get set to 2 when the rule fires for C1 and C2. Then when the rule fires for C1 and C3 the consequent will be that resultSum should be 2 which it already is and the reasoner will say "Okay fine" and continue on it's merry way. 

Now however, assume that instead hasValue is 1 for C1, 2 for C2, 3 for C3 and 4 for C4. Again, what you might assume is that result sum will end up being 10 for each individual. But that is not what will happen. Instead you will end up with resultSum having 5 different values.  For C1 they will be 1, 2, 3, 4, and 5. For C2 the values will be 2, 3, 4, 5, and 6 and so on. If you define resultSum as a functional data property (as many numeric data properties are) you will end up with a contradiction because you have five different values for each instance. 

If you want to see examples of the rule firing write and run the SQWRL rule: 

Concept(?c1) ^ Concept(?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> sqwrl:select(?c1, ?c2, ?v1, ?v2, ?sum)

I hope that makes sense. I know that was a long winded answer but this can be confusing to new users because it's so different from most other languages so I wanted to try and make it clear. 

The way around this is to use a language like Java and a Java library like Apache Jena to make Java objects out of the individuals in your ontology and then you can just use Java code to manipulate their values just as you would for any Java instance. Or you can use SPARQL which is more or less to OWL as SQL is to relational databases. It can also do traditional non-monotonic reasoning.   

Michael







On Thu, Aug 1, 2019 at 3:02 AM Luis Enrique Ramos García <[hidden email]> wrote:
dear friends

I am trying to perform a simple addition operation with protege and swrl as follows:

I have 2 concepts c1 and c2, every concept has a hasValue datatype property, that is

c1 hasValue v1

c2 hasValue v2

c1 and c2 have resultSum datatype as well 


I want to make a simple addition of v1 and v2, and put the result in the sum datatype property, with the rule:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)


when I apply the rule, I do not obtain the result of the sum, but the value of one of the concepts only. That means v1 or v2, but never the sum of both. What I am doing wrong.


I am working with the latest Protege 5.5 and 2.0.6 version of the SWRLTab plugin



Bets regards



Luis Ramos.




_______________________________________________
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
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
<initialvalue.png><addition.png>_______________________________________________
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

smime.p7s (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: simple addition

Michael DeBellis-2
In reply to this post by Luis Enrique Ramos García
Luis, the reason I went into some detail in my original response was to try and show that because of the fact that SWRL doesn't support non-monotonic reasoning when you go to do things like adding up the sum of a property value you can get very strange results. In the first case (all four instances had the property value set to 1) you only get one value but it seems to be the wrong value since each individual addition results in 2 so rather than getting multiple values as you typically would or getting 4 which you would get if you had non-monotonic reasoning and added the value of each concept you get one value of 2 because each time the rule fires the result is 2. The first time the rule asserts that the value must be 2 and sets it, the rest of the time the other firings assert the value should also be 2 which it is and the rule does nothing. 

However, that was a sort of degenerate case (but it can happen when you test things out with a small ontology to start). The normal case was as I described in my second example where each concept has a different value and so you end up with 4 different values. Unfortunately, there is no simple way around this using SWRL its an inherent limitation of the technology. If you've ever taken a logic class think about the things you do in a proof derivation. If at some point you prove X =1 and then later you prove X = 2 your proof has failed (or perhaps succeeded since sometimes you prove a theorem by assuming it's false and then deriving a contradiction like this). 

If you haven't seen this I encourage you to look at Martin's SWRL presentation: https://protege.stanford.edu/conference/2009/slides/SWRL2009ProtegeConference.pdf  He does a great job of describing the limitations of SWRL (especiallly see slides 24 and 25 on addition). 

There actually is one way around this but IMO it's complex and it's usually  better to just use SPARQL or Java with Jena or some other language or library, especially if you already know how to use Jena. But just in case you want to try this here is what you can do: If you have things in a list using a list ontology (see here for some good ones: https://lov.linkeddata.es/dataset/lov/terms?q=list) or if you just have a list like pattern where there is some ordering on your instances and there is a start property (or rather a start instance so it's property is the first one you add) and an end instance/property and a way to determine which individual is the next in the order then you can iterate through that way adding as you go. If you look at my small SWRL tutorial that is what I did to show how it was possible to add up the times of sub-tasks of a task to get the total amount of time that the super-task would take: https://symbolicshacker.blogspot.com/2017/06/swrl-process-modeling-tutorial.html

Cheers,
Michael


On Fri, Aug 2, 2019 at 9:54 PM Luis Enrique Ramos García <[hidden email]> wrote:
Hi Lorenz and Michael, 

Thank for the time invested to talk about this, 

Michael, my concern is not because of the monotonic feature of description logic, I know how to deal with it. I mean, I should see two values in hasSum after triggering the rule, should have two values, hasSum 0 and hasSum 30, because for c1 hasValue is set to 10, and for c2 hasValue is set to 20, thus swrlb:add(?sum, ?ov1, ?ov2) , should give me 30 as value of sum. however it shows the behavior you described at the beginning, and continues adding, that is my concern. Is it possible to avoid these many additions, and obtain the real result of the sum?. I think it should be triggered only one time with the real values of the variables. 

Lorenz, I added a more detailed screen shot, I hope this helps more. 


Luis 





El vie., 2 ago. 2019 a las 16:14, Michael DeBellis (<[hidden email]>) escribió:
I agree with Lorenz, I'm not sure what you want to avoid unless you are just asking is there a way to get SWRL to support non-monotonic reasoning in which case the answer is no. 

On Thu, Aug 1, 2019 at 10:51 PM Luis Enrique Ramos García <[hidden email]> wrote:
Hi Michael, 

Thanks for the support, and invested time.


You are right in the sense of the mistaken rule writing, the current rule is:

concept(?c1) ^ concept(?c2) ^ differentFrom(?c1, ?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> hasSum(?c1, ?sum) hasSum(?c2, ?sum)

I have experience as developer with Jena and OWL API, only that I wanted to show a prototiping, where according the monotonic logic assumption, we should see two values, and get an inconsistency. 


I attach the three states in protege 5, before and after running the rules, without diff and with diff, ther we can see the behavior you explained. 


The question, is there a way to avoid this in protege?



Luis Ramos















El vie., 2 ago. 2019 a las 5:15, Michael DeBellis (<[hidden email]>) escribió:
Slight correction. In the second example, I should have said they will have 4 values not 5 and that C1 will be 2,3,4, and 5; C2 will be 3,4,5, and 6, etc. Note: in the rule as I revised it (but I think this would be the case for yours as well) ?c1 and ?c2 will get bound to the same individual as well as to the other instances of concept. If you don't want the behavior you need to add the SWRL expression: swrlb:differentFrom(?c1, ?c2) to the left hand side of your rule. 

Michael


On Thu, Aug 1, 2019 at 7:59 PM Michael DeBellis <[hidden email]> wrote:
Luis, First I think there may have been  typos in your rule or if not there is an obvious reason it's not working. You wrote:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)

If that is indeed the rule then ?ov1 and ?ov2 aren't going to be bound to any data and so the add function will fail and the rule won't fire. Also, I think you left out a few "^".  I'm going to assume that the rule is really:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  ^  resultSum(?c2, ?sum)  

If that is the rule, there are a few issues that I can think of. 

First, remember that OWL and SWRL don't assume that two individuals are necessarily distinct. I'm not sure if that would cause problems here but I've seen it cause issues with some of my rules in the past. One thing I typically do is to use the Protege command: Edit>Make all individuals different. There are of course times you don't want that assumption but often you do. Also, remember that this command only works for the individuals in your ontology when you run the command. If you add more individuals you need to run the command again. 

What might be a bigger issue though is that even if this rule works I have a feeling it won't be doing what you want it to due to the fact that SWRL doesn't support non-monotonic reasoning. Non-monotonic reasoning is the standard semantics for almost all programming languages. You can have a variable X that is set to 0 then your program can add 1 to X and then it can add 1 to X again resulting in X being 2. With OWL and SWRL you are in the domain of logic and proof though, where things are deduced to have values. You can't have a proof that says X = 0 and then later in the proof say X =1 In proof theory if you have some variable equal to 2 different values you have a contradiction and your proof is invalid and the same is true for OWL/SWRL. 

Forget about the second resultSum (I actually don't think you need it anyway) in your rule consequent and let's just consider if the rule is:

concept(?c1) ^ concept (?c2)  ^  hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> resultSum(?c1, ?sum)  

Assume that you have 4 instances (C1, C2, C3, and C4) of the concept class that are all different, and that each of them have hasValue set to 1. What you might expect is that the rule will fire for each permutation of ?c1 and ?c2. That is correct the rule will fire 16 times. You might also expect that resultSum will be set to 4. E.g., resultSum will get set to 2 the first time for each instance then 3 and then 4. That is incorrect. Instead what will happen is that resultSum will get set to 2 when the rule fires for C1 and C2. Then when the rule fires for C1 and C3 the consequent will be that resultSum should be 2 which it already is and the reasoner will say "Okay fine" and continue on it's merry way. 

Now however, assume that instead hasValue is 1 for C1, 2 for C2, 3 for C3 and 4 for C4. Again, what you might assume is that result sum will end up being 10 for each individual. But that is not what will happen. Instead you will end up with resultSum having 5 different values.  For C1 they will be 1, 2, 3, 4, and 5. For C2 the values will be 2, 3, 4, 5, and 6 and so on. If you define resultSum as a functional data property (as many numeric data properties are) you will end up with a contradiction because you have five different values for each instance. 

If you want to see examples of the rule firing write and run the SQWRL rule: 

Concept(?c1) ^ Concept(?c2) ^ hasValue(?c1, ?v1) ^ hasValue(?c2, ?v2) ^ swrlb:add(?sum, ?v1, ?v2) -> sqwrl:select(?c1, ?c2, ?v1, ?v2, ?sum)

I hope that makes sense. I know that was a long winded answer but this can be confusing to new users because it's so different from most other languages so I wanted to try and make it clear. 

The way around this is to use a language like Java and a Java library like Apache Jena to make Java objects out of the individuals in your ontology and then you can just use Java code to manipulate their values just as you would for any Java instance. Or you can use SPARQL which is more or less to OWL as SQL is to relational databases. It can also do traditional non-monotonic reasoning.   

Michael







On Thu, Aug 1, 2019 at 3:02 AM Luis Enrique Ramos García <[hidden email]> wrote:
dear friends

I am trying to perform a simple addition operation with protege and swrl as follows:

I have 2 concepts c1 and c2, every concept has a hasValue datatype property, that is

c1 hasValue v1

c2 hasValue v2

c1 and c2 have resultSum datatype as well 


I want to make a simple addition of v1 and v2, and put the result in the sum datatype property, with the rule:

concept(?c1) ^ concept (?c2) hasValue(?c1, ?v1) ^hasValue(?c2, ?v2) swrlb:add(?sum, ?ov1, ?ov2) -> resultSum(?c1, ?sum) resultSum(?c2, ?sum)


when I apply the rule, I do not obtain the result of the sum, but the value of one of the concepts only. That means v1 or v2, but never the sum of both. What I am doing wrong.


I am working with the latest Protege 5.5 and 2.0.6 version of the SWRLTab plugin



Bets regards



Luis Ramos.




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