Inferred Knowledge from Swrl rules are not saved back in owl file

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

Inferred Knowledge from Swrl rules are not saved back in owl file

Ramsha
Hi, I want to know how to save the inferences when running the swrl rule
using swrlapi back to the ontology file.

Ps. I use saveonto(); for saving the output but the inferences are not
displaying in the owl output file.



--
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: Inferred Knowledge from Swrl rules are not saved back in owl file

Martin O'Connor-2
Can you describe the problem in more detail, ideally with code fragments.

What does the method ’saveonto’ come from, for example?

Martin

> On May 11, 2020, at 2:59 PM, Ramsha <[hidden email]> wrote:
>
> Hi, I want to know how to save the inferences when running the swrl rule
> using swrlapi back to the ontology file.
>
> Ps. I use saveonto(); for saving the output but the inferences are not
> displaying in the owl output file.
>
>
>
> --
> 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: Inferred Knowledge from Swrl rules are not saved back in owl file

Ramsha
See I load my ontology in java and I can see all the instances and classes of
my ontology. I wanted to write the swrl rule using swrlapi which is listed
below. The rule is giving an inference but when I see the ontology the
inferred knowledge is not saved back in the ontology file. When I open the
outputfile it prompts a msg  "save changes", but the inference is not
present there. (I hope this makes sense to you.)
Public static void InitializeCodeEngine() {
               
//ontology loaded
        String inputFile = "Rules.owl";
        manager = OWLManager.createOWLOntologyManager();
        OWLOntology io = manager.loadOntologyFromOntologyDocument(new
FileInputStream(inputFile));
        rulesFactory = new RulesFactory(io);
               
 SQWRLQueryEngine queryEngine = SWRLAPIFactory.createSQWRLQueryEngine(io);
                               
 //Create and execute a SQWRL query using the SWRLAPI
                         
SQWRLResult result = queryEngine.runSQWRLQuery ("q1","LetterOccurrence(?LO)
^involveLetter(?LO, A ) ^ followedBy(?LO, ?B) ^ swrlx:makeOWLThing(?R, ?LO)
->sqwrl:select(?R)^RuleOccurrence(?R) ^ occurAt(?R, ?LO);
 if (result.next())
                                   
System.out.println( result); }

//save in the the output owl file
public static void saveOnt() {
                factoryOnt=ruleFactory.getOwlOntology();
                File fileformated = new File("OutputRules.owl");
}



--
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: Inferred Knowledge from Swrl rules are not saved back in owl file

Michael DeBellis-2
It looks like you are using SQWRL not SWRL? If that is the case then that explains why the information isn't getting stored in the ontology. SQWRL is strictly a query engine, it only can give you info about the ontology but not make new inferences that are stored in the ontology. 

From:  https://github.com/protegeproject/swrlapi/wiki/SQWRL  

Semantics of SQWRL
SQWRL queries operate on known individuals in the currently loaded OWL ontology. It is very important to note that SQWRL provides no way of accessing the information it accumulates from within a rule so query results cannot be written back to the ontology. There is no way, for example, to insert the result of a computed aggregate count back into the ontology. Such a mechanism could invalidate OWL's open world assumption and lead to nonmonotonicity.

On Mon, May 11, 2020 at 4:42 PM Ramsha <[hidden email]> wrote:
See I load my ontology in java and I can see all the instances and classes of
my ontology. I wanted to write the swrl rule using swrlapi which is listed
below. The rule is giving an inference but when I see the ontology the
inferred knowledge is not saved back in the ontology file. When I open the
outputfile it prompts a msg  "save changes", but the inference is not
present there. (I hope this makes sense to you.)
Public static void InitializeCodeEngine() {

//ontology loaded
        String inputFile = "Rules.owl";
        manager = OWLManager.createOWLOntologyManager();
        OWLOntology io = manager.loadOntologyFromOntologyDocument(new
FileInputStream(inputFile));
        rulesFactory = new RulesFactory(io);

 SQWRLQueryEngine queryEngine = SWRLAPIFactory.createSQWRLQueryEngine(io);

 //Create and execute a SQWRL query using the SWRLAPI

SQWRLResult result = queryEngine.runSQWRLQuery ("q1","LetterOccurrence(?LO)
^involveLetter(?LO, A ) ^ followedBy(?LO, ?B) ^ swrlx:makeOWLThing(?R, ?LO)
->sqwrl:select(?R)^RuleOccurrence(?R) ^ occurAt(?R, ?LO);
 if (result.next())

System.out.println( result); }

//save in the the output owl file
public static void saveOnt() {
                factoryOnt=ruleFactory.getOwlOntology();
                File fileformated = new File("OutputRules.owl");
}



--
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: Inferred Knowledge from Swrl rules are not saved back in owl file

Ramsha
Thanks much for the detailed answer. It clarifies my question.



--
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: Inferred Knowledge from Swrl rules are not saved back in owl file

Martin O'Connor-2

Also note that a lot of ’intermediate’ OWL axioms can be asserted during inference (for example, materializing all subclass relationships between classes in a hierarchy). You typically do not want to save these assertions to the source ontology.

Martin

> On May 12, 2020, at 12:01 AM, Ramsha <[hidden email]> wrote:
>
> Thanks much for the detailed answer. It clarifies my question.
>
>
>
> --
> 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: Inferred Knowledge from Swrl rules are not saved back in owl file

Ramsha
Yes, I am aware of this matter.

Now I have another issue, I run the example mentioned in this link https://github.com/protegeproject/swrlapi/wiki/SWRLRuleEngineAPI  but I can not see any inference.
For running this example, I created an owl file in the protege make the class person, and put some names as individuals and asserted an age greater than 17 to one of the individuals. The swrl rule created in the protege is asserting that individuals in "adult class" but when I run the code it is not giving me any inference. 

On Tue, May 12, 2020 at 8:15 PM Martin O'Connor <[hidden email]> wrote:

Also note that a lot of ’intermediate’ OWL axioms can be asserted during inference (for example, materializing all subclass relationships between classes in a hierarchy). You typically do not want to save these assertions to the source ontology.

Martin

> On May 12, 2020, at 12:01 AM, Ramsha <[hidden email]> wrote:
>
> Thanks much for the detailed answer. It clarifies my question.
>
>
>
> --
> 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


--
Kind Regards,
Ramsha Amin
MS(Computer Science) 
FAST-NUCES, H-11/4, Islamabad

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

Re: Inferred Knowledge from Swrl rules are not saved back in owl file

Ramsha
The query has been resolved.



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