You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Marco Neumann <ma...@gmail.com> on 2020/03/18 11:58:08 UTC

Re: Identify SPARQL query's type

is there some utility function here in the code base now already to do
this, or do I still need to roll my own here?

On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org> wrote:

> On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
> > Hi,
> >
> > I would like to know if Jena offers a way to detect the type of an
> unknow SPARQL request ?Starting from the query string.
> >
> > At the moment the only way I succed to code it without "basic parsing"
> of the query ( sort of thing I prefer avoid, manually parsing string with
> short function often create errors )
> > looks like this :
> >
> > [...]
> >         String queryString = "a query string, may be a select or an
> update";
> >
> >          try{
> >              Query select = QueryFactory.create(queryString);
> >              Service.process_select_query(select);//do some work with
> the select
> >          }
> >          catch(QueryException e){
> >              UpdateRequest update = UpdateFactory.create(queryString);
> >              Service.process_update_query(update);//do some work with
> the update
> >          }
> >          catch(ProcessException e){
> >              //handle this exception
> >          }
> >
> > [...]
> >
> > So is it possible ? Or not ?
>
> Not currently.
>
> You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK keyword
> coming after BASE/PREFIXES/Comments.
>
>         Andy
>
>

-- 


---
Marco Neumann
KONA

Re: Identify SPARQL query's type

Posted by Claus Stadler <cs...@informatik.uni-leipzig.de>.
My current solution builds on the existing jena infrastructure - but it does not modify it.

My uses cases for uniform sparql stmt parsing included parsing query strings against a given prefix mapping and also cleaning queries - so removing unused prefixes.

I have some test cases in [1] of what it looks like:

PrefixMapping pm = RDFDataMgr.loadModel("rdf-prefixes/wikidata.jsonld");
String queryStr = "INSERT {" +
         "  ?s wdt:P279 wd:Q7725634 .\n" +
         "}\n" +
         "  WHERE {\n" +
         "      ?s rdfs:label ?desc \n" +
         "      FILTER (LANG(?desc) = \"en\").\n" +
         "  }\n";


// A SparqlStmtParser currently inherits from Function<String, SparqlStmt>

SparqlStmtParser parser =  SparqlStmtParserImpl.create(pm);
SparqlStmt stmt = parser.apply(queryStr); // Probably 'parse' would a nicer name than the generic apply
SparqlStmtUtils.optimizePrefixes(stmt);
UpdateRequest updateRequest = stmt.getUpdateRequest();


I know its not very well documented, but I hope you can get the gist of the idea :)


Cheers,

Claus

[1] https://github.com/SmartDataAnalytics/jena-sparql-api/blob/def0d3bdf0f4396fbf1ef0715f9697e9bb255029/jena-sparql-api-stmt/src/test/java/org/aksw/jena_sparql_api/stmt/TestSparqlStmtUtils.java#L54




On 18.03.20 14:25, Marco Neumann wrote:
> thank you Claus and Martynas, both very good ideas here. it's a function we
> should move into Jena.
>
> let's look at this in a bit more detail now, I currently envision this to
> be a factory method of org.apache.jena.query.Query returning boolean like
>
> .isSelect()
> .isAsk()
> .isDescribe()
> .isUpdate()
>
> Claus your solution would extend the following?
>
> org.apache.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:100)
>
> how is fuseki implementing this during query parsing at the moment?
>
>
>
>
> On Wed, Mar 18, 2020 at 1:00 PM Martynas Jusevičius <ma...@atomgraph.com>
> wrote:
>
>> I always wondered why there is no class hierarchy for SPARQL commands,
>> similarly to SP vocabulary [1]. Something like
>>
>> Command
>>    Query
>>      Describe
>>      Construct
>>      Select
>>      Ask
>>    Update
>>      ...
>>
>> So that one could check command type doing instanceof Update or
>> instance of Select instead of query.isSelectType() etc.
>>
>> [1] https://github.com/spinrdf/spinrdf/blob/master/etc/sp.ttl
>>
>>
>>
>> On Wed, Mar 18, 2020 at 12:58 PM Marco Neumann <ma...@gmail.com>
>> wrote:
>>> is there some utility function here in the code base now already to do
>>> this, or do I still need to roll my own here?
>>>
>>> On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org> wrote:
>>>
>>>> On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
>>>>> Hi,
>>>>>
>>>>> I would like to know if Jena offers a way to detect the type of an
>>>> unknow SPARQL request ?Starting from the query string.
>>>>> At the moment the only way I succed to code it without "basic
>> parsing"
>>>> of the query ( sort of thing I prefer avoid, manually parsing string
>> with
>>>> short function often create errors )
>>>>> looks like this :
>>>>>
>>>>> [...]
>>>>>          String queryString = "a query string, may be a select or an
>>>> update";
>>>>>           try{
>>>>>               Query select = QueryFactory.create(queryString);
>>>>>               Service.process_select_query(select);//do some work with
>>>> the select
>>>>>           }
>>>>>           catch(QueryException e){
>>>>>               UpdateRequest update =
>> UpdateFactory.create(queryString);
>>>>>               Service.process_update_query(update);//do some work with
>>>> the update
>>>>>           }
>>>>>           catch(ProcessException e){
>>>>>               //handle this exception
>>>>>           }
>>>>>
>>>>> [...]
>>>>>
>>>>> So is it possible ? Or not ?
>>>> Not currently.
>>>>
>>>> You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK
>> keyword
>>>> coming after BASE/PREFIXES/Comments.
>>>>
>>>>          Andy
>>>>
>>>>
>>> --
>>>
>>>
>>> ---
>>> Marco Neumann
>>> KONA
>
-- 
Dipl. Inf. Claus Stadler
Department of Computer Science, University of Leipzig
Research Group: http://aksw.org/
Workpage & WebID: http://aksw.org/ClausStadler
Phone: +49 341 97-32260


