How make org.openrdf.rio parser supports Turtle documents?

76 views Asked by At

I have a java project on Eclipse that read R2RML (.ttl) file. I am using R2RMLReader from it.unibz.inf.ontop.r2rml.R2RMLReader which uses Open RDF Rio org.openrdf.rio.Rio, here is the method code:

public static ArrayList<TripleMaps> readR2RMLFile() {
        String mappingFile= "/path/to/Desktop/r2rmlFile.ttl";

         R2RMLReader reader = null;
          try {
            reader = new R2RMLReader(mappingFile);
          } catch (Exception e) {
            e.printStackTrace();
          }
          ArrayList<OBDAMappingAxiom> axioms = reader.readMappings();
          for (OBDAMappingAxiom ax : axioms)
            System.out.println(ax);
        return null; 
    }

However, the R2RMLReader throws this error:

org.openrdf.rio.UnsupportedRDFormatException: No parser factory available for RDF format Turtle (mimeTypes=text/turtle, application/x-turtle; ext=ttl)
    at org.openrdf.rio.Rio.createParser(Rio.java:198)
    at it.unibz.inf.ontop.r2rml.R2RMLManager.<init>(R2RMLManager.java:71)
    at it.unibz.inf.ontop.r2rml.R2RMLReader.<init>(R2RMLReader.java:63)
    at it.unibz.inf.ontop.r2rml.R2RMLReader.<init>(R2RMLReader.java:54)
    at TripleMaps.readR2RMLFile(TripleMaps.java:170)

What am I missing? Are there any jar files that should I add to the project?

I see this implementation on many tutorials and they use .ttl file format. However, in my project it not working.

I looked into different solutions this org.eclipse.rdf4j.rio.UnsupportedRDFormatException for Turtle format and this RDF4J RIO UnsupportedRDFormatException when adding data to an HTTPRepository using a stand-alone application

However, I am not using maven I downloaded all jar files and added it to the project.

I looked in http://archive.rdf4j.org/javadoc/sesame-2.8.9/org/openrdf/rio/RDFFormat.html , the openrdf/rio/RDFFormat should support Turtle.

"The file extension .ttl is recommend for Turtle documents"

How make org.openrdf.rio parser supports Turtle documents?

1

There are 1 answers

2
Jeen Broekstra On

You are missing the actual Turtle parser implementation, which is contained in a separate jar file from the Sesame Rio parser APIs (see https://search.maven.org/artifact/org.openrdf.sesame/sesame-rio-turtle ).

As suggested in the comments as well, I'd urge you to save yourself a world of pain: use maven to solve these kinds of dependency problems.

Also this: I'm not sure exactly what you're trying to achieve of course, and I don't know what version of the Ontop platform you're using, but the mention of org.openrdf packages indicates it's an old version. That package name is from the old Sesame project, which was replaced by the Eclipse RDF4J more than 6 years ago. I'm also pretty sure that Ontop itself has updated its dependencies to use RDF4J instead of Sesame for a while now. You may want to try upgrading to a more recent version.