Category Archives: apache-jena

Stream Parsing of Turtle syntax with jena

I have a problem and even after hours of search I could not find a suitable solution. I want to parse a huge RDF document in turtle syntax (~8GB). This is why I chose a stream approach offered by jena riot, namely the RDFDataMgr. The file I am processing uses invalid URIs, which contain whitespaces. This raises a fatal exception and the parsing stops. I would like to recognize those invalid URI beforhand and skip the whole statement, as it is of no use anyways. I have tried the proposed solution from the apache email archive, but as the exception raises before the triple gets emitted, it does not work as expected. Does anyone know where I am mistaken or do I have to find another solution? See here the example code I am using:

import org.apache.jena.atlas.lib.Sink;
import org.apache.jena.graph.Triple;
import org.apache.jena.riot.system.StreamRDF;
import org.apache.jena.riot.system.StreamRDFLib;
import org.apache.jena.riot.system.StreamRDFWrapper;
import org.apache.jena.riot.system.SyntaxLabels;
import org.apache.jena.sparql.core.Quad;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.riot.out.SinkQuadOutput;


public class JenaStreamWrapper extends StreamRDFWrapper {

    public static void main(String... argv) throws FileNotFoundException {
        String filename = "file.ttl";
        OutputStream outputStream = new FileOutputStream(new File("file.nq"));
        StreamRDF filtered = new JenaStreamWrapper(StreamRDFLib.writer(outputStream));
        RDFDataMgr.parse(filtered, filename);

    public JenaStreamWrapper(StreamRDF other) {

    public void triple(Triple triple) {
        if ((triple.getSubject().isURI() && triple.getSubject().getURI().contains(" "))
                || (triple.getObject().isURI() && triple.getObject().getURI().contains(" ")))

And here some example statements extracted from the dataset:

@prefix gndo: <> .
@prefix owl: <> .
@prefix dnbt: <> .

<> a gndo:DifferentiatedPerson ;
        owl:sameAs <> ;
        gndo:gndIdentifier "117177040" ;
        gndo:oldAuthorityNumber "(DE-588a)117177040" , "(DE-588a)117177040670 BnF" ;
        owl:sameAs < BnF> ;
        dnbt:deprecatedUri " BnF" ;
        gndo:oldAuthorityNumber "(DE-588)117177040670 BnF" ;
        gndo:variantNameForThePerson "Jourdan, Camille" ;
        gndo:variantNameEntityForThePerson _:node1aj1cbug9x62759112 . 

When executing the code I get the following message:

Exception in thread "main" org.apache.jena.riot.RiotException: [line: 9, col: 55] Bad character in IRI (space): <[space]...>
    at org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(
    at org.apache.jena.riot.lang.LangEngine.raiseException(
    at org.apache.jena.riot.lang.LangEngine.nextToken(
    at org.apache.jena.riot.lang.LangTurtleBase.predicateObjectItem(
    at org.apache.jena.riot.lang.LangTurtleBase.predicateObjectList(
    at org.apache.jena.riot.lang.LangTurtleBase.triples(
    at org.apache.jena.riot.lang.LangTurtleBase.triplesSameSubject(
    at org.apache.jena.riot.lang.LangTurtle.oneTopLevelElement(
    at org.apache.jena.riot.lang.LangTurtleBase.runParser(
    at org.apache.jena.riot.lang.LangBase.parse(
    at org.apache.jena.riot.RDFParserRegistry$
    at org.apache.jena.riot.RDFDataMgr.process(
    at org.apache.jena.riot.RDFDataMgr.parse(
    at org.apache.jena.riot.RDFDataMgr.parse(
    at org.apache.jena.riot.RDFDataMgr.parse(
    at org.apache.jena.riot.RDFDataMgr.parse(
    at zbw.tbl.schemex.additions.JenaStreamWrapper.main(

I am thankful for anykind of useful input.

Cannot find oracle/spatial/rdf/client/jena/Oracle

I am trying to connect to a 12c database in my java web application. I'm using Caelum VRaptor to manage my web service and Apache Tomcat 7 as a server. I've added the sdordfclient.jar to the project, so the oracle.spatial.rdf.client.jena.Oracle is available. When I type in eclipse "import oracle.spatial.rdf.client.jena.Oracle", it recognizes the class. But when I run my project, I get:

java.lang.ClassNotFoundException: oracle.spatial.rdf.client.jena.Oracle
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.valves.AccessLogValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.AbstractHttp11Processor.process(
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$
at org.apache.tomcat.util.threads.TaskThread$

Does anyone know how do I connect to my db?

getting the WHERE from an apache JENA ARQ Query

Is it possible to get the WHERE Clause from a Query org.apache.jena.query.Query ? Haven't found no info enywhere, no documentation anywhere.

Imagine I create a query from a String

String queryString = "    
SELECT ?name ?mbox
      { ?x foaf:name ?name .
        ?x foaf:mbox ?mbox }";

Query query = QueryFactory.create() ;

For example, I can get the variables that the query will request using the query.getResultVars()), but I cannot get any manner to get the WHERE clause/expression or however you wanna call. Just interested in getting this part:

  { ?x foaf:name ?name .
    ?x foaf:mbox ?mbox }

Here's Query API:

How to make apache jena fuseki server serve multiple RDF at the same time

I am using apache jena fuseki server to load the data in a .ttl format and then querying the data.But the problem is i am not able to serve multiple data simultaneously.

I am starting the server using the following command.

 ./fuseki-server --update --mem /ds

The server version i am using is 1.1.1

/home/user/jena-fuseki-1.1.1/./s-put default /home/user/data.ttl

./s-put default /home/user/data.ttl

I am having a rest api from which multiple users can load the data and do SPARQL queries on top of it.But when each time a new user loads the data the server gets the new data and the previous data is gone.

I want each user to have his own data to be maintained by the server.Is there some mistake in the way i am loading data ?

Searching data from RDF files and showing into a webpage with apache jena

I am new in apache jena. I will have to develop simple “Cottage booking” service to be run on Apache Tomcat server. Service should perform a search in a database of the cottages and return a set of bookings for the cottages that fit the requirements set as input to the service. Service uses RDF file as a database with a set of instances (at least 5) that describes some cottages (cottage configurations).

could u please suggest some solution.