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;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.OutputStream;

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) {
        super(other);
    }

    @Override
    public void triple(Triple triple) {
        if ((triple.getSubject().isURI() && triple.getSubject().getURI().contains(" "))
                || (triple.getObject().isURI() && triple.getObject().getURI().contains(" ")))
            System.out.println(triple.getSubject().getURI());
        else
            other.triple(triple);
    }
}

And here some example statements extracted from the dataset:

@prefix gndo: <http://d-nb.info/standards/elementset/gnd#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix dnbt: <http://d-nb.info/standards/elementset/dnb/> .

<http://d-nb.info/gnd/117177040> a gndo:DifferentiatedPerson ;
        owl:sameAs <http://viaf.org/viaf/64153583> ;
        gndo:gndIdentifier "117177040" ;
        gndo:oldAuthorityNumber "(DE-588a)117177040" , "(DE-588a)117177040670 BnF" ;
        owl:sameAs <http://d-nb.info/gnd/117177040670 BnF> ;
        dnbt:deprecatedUri "http://d-nb.info/gnd/117177040670 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): <http://d-nb.info/gnd/117177040670[space]...>
    at org.apache.jena.riot.system.ErrorHandlerFactory$ErrorHandlerStd.fatal(ErrorHandlerFactory.java:136)
    at org.apache.jena.riot.lang.LangEngine.raiseException(LangEngine.java:165)
    at org.apache.jena.riot.lang.LangEngine.nextToken(LangEngine.java:108)
    at org.apache.jena.riot.lang.LangTurtleBase.predicateObjectItem(LangTurtleBase.java:286)
    at org.apache.jena.riot.lang.LangTurtleBase.predicateObjectList(LangTurtleBase.java:280)
    at org.apache.jena.riot.lang.LangTurtleBase.triples(LangTurtleBase.java:249)
    at org.apache.jena.riot.lang.LangTurtleBase.triplesSameSubject(LangTurtleBase.java:190)
    at org.apache.jena.riot.lang.LangTurtle.oneTopLevelElement(LangTurtle.java:46)
    at org.apache.jena.riot.lang.LangTurtleBase.runParser(LangTurtleBase.java:89)
    at org.apache.jena.riot.lang.LangBase.parse(LangBase.java:42)
    at org.apache.jena.riot.RDFParserRegistry$ReaderRIOTLang.read(RDFParserRegistry.java:179)
    at org.apache.jena.riot.RDFDataMgr.process(RDFDataMgr.java:861)
    at org.apache.jena.riot.RDFDataMgr.parse(RDFDataMgr.java:667)
    at org.apache.jena.riot.RDFDataMgr.parse(RDFDataMgr.java:637)
    at org.apache.jena.riot.RDFDataMgr.parse(RDFDataMgr.java:626)
    at org.apache.jena.riot.RDFDataMgr.parse(RDFDataMgr.java:617)
    at zbw.tbl.schemex.additions.JenaStreamWrapper.main(JenaStreamWrapper.java:27)

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(WebappClassLoaderBase.java:1858)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1701)
at br.com.petrobras.ontologia.controller.MapaConceitualController.about(MapaConceitualController.java:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at br.com.caelum.vraptor.interceptor.ExecuteMethodInterceptor.intercept(ExecuteMethodInterceptor.java:61)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
at br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:61)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
at br.com.caelum.vraptor.core.LazyInterceptorHandler.execute(LazyInterceptorHandler.java:61)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:56)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
at br.com.caelum.vraptor.interceptor.InstantiateInterceptor.intercept(InstantiateInterceptor.java:48)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
at br.com.caelum.vraptor.interceptor.FlashInterceptor.intercept(FlashInterceptor.java:83)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
at br.com.caelum.vraptor.interceptor.ExceptionHandlerInterceptor.intercept(ExceptionHandlerInterceptor.java:67)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
at br.com.caelum.vraptor.interceptor.ResourceLookupInterceptor.intercept(ResourceLookupInterceptor.java:69)
at br.com.caelum.vraptor.core.ToInstantiateInterceptorHandler.execute(ToInstantiateInterceptorHandler.java:54)
at br.com.caelum.vraptor.core.DefaultInterceptorStack.next(DefaultInterceptorStack.java:54)
at br.com.caelum.vraptor.core.EnhancedRequestExecution.execute(EnhancedRequestExecution.java:44)
at br.com.caelum.vraptor.VRaptor$1.insideRequest(VRaptor.java:95)
at br.com.caelum.vraptor.ioc.guice.GuiceProvider.provideForRequest(GuiceProvider.java:82)
at br.com.caelum.vraptor.VRaptor.doFilter(VRaptor.java:101)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:436)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

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
    WHERE
      { ?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: https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/Query.html

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 http://192.168.1.38:3030/ds/data default /home/user/data.ttl


./s-put http://192.168.1.38:3030/ds/data 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.