Java API for Snap SPARQL, not just the Protege plugin?

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

Java API for Snap SPARQL, not just the Protege plugin?

kcason

Is there a Snap SPARQL API for Java that takes a query string (formatted like the default query in the Protégé plugin) and returns the results?

 

For example:

 

String myQuery =

“PREFIX owl: <http://www.w3.org/2002/07/owl#>” +

“PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>” +

“PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> “ +

“ “ +

“SELECT ?x (STR(?lab) AS ?label) WHERE { “ +

“    ?x rdf:type owl:Class . “ +

“    OPTIONAL {?x rdfs:label ?lab} “ +

“}” +

“ORDER BY ?label”;

 

ResultSet myResultSet = magicalSnapSparqlEngine.getResults(myQuery);

 

 

This is what it looks like from the Protégé Snap SPARQL plugin:

 

 

 

FYI: I have a query working that uses the de.derivo.sparqldlapi but takes a differently formatted string as input (as far as I can tell).

 

de.derivo.sparqldlapi example:

 

   final String query_string = query_prefix +

            "SELECT *\n" +

            "WHERE { \n" +

            "Type(?myPizza, ont:pizza),\n" +

            "Type(?myEffect, ont:effect),\n" +

            "Type(?myGastroProblem, ont:gastroproblem),\n" +

 

            "PropertyValue(?classD, ont:hasEffect, ?myEffect),\n" +

            "PropertyValue(?classD, ont:exhibits, ?myGastroProblem)\n" +

            "};

 

 

I need this to be formatted more like what the Snap SPARQL plugin takes as input, so I can test it in Protégé before committing it to Java code:

 

   final String query_string = query_prefix +

            "SELECT *\n" +

            "WHERE { \n" +

            "?myPizza a ont:pizza .\n" +

            "?myEffect a ont:effect .\n" +

            "?myGastroProblem a ont:gastroproblem .\n" +

 

            "?classD ont:hasEffect ?myEffect .\n" +

            "?classD ont:exhibits ?myGastroProblem .\n" +

            "};

 

Thanks,

 

-Kenny Cason, CISSP

Radiance Technologies

Cyber Solutions Group

3133 General Hudnell Dr. Ste. 116
San Antonio, TX 78226

[hidden email]

206.550.0049

 


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

Re: Java API for Snap SPARQL, not just the Protege plugin?

Lorenz B.
Apache Jena or RDF4J are the de-facto standard Java APIs for SPARQL

Or you just stick to the Snap SPARQL API, an example how to create parser and use the query engine can be found here [1]


Is there a Snap SPARQL API for Java that takes a query string (formatted like the default query in the Protégé plugin) and returns the results?

 

For example:

 

String myQuery =

“PREFIX owl: <http://www.w3.org/2002/07/owl#>” +

“PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>” +

“PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> “ +

“ “ +

“SELECT ?x (STR(?lab) AS ?label) WHERE { “ +

“    ?x rdf:type owl:Class . “ +

“    OPTIONAL {?x rdfs:label ?lab} “ +

“}” +

“ORDER BY ?label”;

 

ResultSet myResultSet = magicalSnapSparqlEngine.getResults(myQuery);

 

 

This is what it looks like from the Protégé Snap SPARQL plugin:

 

 

 

FYI: I have a query working that uses the de.derivo.sparqldlapi but takes a differently formatted string as input (as far as I can tell).

 

de.derivo.sparqldlapi example:

 

   final String query_string = query_prefix +

            "SELECT *\n" +

            "WHERE { \n" +

            "Type(?myPizza, ont:pizza),\n" +

            "Type(?myEffect, ont:effect),\n" +

            "Type(?myGastroProblem, ont:gastroproblem),\n" +

 

            "PropertyValue(?classD, ont:hasEffect, ?myEffect),\n" +

            "PropertyValue(?classD, ont:exhibits, ?myGastroProblem)\n" +

            "};

 

 

