You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Panián Pazán <pa...@gmail.com> on 2018/09/24 23:06:59 UTC

Problem with Tutorial11.java from "An Introduction to RDF and the Jena RDF API”

Hi,

I’ve just started learning Jena, so I’ve been doing the tutorials I've
found at “An Introduction to RDF and the Jena RDF API”
<http://jena.apache.org/tutorials/rdf_api.html>. Everything was working
fine until I got into Tutorial11. The last part of the code:

// create an empty graph
model = ModelFactory.createDefaultModel();

 // create the resource
Resource r = model.createResource();

// add the property
r.addProperty(RDFS.label, "11")
 .addLiteral(RDFS.label, 11);

// write out the graph
model.write( System.out, "N-TRIPLE");

It’s supposed to produce this output:

_:A... <http://www.w3.org/2000/01/rdf-schema#label> "11" .

But what I get after running it is:

_:B… <http://www.w3.org/2000/01/rdf-schema#label> "11"^^<
http://www.w3.org/2001/XMLSchema#long> .
_:B… <http://www.w3.org/2000/01/rdf-schema#label> "11" .

So they are different literals.

Did I misunderstood anything? Am I doing something different as expected?
I’m using IntelliJ IDEA 2018.2.2 Ultimate edition.

I don’t know if this is the right list to notify it but I think there is
also a typo in that part of the page “An Introduction to RDF and the Jena
RDF API” <http://jena.apache.org/tutorials/rdf_api.html>. The code that
appears there is:

// create the resource
Resource r = model.createResource();

// add the property
r.addProperty(RDFS.label, "11")
 .*addProperty*(RDFS.label, 11);

// write out the Model
model.write(system.out, "N-TRIPLE");

But in the Tutorial11.java the correspondent (working) code is:

 // create the resource
 r = model.createResource();

// add the property
r.addProperty(RDFS.label, "11")
 .*addLiteral*(RDFS.label, 11);

// write out the graph
model.write( System.out, "N-TRIPLE");

Thanks in advance!!
 Panian.

Re: Problem with Tutorial11.java from "An Introduction to RDF and the Jena RDF API”

Posted by Panián Pazán <pa...@gmail.com>.
Yeahp...

Looks like it's something wrong in the turorial. Indeed, according to
Jena's JavaDoc, is the paragraph preceding the code also wrong?

"Jena's interfaces also support typed literals. The old-fashioned way
(shown below) treats typed literals as shorthand for strings: *typed values
are converted in the usual Java way to strings and these strings are stored
in the Model*. For example, try (noting that for simple literals, we can
omit the model.createLiteral(...) call):"

Thanks!!
 Panian.



El mar., 25 sept. 2018 a las 7:43, Lorenz B. (<
buehmann@informatik.uni-leipzig.de>) escribió:

>
>
> > // add the property
> > r.addProperty(RDFS.label, "11")
> >  .addLiteral(RDFS.label, 11);
> I'm wondering whether the tutorial is correct here given the fact that
> the method addLiteral will handle argument 11 in the second call as a
> proper number and thus create a typed literal of type xsd:long, see [1]
>
> [1]
>
> https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Resource.html#addLiteral-org.apache.jena.rdf.model.Property-long-
>
> --
> Lorenz Bühmann
> AKSW group, University of Leipzig
> Group: http://aksw.org - semantic web research center
>
>

Re: Problem with Tutorial11.java from "An Introduction to RDF and the Jena RDF API”

Posted by "Lorenz B." <bu...@informatik.uni-leipzig.de>.

> // add the property
> r.addProperty(RDFS.label, "11")
>  .addLiteral(RDFS.label, 11);
I'm wondering whether the tutorial is correct here given the fact that
the method addLiteral will handle argument 11 in the second call as a
proper number and thus create a typed literal of type xsd:long, see [1]

[1]
https://jena.apache.org/documentation/javadoc/jena/org/apache/jena/rdf/model/Resource.html#addLiteral-org.apache.jena.rdf.model.Property-long-

-- 
Lorenz Bühmann
AKSW group, University of Leipzig
Group: http://aksw.org - semantic web research center