You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Adam Sobieski <ad...@hotmail.com> on 2022/12/11 08:32:39 UTC

RDF-star and Lists in Quoted Triples

Hello. While exploring Jena (v4.6.1)'s RDF-star functionality and features, I'm getting the following output:


@prefix calculus: <http://www.w3.org/community/planning/calculus/ontology#> .
@prefix example:  <http://example.org/#> .
@prefix rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd:      <http://www.w3.org/2001/XMLSchema#> .

<< example:predicate calculus:holdsFor _:b0 >>
        calculus:probability  "0.95"^^xsd:double .

[ rdf:first example:x ; rdf:rest ( example:y example:z ) ] .


while expecting:


@prefix calculus: <http://www.w3.org/community/planning/calculus/ontology#> .
@prefix example:  <http://example.org/#> .
@prefix rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd:      <http://www.w3.org/2001/XMLSchema#> .

<< example:predicate calculus:holdsFor ( example:x example:y example:z ) >>
        calculus:probability  "0.95"^^xsd:double .


To obtain the output, I'm utilizing the following source code:

public static void foo(Model model)
{
  model.setNsPrefix("calculus", "http://www.w3.org/community/planning/calculus/ontology#");
  model.setNsPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
  model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
  model.setNsPrefix("example", "http://example.org/#");

  Resource predicate = model.createResource("http://example.org/#predicate");
  Resource p1 = model.createResource("http://example.org/#x");
  Resource p2 = model.createResource("http://example.org/#y");
  Resource p3 = model.createResource("http://example.org/#z");

  Property calculus_holdsFor = model.createProperty("http://www.w3.org/community/planning/calculus/ontology#holdsFor");
  Property calculus_probability = model.createProperty("http://www.w3.org/community/planning/calculus/ontology#probability");
      
  RDFList list = model.createList(p1, p2, p3);
  Statement s = model.createStatement(predicate, calculus_holdsFor, list);
  Resource quoted = model.createResource(s);
      
  //model.add(s);
  model.add(quoted, calculus_probability, model.createTypedLiteral(0.95));
}
      
public static void main(String[] args) throws IOException
{
  Model model = ModelFactory.createDefaultModel();
  foo(model);           

  RDFDataMgr.write(System.out, model, Lang.TURTLE);
}

Might this be a bug or issue with respect to list-handling in quoted RDF-star triples or with respect to serialization to Turtle-star? Thank you.


Best regards,
Adam Sobieski


Re: RDF-star and Lists in Quoted Triples

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

On 11/12/2022 08:32, Adam Sobieski wrote:
> Hello. While exploring Jena (v4.6.1)'s RDF-star functionality and features, I'm getting the following output:
> 
> 
> @prefix calculus: <http://www.w3.org/community/planning/calculus/ontology#> .
> @prefix example:  <http://example.org/#> .
> @prefix rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
> @prefix xsd:      <http://www.w3.org/2001/XMLSchema#> .
> 
> << example:predicate calculus:holdsFor _:b0 >>
>          calculus:probability  "0.95"^^xsd:double .
> 
> [ rdf:first example:x ; rdf:rest ( example:y example:z ) ] .

That's a (fixable) bug : it should be:

_:b0 rdf:first example:x ; rdf:rest ( example:y example:z ) .

 >      RDFDataMgr.write(System.out, model, Lang.TURTLE);

Workaround: Use RDFFormat.TURTLE_BLOCKS instead of Lang.TURTLE.

Or N-Triples or RDFFormat.TURTLE_FLAT (N-triple using prefixes)

> while expecting:
> 
> 
> @prefix calculus: <http://www.w3.org/community/planning/calculus/ontology#> .
> @prefix example:  <http://example.org/#> .
> @prefix rdf:      <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
> @prefix xsd:      <http://www.w3.org/2001/XMLSchema#> .
> 
> << example:predicate calculus:holdsFor ( example:x example:y example:z ) >>
>          calculus:probability  "0.95"^^xsd:double .

That is illegal syntax.

The syntax for quoted triples does not allow list syntax.

https://www.w3.org/2021/12/rdf-star.html#turtle-star-grammar

The best you can do is put the blank node of the first cons cell of the 
list in the quoted triple but the triples rest will be asserted.

The fact it's illegal is why RIOT is trying to write the list separately.

     Andy

> 
> 
> To obtain the output, I'm utilizing the following source code:
> 
> public static void foo(Model model)
> {
>    model.setNsPrefix("calculus", "http://www.w3.org/community/planning/calculus/ontology#");
>    model.setNsPrefix("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
>    model.setNsPrefix("xsd", "http://www.w3.org/2001/XMLSchema#");
>    model.setNsPrefix("example", "http://example.org/#");
> 
>    Resource predicate = model.createResource("http://example.org/#predicate");
>    Resource p1 = model.createResource("http://example.org/#x");
>    Resource p2 = model.createResource("http://example.org/#y");
>    Resource p3 = model.createResource("http://example.org/#z");
> 
>    Property calculus_holdsFor = model.createProperty("http://www.w3.org/community/planning/calculus/ontology#holdsFor");
>    Property calculus_probability = model.createProperty("http://www.w3.org/community/planning/calculus/ontology#probability");
>        
>    RDFList list = model.createList(p1, p2, p3);
>    Statement s = model.createStatement(predicate, calculus_holdsFor, list);
>    Resource quoted = model.createResource(s);
>        
>    //model.add(s);
>    model.add(quoted, calculus_probability, model.createTypedLiteral(0.95));
> }
>       
> public static void main(String[] args) throws IOException
> {
>    Model model = ModelFactory.createDefaultModel();
>    foo(model);           
> 
>    RDFDataMgr.write(System.out, model, Lang.TURTLE);
> }
> 
> Might this be a bug or issue with respect to list-handling in quoted RDF-star triples or with respect to serialization to Turtle-star? Thank you.
> 
> 
> Best regards,
> Adam Sobieski
>