Re: Identify SPARQL query's type

Posted by Marco Neumann <ma...@gmail.com>.
thank you Claus and Martynas, both very good ideas here. it's a function we
should move into Jena.

let's look at this in a bit more detail now, I currently envision this to
be a factory method of org.apache.jena.query.Query returning boolean like

.isSelect()
.isAsk()
.isDescribe()
.isUpdate()

Claus your solution would extend the following?

org.apache.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:100)

how is fuseki implementing this during query parsing at the moment?




On Wed, Mar 18, 2020 at 1:00 PM Martynas Jusevičius <ma...@atomgraph.com>
wrote:

> I always wondered why there is no class hierarchy for SPARQL commands,
> similarly to SP vocabulary [1]. Something like
>
> Command
>   Query
>     Describe
>     Construct
>     Select
>     Ask
>   Update
>     ...
>
> So that one could check command type doing instanceof Update or
> instance of Select instead of query.isSelectType() etc.
>
> [1] https://github.com/spinrdf/spinrdf/blob/master/etc/sp.ttl
>
>
>
> On Wed, Mar 18, 2020 at 12:58 PM Marco Neumann <ma...@gmail.com>
> wrote:
> >
> > is there some utility function here in the code base now already to do
> > this, or do I still need to roll my own here?
> >
> > On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org> wrote:
> >
> > > On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
> > > > Hi,
> > > >
> > > > I would like to know if Jena offers a way to detect the type of an
> > > unknow SPARQL request ?Starting from the query string.
> > > >
> > > > At the moment the only way I succed to code it without "basic
> parsing"
> > > of the query ( sort of thing I prefer avoid, manually parsing string
> with
> > > short function often create errors )
> > > > looks like this :
> > > >
> > > > [...]
> > > >         String queryString = "a query string, may be a select or an
> > > update";
> > > >
> > > >          try{
> > > >              Query select = QueryFactory.create(queryString);
> > > >              Service.process_select_query(select);//do some work with
> > > the select
> > > >          }
> > > >          catch(QueryException e){
> > > >              UpdateRequest update =
> UpdateFactory.create(queryString);
> > > >              Service.process_update_query(update);//do some work with
> > > the update
> > > >          }
> > > >          catch(ProcessException e){
> > > >              //handle this exception
> > > >          }
> > > >
> > > > [...]
> > > >
> > > > So is it possible ? Or not ?
> > >
> > > Not currently.
> > >
> > > You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK
> keyword
> > > coming after BASE/PREFIXES/Comments.
> > >
> > >         Andy
> > >
> > >
> >
> > --
> >
> >
> > ---
> > Marco Neumann
> > KONA
>


-- 


---
Marco Neumann
KONA

Re: Identify SPARQL query's type

Posted by Martynas Jusevičius <ma...@atomgraph.com>.
I always wondered why there is no class hierarchy for SPARQL commands,
similarly to SP vocabulary [1]. Something like

Command
  Query
    Describe
    Construct
    Select
    Ask
  Update
    ...

So that one could check command type doing instanceof Update or
instance of Select instead of query.isSelectType() etc.

[1] https://github.com/spinrdf/spinrdf/blob/master/etc/sp.ttl



