Thanks for the answers! It solved the error. But I got a followup
question...

After constructing a named graph with the previous code, I tried to SELECT
all the triples in the graph by the following query, and it gives nothing...

/////////////
String selectQueryStr = "SELECT ?s ?p ?o where{GRAPH <http://example.com>{?s
?p ?o}}";
Query selectQuery = QueryFactory.create(selectQueryStr, Syntax.syntaxARQ);
QueryExecution sqe = QueryExecutionFactory.create(selectQuery,
 resultModel);
ResultSet resultset = sqe.execSelect();
//////////

And I found
1) resultset is empty
2) The model generated by CONSTRUCT query is empty. (Only prefixes are
stored.)

Hope I can get another chance to get answers.

Thanks a lot!



With regards,
Jason Koh
cseweb.ucsd.edu/~jbkoh

On Tue, Nov 1, 2016 at 5:34 PM, Martynas Jusevičius <[email protected]>
wrote:

> 1. You haven't followed the example. You are missing Syntax.syntaxARQ
> in QueryFactory.create(), I guess this makes a difference since
> CONSTRUCT with quads is not standard SPARQL.
>
> 2. Because INSERT is an update and not a query? Se UpdateFactory:
> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/update/
> UpdateFactory.html
>
> On Wed, Nov 2, 2016 at 1:30 AM, Jason Koh <[email protected]> wrote:
> >  Dear all,
> >
> > This might be due to my lack of knowledge on SPARQL syntax.
> >
> > 1.
> > I try to construct a named graph via SPARQL query, but it fails.
> > so What I did is like following
> > ///////////
> > Model model = ModelFactory.createDefaultModel();
> > String queryStr ="CONSTRUCT {GRAPH <http://example.com> {<s1> <p1>
> <o1>.} }
> > WHERE{}";
> > Query query = QueryFactory.create(queryStr);
> > QueryExecution qe = QueryExecutionFactory.create(query,  resultModel);
> > /////////
> >
> > It fails at the third line while it is parsing with this error message:
> > Exception in thread "main" org.apache.jena.query.QueryParseException:
> > Encountered " "graph" "GRAPH "" at line 1, column 335.
> >
> > I am thinking that I am following
> > https://jena.apache.org/documentation/query/construct-quad.html
> correctly.
> >
> > Could you tell me the problem in the query?
> >
> >
> > 2.
> > Actually I rather want to use INSERT instead of CONSTRUCT, but
> QueryFactory
> > cannot parse INSERT. Why is that?
> >
> > Thanks!
> >
> >
> > With regards,
> > Jason Koh
> > cseweb.ucsd.edu/~jbkoh
>

Reply via email to