On 15/07/14 11:06, Julien Plu wrote:
Ok, I finally succeed to do it ! Here the method that I've found :

DatasetGraph dg = RDFDataMgr.loadDatasetGraph(PrivacyDeployment.FILE,
Lang.NQUADS);
Iterator<Node> nodeIt = dg.listGraphNodes();

while (nodeIt.hasNext()) {
     Node node = nodeIt.next();
     Graph graph = dg.getGraph(node);
     VirtGraph virtGraph = new VirtGraph(node.getURI(),
PrivacyDeployment.DB_URL, PrivacyDeployment.USER, PrivacyDeployment.PASS);

     for (Triple triple : GraphUtil.findAll(graph).toSet()) {
         virtGraph.add(triple);
     }

     virtGraph.close();
}

But is-there a simpler way to do it ?

Yiou should be able to read it straight into the Virtuoso Dataset DatasetGraph

        VirtDataset vd = new VirtDataset(...)
        RDFDataMgr.read(vd,  Lang.NQUADS) ;

It only depends on the Dataset interface (well, DatasetGraph actually, it'll internally take off the Dataset to get at the quads interface to storage).

        Andy


Best.

-------------------------------------------------------------------------------------------------------------------------------
Julien Plu

PhD Student at Eurecom.
Personal webpage: http://jplu.developpez.com
FOAF file : http://jplu.developpez.com/julien
Email address : [email protected]
Phone : +33493008200
Twitter : @julienplu


2014-07-15 11:22 GMT+02:00 Julien Plu <[email protected]>:

Hi Andy,

After trying what you told me, I'm able now to load a file with quads. But
now it's impossible to copy the content from one Dataset to another one,
here what I'm trying to do :

VirtDataset vd = new VirtDataset("jdbc:virtuoso://localhost:1111", "dba",
"dba");
DatasetGraph vdg = vd.asDatasetGraph();
DatasetGraph dg = RDFDataMgr.loadDatasetGraph("data.nq", Lang.NQUADS);
Iterator<Node> nodeIt = dg.listGraphNodes();

while (nodeIt.hasNext()) {
     Node node = nodeIt.next();
     Graph graph = dg.getGraph(node);

     vdg.addGraph(node, graph);
}

RDFDataMgr.write(System.out, vdg, RDFFormat.NQUADS_UTF8);

When I try to write the final DatasetGraph, I have this exception :

Exception in thread "main" java.lang.UnsupportedOperationException:
subject cannot be null
at com.hp.hpl.jena.graph.Triple.<init>(Triple.java:38)
  at
virtuoso.jena.driver.VirtDataset$VirtDataSetGraph.find(VirtDataset.java:497)
at org.apache.jena.riot.writer.NQuadsWriter.write(NQuadsWriter.java:91)
  at org.apache.jena.riot.RDFDataMgr.write$(RDFDataMgr.java:1274)
at org.apache.jena.riot.RDFDataMgr.write(RDFDataMgr.java:1148)
  at
fr.eurecom.cixty.privacytest.PrivacyDeployment.addData(PrivacyDeployment.java:265)
at
fr.eurecom.cixty.privacytest.PrivacyDeployment.main(PrivacyDeployment.java:81)

I also tried this code :

VirtDataset vd = new VirtDataset("jdbc:virtuoso://localhost:1111", "dba",
"dba");
RDFDataMgr.read(vd.asDatasetGraph(),
Files.newInputStream(Paths.get("data.nq")), Lang.NQUADS);

But the same exception occurs.

Anything I did wrongly ?

Best.


-------------------------------------------------------------------------------------------------------------------------------
Julien Plu

PhD Student at Eurecom.
Personal webpage: http://jplu.developpez.com
FOAF file : http://jplu.developpez.com/julien
Email address : [email protected]
Phone : +33493008200
Twitter : @julienplu


2014-07-13 2:34 GMT+02:00 Julien Plu <[email protected]>
:

Ok thank you !

I will try with a dataset now.


-------------------------------------------------------------------------------------------------------------------------------
Julien Plu

PhD Student at Eurecom.
Personal webpage: http://jplu.developpez.com
FOAF file : http://jplu.developpez.com/julien
Email address : [email protected]
Phone : +33493008200
Twitter : @julienplu


2014-07-12 19:48 GMT+02:00 Andy Seaborne <[email protected]>:

On 11/07/14 15:31, Julien Plu wrote:

Hi,

I try to read a N-QUAD file to load it in a model but unfortunalety
nothing
is loaded. Here what I do :

Model m = RDFDataMgr.loadModel("data.nq", Lang.NQUADS);
RDFDataMgr.write(System.out, m, RDFFormat.NQUADS_UTF8);

At the end nothing is displayed on the console. And I have just one line
inside my file :

<http://example.com/Toto> <http://xmlns.com/foaf/0.1/name> "Toto" <
http://example.com> .

Do-I something wrong ? Or is-there another way to do that ?

Thanks in advance for your answer.

Best.

Julien.


A model is a single graph.  It can't hold named graphs.

If you read N-quads (default and named graphs) into a Model (a single
graph) only the default graph goes into the model.

Use a dataset to get the set of all graphs in the n-quads files.

         Andy






Reply via email to