On Wed, Mar 18, 2020 at 12:58 PM Marco Neumann <ma...@gmail.com> wrote:
>
> is there some utility function here in the code base now already to do
> this, or do I still need to roll my own here?
>
> On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org> wrote:
>
> > On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
> > > Hi,
> > >
> > > I would like to know if Jena offers a way to detect the type of an
> > unknow SPARQL request ?Starting from the query string.
> > >
> > > At the moment the only way I succed to code it without "basic parsing"
> > of the query ( sort of thing I prefer avoid, manually parsing string with
> > short function often create errors )
> > > looks like this :
> > >
> > > [...]
> > >         String queryString = "a query string, may be a select or an
> > update";
> > >
> > >          try{
> > >              Query select = QueryFactory.create(queryString);
> > >              Service.process_select_query(select);//do some work with
> > the select
> > >          }
> > >          catch(QueryException e){
> > >              UpdateRequest update = UpdateFactory.create(queryString);
> > >              Service.process_update_query(update);//do some work with
> > the update
> > >          }
> > >          catch(ProcessException e){
> > >              //handle this exception
> > >          }
> > >
> > > [...]
> > >
> > > So is it possible ? Or not ?
> >
> > Not currently.
> >
> > You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK keyword
> > coming after BASE/PREFIXES/Comments.
> >
> >         Andy
> >
> >
>
> --
>
>
> ---
> Marco Neumann
> KONA

Re: Identify SPARQL query's type

Posted by Andy Seaborne <an...@apache.org>.
On 19/03/2020 09:37, Marco Neumann wrote:
> thank you Claus, there is obviously much more in the Jena-extensions
> (SmartDataAnalytics / jena-sparql-api).
> 
> if you want to contribute your work to the Jena project you will have to
> follow up with Andy directly.

https://github.com/apache/jena/blob/master/CONTRIBUTING.md

> But I am not sure this is necessary at the
> moment since you already provide the code in the public domain conveniently
> as an extension / add-on to the Jena project, which I think is great as is
> for now. Over time we might want to learn from your work and add aspects to
> the overall core Jena project I would think.
> 
> It would be great if we could schedule a zoom session in order to give us
> an overview of the "SmartDataAnalytics / jena-sparql-api" extensions
> 
> could you prepare such a presentation in the coming days?
> 
> best,
> Marco
> 
> 
> 
> On Wed, Mar 18, 2020 at 3:34 PM Claus Stadler <
> cstadler@informatik.uni-leipzig.de> wrote:
> 
>> Hi,
>>
>>
>> The SparqlStmt API built against jena 3.14.0 is now available on Maven
>> Central [1]  in case one want to give it a try (example in [2]) and give
>> feedback and whether one thinks it would be a useful contribution to Jena
>> directly - and what changes would be necessary if so.
>>
>>
>> <dependency>
>>     <groupId>org.aksw.jena-sparql-api</groupId>
>>     <artifactId>jena-sparql-api-stmt</artifactId>
>>     <version>3.14.0-1</version>
>>
>> </dependency>
>>
>>
>> [1]
>> https://search.maven.org/artifact/org.aksw.jena-sparql-api/jena-sparql-api-stmt/3.14.0-1/jar
>>
>> [2]
>> https://github.com/SmartDataAnalytics/jena-sparql-api/blob/def0d3bdf0f4396fbf1ef0715f9697e9bb255029/jena-sparql-api-stmt/src/test/java/org/aksw/jena_sparql_api/stmt/TestSparqlStmtUtils.java#L54
>>
>>
>> Cheers,
>>
>> Claus
>>
>>
>>
>> On 18.03.20 16:04, Andy Seaborne wrote:
>>> Note that parsing the string as a query aborts early as soon as it finds
>> an update keyword so the cost of parsing isn't very large.
>>>
>>>      Andy
>>>
>>> On 18/03/2020 11:58, Marco Neumann wrote:
>>>> is there some utility function here in the code base now already to do
>>>> this, or do I still need to roll my own here?
>>>>
>>>> On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org> wrote:
>>>>
>>>>> On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I would like to know if Jena offers a way to detect the type of an
>>>>> unknow SPARQL request ?Starting from the query string.
>>>>>>
>>>>>> At the moment the only way I succed to code it without "basic parsing"
>>>>> of the query ( sort of thing I prefer avoid, manually parsing string
>> with
>>>>> short function often create errors )
>>>>>> looks like this :
>>>>>>
>>>>>> [...]
>>>>>>           String queryString = "a query string, may be a select or an
>>>>> update";
>>>>>>
>>>>>>            try{
>>>>>>                Query select = QueryFactory.create(queryString);
>>>>>>                Service.process_select_query(select);//do some work with
>>>>> the select
>>>>>>            }
>>>>>>            catch(QueryException e){
>>>>>>                UpdateRequest update =
>> UpdateFactory.create(queryString);
>>>>>>                Service.process_update_query(update);//do some work with
>>>>> the update
>>>>>>            }
>>>>>>            catch(ProcessException e){
>>>>>>                //handle this exception
>>>>>>            }
>>>>>>
>>>>>> [...]
>>>>>>
>>>>>> So is it possible ? Or not ?
>>>>>
>>>>> Not currently.
>>>>>
>>>>> You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK
>> keyword
>>>>> coming after BASE/PREFIXES/Comments.
>>>>>
>>>>>           Andy
>>>>>
>>>>>
>>>>
>> --
>> Dipl. Inf. Claus Stadler
>> Department of Computer Science, University of Leipzig
>> Research Group: http://aksw.org/
>> Workpage & WebID: http://aksw.org/ClausStadler
>> Phone: +49 341 97-32260
>>
>>
> 

