Invalid SWRL atom predicate

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

Invalid SWRL atom predicate

mary
This is my java codecreateOWL.java.
In this code, the main part of creating SWRL rule is in function named public static void myswrl(File file).
Other function in the code is used to create a owl file and ouput it. So the owl file I used in swrl function is created by owl API.
This is owl file which is loaded in the OWLOntology ontology = ontologyManager.loadOntologyFromOntologyDocument(file); file is 1.owl
 The result of the java code is

I got the error Invalid SWRL atom predicate  'SecurityRequirement'. But in my owl file , there is a class named  'SecurityRequirement'. How to deal with this error? Please help me.Thanks advance.
Reply | Threaded
Open this post in threaded view
|

Re: Invalid SWRL atom predicate

Lorenz Buehmann
Do you think sending the same question 3 times will increase the chance to get an answer?

And sharing data + code in pictures isn't really helpful, nobody can reproduce it without writing everything again by hand.

This is my java code createOWL.java
<http://protege-project.136.n4.nabble.com/file/n4668529/createOWL.java>  .
In this code, the main part of creating SWRL rule is in function named
*public static void myswrl(File file).*
Other function in the code is used to create a owl file and ouput it. So the
owl file I used in swrl function is created by owl API.
This is owl file which is loaded in the *OWLOntology ontology =
ontologyManager.loadOntologyFromOntologyDocument(file)*; file is  1.owl
<http://protege-project.136.n4.nabble.com/file/n4668529/1.owl>  
 The result of the java code is 
<http://protege-project.136.n4.nabble.com/file/n4668529/error1.png> 
<http://protege-project.136.n4.nabble.com/file/n4668529/2.png> 
I got the error Invalid SWRL atom predicate  'SecurityRequirement'. But in
my owl file , there is a class named  'SecurityRequirement'. How to deal
with this error? Please help me.Thanks advance.




--
View this message in context: http://protege-project.136.n4.nabble.com/Invalid-SWRL-atom-predicate-tp4668529.html
Sent from the Protege User mailing list archive at Nabble.com.
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

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

Re: Invalid SWRL atom predicate

mary
This post was updated on .
The first question I asked is solved, so I delete it. The second question and the third question is the same, because I think maybe I didn't describe my question clearly. My English is poor. You mean I need to write the code in quesion and don't update it.

The error function is as follows:
    OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = ontologyManager.loadOntologyFromOntologyDocument(file);
    System.out.println(ontology.getClassesInSignature());
    System.out.println(ontology.getObjectPropertiesInSignature());
    SQWRLQueryEngine queryEngine = SWRLAPIFactory.createSQWRLQueryEngine(ontology);
    SQWRLResult result = queryEngine.runSQWRLQuery("q1",  "SecurityRequirement(?s)^hasObject(?s,vold) -> sqwrl:select(?s)");
     if (result.next())
              System.out.println("Name: " + result.getLiteral("x"));
              System.out.println(result.toString());
                         }

The result of code is <http://hello#Object><http://hello#SecurityRequirement>]
[<http://hello#hasSecurityGoal>, <http://hello#hasPath>, <http://hello#With>, <http://hello#hasObject>]
Error parsing SWRL rule or SQWRL query: Invalid SWRL atom predicate 'SecurityRequirement'

The owl file with is loaded in    ' OWLOntology ontology = ontologyManager.loadOntologyFromOntologyDocument(file);' is as follows:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    <b>xmlns:j.0="http://hello#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" >
...
  <rdf:Description rdf:about="http://hello#SecurityRequirement">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
...
  <rdf:Description rdf:about="http://hello#hasObject">
    <rdfs:range rdf:resource="http://hello#Object"/>
    <rdfs:domain rdf:resource="http://hello#SecurityRequirement"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
  </rdf:Description>

Reply | Threaded
Open this post in threaded view
|

Re: Invalid SWRL atom predicate

Martin O'Connor-2

The ontology you enclosed has no base namespace so every entity (e.g., SecurityRequirement) must be qualified with some prefix.

The line

xmlns:j.0="http://hello#

should likely be

xml:base="http://hello#"

Martin

On May 17, 2017, at 1:03 AM, mary <[hidden email]> wrote:

The first question I asked is solved, so I delete it. The second question and
the third question is the same, because I think maybe I didn't describe my
question clearly. My English is poor. You mean I need to write the code in
quesion and don't update it.

The error function is as follows:
   OWLOntologyManager ontologyManager =
OWLManager.createOWLOntologyManager();
   OWLOntology ontology =
ontologyManager.loadOntologyFromOntologyDocument(file);
   System.out.println(ontology.getClassesInSignature());
   System.out.println(ontology.getObjectPropertiesInSignature());
   SQWRLQueryEngine queryEngine =
SWRLAPIFactory.createSQWRLQueryEngine(ontology);
   SQWRLResult result = queryEngine.runSQWRLQuery("q1",
"SecurityRequirement(?s)^hasObject(?s,vold) -> sqwrl:select(?s)");
    if (result.next())
             System.out.println("Name: " + result.getLiteral("x"));
             System.out.println(result.toString());
}

