You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Martynas Jusevicius <ma...@gmail.com> on 2011/09/26 16:16:05 UTC

N-Triples to N-Quads

Hey list,

we have a dump from D2RQ currently in N-Triples format. However we
want to group the triples into named graphs, and since D2RQ doesn't
seem to support it, we probably need to do some post-processing.

Does anyone have experience with such translation? My thought is to
define a match pattern that would group the necessary triples
together, and write them into named graphs with synthetic URI names
using SPARQL Update. This would probably mean URI generation inside
SPARQL query, but I think I've seen examples of this working in Jena?

Comments and tips and links welcome,

Martynas
semantic-web.dk

Re: N-Triples to N-Quads

Posted by Martynas Jusevicius <ma...@gmail.com>.
Hey Andy,

yeah at first we thought about doing text processing - but the triples
in the current dump are not grouped in the way we want. It's just a
serialization of the SQL tables. There's no way to know what graph
URIs to add. That's why we want to use SPARQL match patterns.

Martynas

On Mon, Sep 26, 2011 at 5:25 PM, Andy Seaborne <an...@apache.org> wrote:
> On 26/09/11 15:16, Martynas Jusevicius wrote:
>>
>> Hey list,
>>
>> we have a dump from D2RQ currently in N-Triples format. However we
>> want to group the triples into named graphs, and since D2RQ doesn't
>> seem to support it, we probably need to do some post-processing.
>>
>> Does anyone have experience with such translation? My thought is to
>> define a match pattern that would group the necessary triples
>> together, and write them into named graphs with synthetic URI names
>> using SPARQL Update. This would probably mean URI generation inside
>> SPARQL query, but I think I've seen examples of this working in Jena?
>
> Yes - the URI(string) SPARQL function creates URIs from string expressions.
>  It must be an absolute URI.
>
> URI("http://example/a") => <http://example/a>
>
> SPARQL Update could be used to place triples into named graphs.
>
> But do you need to do this?  Can you use text processing to add graph URI to
> the end of the lines of the NT data?
>
>        Andy
>
>>
>> Comments and tips and links welcome,
>>
>> Martynas
>> semantic-web.dk
>
>

Re: N-Triples to N-Quads

Posted by Andy Seaborne <an...@apache.org>.
On 27/09/11 16:11, Martynas Jusevicius wrote:
> I mean ?date everywhere...
>
> On Tue, Sep 27, 2011 at 5:04 PM, Martynas Jusevicius
> <ma...@gmail.com>  wrote:
>> Hey Andy,
>>
>> I'm trying to implementing it now, and wondering if the whole
>> transformation could be packed into one SPARQL Update query? I mean
>> both the matching and the graph creation and insertion.
>>
>> I tried the following:
>>
>> CREATE GRAPH IRI(fn:concat('http://host/graphs/', string(?date)));

That's not legal SPARQL 1.1

(and TDB does not need CREATE GRAPH - essentially all graphs "exist" 
with zero triples in them).


>> INSERT {
>>     GRAPH IRI(fn:concat('http://host/graphs/', string(?date)))

Ditto although GRAPH ?g works here.


>>     {
>>        ?post dct:created ?data
>>        # more
>>     }
>> }
>> WHERE {
>>     ?post dct:created ?data
>>     # more
>> }
>>
>> but I get a parse error where IRI() is:

Line number

>> Was expecting one of:
>>     <IRIref>  ...
>>     <PNAME_NS>  ...
>>     <PNAME_LN>  ...
>>
>>         at com.hp.hpl.jena.sparql.lang.ParserARQUpdate._parse(ParserARQUpdate.java:58)
>> ...
>>
>> Or will I have to retrieve the match results first and then iterate
>> them to create named graphs?

If you want to pass in the URI from outside the update, then keeping the 
update as a template, with some text processing is a way to go.  It has 
the advantage that you can use a sophisticated text processing system 
(cpp, m4, perl, sed, ... as well as java regexs).

Use a marker like $$G$$

CREATE GRAPH $$G$$
INSERT {
    GRAPH $$G$$ { ... }
} WHERE { .. }

There is no way in a single SPARQL Update to assign to variable and pass 
that outside the operation.


	Andy

>>
>> Martynas
>>
>> On Mon, Sep 26, 2011 at 5:25 PM, Andy Seaborne<an...@apache.org>  wrote:
>>> On 26/09/11 15:16, Martynas Jusevicius wrote:
>>>>
>>>> Hey list,
>>>>
>>>> we have a dump from D2RQ currently in N-Triples format. However we
>>>> want to group the triples into named graphs, and since D2RQ doesn't
>>>> seem to support it, we probably need to do some post-processing.
>>>>
>>>> Does anyone have experience with such translation? My thought is to
>>>> define a match pattern that would group the necessary triples
>>>> together, and write them into named graphs with synthetic URI names
>>>> using SPARQL Update. This would probably mean URI generation inside
>>>> SPARQL query, but I think I've seen examples of this working in Jena?
>>>
>>> Yes - the URI(string) SPARQL function creates URIs from string expressions.
>>>   It must be an absolute URI.
>>>
>>> URI("http://example/a") =>  <http://example/a>
>>>
>>> SPARQL Update could be used to place triples into named graphs.
>>>
>>> But do you need to do this?  Can you use text processing to add graph URI to
>>> the end of the lines of the NT data?
>>>
>>>         Andy
>>>
>>>>
>>>> Comments and tips and links welcome,
>>>>
>>>> Martynas
>>>> semantic-web.dk
>>>
>>>
>>


Re: N-Triples to N-Quads