Re: Identify SPARQL query's type

Posted by Marco Neumann <ma...@gmail.com>.
excellent looking forward to the presentation Claus. would you mind if we
open this zoom event up to the public?

On Thu, Mar 19, 2020 at 6:30 PM Claus Stadler <
cstadler@informatik.uni-leipzig.de> wrote:

> Hi Marco,
>
> I will prepare a presentation of the most important features next week; I
> can't say right now which day is best, but maybe we can arrange that on
> short notice on the weekend or on Monday via direct mail. As for
> contributions to Jena directly, I am already in contact with Andy via some
> recent JIRA issues and PRs :)
>
>
> I also intend to start the discussion on contributing some relevant parts
> of our extension project to jena directly. The reason why this did not
> happen so far is mainly because it takes significantly more efforts to
> polish code up for a such a big community project and ensuring a good level
> of stability - but some parts are stable and probably of more general
> interest :)
>
>
> Cheers,
>
> Claus
>
>
> On 19.03.20 10:37, Marco Neumann wrote:
> > thank you Claus, there is obviously much more in the Jena-extensions
> > (SmartDataAnalytics / jena-sparql-api).
> >
> > if you want to contribute your work to the Jena project you will have to
> > follow up with Andy directly. But I am not sure this is necessary at the
> > moment since you already provide the code in the public domain
> conveniently
> > as an extension / add-on to the Jena project, which I think is great as
> is
> > for now. Over time we might want to learn from your work and add aspects
> to
> > the overall core Jena project I would think.
> >
> > It would be great if we could schedule a zoom session in order to give us
> > an overview of the "SmartDataAnalytics / jena-sparql-api" extensions
> >
> > could you prepare such a presentation in the coming days?
> >
> > best,
> > Marco
> >
> >
> >
> > On Wed, Mar 18, 2020 at 3:34 PM Claus Stadler <
> > cstadler@informatik.uni-leipzig.de> wrote:
> >
> >> Hi,
> >>
> >>
> >> The SparqlStmt API built against jena 3.14.0 is now available on Maven
> >> Central [1]  in case one want to give it a try (example in [2]) and give
> >> feedback and whether one thinks it would be a useful contribution to
> Jena
> >> directly - and what changes would be necessary if so.
> >>
> >>
> >> <dependency>
> >>     <groupId>org.aksw.jena-sparql-api</groupId>
> >>     <artifactId>jena-sparql-api-stmt</artifactId>
> >>     <version>3.14.0-1</version>
> >>
> >> </dependency>
> >>
> >>
> >> [1]
> >>
> https://search.maven.org/artifact/org.aksw.jena-sparql-api/jena-sparql-api-stmt/3.14.0-1/jar
> >>
> >> [2]
> >>
> https://github.com/SmartDataAnalytics/jena-sparql-api/blob/def0d3bdf0f4396fbf1ef0715f9697e9bb255029/jena-sparql-api-stmt/src/test/java/org/aksw/jena_sparql_api/stmt/TestSparqlStmtUtils.java#L54
> >>
> >>
> >> Cheers,
> >>
> >> Claus
> >>
> >>
> >>
> >> On 18.03.20 16:04, Andy Seaborne wrote:
> >>> Note that parsing the string as a query aborts early as soon as it
> finds
> >> an update keyword so the cost of parsing isn't very large.
> >>>      Andy
> >>>
> >>> On 18/03/2020 11:58, Marco Neumann wrote:
> >>>> is there some utility function here in the code base now already to do
> >>>> this, or do I still need to roll my own here?
> >>>>
> >>>> On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org>
> wrote:
> >>>>
> >>>>> On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
> >>>>>> Hi,
> >>>>>>
> >>>>>> I would like to know if Jena offers a way to detect the type of an
> >>>>> unknow SPARQL request ?Starting from the query string.
> >>>>>> At the moment the only way I succed to code it without "basic
> parsing"
> >>>>> of the query ( sort of thing I prefer avoid, manually parsing string
> >> with
> >>>>> short function often create errors )
> >>>>>> looks like this :
> >>>>>>
> >>>>>> [...]
> >>>>>>           String queryString = "a query string, may be a select or
> an
> >>>>> update";
> >>>>>>            try{
> >>>>>>                Query select = QueryFactory.create(queryString);
> >>>>>>                Service.process_select_query(select);//do some work
> with
> >>>>> the select
> >>>>>>            }
> >>>>>>            catch(QueryException e){
> >>>>>>                UpdateRequest update =
> >> UpdateFactory.create(queryString);
> >>>>>>                Service.process_update_query(update);//do some work
> with
> >>>>> the update
> >>>>>>            }
> >>>>>>            catch(ProcessException e){
> >>>>>>                //handle this exception
> >>>>>>            }
> >>>>>>
> >>>>>> [...]
> >>>>>>
> >>>>>> So is it possible ? Or not ?
> >>>>> Not currently.
> >>>>>
> >>>>> You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK
> >> keyword
> >>>>> coming after BASE/PREFIXES/Comments.
> >>>>>
> >>>>>           Andy
> >>>>>
> >>>>>
> >> --
> >> Dipl. Inf. Claus Stadler
> >> Department of Computer Science, University of Leipzig
> >> Research Group: http://aksw.org/
> >> Workpage & WebID: http://aksw.org/ClausStadler
> >> Phone: +49 341 97-32260
> >>
> >>
> --
> Dipl. Inf. Claus Stadler
> Department of Computer Science, University of Leipzig
> Research Group: http://aksw.org/
> Workpage & WebID: http://aksw.org/ClausStadler
> Phone: +49 341 97-32260
>
> --