The result of code is
<http://hello#Object><http://hello#SecurityRequirement>]
[<http://hello#hasSecurityGoal>, <http://hello#hasPath>,
<http://hello#With>, <http://hello#hasObject>]
*Error parsing SWRL rule or SQWRL query: Invalid SWRL atom predicate
'SecurityRequirement'*

The owl file with is loaded in    ' OWLOntology ontology =
ontologyManager.loadOntologyFromOntologyDocument(file);' is as follows:

<rdf:RDF
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:j.0="http://hello#"
   xmlns:owl="http://www.w3.org/2002/07/owl#"
   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema#" >
...
 <rdf:Description rdf:about="http://hello#SecurityRequirement">
   <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
 </rdf:Description>
...
 <rdf:Description rdf:about="http://hello#hasObject">
   <rdfs:range rdf:resource="http://hello#Object"/>
   <rdfs:domain rdf:resource="http://hello#SecurityRequirement"/>
   <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/>
 </rdf:Description>





--
View this message in context: http://protege-project.136.n4.nabble.com/Invalid-SWRL-atom-predicate-tp4668529p4668531.html
Sent from the Protege User mailing list archive at Nabble.com.
_______________________________________________
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: Invalid SWRL atom predicate

mary
In reply to this post by mary
Thankyou for your reply.
I also have problem about modify the xmlns:j.0. I use jena to create owl file.

    OntModel on = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
    File file=new File("C:\\Users\\pf\\Desktop\\example\\1.owl");
    openFile(on,file);
    String exNs="http://hello#";
    OntClass Object=on.createClass(exNs+"SecurityRequirement");

So, all the classes created by this code has the prefix.Sould I change the jar and use another API such as pretege-API? I can't  solve the problem.How can I change the prefix?
Please help me. Thanks advance.
Reply | Threaded
Open this post in threaded view
|

Re: Invalid SWRL atom predicate

Lorenz Buehmann
Then the question is, how to you save the model in Jena? You can

1. define the base prefix when writing the model and
2. use the serialization syntax.



Thankyou for your reply.
I also have problem about modify the xmlns:j.0. I use jena to create owl
file.

    OntModel on = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
null);
    File file=new File("C:\\Users\\pf\\Desktop\\example\\1.owl");
    openFile(on,file);
    String exNs="http://hello#";
    OntClass Object=on.createClass(exNs+"SecurityRequirement");

So, all the classes created by this code has the prefix.Sould I change the
jar and use another API such as pretege-API? I can't  solve the problem.How
can I change the prefix?
Please help me. Thanks advance.



--
View this message in context: http://protege-project.136.n4.nabble.com/Invalid-SWRL-atom-predicate-tp4668529p4668544.html
Sent from the Protege User mailing list archive at Nabble.com.
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

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

Re: Invalid SWRL atom predicate

mary
Thank you for your reply.

