Search in sources :

Example 1 with Graph

use of org.eclipse.rdf4j.model.Graph in project opentheso by miledrousset.

the class WriteRdfFileTest method writeRio.

@Test
public void writeRio() {
    FileOutputStream out = null;
    try {
        // a collection of several RDF statements
        Graph myGraph = null;
        out = new FileOutputStream("test_unesco2.rdf");
        try {
            RDFWriter writer = Rio.createWriter(RDFFormat.RDFXML, out);
            writer.startRDF();
            for (Statement st : myGraph) {
                writer.handleStatement(st);
            }
            writer.endRDF();
        } catch (RDFHandlerException e) {
        // oh no, do something!
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(WriteRdfFileTest.class.getName()).log(Level.SEVERE, null, ex);
    // oh no, do something!
    } finally {
        try {
            out.close();
        } catch (IOException ex) {
            Logger.getLogger(WriteRdfFileTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : Graph(org.eclipse.rdf4j.model.Graph) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) Statement(org.eclipse.rdf4j.model.Statement) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) RDFWriter(org.eclipse.rdf4j.rio.RDFWriter) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with Graph

use of org.eclipse.rdf4j.model.Graph in project rdf4j by eclipse.

the class DAWGTestResultSetUtil method toGraph.

public static Graph toGraph(TupleQueryResult tqr) throws QueryEvaluationException {
    Graph graph = new GraphImpl();
    DAWGTestResultSetWriter writer = new DAWGTestResultSetWriter(new StatementCollector(graph));
    try {
        writer.startQueryResult(tqr.getBindingNames());
        while (tqr.hasNext()) {
            writer.handleSolution(tqr.next());
        }
        writer.endQueryResult();
    } catch (TupleQueryResultHandlerException e) {
        // StatementCollector, foud a bug?
        throw new RuntimeException(e);
    }
    return graph;
}
Also used : Graph(org.eclipse.rdf4j.model.Graph) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) GraphImpl(org.eclipse.rdf4j.model.impl.GraphImpl) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector)

Aggregations

Graph (org.eclipse.rdf4j.model.Graph)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 Statement (org.eclipse.rdf4j.model.Statement)1 GraphImpl (org.eclipse.rdf4j.model.impl.GraphImpl)1 TupleQueryResultHandlerException (org.eclipse.rdf4j.query.TupleQueryResultHandlerException)1 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)1 RDFWriter (org.eclipse.rdf4j.rio.RDFWriter)1 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)1 Test (org.junit.Test)1