protegeproject / swrlapi

Java API for working with the SWRL rule and SQWRL query languages
Other
99 stars 40 forks source link

Creating new instance of class with SWRL #44

Closed canarvaeza closed 6 years ago

canarvaeza commented 6 years ago

Hi, I know this is not the best place to ask this but maybe you have a better response than in the protege forum.

As the topic says I want to create an instance of a class given the achievement of some rules, The classes hierarchy is showed on the image. imagen I made the activities classes because I want to register multiple instances (Activity0001 Type Eat, Activity0002 Type Sit, Activity0003 Type Eat, Activity0025 Type HavingMeal).

I will explain it with natural language and then the approach I tried:

If Person(?p) is involved in a Sit Activity and in an Eat Activity then Person(?p) is involved in a ?havingMeal Activity

The Bold text Activity instance is the one I want to create given the activities the person realized, the instance I create with the rules execution depends of which conditions are achieved in this case I need to create an instance of the HavingMeal class. Sit and Eat instances are already created.

So I created this rule: foaf:Person(?p) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) -> mcontext:isInvolvedIn(?p, ?HA) Which says ?HA is not created on the prefix

foaf:Person(?p) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) -> mcontext:isInvolvedIn(?p, alzheimer:HavingMeal(?HA)) Which says HavingMeal is not an individual.

foaf:Person(?p) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) ^ alzheimer:HavingMeal(?HA) -> mcontext:isInvolvedIn(?p, ?HA) Offcourse I can't do this because I don't know which highLevel activity will be activated

foaf:Person(?p) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) ^ mcontext:Activity(?HA) ->alzheimer:HavingMeal(?HA), mcontext:isInvolvedIn(?p, ?HA) Trying to send an existing instance of the class Acticity and then changing the class to HavingMeal... just don´t work imagen

Well, do I have any option to achieve this? (even using the API, I'm trying first in protégé)

martinjoconnor commented 6 years ago

The mailing is typically the best place for these types of questions.

Are you using the SWRLAPI? The following is not a syntactically valid SWRL rule:

foaf:Person(?p) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) -> mcontext:isInvolvedIn(?p, alzheimer:HavingMeal(?HA))

The second parameter in the mcontext:isInvolvedIn atom is some sort of expression, which is not valid.

Martin

canarvaeza commented 6 years ago

Ok i will post on the mail list but if someone have some idea just comment.

I know is not valid, I was just trying to make something work :(, so I show what I tried.

On Wed, Apr 11, 2018, 23:31 martinjoconnor notifications@github.com wrote:

The mailing is typically the best place for these types of questions.

Are you using the SWRLAPI? The following is not a syntactically SWRL rule:

foaf:Person(?p) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) -> mcontext:isInvolvedIn(?p, alzheimer:HavingMeal(?HA))

The second parameter in the mcontext:isInvolvedIn atom is some sort of expression, which is not valid.

Martin

On Wed, Apr 11, 2018 at 2:24 PM, Cristian Narvaez < notifications@github.com> wrote:

Hi, I know this is not the best place to ask this but maybe you have a better response than in the protege forum.

As the topic says I want to create an instance of a class given the achievement of some rules, The classes hierarchy is showed on the image. [image: imagen] < https://user-images.githubusercontent.com/20783285/38642421-56f9a4b8-3dda-11e8-9874-609b3c3daca5.png

I made the activities classes because I want to register multiple instances (Activity0001 Type Eat, Activity0002 Type Sit, Activity0003 Type Eat, Activity0025 Type HavingMeal).

I will explain it with natural language and then the approach I tried:

If Person(?p) is involved in a Sit Activity and in an Eat Activity then Person(?p) is involved in a ?havingMeal Activity

The Bold text Activity instance is the one I want to create given the activities the person realized, the instance I create with the rules execution depends of which conditions are achieved in this case I need to create an instance of the HavingMeal class. Sit and Eat instances are already created.

So I created this rule: foaf:Person(?p) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) -> mcontext:isInvolvedIn(?p, ?HA) Which says ?HA is not created on the prefix