---
Marco Neumann
KONA

Re: Identify SPARQL query's type

Posted by Claus Stadler <cs...@informatik.uni-leipzig.de>.
Hi Marco,

I will prepare a presentation of the most important features next week; I can't say right now which day is best, but maybe we can arrange that on short notice on the weekend or on Monday via direct mail. As for contributions to Jena directly, I am already in contact with Andy via some recent JIRA issues and PRs :)


I also intend to start the discussion on contributing some relevant parts of our extension project to jena directly. The reason why this did not happen so far is mainly because it takes significantly more efforts to polish code up for a such a big community project and ensuring a good level of stability - but some parts are stable and probably of more general interest :)


Cheers,

Claus


On 19.03.20 10:37, Marco Neumann wrote:
> thank you Claus, there is obviously much more in the Jena-extensions
> (SmartDataAnalytics / jena-sparql-api).
>
> if you want to contribute your work to the Jena project you will have to
> follow up with Andy directly. But I am not sure this is necessary at the
> moment since you already provide the code in the public domain conveniently
> as an extension / add-on to the Jena project, which I think is great as is
> for now. Over time we might want to learn from your work and add aspects to
> the overall core Jena project I would think.
>
> It would be great if we could schedule a zoom session in order to give us
> an overview of the "SmartDataAnalytics / jena-sparql-api" extensions
>
> could you prepare such a presentation in the coming days?
>
> best,
> Marco
>
>
>
> On Wed, Mar 18, 2020 at 3:34 PM Claus Stadler <
> cstadler@informatik.uni-leipzig.de> wrote:
>
>> Hi,
>>
>>
>> The SparqlStmt API built against jena 3.14.0 is now available on Maven
>> Central [1]  in case one want to give it a try (example in [2]) and give
>> feedback and whether one thinks it would be a useful contribution to Jena
>> directly - and what changes would be necessary if so.
>>
>>
>> <dependency>
>>     <groupId>org.aksw.jena-sparql-api</groupId>
>>     <artifactId>jena-sparql-api-stmt</artifactId>
>>     <version>3.14.0-1</version>
>>
>> </dependency>
>>
>>
>> [1]
>> https://search.maven.org/artifact/org.aksw.jena-sparql-api/jena-sparql-api-stmt/3.14.0-1/jar
>>
>> [2]
>> https://github.com/SmartDataAnalytics/jena-sparql-api/blob/def0d3bdf0f4396fbf1ef0715f9697e9bb255029/jena-sparql-api-stmt/src/test/java/org/aksw/jena_sparql_api/stmt/TestSparqlStmtUtils.java#L54
>>
>>
>> Cheers,
>>
>> Claus
>>
>>
>>
>> On 18.03.20 16:04, Andy Seaborne wrote:
>>> Note that parsing the string as a query aborts early as soon as it finds
>> an update keyword so the cost of parsing isn't very large.
>>>      Andy
>>>
>>> On 18/03/2020 11:58, Marco Neumann wrote:
>>>> is there some utility function here in the code base now already to do
>>>> this, or do I still need to roll my own here?
>>>>
>>>> On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org> wrote:
>>>>
>>>>> On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I would like to know if Jena offers a way to detect the type of an
>>>>> unknow SPARQL request ?Starting from the query string.
>>>>>> At the moment the only way I succed to code it without "basic parsing"
>>>>> of the query ( sort of thing I prefer avoid, manually parsing string
>> with
>>>>> short function often create errors )
>>>>>> looks like this :
>>>>>>
>>>>>> [...]
>>>>>>           String queryString = "a query string, may be a select or an
>>>>> update";
>>>>>>            try{
>>>>>>                Query select = QueryFactory.create(queryString);
>>>>>>                Service.process_select_query(select);//do some work with
>>>>> the select
>>>>>>            }
>>>>>>            catch(QueryException e){
>>>>>>                UpdateRequest update =
>> UpdateFactory.create(queryString);
>>>>>>                Service.process_update_query(update);//do some work with
>>>>> the update
>>>>>>            }
>>>>>>            catch(ProcessException e){
>>>>>>                //handle this exception
>>>>>>            }
>>>>>>
>>>>>> [...]
>>>>>>
>>>>>> So is it possible ? Or not ?
>>>>> Not currently.
>>>>>
>>>>> You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK
>> keyword
>>>>> coming after BASE/PREFIXES/Comments.
>>>>>
>>>>>           Andy
>>>>>
>>>>>
>> --
>> Dipl. Inf. Claus Stadler
>> Department of Computer Science, University of Leipzig
>> Research Group: http://aksw.org/
>> Workpage & WebID: http://aksw.org/ClausStadler
>> Phone: +49 341 97-32260
>>
>>
-- 
Dipl. Inf. Claus Stadler
Department of Computer Science, University of Leipzig
Research Group: http://aksw.org/
Workpage & WebID: http://aksw.org/ClausStadler
Phone: +49 341 97-32260