Posted by Martynas Jusevicius <ma...@gmail.com>.
I mean ?date everywhere...

On Tue, Sep 27, 2011 at 5:04 PM, Martynas Jusevicius
<ma...@gmail.com> wrote:
> Hey Andy,
>
> I'm trying to implementing it now, and wondering if the whole
> transformation could be packed into one SPARQL Update query? I mean
> both the matching and the graph creation and insertion.
>
> I tried the following:
>
> CREATE GRAPH IRI(fn:concat('http://host/graphs/', string(?date)));
> INSERT {
>    GRAPH IRI(fn:concat('http://host/graphs/', string(?date)))
>    {
>       ?post dct:created ?data
>       # more
>    }
> }
> WHERE {
>    ?post dct:created ?data
>    # more
> }
>
> but I get a parse error where IRI() is:
> Was expecting one of:
>    <IRIref> ...
>    <PNAME_NS> ...
>    <PNAME_LN> ...
>
>        at com.hp.hpl.jena.sparql.lang.ParserARQUpdate._parse(ParserARQUpdate.java:58)
> ...
>
> Or will I have to retrieve the match results first and then iterate
> them to create named graphs?
>
> Martynas
>
> On Mon, Sep 26, 2011 at 5:25 PM, Andy Seaborne <an...@apache.org> wrote:
>> On 26/09/11 15:16, Martynas Jusevicius wrote:
>>>
>>> Hey list,
>>>
>>> we have a dump from D2RQ currently in N-Triples format. However we
>>> want to group the triples into named graphs, and since D2RQ doesn't
>>> seem to support it, we probably need to do some post-processing.
>>>
>>> Does anyone have experience with such translation? My thought is to
>>> define a match pattern that would group the necessary triples
>>> together, and write them into named graphs with synthetic URI names
>>> using SPARQL Update. This would probably mean URI generation inside
>>> SPARQL query, but I think I've seen examples of this working in Jena?
>>
>> Yes - the URI(string) SPARQL function creates URIs from string expressions.
>>  It must be an absolute URI.
>>
>> URI("http://example/a") => <http://example/a>
>>
>> SPARQL Update could be used to place triples into named graphs.
>>
>> But do you need to do this?  Can you use text processing to add graph URI to
>> the end of the lines of the NT data?
>>
>>        Andy
>>
>>>
>>> Comments and tips and links welcome,
>>>
>>> Martynas
>>> semantic-web.dk
>>
>>
>

Re: N-Triples to N-Quads

Posted by Martynas Jusevicius <ma...@gmail.com>.
Hey Andy,

I'm trying to implementing it now, and wondering if the whole
transformation could be packed into one SPARQL Update query? I mean
both the matching and the graph creation and insertion.

I tried the following:

CREATE GRAPH IRI(fn:concat('http://host/graphs/', string(?date)));
INSERT {
    GRAPH IRI(fn:concat('http://host/graphs/', string(?date)))
    {
       ?post dct:created ?data
       # more
    }
}
WHERE {
    ?post dct:created ?data
    # more
}

but I get a parse error where IRI() is:
Was expecting one of:
    <IRIref> ...
    <PNAME_NS> ...
    <PNAME_LN> ...

        at com.hp.hpl.jena.sparql.lang.ParserARQUpdate._parse(ParserARQUpdate.java:58)
...

Or will I have to retrieve the match results first and then iterate
them to create named graphs?

Martynas

On Mon, Sep 26, 2011 at 5:25 PM, Andy Seaborne <an...@apache.org> wrote:
> On 26/09/11 15:16, Martynas Jusevicius wrote:
>>
>> Hey list,
>>
>> we have a dump from D2RQ currently in N-Triples format. However we
>> want to group the triples into named graphs, and since D2RQ doesn't
>> seem to support it, we probably need to do some post-processing.
>>
>> Does anyone have experience with such translation? My thought is to
>> define a match pattern that would group the necessary triples
>> together, and write them into named graphs with synthetic URI names
>> using SPARQL Update. This would probably mean URI generation inside
>> SPARQL query, but I think I've seen examples of this working in Jena?
>
> Yes - the URI(string) SPARQL function creates URIs from string expressions.
>  It must be an absolute URI.
>
> URI("http://example/a") => <http://example/a>
>
> SPARQL Update could be used to place triples into named graphs.
>
> But do you need to do this?  Can you use text processing to add graph URI to
> the end of the lines of the NT data?
>
>        Andy
>
>>
>> Comments and tips and links welcome,
>>
>> Martynas
>> semantic-web.dk
>
>

Re: N-Triples to N-Quads

Posted by Andy Seaborne <an...@apache.org>.
On 26/09/11 15:16, Martynas Jusevicius wrote:
> Hey list,
>
> we have a dump from D2RQ currently in N-Triples format. However we
> want to group the triples into named graphs, and since D2RQ doesn't
> seem to support it, we probably need to do some post-processing.
>
> Does anyone have experience with such translation? My thought is to
> define a match pattern that would group the necessary triples
> together, and write them into named graphs with synthetic URI names
> using SPARQL Update. This would probably mean URI generation inside
> SPARQL query, but I think I've seen examples of this working in Jena?

Yes - the URI(string) SPARQL function creates URIs from string 
expressions.  It must be an absolute URI.

URI("http://example/a") => <http://example/a>

SPARQL Update could be used to place triples into named graphs.

But do you need to do this?  Can you use text processing to add graph 
URI to the end of the lines of the NT data?

	Andy

>
> Comments and tips and links welcome,
>
> Martynas
> semantic-web.dk