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 <a...@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

Reply via email to