I use this part of code to add xml:base="http://example.org/">.

    final String NS = "http://example.org/";
    OntModel model = ModelFactory.createOntologyModel();
    model.createOntology( NS );
    RDFWriter writer = model.getWriter( "RDF/XML-ABBREV" );
    writer.setProperty( "xmlbase", NS );
    writer.write( model.getBaseModel(), System.out, NS );            //output
    OntClass sr=model.createClass(NS+"SecurityRequirement");
    outputFile(model);                                                 //save to owl file

The function of save model to a owl file is as follows:

        public static void outputFile(OntModel ontModel)
        {
                FileOutputStream out = null;
                try {
                        File newFile = new File("D:\\owl_example\\5.owl");
                        out = new FileOutputStream(newFile);
                        ontModel.write(out);
                        out.close();
                } catch (FileNotFoundException e) {
                e.printStackTrace();
                } catch (IOException e) {
                e.printStackTrace();}
                }

But the direct ouput of the code is:

    <rdf:RDF
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns:owl="http://www.w3.org/2002/07/owl#"
        xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
      xml:base="http://example.org/">
      <owl:Ontology rdf:about=""/>
    </rdf:RDF>

And the content of owl file which I saved is as follows:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" > 
  <rdf:Description rdf:about="http://example.org/">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://example.org/SecurityRequirement">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
</rdf:RDF>

Clearly in the owl file which I saved misses   xml:base="http://example.org/">. It is different with the direct ouput of code.

And if I use the function:model.createResource(NS+"vold",ob); to create a individual, will add 'xmlns:j.0= ' to my owl file.

So, the first question is how can I save  xml:base="http://example.org/"> to my owl file?
the second question is how to create individual to avoid adding the 'xmlns:j.0='?
I know there is large gap between the owl which I created  with java and the owl created by protege tool. My owl file is so weird.

Please help me. Thanks advance.

What's wrong with my method to add
Reply | Threaded
Open this post in threaded view
|

Re: Invalid SWRL atom predicate

Martin O'Connor-2

You might want to ask this question on the Jena mailing list.

Note, that both Protege and the SWRLAPI use the OWLAPI so it may be a better choice if you plan to work with either of these.

Martin

> On May 18, 2017, at 6:37 AM, mary <[hidden email]> wrote:
>
> Thank you for your reply.
>
> I use this part of code to add xml:base="http://example.org/">.
>
>    final String NS = "http://example.org/";
>    OntModel model = ModelFactory.createOntologyModel();
>    model.createOntology( NS );
>    RDFWriter writer = model.getWriter( "RDF/XML-ABBREV" );
>    writer.setProperty( "xmlbase", NS );
>    writer.write( model.getBaseModel(), System.out, NS );          
> //output
>    OntClass sr=model.createClass(NS+"SecurityRequirement");
>    *outputFile*(model);                                                
> //save to owl file
>
> The function of save model to a owl file is as follows:
>
> public static void *outputFile*(OntModel ontModel)
> {
> FileOutputStream out = null;
> try {
> File newFile = new File("D:\\owl_example\\5.owl");
> out = new FileOutputStream(newFile);
> ontModel.write(out);
> out.close();
> } catch (FileNotFoundException e) {
> e.printStackTrace();
> } catch (IOException e) {
> e.printStackTrace();}
> }
>
> But the direct ouput of the code is:
>
>    <rdf:RDF
>        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>        xmlns:owl="http://www.w3.org/2002/07/owl#"
>        xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>        xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
>      xml:base="http://example.org/">
>      <owl:Ontology rdf:about=""/>
>    </rdf:RDF>
>
> And the content of owl file which I saved is as follows:
>
> <rdf:RDF
>    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>    xmlns:owl="http://www.w3.org/2002/07/owl#"
>    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" >
>  <rdf:Description rdf:about="http://example.org/">
>    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
>  </rdf:Description>
>  <rdf:Description rdf:about="http://example.org/SecurityRequirement">
>    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
>  </rdf:Description>
> </rdf:RDF>
>
> Clearly in the owl file which I saved misses  
> xml:base="http://example.org/">. It is different with the direct ouput of
> code.
>
> And if I use the function:model.createResource(NS+"vold",ob); to create a
> individual, will add 'xmlns:j.0= ' to my owl file.
>
> So, the first question is how can I save  xml:base="http://example.org/"> to
> my owl file?
> the second question is how to create individual to avoid adding the
> 'xmlns:j.0='?
> I know there is large gap between the owl which I created  with java and the
> owl created by protege tool. My owl file is so weird.
>
> Please help me. Thanks advance.
>
> What's wrong with my method to add
>
>
>
> --
> View this message in context: http://protege-project.136.n4.nabble.com/Invalid-SWRL-atom-predicate-tp4668529p4668547.html
> Sent from the Protege User mailing list archive at Nabble.com.
> _______________________________________________
> 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: Invalid SWRL atom predicate

