Search in sources :

Example 1 with RDFHandlerException

use of org.eclipse.rdf4j.rio.RDFHandlerException in project graal by graphik-team.

the class Producer method run.

@Override
public void run() {
    org.eclipse.rdf4j.rio.RDFParser rdfParser = Rio.createParser(format);
    if (this.config != null) {
        rdfParser.setParserConfig(config);
    }
    rdfParser.setRDFHandler(new RDFListener(buffer));
    try {
        rdfParser.parse(this.reader, "");
    } catch (RDFParseException e) {
        throw new ParseError("An error occured while parsing", e);
    } catch (RDFHandlerException e) {
        throw new ParseError("An error occured while parsing", e);
    } catch (IOException e) {
        throw new ParseError("An error occured while parsing", e);
    }
    buffer.close();
    try {
        this.reader.close();
    } catch (IOException e) {
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) ParseError(fr.lirmm.graphik.graal.api.io.ParseError) IOException(java.io.IOException) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException)

Example 2 with RDFHandlerException

use of org.eclipse.rdf4j.rio.RDFHandlerException in project opentheso by miledrousset.

the class ReadRdfFile_rdf4j method readFile.

// TODO add test methods here.
// The methods must be annotated with annotation @Test. For example:
// 
@Test
public void readFile() {
    File file = new File("/Users/Miled/Desktop/Bureau2/test_unesco.rdf");
    RDFParser rdfParser = Rio.createParser(RDFFormat.RDFXML);
    Model model = new LinkedHashModel();
    rdfParser.setRDFHandler(new StatementCollector(model));
    Rio.write(model, System.out, RDFFormat.TURTLE);
    try {
        rdfParser.parse(new FileReader(file), "http://example.org");
        /*       for (Statement statement : model) {
                
        //        writeLine(statement.getObject().stringValue(), statement.getSubject().stringValue());

                System.out.println("LocalName = " + statement.getPredicate().getLocalName());

                System.out.println("objet = " + statement.getObject().stringValue());
                System.out.println("predicat = " + statement.getPredicate());
                System.out.println("URI = " + statement.getSubject());
                System.out.println("");
               
           //     model.getNamespace(statement.getClass().getgetObject().stringValue());

            } */
        for (Statement statement2 : model) {
            Literal literal = (SimpleLiteral) statement2;
            System.out.println(literal.getLabel());
            // System.out.println(literal.getLanguage());
            System.out.println(literal.getDatatype());
        }
    } catch (IOException e) {
    // handle IO problems (e.g. the file could not be read)
    } catch (RDFParseException e) {
    // handle unrecoverable parse error
    } catch (RDFHandlerException e) {
    // handle a problem encountered by the RDFHandler
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector) Statement(org.eclipse.rdf4j.model.Statement) Literal(org.eclipse.rdf4j.model.Literal) SimpleLiteral(org.eclipse.rdf4j.model.impl.SimpleLiteral) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) Model(org.eclipse.rdf4j.model.Model) FileReader(java.io.FileReader) SimpleLiteral(org.eclipse.rdf4j.model.impl.SimpleLiteral) LinkedHashModel(org.eclipse.rdf4j.model.impl.LinkedHashModel) IOException(java.io.IOException) RDFParser(org.eclipse.rdf4j.rio.RDFParser) File(java.io.File) RDFParseException(org.eclipse.rdf4j.rio.RDFParseException) Test(org.junit.Test)

Example 3 with RDFHandlerException

use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.

the class TurtleWriter method endRDF.

@Override
public void endRDF() throws RDFHandlerException {
    if (!writingStarted) {
        throw new RuntimeException("Document writing has not yet started");
    }
    try {
        closePreviousStatement();
        writer.flush();
    } catch (IOException e) {
        throw new RDFHandlerException(e);
    } finally {
        writingStarted = false;
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) IOException(java.io.IOException)

Example 4 with RDFHandlerException

use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.

the class TriXWriter method endRDF.

public void endRDF() throws RDFHandlerException {
    if (!writingStarted) {
        throw new RDFHandlerException("Document writing has not yet started");
    }
    try {
        if (inActiveContext) {
            xmlWriter.endTag(CONTEXT_TAG);
            inActiveContext = false;
            currentContext = null;
        }
        xmlWriter.endTag(ROOT_TAG);
        xmlWriter.endDocument();
    } catch (IOException e) {
        throw new RDFHandlerException(e);
    } finally {
        writingStarted = false;
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) IOException(java.io.IOException)

Example 5 with RDFHandlerException

use of org.eclipse.rdf4j.rio.RDFHandlerException in project rdf4j by eclipse.

the class TriXWriter method handleStatement.

public void handleStatement(Statement st) throws RDFHandlerException {
    if (!writingStarted) {
        throw new RDFHandlerException("Document writing has not yet been started");
    }
    try {
        Resource context = st.getContext();
        if (inActiveContext && !contextsEquals(context, currentContext)) {
            // Close currently active context
            xmlWriter.endTag(CONTEXT_TAG);
            inActiveContext = false;
        }
        if (!inActiveContext) {
            // Open new context
            xmlWriter.startTag(CONTEXT_TAG);
            if (context != null) {
                writeValue(context);
            }
            currentContext = context;
            inActiveContext = true;
        }
        xmlWriter.startTag(TRIPLE_TAG);
        writeValue(st.getSubject());
        writeValue(st.getPredicate());
        writeValue(st.getObject());
        xmlWriter.endTag(TRIPLE_TAG);
    } catch (IOException e) {
        throw new RDFHandlerException(e);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) Resource(org.eclipse.rdf4j.model.Resource) IOException(java.io.IOException)

Aggregations

RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)59 IOException (java.io.IOException)41 RDFParseException (org.eclipse.rdf4j.rio.RDFParseException)19 Resource (org.eclipse.rdf4j.model.Resource)11 Value (org.eclipse.rdf4j.model.Value)10 RDFLoader (org.eclipse.rdf4j.repository.util.RDFLoader)8 BNode (org.eclipse.rdf4j.model.BNode)7 IRI (org.eclipse.rdf4j.model.IRI)7 Literal (org.eclipse.rdf4j.model.Literal)7 Statement (org.eclipse.rdf4j.model.Statement)6 StatementCollector (org.eclipse.rdf4j.rio.helpers.StatementCollector)6 ParsedIRI (org.eclipse.rdf4j.common.net.ParsedIRI)4 TupleQueryResultHandlerException (org.eclipse.rdf4j.query.TupleQueryResultHandlerException)4 RDFInserter (org.eclipse.rdf4j.repository.util.RDFInserter)4 SAXException (org.xml.sax.SAXException)4 RDFFormat (org.eclipse.rdf4j.rio.RDFFormat)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2