Interface RDFParser

All Known Implementing Classes:
AbstractRDFParser, JsonLdParser, RDF4JParser

public interface RDFParser
Parse an RDF source into a target (e.g. a Graph/Dataset).

Experimental

This interface (and its implementations) should be considered at risk; they might change or be removed in the next minor update of Commons RDF. It may move to the the org.apache.commons.rdf.api package when it has stabilized.

Description

This interface follows the Builder pattern, allowing to set parser settings like contentType(RDFSyntax) and base(IRI). A caller MUST call one of the source methods (e.g. source(IRI), source(Path), source(InputStream)), and MUST call one of the target methods (e.g. target(Consumer), target(Dataset), target(Graph)) before calling parse() on the returned RDFParser - however methods can be called in any order.

The call to parse() returns a Future, allowing asynchronous parse operations. Callers are recommended to check Future.get() to ensure parsing completed successfully, or catch exceptions thrown during parsing.

Setting a method that has already been set will override any existing value in the returned builder - regardless of the parameter type (e.g. source(IRI) will override a previous source(Path). Settings can be unset by passing null - note that this may require casting, e.g. contentType( (RDFSyntax) null ) to undo a previous call to contentType(RDFSyntax).

It is undefined if a RDFParser is mutable or thread-safe, so callers should always use the returned modified RDFParser from the builder methods. The builder may return itself after modification, or a cloned builder with the modified settings applied. Implementations are however encouraged to be immutable, thread-safe and document this. As an example starting point, see org.apache.commons.rdf.simple.AbstractRDFParser.

Example usage:

Graph g1 = rDFTermFactory.createGraph();
new ExampleRDFParserBuilder().source(Paths.get("/tmp/graph.ttl")).contentType(RDFSyntax.TURTLE).target(g1).parse()
        .get(30, TimeUnit.Seconds);