Lorenz Buehmann
@Mary

you should not modify the RDFWriter object of the model, instead use

ontModel.write(out, "RDF/XML-ABBREV", NS);


> You might want to ask this question on the Jena mailing list.
>
> Note, that both Protege and the SWRLAPI use the OWLAPI so it may be a better choice if you plan to work with either of these.
>
> Martin
>
>> On May 18, 2017, at 6:37 AM, mary <[hidden email]> wrote:
>>
>> Thank you for your reply.
>>
>> I use this part of code to add xml:base="http://example.org/">.
>>
>>    final String NS = "http://example.org/";
>>    OntModel model = ModelFactory.createOntologyModel();
>>    model.createOntology( NS );
>>    RDFWriter writer = model.getWriter( "RDF/XML-ABBREV" );
>>    writer.setProperty( "xmlbase", NS );
>>    writer.write( model.getBaseModel(), System.out, NS );          
>> //output
>>    OntClass sr=model.createClass(NS+"SecurityRequirement");
>>    *outputFile*(model);                                                
>> //save to owl file
>>
>> The function of save model to a owl file is as follows:
>>
>> public static void *outputFile*(OntModel ontModel)
>> {
>> FileOutputStream out = null;
>> try {
>> File newFile = new File("D:\\owl_example\\5.owl");
>> out = new FileOutputStream(newFile);
>> ontModel.write(out);
>> out.close();
>> } catch (FileNotFoundException e) {
>> e.printStackTrace();
>> } catch (IOException e) {
>> e.printStackTrace();}
>> }
>>
>> But the direct ouput of the code is:
>>
>>    <rdf:RDF
>>        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>        xmlns:owl="http://www.w3.org/2002/07/owl#"
>>        xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>>        xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
>>      xml:base="http://example.org/">
>>      <owl:Ontology rdf:about=""/>
>>    </rdf:RDF>
>>
>> And the content of owl file which I saved is as follows:
>>
>> <rdf:RDF
>>    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
>>    xmlns:owl="http://www.w3.org/2002/07/owl#"
>>    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
>>    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" >
>>  <rdf:Description rdf:about="http://example.org/">
>>    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
>>  </rdf:Description>
>>  <rdf:Description rdf:about="http://example.org/SecurityRequirement">
>>    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
>>  </rdf:Description>
>> </rdf:RDF>
>>
>> Clearly in the owl file which I saved misses  
>> xml:base="http://example.org/">. It is different with the direct ouput of
>> code.
>>
>> And if I use the function:model.createResource(NS+"vold",ob); to create a
>> individual, will add 'xmlns:j.0= ' to my owl file.
>>
>> So, the first question is how can I save  xml:base="http://example.org/"> to
>> my owl file?
>> the second question is how to create individual to avoid adding the
>> 'xmlns:j.0='?
>> I know there is large gap between the owl which I created  with java and the
>> owl created by protege tool. My owl file is so weird.
>>
>> Please help me. Thanks advance.
>>
>> What's wrong with my method to add
>>
>>
>>
>> --
>> View this message in context: http://protege-project.136.n4.nabble.com/Invalid-SWRL-atom-predicate-tp4668529p4668547.html
>> Sent from the Protege User mailing list archive at Nabble.com.
>> _______________________________________________
>> 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
>
--
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user