You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Marc Agate <ag...@gmail.com> on 2019/11/22 15:45:06 UTC

Issue while reading Model or Graph from Trig Strings

Hi all,

I need to build Models or Graphs from strings being a trig serialization of a rdf resource.
I tried to do using Model.read or RDFDataMgr but both produce empty models or graphs.
When I do the same operation with Turtle serialization, it works just fine.

What do you think ?

Run the following code to see that by yourself:
 
 https://github.com/buda-base/editserv/blob/master/src/test/java/editservio/bdrc/edit/test/RDFDataMgrCheck.java

Thx

Marc

Re: Issue while reading Model or Graph from Trig Strings

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

An RDF Model can not hold quads. That is what a Dataset is for.

TriG is a dataset format, so is N-Quads.

The only design choice Jena has made is that reading TriG into a unnamed 
graph is that it takes the default graph from the dataset.  Implicitly 
merging data is a bad idea.  If you expected the reading to merge all 
the graph in the data into one graph, then you can add that step with an 
appropriately-written StreamRDF.

Your data is in a dataset format which is why it isn't mentioned in the 
table you reference. Your TriG represents a dataset with two graphs - it 
has one named graph and, because a dataset always has a default graph, 
even if empty, it has an default graph.

     Andy

On 24/11/2019 00:40, Marc Agate wrote:
> Thanks Andy for your very informative email. We are using trig precisely because we are dealing with quads (i.e named graphs).
> As I said earlier, I am going to use DatasetGraph for now, as suggested by Martynas, but I think that something should be done in Jena so there is a Jena reader for Trig (which is lacking according to this doc : https://jena.apache.org/documentation/io/rdf-input.html <https://jena.apache.org/documentation/io/rdf-input.html>)
> 
> Best
> 
> Marc
> 
>> Le 22 nov. 2019 à 14:00, Andy Seaborne <an...@apache.org> a écrit :
>>
>> If you read TriG into model, it takes the default graph only.
>>
>> The TriG has a named graphs in it.  bdg:T1642 { ... }
>> Remove the name and it should work.
>>
>> The Turtle does not have a name (so it is the same as Trig+default graph)
>>
>>     Andy
>>
>> On 22/11/2019 17:22, Marc Agate wrote:
>>> Hi Martynas !
>>> The method you are pointing me to effectively works and I can use it to solve the issue for now. However, the RDFDataMgr documentation says (about read methods/operations):
>>> read -- Read data from a location into a Model, Dataset, etc. The methods in this class treat all types of Model in the same way. For behavior specific to a subtype of Model, use the methods of that specific class.
>>> Therefore, both https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.graph.Graph-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang- AND https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.rdf.model.Model-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang- should work.
>>> I am wondering why they don't: Am I using them wrongly or is this just a bug ?
>>> Best
>>> Marc
>>> On 2019/11/22 15:56:16, Martynas Jusevičius <ma...@atomgraph.com> wrote:
>>>> I think you want to read a Dataset:
>>>> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.query.Dataset-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang-
>>>>
>>>> On Fri, 22 Nov 2019 at 16.45, Marc Agate <ag...@gmail.com> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> I need to build Models or Graphs from strings being a trig serialization
>>>>> of a rdf resource.
>>>>> I tried to do using Model.read or RDFDataMgr but both produce empty models
>>>>> or graphs.
>>>>> When I do the same operation with Turtle serialization, it works just fine.
>>>>>
>>>>> What do you think ?
>>>>>
>>>>> Run the following code to see that by yourself:
>>>>>
>>>>>
>>>>> https://github.com/buda-base/editserv/blob/master/src/test/java/editservio/bdrc/edit/test/RDFDataMgrCheck.java
>>>>>
>>>>> Thx
>>>>>
>>>>> Marc
>>>>>
>>>>
> 
> 

Re: Issue while reading Model or Graph from Trig Strings

Posted by Marc Agate <ma...@tbrc.org>.
Thanks Andy for your very informative email. We are using trig precisely because we are dealing with quads (i.e named graphs).
As I said earlier, I am going to use DatasetGraph for now, as suggested by Martynas, but I think that something should be done in Jena so there is a Jena reader for Trig (which is lacking according to this doc : https://jena.apache.org/documentation/io/rdf-input.html <https://jena.apache.org/documentation/io/rdf-input.html>)

Best

Marc

> Le 22 nov. 2019 à 14:00, Andy Seaborne <an...@apache.org> a écrit :
> 
> If you read TriG into model, it takes the default graph only.
> 
> The TriG has a named graphs in it.  bdg:T1642 { ... }
> Remove the name and it should work.
> 
> The Turtle does not have a name (so it is the same as Trig+default graph)
> 
>    Andy
> 
> On 22/11/2019 17:22, Marc Agate wrote:
>> Hi Martynas !
>> The method you are pointing me to effectively works and I can use it to solve the issue for now. However, the RDFDataMgr documentation says (about read methods/operations):
>> read -- Read data from a location into a Model, Dataset, etc. The methods in this class treat all types of Model in the same way. For behavior specific to a subtype of Model, use the methods of that specific class.
>> Therefore, both https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.graph.Graph-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang- AND https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.rdf.model.Model-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang- should work.
>> I am wondering why they don't: Am I using them wrongly or is this just a bug ?
>> Best
>> Marc
>> On 2019/11/22 15:56:16, Martynas Jusevičius <ma...@atomgraph.com> wrote:
>>> I think you want to read a Dataset:
>>> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.query.Dataset-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang-
>>> 
>>> On Fri, 22 Nov 2019 at 16.45, Marc Agate <ag...@gmail.com> wrote:
>>> 
>>>> Hi all,
>>>> 
>>>> I need to build Models or Graphs from strings being a trig serialization
>>>> of a rdf resource.
>>>> I tried to do using Model.read or RDFDataMgr but both produce empty models
>>>> or graphs.
>>>> When I do the same operation with Turtle serialization, it works just fine.
>>>> 
>>>> What do you think ?
>>>> 
>>>> Run the following code to see that by yourself:
>>>> 
>>>> 
>>>> https://github.com/buda-base/editserv/blob/master/src/test/java/editservio/bdrc/edit/test/RDFDataMgrCheck.java
>>>> 
>>>> Thx
>>>> 
>>>> Marc
>>>> 
>>> 


Re: Issue while reading Model or Graph from Trig Strings

Posted by Andy Seaborne <an...@apache.org>.
If you read TriG into model, it takes the default graph only.

The TriG has a named graphs in it.  bdg:T1642 { ... }
Remove the name and it should work.

The Turtle does not have a name (so it is the same as Trig+default graph)

     Andy

On 22/11/2019 17:22, Marc Agate wrote:
> Hi Martynas !
> 
> The method you are pointing me to effectively works and I can use it to solve the issue for now. However, the RDFDataMgr documentation says (about read methods/operations):
> 
> read -- Read data from a location into a Model, Dataset, etc. The methods in this class treat all types of Model in the same way. For behavior specific to a subtype of Model, use the methods of that specific class.
> 
> Therefore, both https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.graph.Graph-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang- AND https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.rdf.model.Model-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang- should work.
> 
> I am wondering why they don't: Am I using them wrongly or is this just a bug ?
> 
> Best
> 
> Marc
> 
> On 2019/11/22 15:56:16, Martynas Jusevičius <ma...@atomgraph.com> wrote:
>> I think you want to read a Dataset:
>> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.query.Dataset-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang-
>>
>> On Fri, 22 Nov 2019 at 16.45, Marc Agate <ag...@gmail.com> wrote:
>>
>>> Hi all,
>>>
>>> I need to build Models or Graphs from strings being a trig serialization
>>> of a rdf resource.
>>> I tried to do using Model.read or RDFDataMgr but both produce empty models
>>> or graphs.
>>> When I do the same operation with Turtle serialization, it works just fine.
>>>
>>> What do you think ?
>>>
>>> Run the following code to see that by yourself:
>>>
>>>
>>> https://github.com/buda-base/editserv/blob/master/src/test/java/editservio/bdrc/edit/test/RDFDataMgrCheck.java
>>>
>>> Thx
>>>
>>> Marc
>>>
>>

Re: Issue while reading Model or Graph from Trig Strings

Posted by Marc Agate <ag...@gmail.com>.
Hi Martynas !

The method you are pointing me to effectively works and I can use it to solve the issue for now. However, the RDFDataMgr documentation says (about read methods/operations):

read -- Read data from a location into a Model, Dataset, etc. The methods in this class treat all types of Model in the same way. For behavior specific to a subtype of Model, use the methods of that specific class.

Therefore, both https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.graph.Graph-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang- AND https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.rdf.model.Model-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang- should work.

I am wondering why they don't: Am I using them wrongly or is this just a bug ?

Best

Marc

On 2019/11/22 15:56:16, Martynas Jusevičius <ma...@atomgraph.com> wrote: 
> I think you want to read a Dataset:
> https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.query.Dataset-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang-
> 
> On Fri, 22 Nov 2019 at 16.45, Marc Agate <ag...@gmail.com> wrote:
> 
> > Hi all,
> >
> > I need to build Models or Graphs from strings being a trig serialization
> > of a rdf resource.
> > I tried to do using Model.read or RDFDataMgr but both produce empty models
> > or graphs.
> > When I do the same operation with Turtle serialization, it works just fine.
> >
> > What do you think ?
> >
> > Run the following code to see that by yourself:
> >
> >
> > https://github.com/buda-base/editserv/blob/master/src/test/java/editservio/bdrc/edit/test/RDFDataMgrCheck.java
> >
> > Thx
> >
> > Marc
> >
> 

Re: Issue while reading Model or Graph from Trig Strings

Posted by Martynas Jusevičius <ma...@atomgraph.com>.
I think you want to read a Dataset:
https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/riot/RDFDataMgr.html#read-org.apache.jena.query.Dataset-java.io.StringReader-java.lang.String-org.apache.jena.riot.Lang-

On Fri, 22 Nov 2019 at 16.45, Marc Agate <ag...@gmail.com> wrote:

> Hi all,
>
> I need to build Models or Graphs from strings being a trig serialization
> of a rdf resource.
> I tried to do using Model.read or RDFDataMgr but both produce empty models
> or graphs.
> When I do the same operation with Turtle serialization, it works just fine.
>
> What do you think ?
>
> Run the following code to see that by yourself:
>
>
> https://github.com/buda-base/editserv/blob/master/src/test/java/editservio/bdrc/edit/test/RDFDataMgrCheck.java
>
> Thx
>
> Marc
>