I need this to be formatted more like what the Snap SPARQL plugin takes as input, so I can test it in Protégé before committing it to Java code:

 

   final String query_string = query_prefix +

            "SELECT *\n" +

            "WHERE { \n" +

            "?myPizza a ont:pizza .\n" +

            "?myEffect a ont:effect .\n" +

            "?myGastroProblem a ont:gastroproblem .\n" +

 

            "?classD ont:hasEffect ?myEffect .\n" +

            "?classD ont:exhibits ?myGastroProblem .\n" +

            "};

 

Thanks,

 

-Kenny Cason, CISSP

Radiance Technologies

Cyber Solutions Group

3133 General Hudnell Dr. Ste. 116
San Antonio, TX 78226

[hidden email]

206.550.0049

 


_______________________________________________
protege-dev mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-dev
-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

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

Re: Java API for Snap SPARQL, not just the Protege plugin?

kcason

Thanks, that does the trick!

 

The TestParser.java query returns a SPARQLQueryResult object. I know there is a ResultSet method to convert ResultSets to JSON strings. Is there a known way to turn a SPARQLQueryResult object into JSON or into a ResultSet?

 

I can write one myself but I’d rather not reinvent the wheel.

 

Here is the call from TestParser.java:

 

 

    private static void parse(OWLOntology ontology, String s) {

       
SPARQLTokenizer tokenizer = new SPARQLTokenizerJavaCCImpl(ontology, new StringReader(s));
       
SPARQLParserImpl parser = new SPARQLParserImpl(tokenizer);

       
Query query = parser.parseQuery();


       
SPARQLQueryResult result = queryEngine.ask(query.asSelectQuery());

 

 

Thanks as usual!

 

-Kenny

 

From: protege-dev <[hidden email]> On Behalf Of Lorenz B.
Sent: Friday, May 17, 2019 12:42 AM
To: [hidden email]
Subject: Re: [protege-dev] Java API for Snap SPARQL, not just the Protege plugin?

 

CAUTION: External Email



Apache Jena or RDF4J are the de-facto standard Java APIs for SPARQL

 

Or you just stick to the Snap SPARQL API, an example how to create parser and use the query engine can be found here [1]

 



Is there a Snap SPARQL API for Java that takes a query string (formatted like the default query in the Protégé plugin) and returns the results?

 

For example:

 

String myQuery =

“PREFIX owl: <http://www.w3.org/2002/07/owl#>” +

“PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>” +

“PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> “ +

“ “ +

“SELECT ?x (STR(?lab) AS ?label) WHERE { “ +

“    ?x rdf:type owl:Class . “ +

“    OPTIONAL {?x rdfs:label ?lab} “ +

“}” +

“ORDER BY ?label”;

 

ResultSet myResultSet = magicalSnapSparqlEngine.getResults(myQuery);

 

 

This is what it looks like from the Protégé Snap SPARQL plugin:

 

 

 

FYI: I have a query working that uses the de.derivo.sparqldlapi but takes a differently formatted string as input (as far as I can tell).

 

de.derivo.sparqldlapi example:

 

   final String query_string = query_prefix +

            "SELECT *\n" +

            "WHERE { \n" +

            "Type(?myPizza, ont:pizza),\n" +

            "Type(?myEffect, ont:effect),\n" +

            "Type(?myGastroProblem, ont:gastroproblem),\n" +

 

            "PropertyValue(?classD, ont:hasEffect, ?myEffect),\n" +

            "PropertyValue(?classD, ont:exhibits, ?myGastroProblem)\n" +

            "};

 

 

I need this to be formatted more like what the Snap SPARQL plugin takes as input, so I can test it in Protégé before committing it to Java code:

 

   final String query_string = query_prefix +

            "SELECT *\n" +

            "WHERE { \n" +

            "?myPizza a ont:pizza .\n" +

            "?myEffect a ont:effect .\n" +

            "?myGastroProblem a ont:gastroproblem .\n" +

 

            "?classD ont:hasEffect ?myEffect .\n" +

            "?classD ont:exhibits ?myGastroProblem .\n" +

            "};

 

Thanks,

 

-Kenny Cason, CISSP

Radiance Technologies

Cyber Solutions Group

3133 General Hudnell Dr. Ste. 116
San Antonio, TX 78226

[hidden email]

206.550.0049

 



_______________________________________________
protege-dev mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-dev
-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center

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