You have to log in to edit pages.
{{#vardefine:category|Thing}}{{#vardefine:package|smwbp_ontology_templates}}{{#vardefine:templatename|o.thing}}
Form editing notes
Free text:
This page describes how to set up a [[SPARQL endpoint]] that can process standard SPARQL queries and return results that include inferences provided by a server-side Pellet reasoner. The following posts provide background and alternative perspectives: * http://lists.owldl.com/pipermail/pellet-users/2009-July/003798.html * http://blog.fmeyer.org/entry/configuring_joseki__pellet__tdb == 1. Download TDB and Joseki == 1. Download TDB-0.8.2 [http://sourceforge.net/projects/jena/files/] and Joseki-3.4.0 [http://sourceforge.net/projects/joseki/] TDB is a triple store affiliated with Jena. It allows you to load data into a directory. When you use TDB to load data into a directory, it populates the directory with index files. TDB can also be used to query the data that it has set up in a directory. Joseki is a web application that ... == 2. Install/configure TDB == 2.1 Extract TDB-0.8.2.zip to a destination directory. In this tutorial, we will use: <code>/opt/tdb</code>. Then, register that directory in the <code>TDBROOT</code> environment variable. % export TDBROOT=/opt/tdb % ls $TDBROOT ChangeLog.txt README.txt Store bin bin2 copyright.txt doc lib tdb-src-0.8.2.zip tdb.ttl testing tmp 2.2 Add <code>/opt/tdb/lib</code> to your classpath: export CLASSPATH=$CLASSPATH:$TDBROOT/lib 2.3 The installation can be tested by running the shell script: % bin/tdbverify TDB test suite (development) ... OK (1060 tests) Note: This '''must''' be run from $TDBROOT (<code>/opt/tdb</code>). Feedback from Xian: I tried TDB 0.8.7 and TDB 0.8.5, both of their tdbverify commands don't work. TDB 0.8.2 tdbverify works as described here. Then how shall we verify the TDB installation? Also, JAVA_HOME needs to be added if not. If you get a "Permission denied" or "NoClassDefFoundError", chmod +x bin/* Unless you are using Cygwin, do '''not''' worry about the error: uname: illegal option -- o usage: uname [-amnprsv] (If you want, you can just comment out the <code>if [ "$(uname -o)" = "Cygwin" ]</code> check in <code>$TDBROOT/bin/make_classpath</code>) 2.4 To use the tdb command line utility, you need to set up <code>TDBROOT</code> (as before). You also need to set up your <code>PATH</code>: export PATH=$TDBROOT/bin:$PATH 2.5 Create a directory that <code>tdbloader</code> can use to "set up shop", i.e., store index files: mkdir /work/data/bloggers-db-dir 2.6 Use <code>tdbloader</code> to load [http://planetrdf.com/bloggers.rdf data] or [http://www.w3.org/People/Berners-Lee/card data] into the database directory: %tdbloader --loc=/work/data/bloggers-db-dir bloggers.rdf ** Secondary indexes Index SPO->POS: 845 triples indexed in 0.04s [21,666 slots/s] Index SPO->OSP: 845 triples indexed in 0.03s [24,852 slots/s] -- Finish index phase : 2009/10/21 19:35:24 ** Close graph Time for load: 0.63s [1,353 triples/s] 2.7 Issue a query to the database directory with <code>tdbquery</code>: tdbquery --loc=/work/data/bloggers-db-dir --query=$TDBROOT/testing/Basic/basic-00.rq Part of [http://planetrdf.com/bloggers.rdf bloggers.rdf] looks like: [[File:Bloggers.rdf.jpg|Part of the bloggers.rdf]] == 3. Install Joseki == 3.1 Extract joseki-3.4.0.zip to a destination directory. In this tutorial, we will use: <code>/opt/joseki</code> % export JOSEKIROOT=/opt/joseki % ls $JOSEKIROOT ChangeLog.txt CopyrightNotice.txt Data README.txt bin doc etc joseki-3.4.0-sources.jar joseki-config-example.ttl joseki-config-sdb.ttl joseki-config-tdb.ttl joseki-config.ttl lib pom.xml sdb.ttl webapps 3.2 Turn on Joseki by running the shell script from <code>$JOSEKIROOT</code>: cd $JOSEKIROOT bin/rdfserver You might need to: chmod +x bin/* 3.3 http://localhost:2020 should provide the SPARQLer webpage. Load http://localhost:2020/query.html ("General purpose SPARQL processor") and paste a SPARQL query into the appropriate field. You can use the query that we used to demonstrate TDB's <code>tdbquery</code> above in Section 2.7: %cat $TDBROOT/testing/Basic/basic-00.rq PREFIX : <http://example> SELECT * { ?x ?p ?z } 3.4 As can be seen in <code>$JOSEKIROOT/bin/rdfserver</code>'s output, Joseki uses <code>$JOSEKIROOT/joseki-config.ttl</code> as a default configuration file: 15:59:34 INFO Configuration :: ==== Configuration ==== 15:59:34 INFO Configuration :: Loading : <joseki-config.ttl> In <code>joseki-config.ttl</code>, a <code>joseki:Service</code> is created that refers to the <code>joseki:dataset <#books></code>: # Service 2 - SPARQL processor only handling a given dataset <#service2> rdf:type joseki:Service; rdfs:label "SPARQL on the books model"; joseki:serviceRef "books"; ... joseki:dataset <#books>; ... joseki:processor joseki:ProcessorSPARQL_FixedDS; . <code><#books></code> is described in the Datasets section as a <code>ja:RDFDataset</code> at <code><file:Data/books.n3></code>. This is <code>$JOSEKIROOT/Data/books.n3</code> on your local system, and the data set you are querying from http://localhost:2020/query.html. ## -------------------------------------------------------------- ## Datasets <#books> rdf:type ja:RDFDataset; rdfs:label "Books"; ja:defaultGraph [ rdfs:label "books.n3"; a ja:MemoryModel; ja:content [ ja:externalContent <file:Data/books.n3> ]; ]; . books.n3 looks like: [[File:Books.n3.jpg]] == 4. Configure Joseki to query data in a TDB directory == Feedback from Xian: The versions of TDB and Joseki will impact the output of this step. By using the latest Joseki(3.4.2) and TDB 0.8.2, Joseki server wouldn't be started after making below changes to make_classpath: 18:08:29 WARN RDFServer :: RDFServer: Failed to create web application server: java.lang.SecurityException: sealing violation: can't seal package org.mortbay.jetty: already loaded 18:08:29 WARN RDFServer :: Exception (server startup): java.lang.SecurityException: sealing violation: can't seal package org.mortbay.jetty: already loaded java.lang.SecurityException: sealing violation: can't seal package org.mortbay.jetty: already loaded at java.net.URLClassLoader.defineClass(URLClassLoader.java:242) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at org.joseki.RDFServer.start(RDFServer.java:169) at joseki.rdfserver.main(rdfserver.java:86) Possible reason could be the version conflict of Jetty: TDB 0.8.2 uses an older version of Jetty while Joseki 3.4.2 uses a newer version of Jetty. See a similar post at http://jira.openqa.org/browse/SRC-471 4.1 Instead of querying plain RDF files on disk (like in the <code>books.n3</code> example above in Section 3.3), Joseki can query data in a TDB directory (like <code>blogger-db-dir</code> that was created above in Section 2.6). To do so, you will need a new [[File:Joseki-config-bloggers-tdb.ttl | joseki-configuration file]] and a new [[File:Make classpath-tdb.sh|$JOSEKIROOT/bin/make_classpath file]]. While we discuss the steps that we took to make these for you, you can download them and tweak the absolute paths. It might be instructive to diff the new files with their off-the-shelf versions. 4.2 Duplicate the <code>joseki-config.ttl</code> file that was used by default in Section 3.2: cp $JOSEKIROOT/joseki-config.ttl $JOSEKIROOT/joseki-config-bloggers-tdb.ttl 4.3 Add the tdb namespace prefix to <code>$JOSEKIROOT/joseki-config-bloggers-tdb.ttl</code>: @prefix tdb: <http://jena.hpl.hp.com/2008/tdb#> . 4.4 Comment out <code>#service1</code> (because we want to use the same 'sparql' joseki:serviceRef, and we prefer a FixedDS instead of a general endpoint). #<#service1> # rdf:type joseki:Service ; # rdfs:label "service point" ; # joseki:serviceRef "sparql" ; # web.xml must route this name to Joseki # joseki:processor joseki:ProcessorSPARQL ; # . 4.5 In the "Services" section, change # Service 2 - SPARQL processor only handling a given dataset <#service2> rdf:type joseki:Service ; rdfs:label "SPARQL<strike> on the books model</strike>" ; joseki:serviceRef "<strike>books</strike>" ; # web.xml must route this name to Joseki # dataset part joseki:dataset <#<strike>books</strike>> ; # Service part. # This processor will not allow either the protocol, # nor the query, to specify the dataset. joseki:processor joseki:ProcessorSPARQL_FixedDS ; . to # Service 2 - SPARQL processor only handling a given dataset '''in a TDB directory''' <#service2> rdf:type joseki:Service ; rdfs:label "SPARQL'''-TDB'''" ; joseki:serviceRef "'''sparql'''" ; # web.xml must route this name to Joseki # dataset part joseki:dataset <#'''bloggers-dataset'''> ; # Service part. # This processor will not allow either the protocol, # nor the query, to specify the dataset. joseki:processor joseki:ProcessorSPARQL_FixedDS ; . 4.6 In the "Datasets" section, add these 14 lines: [] ja:loadClass "com.hp.hpl.jena.tdb.TDB" . ## Initialize TDB. tdb:DatasetTDB rdfs:subClassOf ja:RDFDataset . tdb:GraphTDB rdfs:subClassOf ja:Model . <#'''bloggers-dataset'''> a ja:RDFDataset; ja:defaultGraph [ a ja:InfModel; ja:baseModel [ a tdb:GraphTDB; tdb:location "/work/data/bloggers-db-dir"; ]; ]; . The <code>tdb:location</code> needs to match the <code>--loc</code> parameter that <code>tdbloader</code> used above in Section 2.6. 4.7 We just asked Joseki to load <code>com.hp.hpl.jena.tdb.TDB</code>, so we need to make sure Joseki has it in its classpath when it runs. Add the following lines to <code>$JOSEKIROOT/bin/make_classpath</code>: TDBROOTLIBDIR="/opt/tdb/lib" <-- under LIBDIR="$DIRROOT/lib" on line 18 ... for jar in "$TDBROOTLIBDIR"/*.jar <-- under "# Append any jars in the lib/ directory" section on line 39/40 do # Check for no expansion [ -e "$jar" ] || break echo "Path: $jar" [ "$CP" != "" ] && CP="${CP}${SEP}" CP="${CP}$jar" done 4.8 Turn on Joseki, just like in Section 2.6, but with an additional argument for a non-default configuration file: Feedback from Xian: This tutorial didn't mention how to turn off Joseki before this. It should be "Section 3.2" rather than "Section 2.6" cd $JOSEKIROOT bin/rdfserver joseki-config-bloggers-tdb.ttl 4.9 Load http://localhost:2020/sparql.html to query <code>/work/data/bloggers-db-dir</code>. prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix dc: <http://purl.org/dc/elements/1.1/> select ?self ?title where { ?self rdfs:seeAlso ?self . optional { ?self dc:title ?title } } order by $self == 5. Configure Joseki to query inferences from data+ontology in a single TDB directory == 5.1 If the TDB directory contains raw data and ontology data, Joseki can apply a reasoner and return inferenced statements as well as the original statements. To do so, you will need a new [[File:Joseki-config-bloggers-tdb-pellet.ttl|joseki-configuration file]] and a new [[File:Make classpath-tdb-pellet.sh|$JOSEKIROOT/bin/make_classpath file]] (again). While we discuss the steps that we took to make these for you, you can download them and tweak the absolute paths (again). As before, it might be instructive to diff the new files with their off-the-shelf versions. cp $JOSEKIROOT/joseki-config-bloggers-tdb.ttl $JOSEKIROOT/joseki-config-bloggers-tdb'''-pellet'''.ttl 5.2 In <code>$JOSEKIROOT/joseki-config-bloggers-tdb-pellet.ttl</code>, change # Service 2 - SPARQL processor for only handling a given dataset in a TDB directory <#service2> rdf:type joseki:Service ; rdfs:label "SPARQL-TDB" ; joseki:serviceRef "sparql" ; # web.xml must route this name to Joseki # dataset part joseki:dataset <#bloggers-dataset> ; to # Service 2 - SPARQL processor for only handling a given dataset in a TDB directory <#service2> rdf:type joseki:Service ; rdfs:label "SPARQL-TDB" ; joseki:serviceRef "sparql" ; # web.xml must route this name to Joseki # dataset part joseki:dataset <#bloggers-dataset'''_reasoning'''> ; 5.3 After <#bloggers-dataset> a ja:RDFDataset; ja:defaultGraph [ a ja:InfModel; ja:baseModel [ a tdb:GraphTDB; tdb:location "/work/data/blogger-db-dir"; ]; ]; . add the 15 lines: Feedback from Xian: Will "bloggers-dataset" be usable? If not, why not replace them with "bloggers-dataset_reasoning"? <#bloggers-dataset'''_reasoning'''> a ja:RDFDataset; ja:defaultGraph [ a ja:InfModel; ja:reasoner [ ja:reasonerClass "org.mindswap.pellet.jena.PelletReasonerFactory"; ]; ja:baseModel <#data_and_ontology_graph> ]; . <#data_and_ontology_graph> a tdb:GraphTDB ; tdb:location "/work/data/blogger-db-dir" ; . * Another example of a modified Joseki configuration file is [http://tw.rpi.edu/proj/portal.wiki/images/1/1d/Joseki-config-tdb.ttl here] 5.4 We just asked Joseki to load <code>org.mindswap.pellet.jena.PelletReasonerFactory</code>, so we need to make sure Joseki has it in its classpath when it runs. Add the following lines to <code>$JOSEKIROOT/bin/make_classpath</code>: <pre> PELLETLIBDIR="/opt/pellet/lib" <-- under LIBDIR="$DIRROOT/lib" on line 18 ... # Prepend any jars in the pellet lib directory <-- under "# Append any jars in the lib/ directory" section on line 39/40 for jar in "$PELLETLIBDIR"/*.jar do # Check for no expansion [ -e "$jar" ] || break #echo "Path: $jar" [ "$CP" != "" ] && CP="${CP}${SEP}" CP="${CP}$jar" done </pre> Reason to do this is that every time you run the rdfserver script of joseki, the classpath is dynamically generated, by invoking the make_classpath script. So, we need to put the lib directory of pellet into the classpath so that joseki can find necessary jars. * A less desirable alternative is to copy $PELLETROOT/lib/*.jar into $JOSEKIROOT/lib directory. 5.5 Run Joseki, just like in Section 2.6, but with an additional argument for a non-default configuration file: cd $JOSEKIROOT bin/rdfserver joseki-config-bloggers-tdb'''-pellet'''.ttl 5.6 Load http://localhost:2020/sparql.html to query inferences from <code>/work/data/bloggers-db-dir</code>. prefix sioc: <http://rdfs.org/sioc/ns#> select ?created ?creator where { ?created sioc:has_creator ?creator . } 5.7 No results?! That's because bloggers.rdf does not have any ontology elements. Try adding %cat bloggers-ontology.ttl @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix foaf: <http://xmlns.com/foaf/0.1/> . @prefix sioc: <http://rdfs.org/sioc/ns#> . foaf:maker rdfs:subPropertyOf sioc:has_creator . with tdbloader --loc=/work/data/bloggers-db-dir bloggers-ontology.ttl == 5. Configure Joseki to query inferences from data in a TDB directory, with ontologies in separate files == * Or here if you don't want to use TDB as the triple store, instead you just want to use some rdf/owl files, you can change it to: <pre> <#baseGraph> a ja:MemoryModel ; ja:content [ ja:externalContent <file:data/tbox.owl> ; ja:externalContent <file:data/abox.owl> ] . </pre> == Misc == === No TDB Base URI parameter === When loading RDF files with relative URIs , it is desirable for triple stores to take in a base URI as a parameter during load time. All relative URIs would be resolved with respect to this base URI. According to the authors (Jan 2011), TDB does not accept a parameter for the base URI. The current solution is to include the xml:base="" attribute on the rdf:RDF element; otherwise, it will use the file location. If you do not want the file location, you can use [http://librdf.org/raptor/INSTALL.html rapper] to add the xml:base attribute: for owl in *.owl; do rapper -g -o rdfxml -I http://escience.rpi.edu/2010/mlso/PML/$owl $owl > load-me/$owl; done
Summary:
This is a minor edit Watch this page
Cancel