SQWRL query in Eclipse results run-time error

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

SQWRL query in Eclipse results run-time error

Kumaar
Hello, I have gone through the instructions of developers earlier in creating
sqwrl rules in protege. I am new to java programming. Generated a simple
coding for getting results into eclipse-java using the owl file created in
protege 5.0

I have created the java file as below:
~~~~~~~~~~~~~~~~~~~~~~~

package swrlapiExample;

import java.io.File;

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.swrlapi.factory.SWRLAPIFactory;
import org.swrlapi.parser.SWRLParseException;
import org.swrlapi.sqwrl.SQWRLQueryEngine;
import org.swrlapi.sqwrl.SQWRLResult;
import org.swrlapi.sqwrl.exceptions.SQWRLException;
import org.semanticweb.owlapi.model.OWLOntologyManager.*;
 
@SuppressWarnings("unused")
public class SWRLAPIExample
{
  public static void main(String[] args)
  {
    try {

    // Create OWLOntology instance using the OWLAPI
    OWLOntologyManager ontologyManager =
OWLManager.createOWLOntologyManager();
    OWLOntology ontology =
ontologyManager.loadOntologyFromOntologyDocument(new
File("C://Kumaar/univer.owl"));
   
    // Create SQWRL query engine using the SWRLAPI
    SQWRLQueryEngine queryEngine =
SWRLAPIFactory.createSQWRLQueryEngine(ontology);
   
    // Create and execute a SQWRL query
    //SQWRLResult result = queryEngine.runSQWRLQuery("Q1", "Person(?p) ^
hasName(?p, ?name) ^ hasSalary(?p, ?salary)" + " -> sqwrl:select(?name,
?salary)");
    SQWRLResult result = queryEngine.runSQWRLQuery("Q1", "Student(?stu) ^
studies(?stu, ?sub)" + " -> sqwrl:select(?stu) ^ sqwrl:count(?sub)");
    // Process the results of the SQWRL query
    while (result.next()) {
      System.out.println("Students : " +
result.getLiteral("stu").getString());
      System.out.println(" Subjects : " +
result.getLiteral("sub").getInteger());
    }
 
   }
   
    catch (SQWRLException | OWLOntologyCreationException |
SWRLParseException e) {
        System.err.println("Error running SQWRL query: " + e.getMessage());
        System.exit(-1);
      }
  }
}


Got Error in run time as below :
~~~~~~~~~~~~~~~~~~~

Exception in thread "main" org.swrlapi.exceptions.SWRLRuleEngineException:
Error creating query engine Drools. Exception: java.lang.NoSuchMethodError.
Message:
org.semanticweb.owlapi.model.OWLOntologyManager.getIRIMappers()Lorg/semanticweb/owlapi/util/PriorityCollection;
        at
org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSQWRLQueryEngine(DefaultSWRLRuleAndQueryEngineFactory.java:113)
        at
org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSQWRLQueryEngine(DefaultSWRLRuleAndQueryEngineFactory.java:84)
        at
org.swrlapi.factory.SWRLAPIFactory.createSQWRLQueryEngine(SWRLAPIFactory.java:62)
        at org.swrlapi.example.SWRLAPIExample.main(SWRLAPIExample.java:28)
Caused by: java.lang.NoSuchMethodError:
org.semanticweb.owlapi.model.OWLOntologyManager.getIRIMappers()Lorg/semanticweb/owlapi/util/PriorityCollection;
        at
org.swrlapi.factory.DefaultSWRLAPIOWLOntology.addSWRLAPIOntologies(DefaultSWRLAPIOWLOntology.java:1740)
        at
org.swrlapi.factory.DefaultSWRLAPIOWLOntology.<init>(DefaultSWRLAPIOWLOntology.java:161)
        at
org.swrlapi.factory.SWRLAPIInternalFactory.createSWRLAPIOntology(SWRLAPIInternalFactory.java:248)
        at
org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSQWRLQueryEngine(DefaultSWRLRuleAndQueryEngineFactory.java:94)
        ... 3 more


attached owl file with this forum.  univer.owl
<http://protege-project.136.n4.nabble.com/file/t376837/univer.owl>  

kindly let me know what am I missing to get the result ?

Regards
Kumaar



-----
Regards
Kumaar
--
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
Regards
Kumaar
Reply | Threaded
Open this post in threaded view
|

Re: SQWRL query in Eclipse results run-time error

Martin O'Connor-2

It looks like you have may have some incorrect dependency versions in your POM.

I would use the latest 2.0.5 SWRLAPI and start with the following skeleton SWRLAPI project:


It should help you nail down your dependencies.

Martin

On Jul 23, 2018, at 11:52 AM, Kumaar <[hidden email]> wrote:

Hello, I have gone through the instructions of developers earlier in creating
sqwrl rules in protege. I am new to java programming. Generated a simple
coding for getting results into eclipse-java using the owl file created in
protege 5.0

I have created the java file as below:
~~~~~~~~~~~~~~~~~~~~~~~

package swrlapiExample;

import java.io.File;

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import org.swrlapi.factory.SWRLAPIFactory;
import org.swrlapi.parser.SWRLParseException;
import org.swrlapi.sqwrl.SQWRLQueryEngine;
import org.swrlapi.sqwrl.SQWRLResult;
import org.swrlapi.sqwrl.exceptions.SQWRLException;
import org.semanticweb.owlapi.model.OWLOntologyManager.*;

@SuppressWarnings("unused")
public class SWRLAPIExample
{
 public static void main(String[] args)
 {
   try {

    // Create OWLOntology instance using the OWLAPI
    OWLOntologyManager ontologyManager =
OWLManager.createOWLOntologyManager();
    OWLOntology ontology =
ontologyManager.loadOntologyFromOntologyDocument(new
File("<a href="C://Kumaar/univer.owl" class="">C://Kumaar/univer.owl"));
   
    // Create SQWRL query engine using the SWRLAPI
    SQWRLQueryEngine queryEngine =
SWRLAPIFactory.createSQWRLQueryEngine(ontology);
   
    // Create and execute a SQWRL query
    //SQWRLResult result = queryEngine.runSQWRLQuery("Q1", "Person(?p) ^
hasName(?p, ?name) ^ hasSalary(?p, ?salary)" + " -> sqwrl:select(?name,
?salary)");
    SQWRLResult result = queryEngine.runSQWRLQuery("Q1", "Student(?stu) ^
studies(?stu, ?sub)" + " -> sqwrl:select(?stu) ^ sqwrl:count(?sub)");
    // Process the results of the SQWRL query
    while (result.next()) {
      System.out.println("Students : " +
result.getLiteral("stu").getString());
      System.out.println(" Subjects : " +
result.getLiteral("sub").getInteger());
    }

  }

   catch (SQWRLException | OWLOntologyCreationException |
SWRLParseException e) {
       System.err.println("Error running SQWRL query: " + e.getMessage());
       System.exit(-1);
     }
 }
}


Got Error in run time as below :
~~~~~~~~~~~~~~~~~~~

Exception in thread "main" org.swrlapi.exceptions.SWRLRuleEngineException:
Error creating query engine Drools. Exception: java.lang.NoSuchMethodError.
Message:
org.semanticweb.owlapi.model.OWLOntologyManager.getIRIMappers()Lorg/semanticweb/owlapi/util/PriorityCollection;
at
org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSQWRLQueryEngine(DefaultSWRLRuleAndQueryEngineFactory.java:113)
at
org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSQWRLQueryEngine(DefaultSWRLRuleAndQueryEngineFactory.java:84)
at
org.swrlapi.factory.SWRLAPIFactory.createSQWRLQueryEngine(SWRLAPIFactory.java:62)
at org.swrlapi.example.SWRLAPIExample.main(SWRLAPIExample.java:28)
Caused by: java.lang.NoSuchMethodError:
org.semanticweb.owlapi.model.OWLOntologyManager.getIRIMappers()Lorg/semanticweb/owlapi/util/PriorityCollection;
at
org.swrlapi.factory.DefaultSWRLAPIOWLOntology.addSWRLAPIOntologies(DefaultSWRLAPIOWLOntology.java:1740)
at
org.swrlapi.factory.DefaultSWRLAPIOWLOntology.<init>(DefaultSWRLAPIOWLOntology.java:161)
at
org.swrlapi.factory.SWRLAPIInternalFactory.createSWRLAPIOntology(SWRLAPIInternalFactory.java:248)
at
org.swrlapi.factory.DefaultSWRLRuleAndQueryEngineFactory.createSQWRLQueryEngine(DefaultSWRLRuleAndQueryEngineFactory.java:94)
... 3 more


attached owl file with this forum.  univer.owl
<http://protege-project.136.n4.nabble.com/file/t376837/univer.owl>  

kindly let me know what am I missing to get the result ?

Regards
Kumaar



-----
Regards
Kumaar
--
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: SQWRL query in Eclipse results run-time error

Kumaar
Yes Martin, Block of errors vanished after updating swrlapi2.0.5 and gave an
another error for stated below

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further
details

while searched for the solution I got to know according to the below site we
have to update an older version of slf4j - link for source -
http://mvnrepository.com/artifact/org.slf4j/slf4j-simple/1.6.2

solution link:
https://stackoverflow.com/questions/7421612/slf4j-failed-to-load-class-org-slf4j-impl-staticloggerbinder

all other errors vanished and only one is present now

"Error running SQWRL query: expecting literal type for column stu"

please suggest if any,  also going through the below solution source

https://github.com/protegeproject/swrlapi/wiki/SQWRLQueryAPI#processing-result-columns





-----
Regards
Kumaar
--
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
Regards
Kumaar
Reply | Threaded
Open this post in threaded view
|

Re: SQWRL query in Eclipse results run-time error

Kumaar
read about the column names and updated the below swrl query in java

SQWRLResult result = queryEngine.runSQWRLQuery("Q1", "Student(?stu) ^
studies(?stu, ?sub)" + " -> sqwrl:select(?stu) ^ sqwrl:count(?stu) ^
sqwrl:columnNames(Student, countOfStudents)");          
    // Process the results of the SQWRL query
    while (result.next()) {
      System.out.println(" Students : " +
result.getLiteral("Students").getString());
      System.out.println(" Subjects : " +
result.getLiteral("countOfStudents").getInteger());

getting error below

Error running SQWRL query: Expecting boolean or OWL entity name, got
'countOfStudents'

please suggest



-----
Regards
Kumaar
--
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
Regards
Kumaar
Reply | Threaded
Open this post in threaded view
|

Re: SQWRL query in Eclipse results run-time error

Lorenz Buehmann


On 24.07.2018 05:10, Kumaar wrote:

> read about the column names and updated the below swrl query in java
>
> SQWRLResult result = queryEngine.runSQWRLQuery("Q1", "Student(?stu) ^
> studies(?stu, ?sub)" + " -> sqwrl:select(?stu) ^ sqwrl:count(?stu) ^
> sqwrl:columnNames(Student, countOfStudents)");          
>     // Process the results of the SQWRL query
>     while (result.next()) {
>       System.out.println(" Students : " +
> result.getLiteral("Students").getString());
>       System.out.println(" Subjects : " +
> result.getLiteral("countOfStudents").getInteger());
>
> getting error below
>
> Error running SQWRL query: Expecting boolean or OWL entity name, got
> 'countOfStudents'
>
> please suggest
Are you sure that there is no error before? I mean, you set a column
name "Student" but then you call result.getLiteral("Students") - that
can't work.

>
>
>
> -----
> Regards
> Kumaar
> --
> 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: SQWRL query in Eclipse results run-time error

Kumaar
This post was updated on .
Yes, lately I have corrected that typo after the posting.

Here is the latest coding in protege:
university7:Student(?stu) ^ university7:studies(?stu, ?sub) ->
sqwrl:select(?stu) ^ sqwrl:count(?stu) ^ sqwrl:columnNames("StudentName",
"Description", "Count")

screenshot in protege:
<http://protege-project.136.n4.nabble.com/file/t376837/protege-univer.png


Here is the latest coding in java:
SQWRLResult result = queryEngine.runSQWRLQuery("Q1", "university7:Student(?stu) ^ university7:studies(?stu, ?sub)" + " -> sqwrl:select(?stu) ^ sqwrl:count(?stu) ^ sqwrl:columnNames(StudentName)");

System.out.println(" Subjects : " + result.getLiteral("StudentName").getString());

Error message :
Error running SQWRL query: Expecting boolean or OWL entity name, got
'StudentName'

please kindly provide a solution for this.



-----
Regards
Kumaar
--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
protege-user@lists.stanford.edu
https://mailman.stanford.edu/mailman/listinfo/protege-user
Regards
Kumaar
Reply | Threaded
Open this post in threaded view
|

Re: SQWRL query in Eclipse results run-time error

Lorenz Buehmann


On 24.07.2018 08:22, Kumaar wrote:

> Yes, lately I have corrected that typo after the posting.
>
> Here is the latest coding in protege:
> university7:Student(?stu) ^ university7:studies(?stu, ?sub) ->
> sqwrl:select(?stu) ^ sqwrl:count(?stu) ^ sqwrl:columnNames("StudentName",
> "Description", "Count")
>
> screenshot in protege:
> <http://protege-project.136.n4.nabble.com/file/t376837/protege-univer.png>
>
>
> Here is the latest coding in java:
> SQWRLResult result = queryEngine.runSQWRLQuery("Q1",
> "university7:Student(?stu) ^ university7:studies(?stu, ?sub)" + " ->
> sqwrl:select(?stu) ^ sqwrl:count(?stu) ^ sqwrl:columnNames(StudentName,
> Description, Count)");
well I don't get what you're doing here. You select one variables + you
make a count, thus, only two result elements, but you try to assign 3
columns names. that can't work.

and what's the goal of the query? you're selecting each student and you
count the students. this would result in each row containing a student
and the number of students, or not?

I guess, it would be easier if you share the ontology + say what you're
trying to achieve with the query

>
> Error message :
> Error running SQWRL query: Expecting boolean or OWL entity name, got
> 'StudentName'
>
> please kindly provide a solution for this.
>
>
>
> -----
> Regards
> Kumaar
> --
> 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: SQWRL query in Eclipse results run-time error

Kumaar
That's right Lorenz, as per the earlier message posted I will be getting the
two results which could be retrieving answers for listing the "Student
Names(in string)" and "Number of Students( return type in integer)".

My goal in this java coding is to get the swrl query executed in
eclipse-java and get the answer to be displayed as an output using
dependency swrlapi 2.0.5 jar

Also, I require the swrl rule named "listCol" in protege to get the
displayed. Both are similar goals are similar to each other.

First goal is to create, execute the query in eclipse-java, display output
in java and second goal is to get the output of resultant rule from protege
to get displayed in eclipse-java

I have attached my owl file for reference  univer.owl
<http://protege-project.136.n4.nabble.com/file/t376837/univer.owl>  

Also, Attached the screenshots of protege

Protege rule for the below java code: Name of the rule in protege is
"listCol"
university7:Student(?stu) ^ university7:studies(?stu, ?sub) ->
sqwrl:select(?stu) ^ sqwrl:count(?stu) ^
sqwrl:columnNames("ListOfStudentNames", "NoOfStudents")

Java code :
SQWRLResult result = queryEngine.runSQWRLQuery("Q1",
"university7:Student(?stu) ^ university7:studies(?stu, ?sub) ->
sqwrl:select(?stu) ^ sqwrl:count(?stu) ^
sqwrl:columnNames(ListOfStudentNames,NoOfStudents)");
 //Process the results of the SQWRL query
 while (result.next()) {
 System.out.println(" Subjects : " +
result.getLiteral("ListOfStudentNames").getString());
 System.out.println(" Subjects : " +
result.getLiteral("NoOfStudents").getInteger());
}


Error retrieved in java:
Error running SQWRL query: Expecting boolean or OWL entity name, got
'ListOfStudentNames'

Kindly provide a solution for first goal as soon as possible.



-----
Regards
Kumaar
--
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
Regards
Kumaar
Reply | Threaded
Open this post in threaded view
|

Re: SQWRL query in Eclipse results run-time error

Martin O'Connor-2
The SQWRLResult interface is described here:


The ?stu variable binds to an OWL individual so you will need to use the getNamedIndividual method to retrieve its value.

Martin

On Jul 24, 2018, at 6:04 AM, Kumaar <[hidden email]> wrote:

That's right Lorenz, as per the earlier message posted I will be getting the
two results which could be retrieving answers for listing the "Student
Names(in string)" and "Number of Students( return type in integer)".

My goal in this java coding is to get the swrl query executed in
eclipse-java and get the answer to be displayed as an output using
dependency swrlapi 2.0.5 jar

Also, I require the swrl rule named "listCol" in protege to get the
displayed. Both are similar goals are similar to each other.

First goal is to create, execute the query in eclipse-java, display output
in java and second goal is to get the output of resultant rule from protege
to get displayed in eclipse-java

I have attached my owl file for reference  univer.owl
<http://protege-project.136.n4.nabble.com/file/t376837/univer.owl>   

Also, Attached the screenshots of protege

Protege rule for the below java code: Name of the rule in protege is
"listCol"
university7:Student(?stu) ^ university7:studies(?stu, ?sub) ->
sqwrl:select(?stu) ^ sqwrl:count(?stu) ^
sqwrl:columnNames("ListOfStudentNames", "NoOfStudents")

Java code :
SQWRLResult result = queryEngine.runSQWRLQuery("Q1",
"university7:Student(?stu) ^ university7:studies(?stu, ?sub) ->
sqwrl:select(?stu) ^ sqwrl:count(?stu) ^
sqwrl:columnNames(ListOfStudentNames,NoOfStudents)");
//Process the results of the SQWRL query
while (result.next()) {
System.out.println(" Subjects : " +
result.getLiteral("ListOfStudentNames").getString());
System.out.println(" Subjects : " +
result.getLiteral("NoOfStudents").getInteger());
}


Error retrieved in java:
Error running SQWRL query: Expecting boolean or OWL entity name, got
'ListOfStudentNames'

Kindly provide a solution for first goal as soon as possible.



-----
Regards
Kumaar
--
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: SQWRL query in Eclipse results run-time error

Kumaar
This post was updated on .
Thank you Martin, I have resolved this first Goal !

SQWRLResult result = queryEngine.runSQWRLQuery("Q1", "university7:Student(?stu) ^ university7:studies(?stu, ?sub) -> sqwrl:select(?stu) ^ sqwrl:count(?sub) ");

System.out.println(" Students Name : " + result.getNamedIndividual("stu"));
System.out.println(" Students subjects count : " + result.getLiteral(1));

output:
 Students Name : university7:student1
 Students subjects count : "2"^^xsd:int
 Students Name : university7:student2
 Students subjects count : "3"^^xsd:int
 Students Name : university7:student3
 Students subjects count : "2"^^xsd:int



-----
Regards
Kumaar
--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
protege-user@lists.stanford.edu
https://mailman.stanford.edu/mailman/listinfo/protege-user
Regards
Kumaar