Re: Identify SPARQL query's type

Posted by Marco Neumann <ma...@gmail.com>.
thank you Claus, there is obviously much more in the Jena-extensions
(SmartDataAnalytics / jena-sparql-api).

if you want to contribute your work to the Jena project you will have to
follow up with Andy directly. But I am not sure this is necessary at the
moment since you already provide the code in the public domain conveniently
as an extension / add-on to the Jena project, which I think is great as is
for now. Over time we might want to learn from your work and add aspects to
the overall core Jena project I would think.

It would be great if we could schedule a zoom session in order to give us
an overview of the "SmartDataAnalytics / jena-sparql-api" extensions

could you prepare such a presentation in the coming days?

best,
Marco



On Wed, Mar 18, 2020 at 3:34 PM Claus Stadler <
cstadler@informatik.uni-leipzig.de> wrote:

> Hi,
>
>
> The SparqlStmt API built against jena 3.14.0 is now available on Maven
> Central [1]  in case one want to give it a try (example in [2]) and give
> feedback and whether one thinks it would be a useful contribution to Jena
> directly - and what changes would be necessary if so.
>
>
> <dependency>
>    <groupId>org.aksw.jena-sparql-api</groupId>
>    <artifactId>jena-sparql-api-stmt</artifactId>
>    <version>3.14.0-1</version>
>
> </dependency>
>
>
> [1]
> https://search.maven.org/artifact/org.aksw.jena-sparql-api/jena-sparql-api-stmt/3.14.0-1/jar
>
> [2]
> https://github.com/SmartDataAnalytics/jena-sparql-api/blob/def0d3bdf0f4396fbf1ef0715f9697e9bb255029/jena-sparql-api-stmt/src/test/java/org/aksw/jena_sparql_api/stmt/TestSparqlStmtUtils.java#L54
>
>
> Cheers,
>
> Claus
>
>
>
> On 18.03.20 16:04, Andy Seaborne wrote:
> > Note that parsing the string as a query aborts early as soon as it finds
> an update keyword so the cost of parsing isn't very large.
> >
> >     Andy
> >
> > On 18/03/2020 11:58, Marco Neumann wrote:
> >> is there some utility function here in the code base now already to do
> >> this, or do I still need to roll my own here?
> >>
> >> On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org> wrote:
> >>
> >>> On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
> >>>> Hi,
> >>>>
> >>>> I would like to know if Jena offers a way to detect the type of an
> >>> unknow SPARQL request ?Starting from the query string.
> >>>>
> >>>> At the moment the only way I succed to code it without "basic parsing"
> >>> of the query ( sort of thing I prefer avoid, manually parsing string
> with
> >>> short function often create errors )
> >>>> looks like this :
> >>>>
> >>>> [...]
> >>>>          String queryString = "a query string, may be a select or an
> >>> update";
> >>>>
> >>>>           try{
> >>>>               Query select = QueryFactory.create(queryString);
> >>>>               Service.process_select_query(select);//do some work with
> >>> the select
> >>>>           }
> >>>>           catch(QueryException e){
> >>>>               UpdateRequest update =
> UpdateFactory.create(queryString);
> >>>>               Service.process_update_query(update);//do some work with
> >>> the update
> >>>>           }
> >>>>           catch(ProcessException e){
> >>>>               //handle this exception
> >>>>           }
> >>>>
> >>>> [...]
> >>>>
> >>>> So is it possible ? Or not ?
> >>>
> >>> Not currently.
> >>>
> >>> You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK
> keyword
> >>> coming after BASE/PREFIXES/Comments.
> >>>
> >>>          Andy
> >>>
> >>>
> >>
> --
> Dipl. Inf. Claus Stadler
> Department of Computer Science, University of Leipzig
> Research Group: http://aksw.org/
> Workpage & WebID: http://aksw.org/ClausStadler
> Phone: +49 341 97-32260
>
>