foaf:Person(?p) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) -> mcontext:isInvolvedIn(?p, alzheimer:HavingMeal(?HA)) Which says HavingMeal is not an individual.

foaf:Person(?p) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) ^ alzheimer:HavingMeal(?HA) -> mcontext:isInvolvedIn(?p, ?HA) Offcourse I can't do this because I don't know which highLevel activity will be activated

foaf:Person(?p) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) ^ mcontext:Activity(?HA) ->alzheimer:HavingMeal(?HA), mcontext:isInvolvedIn(?p, ?HA) Trying to send an existing instance of the class Acticity and then changing the class to HavingMeal... just don´t work [image: imagen] < https://user-images.githubusercontent.com/20783285/38643821-bc3d08c0-3dde-11e8-84c2-e03b0f7fab0a.png

Well, do I have any option to achieve this? (even using the API, I'm trying first in protégé)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/protegeproject/swrlapi/issues/44, or mute the thread < https://github.com/notifications/unsubscribe-auth/ABpq-9eS96gmFWZstrkah5TyZKCMpzxkks5tnnSZgaJpZM4TQxme

.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/protegeproject/swrlapi/issues/44#issuecomment-380602128, or mute the thread https://github.com/notifications/unsubscribe-auth/AT0gtXJxTqhr6wqhAP5a2wWR1gSX2ijcks5tnnYYgaJpZM4TQxme .

martinjoconnor commented 6 years ago

I re-read the question but am having a hard time understanding it. I would reformulate before posting to the list.

For example, what do you mean by 'creating a new instance of a class'? Do you mean classifying an existing existence to be an instance of a class (a relatively common thing to do in SWRL) or something else?

The SWRLAPI has a custom, non standard built-in for creating new individuals [1] but it generally used for specialized purposes. Creating new individuals during reasoning is not something that one can do in OWL or SWRL.

[1] https://github.com/protegeproject/swrlapi/wiki/ExtensionsBuiltInLibrary

canarvaeza commented 6 years ago

If the system recognize that all the conditions to the havingMeal activity are check (with the swrl) then I create an individual of type havingMeal And relate it with the user (also using swrl).

Creating an instance of any type (In this case Activity cause is the HighContextActivity parent) was an approach to solve the situation.

I will see the link and tell you if that work.

Thanks for your help :)

canarvaeza commented 6 years ago

Hi, It was not possible to reproduce the example of [1] in protégé (I can't see the new individual)

Here the ontology code.

SWRLBuidInTest.zip

The first rule was used to test if individuals where recognized.

I was also thinking that this approach is not the best since I don't have any individual from which I could copy the info, as I say the only moment I know which highLevelActivity instance will be created is when all conditions are validated.

I'm writing now a question on the protégé mail list, but I have more questions related to the use of the library (not bugs like this question), can I get some e-mail or Twitter to ask directly?

[1] https://github.com/protegeproject/swrlapi/wiki/ExtensionsBuiltInLibrary

canarvaeza commented 6 years ago

Hi, I get a good result using this rule

foaf:Person(?p) ^ alzheimer:Sit(?A1) ^ alzheimer:Eat(?A2) ^ mcontext:isInvolvedIn(?p, ?A1) ^ mcontext:isInvolvedIn(?p, ?A2) ^ activity:HighContextActivity(?HA) -> alzheimer:HavingMeal(?HA) ^ mcontext:isInvolvedIn(?p, ?HA)

At the end ?HA instance's class is changed to HavingMeal and then related to the user. I think will be easier if y manage the empty individual creation out of the SWRL rule, that is when i'm creating my RDF stream. Nevertheless, if you think there is good solution to my problem please post it, as if you know why the example above is not working.

I have other question, does this checks works? imagen Because i checked only one rule and all the rules were executed.

Thanks

martinjoconnor commented 6 years ago

Great that you got it working.

Please post all questions to Protege mailing list. We'd like others to benefit from answers to questions.

Martin