Running SWRL Rules makes my ontology file empty.

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

Running SWRL Rules makes my ontology file empty.

Ramsha
Hi, I am finding difficulty in displaying the inference from the SWRl rule. I
have made my swrl rule in the protege and trying to run the rules using
swrlapi.

I follow the link
https://github.com/protegeproject/swrlapi/wiki/SWRLRuleEngineAPI and the
rule mentioned (Adult) in it is working fine as I tried running this rule
before running mine. I am following the same steps mentioned in this link to
see the inference of my rules. Please Help.

1- Load an ontology
2- Create a SWRL rule engine using the SWRLAPI  
 SWRLRuleEngine ruleEngine = SWRLAPIFactory.createSWRLRuleEngine(ontology);
 
3- Run the rule engine
 ruleEngine.infer();

4- save the result in an output ontology but when I load my output file all
my classes, individuals disappear. In short, the owl file (output ontology
file) gets empty. I don't know what is the cause of this strange behavior.

My SWRL rule is : rules:LetterOccurrence(?LO) ^ rules:involveLetter(?LO,
rules:A) ^ rules:followedBy(?LO, ?LOF) ^ rules:LetterOccurrence(?LOF) ^
rules:involveLetter(?LOF, ?L) ^ rules:xyzLetter(?L) ^ swrlx:makeOWLThing(?R,
?LO, ?LOF) -> rules:RuleOccurrence(?R) ^ rules:occurAt(?R, ?LO) ^
rules:hasRuleType(?R, rules:XYZ)


Whole code:
public static void InitializeTajweedEngine() {
               
                String inputFile = "RulesMinimal.owl";

                manager = OWLManager.createOWLOntologyManager();
                OWLOntology o;
                try {
                        o = manager.loadOntologyFromOntologyDocument(new
FileInputStream(inputFile));
                        ruleFactory = new RuleFactory(o);
                       
                        SWRLRuleEngine swrlRuleEngine = SWRLAPIFactory.createSWRLRuleEngine(o);
                        swrlRuleEngine.infer();
       
       
        } catch (OWLOntologyCreationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
        }
               
        }
        public static void saveOnt()

{
        factoryOnt=ruleFactory.getOwlOntology();
        File fileformated = new File("OutputRM.owl");
        OWLDocumentFormat format = manager.getOntologyFormat(factoryOnt);
        OWLXMLOntologyFormat owlxmlFormat = new OWLXMLOntologyFormat();
        if (format.isPrefixOWLOntologyFormat()) {
        owlxmlFormat.copyPrefixesFrom(format.asPrefixOWLOntologyFormat()); }
        try {
        manager.saveOntology(factoryOnt, owlxmlFormat,
        IRI.create(fileformated.toURI())); }
        catch (OWLOntologyStorageException e) {
        e.getMessage(); e.printStackTrace(); }}
        }

Ps: The rule works fine when run in the protege editor.



--
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: Running SWRL Rules makes my ontology file empty.

Martin O'Connor-2

It is not clear from these code fragments that you are saving the ontology that the rule engine is operating on (variable o in the code).

Where is the code that saves this ontology after the inference step?

Martin

On May 13, 2020, at 6:04 PM, Ramsha <[hidden email]> wrote:

Hi, I am finding difficulty in displaying the inference from the SWRl rule. I
have made my swrl rule in the protege and trying to run the rules using
swrlapi.

I follow the link
https://github.com/protegeproject/swrlapi/wiki/SWRLRuleEngineAPI and the
rule mentioned (Adult) in it is working fine as I tried running this rule
before running mine. I am following the same steps mentioned in this link to
see the inference of my rules. Please Help.

1- Load an ontology
2- Create a SWRL rule engine using the SWRLAPI  
SWRLRuleEngine ruleEngine = SWRLAPIFactory.createSWRLRuleEngine(ontology);

3- Run the rule engine
ruleEngine.infer();

4- save the result in an output ontology but when I load my output file all
my classes, individuals disappear. In short, the owl file (output ontology
file) gets empty. I don't know what is the cause of this strange behavior.

My SWRL rule is : rules:LetterOccurrence(?LO) ^ rules:involveLetter(?LO,
rules:A) ^ rules:followedBy(?LO, ?LOF) ^ rules:LetterOccurrence(?LOF) ^
rules:involveLetter(?LOF, ?L) ^ rules:xyzLetter(?L) ^ swrlx:makeOWLThing(?R,
?LO, ?LOF) -> rules:RuleOccurrence(?R) ^ rules:occurAt(?R, ?LO) ^
rules:hasRuleType(?R, rules:XYZ)


Whole code:
public static void InitializeTajweedEngine() {

String inputFile = "RulesMinimal.owl";

manager = OWLManager.createOWLOntologyManager();
OWLOntology o;
try {
o = manager.loadOntologyFromOntologyDocument(new
FileInputStream(inputFile));
ruleFactory = new RuleFactory(o);

SWRLRuleEngine swrlRuleEngine = SWRLAPIFactory.createSWRLRuleEngine(o);
swrlRuleEngine.infer();


} catch (OWLOntologyCreationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
public static void saveOnt()

{
factoryOnt=ruleFactory.getOwlOntology();
File fileformated = new File("OutputRM.owl");
OWLDocumentFormat format = manager.getOntologyFormat(factoryOnt);
OWLXMLOntologyFormat owlxmlFormat = new OWLXMLOntologyFormat();
if (format.isPrefixOWLOntologyFormat()) {
owlxmlFormat.copyPrefixesFrom(format.asPrefixOWLOntologyFormat()); }
try {
manager.saveOntology(factoryOnt, owlxmlFormat,
IRI.create(fileformated.toURI())); }
catch (OWLOntologyStorageException e) {
e.getMessage(); e.printStackTrace(); }}
}

Ps: The rule works fine when run in the protege editor.



--
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: Running SWRL Rules makes my ontology file empty.

Ramsha
This post was updated on .
In reply to this post by Ramsha
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Running SWRL Rules makes my ontology file empty.

Ramsha
In reply to this post by Martin O'Connor-2
Thank you, Mr. Martin, for pointing out that I am missing saving the
ontology.  My rule works now.



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