-- 


---
Marco Neumann
KONA

Re: Identify SPARQL query's type

Posted by Claus Stadler <cs...@informatik.uni-leipzig.de>.
Hi,


The SparqlStmt API built against jena 3.14.0 is now available on Maven Central [1]  in case one want to give it a try (example in [2]) and give feedback and whether one thinks it would be a useful contribution to Jena directly - and what changes would be necessary if so.


<dependency>
   <groupId>org.aksw.jena-sparql-api</groupId>
   <artifactId>jena-sparql-api-stmt</artifactId>
   <version>3.14.0-1</version>

</dependency>


[1] https://search.maven.org/artifact/org.aksw.jena-sparql-api/jena-sparql-api-stmt/3.14.0-1/jar

[2] https://github.com/SmartDataAnalytics/jena-sparql-api/blob/def0d3bdf0f4396fbf1ef0715f9697e9bb255029/jena-sparql-api-stmt/src/test/java/org/aksw/jena_sparql_api/stmt/TestSparqlStmtUtils.java#L54


Cheers,

Claus



On 18.03.20 16:04, Andy Seaborne wrote:
> Note that parsing the string as a query aborts early as soon as it finds an update keyword so the cost of parsing isn't very large.
>
>     Andy
>
> On 18/03/2020 11:58, Marco Neumann wrote:
>> is there some utility function here in the code base now already to do
>> this, or do I still need to roll my own here?
>>
>> On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org> wrote:
>>
>>> On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
>>>> Hi,
>>>>
>>>> I would like to know if Jena offers a way to detect the type of an
>>> unknow SPARQL request ?Starting from the query string.
>>>>
>>>> At the moment the only way I succed to code it without "basic parsing"
>>> of the query ( sort of thing I prefer avoid, manually parsing string with
>>> short function often create errors )
>>>> looks like this :
>>>>
>>>> [...]
>>>>          String queryString = "a query string, may be a select or an
>>> update";
>>>>
>>>>           try{
>>>>               Query select = QueryFactory.create(queryString);
>>>>               Service.process_select_query(select);//do some work with
>>> the select
>>>>           }
>>>>           catch(QueryException e){
>>>>               UpdateRequest update = UpdateFactory.create(queryString);
>>>>               Service.process_update_query(update);//do some work with
>>> the update
>>>>           }
>>>>           catch(ProcessException e){
>>>>               //handle this exception
>>>>           }
>>>>
>>>> [...]
>>>>
>>>> So is it possible ? Or not ?
>>>
>>> Not currently.
>>>
>>> You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK keyword
>>> coming after BASE/PREFIXES/Comments.
>>>
>>>          Andy
>>>
>>>
>>
-- 
Dipl. Inf. Claus Stadler
Department of Computer Science, University of Leipzig
Research Group: http://aksw.org/
Workpage & WebID: http://aksw.org/ClausStadler
Phone: +49 341 97-32260


