You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Olivier Rossel <ol...@gmail.com> on 2013/01/08 20:49:55 UTC

Retrieving CONSTRUCT results as n3

My current code is like this:
QueryExecution exec =
QueryExecutionFactory.create(QueryFactory.create(queryString,
Syntax.syntaxSPARQL_11), new
DatasetImpl(ModelFactory.createDefaultModel()));
exec.execConstruct().write(byteArrayOutputStream);

And my queries are like that:
CONSTRUCT { ... } WHERE { SERVICE <http://bla.com/sparql/> {... } }

Is it possible to configure Jena so those CONSTRUCT are sent with an
"Accept: text/n3" header?
BTW, is it even legal to demand "text/n3" as a result format?

Re: Retrieving CONSTRUCT results as n3

Posted by Martynas Jusevičius <ma...@graphity.org>.
Olivier, what are you trying to achieve? Wouldn't QueryEngineHTTP help you here?
http://jena.apache.org/documentation/javadoc/arq/com/hp/hpl/jena/sparql/engine/http/QueryEngineHTTP.html

On Wed, Jan 9, 2013 at 2:22 PM, Olivier Rossel <ol...@gmail.com> wrote:
> QueryExecutionFactory

Re: Retrieving CONSTRUCT results as n3

Posted by Rob Vesse <rv...@yarcdata.com>.
The fact that you want to set the Accept header implies to me that this
code is in some sort of HTTP server or servlet?  I'm struggling to
understand why you need to set an Accept header at all here?

As I already said the write() method does not do any trickery regarding
Accept headers because Accept headers are a HTTP feature and the write()
code is distinct from any HTTP functionality.

If you are using say the Java servlets API you can fairly easily set a
HTTP response header should you need to, see
http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.
html

It may be worth you looking at some of the Fuseki utility code for some
pointers, see ResponseModel.java
(http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apac
he/jena/fuseki/servlets/ResponseModel.java?view=markup) and
ResponseResultSet.java
(http://svn.apache.org/viewvc/jena/trunk/jena-fuseki/src/main/java/org/apac
he/jena/fuseki/servlets/ResponseResultSet.java?view=markup)

You really need to clarify what exactly you are doing here?  It sounds
like you are trying to send back some sort of response over HTTP in which
case the relevant header would be Content-Type not Accept anyway.

Rob


On 1/9/13 12:22 PM, "Olivier Rossel" <ol...@gmail.com> wrote:

>Ok, thanks for that information.
>So back to my initial concern.
>In this code:
>QueryExecution exec =
>QueryExecutionFactory.create(QueryFactory.create(queryString,
>Syntax.syntaxSPARQL_11), new
>DatasetImpl(ModelFactory.createDefaultModel()));
>exec.execConstruct().write(byteArrayOutputStream);
>
>Is there a way to set the Accept header?
>(and not rely on some Jena trickery in the write(...,...) method)
>
>Envoyé de mon iPhone
>
>Le 9 janv. 2013 à 12:19, Rob Vesse <rv...@yarcdata.com> a écrit :
>
>> No the write() methods do not set any kind of HTTP header, it is
>>separate
>> infrastructure from any HTTP request/response machinery
>> 
>> 
>> Fuseki has separate machinery that determines the appropriate writer to
>>be
>> used based on the users Accept header and then sets the appropriate
>> Content-Type header before writing out the response
>> 
>> Rob
>> 
>> On 1/9/13 11:01 AM, "Olivier Rossel" <ol...@gmail.com> wrote:
>> 
>>>> The current accept negotiation in Fuseki is based on
>>>> 
>>>> application/rdf+xml, text/turtle, application/turtle,
>>>> application/x-turtle,
>>>> application/n-triples, text/plain
>>> 
>>> Interesting, thanks for that list!
>>> 
>>> 
>>>> "Accept: text/turtle" is to be preferred.
>>>> 
>>>>    r.write(byteArrayOutputStream, "TTL");
>>> 
>>> So the r.write(..., ...) method effectively set an Accept header, true?
>> 


Re: Retrieving CONSTRUCT results as n3

Posted by Olivier Rossel <ol...@gmail.com>.
Ok, thanks for that information.
So back to my initial concern.
In this code:
QueryExecution exec =
QueryExecutionFactory.create(QueryFactory.create(queryString,
Syntax.syntaxSPARQL_11), new
DatasetImpl(ModelFactory.createDefaultModel()));
exec.execConstruct().write(byteArrayOutputStream);

Is there a way to set the Accept header?
(and not rely on some Jena trickery in the write(...,...) method)

Envoyé de mon iPhone

Le 9 janv. 2013 à 12:19, Rob Vesse <rv...@yarcdata.com> a écrit :

> No the write() methods do not set any kind of HTTP header, it is separate
> infrastructure from any HTTP request/response machinery
> 
> 
> Fuseki has separate machinery that determines the appropriate writer to be
> used based on the users Accept header and then sets the appropriate
> Content-Type header before writing out the response
> 
> Rob
> 
> On 1/9/13 11:01 AM, "Olivier Rossel" <ol...@gmail.com> wrote:
> 
>>> The current accept negotiation in Fuseki is based on
>>> 
>>> application/rdf+xml, text/turtle, application/turtle,
>>> application/x-turtle,
>>> application/n-triples, text/plain
>> 
>> Interesting, thanks for that list!
>> 
>> 
>>> "Accept: text/turtle" is to be preferred.
>>> 
>>>    r.write(byteArrayOutputStream, "TTL");
>> 
>> So the r.write(..., ...) method effectively set an Accept header, true?
> 

Re: Retrieving CONSTRUCT results as n3

Posted by Rob Vesse <rv...@yarcdata.com>.
No the write() methods do not set any kind of HTTP header, it is separate
infrastructure from any HTTP request/response machinery


Fuseki has separate machinery that determines the appropriate writer to be
used based on the users Accept header and then sets the appropriate
Content-Type header before writing out the response

Rob

On 1/9/13 11:01 AM, "Olivier Rossel" <ol...@gmail.com> wrote:

>> The current accept negotiation in Fuseki is based on
>>
>> application/rdf+xml, text/turtle, application/turtle,
>>application/x-turtle,
>> application/n-triples, text/plain
>
>Interesting, thanks for that list!
>
>
>> "Accept: text/turtle" is to be preferred.
>>
>>     r.write(byteArrayOutputStream, "TTL");
>
>So the r.write(..., ...) method effectively set an Accept header, true?


Re: Retrieving CONSTRUCT results as n3

Posted by Olivier Rossel <ol...@gmail.com>.
> The current accept negotiation in Fuseki is based on
>
> application/rdf+xml, text/turtle, application/turtle, application/x-turtle,
> application/n-triples, text/plain

Interesting, thanks for that list!


> "Accept: text/turtle" is to be preferred.
>
>     r.write(byteArrayOutputStream, "TTL");

So the r.write(..., ...) method effectively set an Accept header, true?

Re: Retrieving CONSTRUCT results as n3

Posted by Andy Seaborne <an...@apache.org>.
On 08/01/13 20:35, Jean-Marc Vanel wrote:
> 2013/1/8 Olivier Rossel <ol...@gmail.com>:
>> My current code is like this:
>> QueryExecution exec =
>> QueryExecutionFactory.create(QueryFactory.create(queryString,
>> Syntax.syntaxSPARQL_11), new
>> DatasetImpl(ModelFactory.createDefaultModel()));
>> exec.execConstruct().write(byteArrayOutputStream);
>
> Here is the recipe :
>
>                  Model r = exec.execConstruct();
>                  r.write(byteArrayOutputStream, "N3");
>
>> And my queries are like that:
>> CONSTRUCT { ... } WHERE { SERVICE <http://bla.com/sparql/> {... } }
>>
>> Is it possible to configure Jena so those CONSTRUCT are sent with an
>> "Accept: text/n3" header?

The web part would be Fuseki.

>
> I didn't see a way to control this with Jena API :( .
>
>> BTW, is it even legal to demand "text/n3" as a result format?
>
> yes.

The current accept negotiation in Fuseki is based on

application/rdf+xml, text/turtle, application/turtle, 
application/x-turtle, application/n-triples, text/plain

that's the set checked, respecting q= against the Accept header.

It does not include text/n3.  That could be added but it will be treated 
as Turtle.

Turtle is not a strict subset of N3 currently. The prefix names are 
broader that N3 defines, and there are differences in the treatment of 
numbers - small things but they break data exchange.

Generally in Jena, N3 is treated as Turtle.

"Accept: text/turtle" is to be preferred.

     r.write(byteArrayOutputStream, "TTL");

There is no strict, compliant N3 parser that covers the beyond-Turtle 
and beyond RDF features of N3.  The "beyond-Turtle but still RDF" 
features are just a matter of writing the parser; the "beyond RDF" 
features are fundamental change to Jena (formulae/graph literals).  They 
are not interoperable with other systems.

You can't create N3-beyond-RDF with CONSTRUCT.

	Andy


Re: Retrieving CONSTRUCT results as n3

Posted by Jean-Marc Vanel <je...@gmail.com>.
2013/1/8 Olivier Rossel <ol...@gmail.com>:
> My current code is like this:
> QueryExecution exec =
> QueryExecutionFactory.create(QueryFactory.create(queryString,
> Syntax.syntaxSPARQL_11), new
> DatasetImpl(ModelFactory.createDefaultModel()));
> exec.execConstruct().write(byteArrayOutputStream);

Here is the recipe :

                Model r = exec.execConstruct();
                r.write(byteArrayOutputStream, "N3");

> And my queries are like that:
> CONSTRUCT { ... } WHERE { SERVICE <http://bla.com/sparql/> {... } }
>
> Is it possible to configure Jena so those CONSTRUCT are sent with an
> "Accept: text/n3" header?

I didn't see a way to control this with Jena API :( .

> BTW, is it even legal to demand "text/n3" as a result format?

yes.



-- 
Jean-Marc Vanel
Déductions SARL - Consulting, services, training,
Rule-based programming, Semantic Web
http://deductions-software.com/
+33 (0)6 89 16 29 52
Twitter: @jmvanel ; chat: irc://irc.freenode.net#eulergui