You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by ag...@gmail.com, ag...@gmail.com on 2018/06/03 11:43:58 UTC

Jena writing TURTLE instead of TRIG

Hi,

There is obviously an issue with the Model.write method for TriG format.

Run the following to see that ttl is returned when Trig is requested...Formats names are based on https://jena.apache.org/documentation/io/

package io.bdrc.ldspdi.test;

import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;

public class WriteTrigTest {
    
    public static void main(String[] args) {
        Model mod=ModelFactory.createDefaultModel();
        mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
        System.out.println("***************** TURTLE **************************");
        mod.write(System.out,"TURTLE");
        System.out.println("***************** JSON   **************************");
        mod.write(System.out,"RDF/JSON");
        System.out.println("***************** TRIG   **************************");
        mod.write(System.out,"TriG");
    }

}

Marc

Re: Jena writing TURTLE instead of TRIG

Posted by Martynas Jusevičius <ma...@atomgraph.com>.
*do not

On Sun, Jun 3, 2018 at 2:48 PM, Martynas Jusevičius <ma...@atomgraph.com>
wrote:

> Try reading RDF 1.1 Primer, it should help: https://www.w3.org/TR/
> rdf11-primer/#section-trig
>
> BTW use Factory classes as Andy mentioned, do now instantiate *Impl
> classes yourself.
>
> On Sun, Jun 3, 2018 at 2:45 PM, agate.marc@gmail.com <agate.marc@gmail.com
> > wrote:
>
>>
>>
>> On 2018/06/03 12:29:25, Andy Seaborne <an...@apache.org> wrote:
>> >
>> >
>> > On 03/06/18 13:21, agate.marc@gmail.com wrote:
>> > >
>> > >
>> > > On 2018/06/03 11:46:26, Martynas Jusevičius <ma...@atomgraph.com>
>> wrote:
>> > >> TriG without named graphs is Turtle, AFAIK.
>> > >>
>> > >> And you can't have named graphs in Model since it only contains
>> triples,
>> > >> not quads.
>> > >>
>> > >> If you want named graphs (but you're not using them right now), you
>> should
>> > >> look into Dataset:
>> > >> https://jena.apache.org/documentation/javadoc/arq/org/apache
>> /jena/query/Dataset.html
>> > >>
>> > >> On Sun, Jun 3, 2018 at 1:43 PM, agate.marc@gmail.com <
>> agate.marc@gmail.com>
>> > >> wrote:
>> > >>
>> > >>> Hi,
>> > >>>
>> > >>> There is obviously an issue with the Model.write method for TriG
>> format.
>> > >>>
>> > >>> Run the following to see that ttl is returned when Trig is
>> > >>> requested...Formats names are based on https://jena.apache.org/
>> > >>> documentation/io/
>> > >>>
>> > >>> package io.bdrc.ldspdi.test;
>> > >>>
>> > >>> import org.apache.jena.rdf.model.Model;
>> > >>> import org.apache.jena.rdf.model.ModelFactory;
>> > >>>
>> > >>> public class WriteTrigTest {
>> > >>>
>> > >>>      public static void main(String[] args) {
>> > >>>          Model mod=ModelFactory.createDefaultModel();
>> > >>>          mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
>> > >>>          System.out.println("***************** TURTLE
>> > >>> **************************");
>> > >>>          mod.write(System.out,"TURTLE");
>> > >>>          System.out.println("***************** JSON
>> > >>>   **************************");
>> > >>>          mod.write(System.out,"RDF/JSON");
>> > >>>          System.out.println("***************** TRIG
>> > >>>   **************************");
>> > >>>          mod.write(System.out,"TriG");
>> > >>>      }
>> > >>>
>> > >>> }
>> > >>>
>> > >>> Marc
>> > >>>
>> > >>
>> > > Thanks ! It is not clear in the docs that printing Trig format
>> requires a Named graph.
>> >
>> > It doesn't.
>> >
>> > There is no requirement in TriG to write the default graph inside {}.
>> >
>> > So writing a model as TriG is the same as writing it as Turtle.  The
>> > formats overlap (by design of the specs). A model on its own is treated
>> > as a dataset with a default graph.
>> >
>> > ----
>> > Writing TriG:
>> > The prefixes are prefixes are the prfixes of the default graph.
>> >
>> >  > The following code does the job (but I am loosing the Prefix Map in
>> > the process... any clue ?):
>> > >
>> > > public class WriteTrigTest {
>> > >
>> > >      public static void main(String[] args) {
>> > >          Model mod=ModelFactory.createDefaultModel();
>> > >          mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
>> > >          DatasetImpl impl=new DatasetImpl(ModelFactory.creat
>> eDefaultModel());
>> >
>> > Dataset ds = DatasetFactory.create....
>> >
>> > >          impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281",
>> mod);
>> > >          RDFDataMgr.write(System.out, impl.asDatasetGraph(),
>> Lang.TRIG) ;
>> >
>> > ds.getDefaultModel().setNsPrefixes(mod);
>> >
>> > >      }
>> > >
>> > > }
>> > >
>> >
>> Ok, I got that. Then why bother with two formats (Trig and Turtle) if
>> they are the same ? Is it the case that all valid Turtle are also valid
>> Trig and vice versa ? It's not clear and it looks like the difference
>> between Trig and Turtle is related to "named graph" (i.e Trig is better
>> suited to serialize a named graph):
>>
>> this works:
>>
>> DatasetImpl impl=new DatasetImpl(ModelFactory.createDefaultModel());
>>         impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281",
>> mod);
>>         RDFDataMgr.write(System.out, impl.asDatasetGraph(), Lang.TRIG) ;
>>
>> while this fails:
>>
>> DatasetImpl impl=new DatasetImpl(ModelFactory.createDefaultModel());
>>         impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281",
>> mod);
>>         RDFDataMgr.write(System.out, impl.asDatasetGraph(), Lang.TURTLE) ;
>>
>> Marc
>>
>
>

Re: Jena writing TURTLE instead of TRIG

Posted by Martynas Jusevičius <ma...@atomgraph.com>.
Try reading RDF 1.1 Primer, it should help:
https://www.w3.org/TR/rdf11-primer/#section-trig

BTW use Factory classes as Andy mentioned, do now instantiate *Impl classes
yourself.

On Sun, Jun 3, 2018 at 2:45 PM, agate.marc@gmail.com <ag...@gmail.com>
wrote:

>
>
> On 2018/06/03 12:29:25, Andy Seaborne <an...@apache.org> wrote:
> >
> >
> > On 03/06/18 13:21, agate.marc@gmail.com wrote:
> > >
> > >
> > > On 2018/06/03 11:46:26, Martynas Jusevičius <ma...@atomgraph.com>
> wrote:
> > >> TriG without named graphs is Turtle, AFAIK.
> > >>
> > >> And you can't have named graphs in Model since it only contains
> triples,
> > >> not quads.
> > >>
> > >> If you want named graphs (but you're not using them right now), you
> should
> > >> look into Dataset:
> > >> https://jena.apache.org/documentation/javadoc/arq/org/
> apache/jena/query/Dataset.html
> > >>
> > >> On Sun, Jun 3, 2018 at 1:43 PM, agate.marc@gmail.com <
> agate.marc@gmail.com>
> > >> wrote:
> > >>
> > >>> Hi,
> > >>>
> > >>> There is obviously an issue with the Model.write method for TriG
> format.
> > >>>
> > >>> Run the following to see that ttl is returned when Trig is
> > >>> requested...Formats names are based on https://jena.apache.org/
> > >>> documentation/io/
> > >>>
> > >>> package io.bdrc.ldspdi.test;
> > >>>
> > >>> import org.apache.jena.rdf.model.Model;
> > >>> import org.apache.jena.rdf.model.ModelFactory;
> > >>>
> > >>> public class WriteTrigTest {
> > >>>
> > >>>      public static void main(String[] args) {
> > >>>          Model mod=ModelFactory.createDefaultModel();
> > >>>          mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
> > >>>          System.out.println("***************** TURTLE
> > >>> **************************");
> > >>>          mod.write(System.out,"TURTLE");
> > >>>          System.out.println("***************** JSON
> > >>>   **************************");
> > >>>          mod.write(System.out,"RDF/JSON");
> > >>>          System.out.println("***************** TRIG
> > >>>   **************************");
> > >>>          mod.write(System.out,"TriG");
> > >>>      }
> > >>>
> > >>> }
> > >>>
> > >>> Marc
> > >>>
> > >>
> > > Thanks ! It is not clear in the docs that printing Trig format
> requires a Named graph.
> >
> > It doesn't.
> >
> > There is no requirement in TriG to write the default graph inside {}.
> >
> > So writing a model as TriG is the same as writing it as Turtle.  The
> > formats overlap (by design of the specs). A model on its own is treated
> > as a dataset with a default graph.
> >
> > ----
> > Writing TriG:
> > The prefixes are prefixes are the prfixes of the default graph.
> >
> >  > The following code does the job (but I am loosing the Prefix Map in
> > the process... any clue ?):
> > >
> > > public class WriteTrigTest {
> > >
> > >      public static void main(String[] args) {
> > >          Model mod=ModelFactory.createDefaultModel();
> > >          mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
> > >          DatasetImpl impl=new DatasetImpl(ModelFactory.
> createDefaultModel());
> >
> > Dataset ds = DatasetFactory.create....
> >
> > >          impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281",
> mod);
> > >          RDFDataMgr.write(System.out, impl.asDatasetGraph(),
> Lang.TRIG) ;
> >
> > ds.getDefaultModel().setNsPrefixes(mod);
> >
> > >      }
> > >
> > > }
> > >
> >
> Ok, I got that. Then why bother with two formats (Trig and Turtle) if they
> are the same ? Is it the case that all valid Turtle are also valid Trig and
> vice versa ? It's not clear and it looks like the difference between Trig
> and Turtle is related to "named graph" (i.e Trig is better suited to
> serialize a named graph):
>
> this works:
>
> DatasetImpl impl=new DatasetImpl(ModelFactory.createDefaultModel());
>         impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281", mod);
>         RDFDataMgr.write(System.out, impl.asDatasetGraph(), Lang.TRIG) ;
>
> while this fails:
>
> DatasetImpl impl=new DatasetImpl(ModelFactory.createDefaultModel());
>         impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281", mod);
>         RDFDataMgr.write(System.out, impl.asDatasetGraph(), Lang.TURTLE) ;
>
> Marc
>

Re: Jena writing TURTLE instead of TRIG

Posted by ag...@gmail.com, ag...@gmail.com.

On 2018/06/03 12:29:25, Andy Seaborne <an...@apache.org> wrote: 
> 
> 
> On 03/06/18 13:21, agate.marc@gmail.com wrote:
> > 
> > 
> > On 2018/06/03 11:46:26, Martynas Jusevičius <ma...@atomgraph.com> wrote:
> >> TriG without named graphs is Turtle, AFAIK.
> >>
> >> And you can't have named graphs in Model since it only contains triples,
> >> not quads.
> >>
> >> If you want named graphs (but you're not using them right now), you should
> >> look into Dataset:
> >> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/Dataset.html
> >>
> >> On Sun, Jun 3, 2018 at 1:43 PM, agate.marc@gmail.com <ag...@gmail.com>
> >> wrote:
> >>
> >>> Hi,
> >>>
> >>> There is obviously an issue with the Model.write method for TriG format.
> >>>
> >>> Run the following to see that ttl is returned when Trig is
> >>> requested...Formats names are based on https://jena.apache.org/
> >>> documentation/io/
> >>>
> >>> package io.bdrc.ldspdi.test;
> >>>
> >>> import org.apache.jena.rdf.model.Model;
> >>> import org.apache.jena.rdf.model.ModelFactory;
> >>>
> >>> public class WriteTrigTest {
> >>>
> >>>      public static void main(String[] args) {
> >>>          Model mod=ModelFactory.createDefaultModel();
> >>>          mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
> >>>          System.out.println("***************** TURTLE
> >>> **************************");
> >>>          mod.write(System.out,"TURTLE");
> >>>          System.out.println("***************** JSON
> >>>   **************************");
> >>>          mod.write(System.out,"RDF/JSON");
> >>>          System.out.println("***************** TRIG
> >>>   **************************");
> >>>          mod.write(System.out,"TriG");
> >>>      }
> >>>
> >>> }
> >>>
> >>> Marc
> >>>
> >>
> > Thanks ! It is not clear in the docs that printing Trig format requires a Named graph.
> 
> It doesn't.
> 
> There is no requirement in TriG to write the default graph inside {}.
> 
> So writing a model as TriG is the same as writing it as Turtle.  The 
> formats overlap (by design of the specs). A model on its own is treated 
> as a dataset with a default graph.
> 
> ----
> Writing TriG:
> The prefixes are prefixes are the prfixes of the default graph.
> 
>  > The following code does the job (but I am loosing the Prefix Map in 
> the process... any clue ?):
> > 
> > public class WriteTrigTest {
> >      
> >      public static void main(String[] args) {
> >          Model mod=ModelFactory.createDefaultModel();
> >          mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
> >          DatasetImpl impl=new DatasetImpl(ModelFactory.createDefaultModel());
> 
> Dataset ds = DatasetFactory.create....
> 
> >          impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281", mod);
> >          RDFDataMgr.write(System.out, impl.asDatasetGraph(), Lang.TRIG) ;
> 
> ds.getDefaultModel().setNsPrefixes(mod);
> 
> >      }
> > 
> > }
> > 
> 
Ok, I got that. Then why bother with two formats (Trig and Turtle) if they are the same ? Is it the case that all valid Turtle are also valid Trig and vice versa ? It's not clear and it looks like the difference between Trig and Turtle is related to "named graph" (i.e Trig is better suited to serialize a named graph):

this works:

DatasetImpl impl=new DatasetImpl(ModelFactory.createDefaultModel());
        impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281", mod);
        RDFDataMgr.write(System.out, impl.asDatasetGraph(), Lang.TRIG) ; 

while this fails:

DatasetImpl impl=new DatasetImpl(ModelFactory.createDefaultModel());
        impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281", mod);
        RDFDataMgr.write(System.out, impl.asDatasetGraph(), Lang.TURTLE) ;

Marc

Re: Jena writing TURTLE instead of TRIG

Posted by Andy Seaborne <an...@apache.org>.

On 03/06/18 13:21, agate.marc@gmail.com wrote:
> 
> 
> On 2018/06/03 11:46:26, Martynas Jusevičius <ma...@atomgraph.com> wrote:
>> TriG without named graphs is Turtle, AFAIK.
>>
>> And you can't have named graphs in Model since it only contains triples,
>> not quads.
>>
>> If you want named graphs (but you're not using them right now), you should
>> look into Dataset:
>> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/Dataset.html
>>
>> On Sun, Jun 3, 2018 at 1:43 PM, agate.marc@gmail.com <ag...@gmail.com>
>> wrote:
>>
>>> Hi,
>>>
>>> There is obviously an issue with the Model.write method for TriG format.
>>>
>>> Run the following to see that ttl is returned when Trig is
>>> requested...Formats names are based on https://jena.apache.org/
>>> documentation/io/
>>>
>>> package io.bdrc.ldspdi.test;
>>>
>>> import org.apache.jena.rdf.model.Model;
>>> import org.apache.jena.rdf.model.ModelFactory;
>>>
>>> public class WriteTrigTest {
>>>
>>>      public static void main(String[] args) {
>>>          Model mod=ModelFactory.createDefaultModel();
>>>          mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
>>>          System.out.println("***************** TURTLE
>>> **************************");
>>>          mod.write(System.out,"TURTLE");
>>>          System.out.println("***************** JSON
>>>   **************************");
>>>          mod.write(System.out,"RDF/JSON");
>>>          System.out.println("***************** TRIG
>>>   **************************");
>>>          mod.write(System.out,"TriG");
>>>      }
>>>
>>> }
>>>
>>> Marc
>>>
>>
> Thanks ! It is not clear in the docs that printing Trig format requires a Named graph.

It doesn't.

There is no requirement in TriG to write the default graph inside {}.

So writing a model as TriG is the same as writing it as Turtle.  The 
formats overlap (by design of the specs). A model on its own is treated 
as a dataset with a default graph.

----
Writing TriG:
The prefixes are prefixes are the prfixes of the default graph.

 > The following code does the job (but I am loosing the Prefix Map in 
the process... any clue ?):
> 
> public class WriteTrigTest {
>      
>      public static void main(String[] args) {
>          Model mod=ModelFactory.createDefaultModel();
>          mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
>          DatasetImpl impl=new DatasetImpl(ModelFactory.createDefaultModel());

Dataset ds = DatasetFactory.create....

>          impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281", mod);
>          RDFDataMgr.write(System.out, impl.asDatasetGraph(), Lang.TRIG) ;

ds.getDefaultModel().setNsPrefixes(mod);

>      }
> 
> }
> 

Re: Jena writing TURTLE instead of TRIG

Posted by ag...@gmail.com, ag...@gmail.com.

On 2018/06/03 11:46:26, Martynas Jusevičius <ma...@atomgraph.com> wrote: 
> TriG without named graphs is Turtle, AFAIK.
> 
> And you can't have named graphs in Model since it only contains triples,
> not quads.
> 
> If you want named graphs (but you're not using them right now), you should
> look into Dataset:
> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/Dataset.html
> 
> On Sun, Jun 3, 2018 at 1:43 PM, agate.marc@gmail.com <ag...@gmail.com>
> wrote:
> 
> > Hi,
> >
> > There is obviously an issue with the Model.write method for TriG format.
> >
> > Run the following to see that ttl is returned when Trig is
> > requested...Formats names are based on https://jena.apache.org/
> > documentation/io/
> >
> > package io.bdrc.ldspdi.test;
> >
> > import org.apache.jena.rdf.model.Model;
> > import org.apache.jena.rdf.model.ModelFactory;
> >
> > public class WriteTrigTest {
> >
> >     public static void main(String[] args) {
> >         Model mod=ModelFactory.createDefaultModel();
> >         mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
> >         System.out.println("***************** TURTLE
> > **************************");
> >         mod.write(System.out,"TURTLE");
> >         System.out.println("***************** JSON
> >  **************************");
> >         mod.write(System.out,"RDF/JSON");
> >         System.out.println("***************** TRIG
> >  **************************");
> >         mod.write(System.out,"TriG");
> >     }
> >
> > }
> >
> > Marc
> >
> 
Thanks ! It is not clear in the docs that printing Trig format requires a Named graph. The following code does the job (but I am loosing the Prefix Map in the process... any clue ?):

public class WriteTrigTest {
    
    public static void main(String[] args) {
        Model mod=ModelFactory.createDefaultModel();
        mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
        DatasetImpl impl=new DatasetImpl(ModelFactory.createDefaultModel());
        impl.addNamedModel("http://purl.bdrc.io/resource/T00AG0281", mod);
        RDFDataMgr.write(System.out, impl.asDatasetGraph(), Lang.TRIG) ;        
    }

}

Re: Jena writing TURTLE instead of TRIG

Posted by Martynas Jusevičius <ma...@atomgraph.com>.
TriG without named graphs is Turtle, AFAIK.

And you can't have named graphs in Model since it only contains triples,
not quads.

If you want named graphs (but you're not using them right now), you should
look into Dataset:
https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/Dataset.html

On Sun, Jun 3, 2018 at 1:43 PM, agate.marc@gmail.com <ag...@gmail.com>
wrote:

> Hi,
>
> There is obviously an issue with the Model.write method for TriG format.
>
> Run the following to see that ttl is returned when Trig is
> requested...Formats names are based on https://jena.apache.org/
> documentation/io/
>
> package io.bdrc.ldspdi.test;
>
> import org.apache.jena.rdf.model.Model;
> import org.apache.jena.rdf.model.ModelFactory;
>
> public class WriteTrigTest {
>
>     public static void main(String[] args) {
>         Model mod=ModelFactory.createDefaultModel();
>         mod.read("http://purl.bdrc.io/resource/T00AG0281.ttl");
>         System.out.println("***************** TURTLE
> **************************");
>         mod.write(System.out,"TURTLE");
>         System.out.println("***************** JSON
>  **************************");
>         mod.write(System.out,"RDF/JSON");
>         System.out.println("***************** TRIG
>  **************************");
>         mod.write(System.out,"TriG");
>     }
>
> }
>
> Marc
>