Re: Identify SPARQL query's type

Posted by Andy Seaborne <an...@apache.org>.
Note that parsing the string as a query aborts early as soon as it finds 
an update keyword so the cost of parsing isn't very large.

     Andy

On 18/03/2020 11:58, Marco Neumann wrote:
> is there some utility function here in the code base now already to do
> this, or do I still need to roll my own here?
> 
> On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org> wrote:
> 
>> On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
>>> Hi,
>>>
>>> I would like to know if Jena offers a way to detect the type of an
>> unknow SPARQL request ?Starting from the query string.
>>>
>>> At the moment the only way I succed to code it without "basic parsing"
>> of the query ( sort of thing I prefer avoid, manually parsing string with
>> short function often create errors )
>>> looks like this :
>>>
>>> [...]
>>>          String queryString = "a query string, may be a select or an
>> update";
>>>
>>>           try{
>>>               Query select = QueryFactory.create(queryString);
>>>               Service.process_select_query(select);//do some work with
>> the select
>>>           }
>>>           catch(QueryException e){
>>>               UpdateRequest update = UpdateFactory.create(queryString);
>>>               Service.process_update_query(update);//do some work with
>> the update
>>>           }
>>>           catch(ProcessException e){
>>>               //handle this exception
>>>           }
>>>
>>> [...]
>>>
>>> So is it possible ? Or not ?
>>
>> Not currently.
>>
>> You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK keyword
>> coming after BASE/PREFIXES/Comments.
>>
>>          Andy
>>
>>
> 

Re: Identify SPARQL query's type

Posted by Claus Stadler <cs...@informatik.uni-leipzig.de>.
Hi,


I created an abstraction for this awhile ago - essentially there is an interface 'SparqlStmt' with implementations that wrap an UpdateRequest or a Query. Correspondingly, there is a SparqlStmtParser interface whose implementation is makes use of a SparqlQueryParser and SparqlUpdateParser.

If the statement cannot be parsed, it attempts to to get the location of the parse error (line / col) and decide on the statement type on this basis.


Its on maven central - but I see its not there for jena 3.14.0 but I could do it today.

https://search.maven.org/artifact/org.aksw.jena-sparql-api/jena-sparql-api-stmt/3.13.1-1/jar


I would also gladly contribute it to jena directly :)


Cheers,

Claus



https://github.com/SmartDataAnalytics/jena-sparql-api/blob/fa5fe33b0e7ac80586cdb3522aa5e0d75718db26/jena-sparql-api-stmt/src/main/java/org/aksw/jena_sparql_api/stmt/SparqlStmtParserImpl.java#L57




On 18.03.20 12:58, Marco Neumann wrote:
> is there some utility function here in the code base now already to do
> this, or do I still need to roll my own here?
>
> On Tue, Jul 30, 2013 at 4:25 PM Andy Seaborne <an...@apache.org> wrote:
>
>> On 30/07/13 10:13, Arthur Vaïsse-Lesteven wrote:
>>> Hi,
>>>
>>> I would like to know if Jena offers a way to detect the type of an
>> unknow SPARQL request ?Starting from the query string.
>>> At the moment the only way I succed to code it without "basic parsing"
>> of the query ( sort of thing I prefer avoid, manually parsing string with
>> short function often create errors )
>>> looks like this :
>>>
>>> [...]
>>>          String queryString = "a query string, may be a select or an
>> update";
>>>           try{
>>>               Query select = QueryFactory.create(queryString);
>>>               Service.process_select_query(select);//do some work with
>> the select
>>>           }
>>>           catch(QueryException e){
>>>               UpdateRequest update = UpdateFactory.create(queryString);
>>>               Service.process_update_query(update);//do some work with
>> the update
>>>           }
>>>           catch(ProcessException e){
>>>               //handle this exception
>>>           }
>>>
>>> [...]
>>>
>>> So is it possible ? Or not ?
>> Not currently.
>>
>> You could use a regexp to spot the SELECT/CONSTRUCT/DESCRIBE/ASK keyword
>> coming after BASE/PREFIXES/Comments.
>>
>>          Andy
>>
>>
-- 
Dipl. Inf. Claus Stadler
Department of Computer Science, University of Leipzig
Research Group: http://aksw.org/
Workpage & WebID: http://aksw.org/ClausStadler
Phone: +49 341 97-32260