You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Alejandro Rodríguez González <al...@gmail.com> on 2013/10/02 14:13:30 UTC
Working with quads. Some questions
Hi all,
I'm trying to create a small program which convert an RDF file into quads
adding context.
I've been looking at the examples in the API and some information on
Google, but I don't know exactly what I'm doing wrong.
I create my quads in the following way:
ArrayList<Quad> quads = new ArrayList<Quad>();
quads.add(new Quad(this.assertionNode, this.rdfTypeNode,
this.nanoPubSchemaAssertionNode, this.nanoPubNode));
quads.add(new Quad(this.nanoPubNode, this.purlCoverageNode,
getNodeFromString(coverageContent), this.provenanceNode));
The "nodes" are created using NodeFactory. Just an example with the nodes
used in the example presented before:
this.assertionNode = NodeFactory.createLiteral("
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0
");
this.nanoPubNode = NodeFactory.createLiteral("
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0
");
this.provenanceNode = NodeFactory.createLiteral("
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158
");
etc.
Once I've created all my structure, I try to print it on screen and store
it on a .nq file using this code:
Dataset ds = TDBFactory.createDataset();
DatasetGraph dsg = ds.asDatasetGraph();
for (int i = 0; i < quads.size(); i++) {
dsg.add(quads.get(i));
}
RDFDataMgr.write(new FileOutputStream(new File("output/nquad2.nq")),
dsg, RDFFormat.NQUADS);
System.out.println(dsg.toString());
The output that I get in the console is the following:
(dataset
(graph)
(graph "
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0
"
(triple "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" "
http://www.nanopub.org/nschema#Assertion" "
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0
")
)
(graph "
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0
"
(triple "http://purl.org/dc/elements/1.1/description" "\"Output from
SADI Service\"@en" "
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158
")
))
Which, it is the one that "I desire". However, in the file, I've the
following:
"http://www.w3.org/1999/02/22-rdf-syntax-ns#type" "
http://www.nanopub.org/nschema#Assertion" "
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0"
"
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0"
.
"http://purl.org/dc/elements/1.1/description" "\"Output from SADI
Service\"@en" "
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158"
"
http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0"
.
My questions are:
1) Why is the order of the nodes different? I mean, I expect to have:
context, s, p, o (like when it is printed)
2) Why, even using RDFFormat.NQUADS the serialization is between " " and
not between <> ?
Probably I'm missing something ...
Thanks for your time.
Cheers,
Alejandro
--
Dr. Alejandro Rodríguez González - PhD
Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA
Polytechnic University of Madrid
http://www.alejandrorg.com
Phone: +34 914524900 . Ext: 25550
*Once the game is over, the king and the pawn go back in the same box. -
Italian proverb*
Re: Working with quads. Some questions
Posted by Alejandro Rodríguez González <al...@gmail.com>.
Hi Rob,
Thanks for your reply. I saw the errors with the uri/literal creation.
Completely true!
And about the Nquad specification, yep, I think I understand my problem!
Thanks!
On 2 October 2013 14:13, Alejandro Rodríguez González <
alejandro.rod.gnz@gmail.com> wrote:
> Hi all,
>
> I'm trying to create a small program which convert an RDF file into quads
> adding context.
>
> I've been looking at the examples in the API and some information on
> Google, but I don't know exactly what I'm doing wrong.
>
> I create my quads in the following way:
>
> ArrayList<Quad> quads = new ArrayList<Quad>();
> quads.add(new Quad(this.assertionNode, this.rdfTypeNode,
> this.nanoPubSchemaAssertionNode, this.nanoPubNode));
> quads.add(new Quad(this.nanoPubNode, this.purlCoverageNode,
> getNodeFromString(coverageContent), this.provenanceNode));
>
> The "nodes" are created using NodeFactory. Just an example with the nodes
> used in the example presented before:
>
> this.assertionNode = NodeFactory.createLiteral("
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0
> ");
>
> this.nanoPubNode = NodeFactory.createLiteral("
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0
> ");
>
> this.provenanceNode = NodeFactory.createLiteral("
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158
> ");
>
> etc.
>
> Once I've created all my structure, I try to print it on screen and store
> it on a .nq file using this code:
>
> Dataset ds = TDBFactory.createDataset();
> DatasetGraph dsg = ds.asDatasetGraph();
> for (int i = 0; i < quads.size(); i++) {
> dsg.add(quads.get(i));
> }
> RDFDataMgr.write(new FileOutputStream(new File("output/nquad2.nq")),
> dsg, RDFFormat.NQUADS);
> System.out.println(dsg.toString());
>
> The output that I get in the console is the following:
>
> (dataset
> (graph)
> (graph "
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0
> "
> (triple "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" "
> http://www.nanopub.org/nschema#Assertion" "
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0
> ")
> )
> (graph "
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0
> "
> (triple "http://purl.org/dc/elements/1.1/description" "\"Output from
> SADI Service\"@en" "
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158
> ")
> ))
>
>
> Which, it is the one that "I desire". However, in the file, I've the
> following:
>
> "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" "
> http://www.nanopub.org/nschema#Assertion" "
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0"
> "
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/assertion/6bfba5c26cedaa3caf460d36d25ceef0"
> .
> "http://purl.org/dc/elements/1.1/description" "\"Output from SADI
> Service\"@en" "
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/provenance/1380725119158"
> "
> http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/nanopublication/6bfba5c26cedaa3caf460d36d25ceef0"
> .
>
> My questions are:
>
> 1) Why is the order of the nodes different? I mean, I expect to have:
> context, s, p, o (like when it is printed)
> 2) Why, even using RDFFormat.NQUADS the serialization is between " " and
> not between <> ?
>
> Probably I'm missing something ...
>
> Thanks for your time.
>
> Cheers,
>
> Alejandro
>
> --
> Dr. Alejandro Rodríguez González - PhD
>
> Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA
> Polytechnic University of Madrid
> http://www.alejandrorg.com
> Phone: +34 914524900 . Ext: 25550
>
>
> *Once the game is over, the king and the pawn go back in the same box. -
> Italian proverb*
>
--
Dr. Alejandro Rodríguez González - PhD
Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA
Polytechnic University of Madrid
http://www.alejandrorg.com
Phone: +34 914524900 . Ext: 25550
*Once the game is over, the king and the pawn go back in the same box. -
Italian proverb*
Re: SPAM-HIGH: Working with quads. Some questions
Posted by Rob Vesse <rv...@dotnetrdf.org>.
Comments inline:
On 10/2/13 1:13 PM, "Alejandro Rodríguez González"
<al...@gmail.com> wrote:
>Hi all,
>
>I'm trying to create a small program which convert an RDF file into quads
>adding context.
>
>I've been looking at the examples in the API and some information on
>Google, but I don't know exactly what I'm doing wrong.
>
>I create my quads in the following way:
>
>ArrayList<Quad> quads = new ArrayList<Quad>();
>quads.add(new Quad(this.assertionNode, this.rdfTypeNode,
> this.nanoPubSchemaAssertionNode, this.nanoPubNode));
>quads.add(new Quad(this.nanoPubNode, this.purlCoverageNode,
> getNodeFromString(coverageContent), this.provenanceNode));
>
>The "nodes" are created using NodeFactory. Just an example with the nodes
>used in the example presented before:
>
>this.assertionNode = NodeFactory.createLiteral("
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/a
>ssertion/6bfba5c26cedaa3caf460d36d25ceef0
>");
>
>this.nanoPubNode = NodeFactory.createLiteral("
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/n
>anopublication/6bfba5c26cedaa3caf460d36d25ceef0
>");
>
>this.provenanceNode = NodeFactory.createLiteral("
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/p
>rovenance/1380725119158
>");
If these are URIs you should be calling NodeFactory.createUri() not
NodeFactory.createLiteral()
>
>etc.
>
>Once I've created all my structure, I try to print it on screen and store
>it on a .nq file using this code:
>
> Dataset ds = TDBFactory.createDataset();
> DatasetGraph dsg = ds.asDatasetGraph();
> for (int i = 0; i < quads.size(); i++) {
> dsg.add(quads.get(i));
> }
> RDFDataMgr.write(new FileOutputStream(new File("output/nquad2.nq")),
> dsg, RDFFormat.NQUADS);
> System.out.println(dsg.toString());
>
>The output that I get in the console is the following:
>
>(dataset
> (graph)
> (graph "
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/a
>ssertion/6bfba5c26cedaa3caf460d36d25ceef0
>"
> (triple "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" "
>http://www.nanopub.org/nschema#Assertion" "
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/n
>anopublication/6bfba5c26cedaa3caf460d36d25ceef0
>")
> )
> (graph "
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/n
>anopublication/6bfba5c26cedaa3caf460d36d25ceef0
>"
> (triple "http://purl.org/dc/elements/1.1/description" "\"Output from
>SADI Service\"@en" "
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/p
>rovenance/1380725119158
>")
> ))
>
>
>Which, it is the one that "I desire". However, in the file, I've the
>following:
>
>"http://www.w3.org/1999/02/22-rdf-syntax-ns#type" "
>http://www.nanopub.org/nschema#Assertion" "
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/n
>anopublication/6bfba5c26cedaa3caf460d36d25ceef0"
>"
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/a
>ssertion/6bfba5c26cedaa3caf460d36d25ceef0"
>.
>"http://purl.org/dc/elements/1.1/description" "\"Output from SADI
>Service\"@en" "
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/p
>rovenance/1380725119158"
>"
>http://biordf.org:8080/cgi-bin/services/retrieveProteomeProtiens_sync.pl/n
>anopublication/6bfba5c26cedaa3caf460d36d25ceef0"
>.
>
>My questions are:
>
>1) Why is the order of the nodes different? I mean, I expect to have:
>context, s, p, o (like when it is printed)
Because Jena follows the NQuads specification and the NQuads specification
mandates that the context which is an optional field in NQuads is written
last.
>2) Why, even using RDFFormat.NQUADS the serialization is between " " and
>not between <> ?
Because as previously noted you created literals when your question
implies you meant to create URIs, as noted earlier use
NodeFactory.createURI() instead
Rob
>
>Probably I'm missing something ...
>
>Thanks for your time.
>
>Cheers,
>
>Alejandro
>
>--
>Dr. Alejandro Rodríguez González - PhD
>
>Bioinformatics at Centre for Plant Biotechnology and Genomics UPM-INIA
>Polytechnic University of Madrid
>http://www.alejandrorg.com
>Phone: +34 914524900 . Ext: 25550
>
>
>*Once the game is over, the king and the pawn go back in the same box. -
>Italian proverb*