I am not sure if we should be saying anything about RDF parser and
writer interfaces.

Anyhow, I still felt a need to parse generic RDF files with Commons
RDF, and Apache Jena RIOT has a great collection of RDF parsers, so I
wrote a quick binding to see how it can generate and populate
arbitrary Commons RDF Graphs:

https://github.com/stain/commonsrdf-parser-jena


This works with a configurable Graph and RDFTermFactory implementation
together with Jena's StreamRDF - so no intermediate Jena graphs would
be in existence during parsing.


I was playing a bit with what kind of interface parsing would look
like - and ended up with a Factory pattern:

    Parser parser = new JenaParser();
    Path filePath = Paths.get("/tmp/file.rdf");
    Graph g = parser.contentType(Parser.RDFXML).path(examplePath).parse();


This way you don't need to have multiple parse() methods, and can
support many of the optionals easily, e.g. base or content type.  As
even the source is a method, then if path(), url() or inputStream() is
not appropriate for you, you can add a fourth source type by
extension.


A similar interface for writing could be made, but I didn't get too far.


Note that this is not Jena's Commons RDF implementation
https://issues.apache.org/jira/browse/JENA-1015


-- 
Stian Soiland-Reyes
Apache Taverna (incubating), Apache Commons RDF (incubating)
http://orcid.org/0000-0001-9842-9718

Reply via email to