Opis Zagadnienia
SemWeb_SPARQL
* research on SPARQL,
* provide a presentation,
* look for language support
* other tools
* look for/build Prolog API, e.g. SeRQL
Spotkania
20090326
PROJECT
What is SPARQL
Resource Description Framework (RDF) sets a standard for describing metadata in a way that computers can understand and process it, and integrate information from disparate information sources on the Web. RDF has needed a standard query language for some time and having one will make many development tasks much easier. Or how would you feel using relational databases without SQL?
SPARQL (‘sparkle’) is a standardized query language for RDF data. It offers developers of Semantic Web applications a way to write queries across this wide range of information. Used with a common protocol, applications can access and combine information from multiple sources on the Web. For example, SPARQL can be used to write Semantic Web applications in areas like financial markets, tourism, transportation, and pharmaceuticals.
SPARQL, which is both a query language and a data access protocol, has the ability to become a key component in Web 2.0 applications: as a standard backed by a flexible data model, it can provide a common query mechanism for all Web 2.0 applications – just what Web 2.0 needs. As SPARQL emerges, we can expect to see a fast growing number of application developers
Introduction
RDF – flexible and extensible way to represent information about WWW resources
SPARQL - query language for getting information from RDF graphs. It provides facilities to:
extract information in the form of URIs, blank nodes, plain and typed literals.
extract RDF subgraphs.
construct new RDF graphs based on information in the queried graphs
matching graph patterns
variables – global scope; indicated by ‘?‘ or ‘$‘
query terms – based on Turtle syntax
terms delimited by „<>” are relative
URI references
data description format - Turtle
Graph Patterns
Basic Graph Pattern – set of Triple Patterns
Group Pattern - a set of graph patterns must all match
Value Constraints - restrict RDF terms in a solution
Optional Graph Patterns .- additional patterns may extend the solution
Alternative Graph Pattern – two or more possible patterns are tried
Patterns on Named Graphs - patterns are matched against named graphs
Basic Graph Pattern
SELECT ?x ?v WHERE { ?x ?x ?v }
rdf:type rdf:type rdf:Property
Basic Graph Pattern - Multiple Matches
Data:
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Johnny Lee Outlaw" .
_:a foaf:mbox <mailto:jlow@example.com> .
_:b foaf:name "Peter Goodguy" .
_:b foaf:mbox <mailto:peter@example.org> .
_:c foaf:mbox <mailto:carol@example.org> .
Query:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox
WHERE
{ ?x foaf:name ?name .
?x foaf:mbox ?mbox }
Query Result:
name | mbox |
„Johnny Lee Outlaw” | <mailto:jlow@example.com> |
„Peter Goodguy” | <mailto:peter@example.org> |
Basic Graph Pattern - Blank Nodes
Data:
@prefix foaf: <http://xmlns.com/foaf/0.1/> .\\
_:a foaf:name "Alice" .\\
_:b foaf:name "Bob" .\\
Query:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>\\
SELECT ?x ?name\\
WHERE { ?x foaf:name ?name }\\
x | name |
_:c | „Alice” |
_:d | „Bob” |
Group Pattern
In a SPARQL query string, a group graph pattern is delimited with braces: {}. For example, this query's query pattern is a group graph pattern of one basic graph pattern.
PREFIX foaf: <http://xmlns.com/foaf/0.1/> \\
SELECT ?name ?mbox\\
WHERE {
?x foaf:name ?name .
?x foaf:mbox ?mbox .
}
The same solutions would be obtained from a query that grouped the triple patterns into two basic graph patterns. For example, the query below has a different structure but would yield the same solutions as the previous query:
PREFIX foaf: <http://xmlns.com/foaf/0.1/> \\
SELECT ?name ?mbox \\
WHERE {
{ ?x foaf:name ?name . }
{ ?x foaf:mbox ?mbox . }
}
Value Constraints
Constraints can be given in an optional graph pattern. For example:
{
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix : <http://example.org/book/>
@prefix ns: <http://example.org/ns#> .
}
:book1 dc:title "SPARQL Tutorial" .
:book1 ns:price 42 .
:book2 dc:title "The Semantic Web" .
:book2 ns:price 23 .
Query:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX ns: <http://example.org/ns#>
SELECT ?title ?price
WHERE { ?x dc:title ?title .
OPTIONAL { ?x ns:price ?price . FILTER (?price < 30) }
}
Query results:
title | price |
„SPARQL Tutorial” |
„The Semantic Web” | 23 |
Optional graph patterns
{
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix : <http://example.org/book/>
@prefix ns: <http://example.org/ns#> .
}
:book1 dc:title "SPARQL Tutorial" .
:book1 ns:price 42 .
:book2 dc:title "The Semantic Web" .
:book2 ns:price 23 .
Query:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX ns: <http://example.org/ns#>
SELECT ?title ?price
WHERE { ?x dc:title ?title .
OPTIONAL { ?x ns:price ?price . FILTER (?price < 30) }
}
Query results:
title | price |
„SPARQL Tutorial” |
„The Semantic Web” | 23 |
Multiple Optional Blocks
Graph patterns are defined recursively. A graph pattern may have zero or more optional graph patterns, and any part of a query pattern may have an optional part. In this example, there are two optional graph patterns.
Data:
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Alice" .
_:a foaf:homepage <http://work.example.org/alice/> .
_:b foaf:name "Bob" .
_:b foaf:mbox <mailto:bob@work.example> .
Query:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?name ?mbox ?hpage
WHERE { ?x foaf:name ?name .
OPTIONAL { ?x foaf:mbox ?mbox } .
OPTIONAL { ?x foaf:homepage ?hpage }
}
Query result:
Alternative Graph Patterns
SPARQL provides a means of combining graph patterns so that one of several alternative graph patterns may match. If more than one of the alternatives matches, all the possible pattern solutions are found.
Pattern alternatives are syntactically specified with the UNION keyword.
Data:
@prefix dc10: <http://purl.org/dc/elements/1.0/> .
@prefix dc11: <http://purl.org/dc/elements/1.1/> .
_:a dc10:title "SPARQL Query Language Tutorial" .
_:a dc10:creator "Alice" .
_:b dc11:title "SPARQL Protocol Tutorial" .
_:b dc11:creator "Bob" .
_:c dc10:title "SPARQL" .
_:c dc11:title "SPARQL (updated)" .
Query:
PREFIX dc10: <http://purl.org/dc/elements/1.0/>
PREFIX dc11: <http://purl.org/dc/elements/1.1/>
SELECT ?title
WHERE { { ?book dc10:title ?title } UNION { ?book dc11:title ?title } }
Query result:
title |
„SPARQL Protocol Tutorial” |
„SPARQL” |
„SPARQL (updated)„ |
„SPARQL Query Language Tutorial” |
This will return results with the variable x bound for solutions from the left branch of the UNION, and y bound for the solutions from the right branch. If neither part of the UNION pattern matched, then the graph pattern would not match.
PREFIX dc10: <http://purl.org/dc/elements/1.0/>
PREFIX dc11: <http://purl.org/dc/elements/1.1/>
SELECT ?title ?author
WHERE { { ?book dc10:title ?title . ?book dc10:creator ?author }
UNION
{ ?book dc11:title ?title . ?book dc11:creator ?author }
}
author | title |
„Alice” | „SPARQL Protocol Tutorial” |
„Bob” | „SPARQL Query Language Tutorial” |
RDF Dataset
RDF Dataset- The Relationship between Named and Background Graphs (I)
# Background graph
@prefix dc: <http://purl.org/dc/elements/1.1/> .
<http://example.org/bob> dc:publisher "Bob" .
<http://example.org/alice> dc:publisher "Alice" .
# Graph: http://example.org/bob
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Bob" .
_:a foaf:mbox <mailto:bob@oldcorp.example.org> .
# Graph: http://example.org/alice
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:alice@work.example.org> .
RDF Dataset- The Relationship between Named and Background Graphs (II)
# Background graph
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:x foaf:name "Bob" .
_:x foaf:mbox <mailto:bob@oldcorp.example.org> .
_:y foaf:name "Alice" .
_:y foaf:mbox <mailto:alice@work.example.org> .
# Graph: http://example.org/bob
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Bob" .
_:a foaf:mbox <mailto:bob@oldcorp.example.org> .
# Graph: http://example.org/alice
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:alice@work.example.org> .
Querying the Dataset
The use of GRAPH changes the active graph for matching basic graph patterns within part of the query. Outside the use of GRAPH, the default graph is matched by basic graph patterns.
# Graph: http://example.org/foaf/aliceFoaf
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:alice@work.example> .
_:a foaf:knows _:b .
_:b rdfs:seeAlso <http://example.org/foaf/bobFoaf> .
<http://example.org/foaf/bobFoaf> rdf:type foaf:PersonalProfileDocument .
_:b foaf:name "Bob" .
_:b foaf:mbox <mailto:bob@work.example> .
_:b foaf:age 32 .
# Graph: http://example.org/foaf/bobFoaf
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
_:1 foaf:mbox <mailto:bob@work.example> .
_:1 rdfs:seeAlso <http://example.org/foaf/bobFoaf> .
_:1 foaf:age 35 .
<http://example.org/foaf/bobFoaf> rdf:type foaf:PersonalProfileDocument .
Querying the Dataset - Accessing Graph Labels
Query:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?src ?bobAge
WHERE { GRAPH ?src
{
?x foaf:mbox <mailto:bob@work.example> .
?x foaf:age ?bobAge }
}
Query results:
Querying the Dataset - Restricting by Graph Label
Query:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX data: <http://example.org/foaf/>
SELECT ?age
WHERE
{
GRAPH data:bobFoaf
{
?x foaf:mbox <mailto:bob@work.example> .
?x foaf:age ?age }
}
Query results:
Querying the Dataset - Restricting via Query Pattern
Query:
PREFIX data: <http://example.org/foaf/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?mbox ?age ?ppd
WHERE
{ GRAPH data:aliceFoaf
{ ?alice foaf:mbox <mailto:alice@work.example> ;
foaf:knows ?whom .
?whom foaf:mbox ?mbox ;
rdfs:seeAlso ?ppd .
?ppd a foaf:PersonalProfileDocument . } .
GRAPH ?ppd
{
?w foaf:mbox ?mbox ;
foaf:age ?age
}
}
Query results:
Query Execution and Ordering
SELECT
CONSTRUCT
DESCRIBE
ASK
CONSTRUCT Examples(I)
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:alice@example.org> .
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>
CONSTRUCT { <http://example.org/person#Alice> vcard:FN ?name }
WHERE { ?x foaf:name ?name }
@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>.
<http://example.org/person#Alice> vcard:FN "Alice" .
extracting a whole graph from the target RDF dataset
CONSTRUCT { ?s ?p ?o }
WHERE { GRAPH <http://example.org/myGraph> { ?s ?p ?o } . }
CONSTRUCT Examples(II)
accesing a graph conditional on other information contained in the metadata about named graphs in the dataset
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX app: <http://example.org/ns#>
CONSTRUCT { ?s ?p ?o }
WHERE { GRAPH ?g { ?s ?p ?o } .
{ ?g dc:publisher <http://www.w3.org/> } .
{ ?g dc:date ?date } .
FILTER app:myDate(?date) > "2005-02-8T00:00:00Z"^^xsd:dateTime. }
DESCRIBE
PREFIX ent: <http://myorg.example/employees#> DESCRIBE ?x
WHERE { ?x ent:employeeId "1234" }
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0> .
@prefix myOrg: <http://myorg.example/employees#> .
_:a myOrg:employeeId "1234" ;
foaf:mbox_sha1sum "ABCD1234" ;
vcard:N [ vcard:Family "Smith" ;
vcard:Given "John" ] .
foaf:mbox_sha1sum rdf:type owl:InverseFunctionalProperty .
ASK
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
_:a foaf:name "Alice" .
_:a foaf:homepage <http://work.example.org/alice/> .
_:b foaf:name "Bob" .
_:b foaf:mbox <mailto:bob@work.example> .
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
ASK { ?x foaf:name "Alice" } .
Testing Values
Named functions and syntactically constructed operations:
operands: subset of XML Schema DataTypes {xsd:string, xsd:decimal, xsd:double, xsd:dateTime} and types derived from xsd:decimal.
Subset of XPath functions and operators
Operands: xs:string, xs:double, xs:float, xs:decimal, xs:integer, xs:dateTime
additional operators: sop:RDFterm-equal, sop:bound , sop:isURI, sop:isBlank, sop:isLiteral, sop:str , sop:lang, sop:datatype, sop:logical-or, sop:logical-and
Type Promotion : xs:double, xs:float, xs:decimal
Support for SPARQL
Twinkle: A SPARQL Query Tool
Twinkle is a simple GUI interface that wraps the ARQ SPARQL query engine. The tool should be useful both for people wanting to learn the SPARQL query language, as well as those doing Semantic Web development.
Twinkle was originally inspired by Elliotte Harold's XQuisitor which provides a simple GUI interface for playing with XQuery.
Features:
Load, edit and save SPARQL queries
Insert PREFIX statements into queries
Configure custom namespaces so they can be quickly inserted into queries
Cancel long running queries
Save results to file
Query local files and remote RDF documents
Query RDF data held in relational databases
Query online SPARQL endpoints, such as DBpedia, reyvu.com and GovTrack.
Query using standard SPARQL, or the ARQ extended syntax which supports COUNT, etc.
Use ARQ extension functions and property functions
Apply inferencing (e.g. Jena rules, RDF Schema, OWL ontology) when running queries
Configure commonly used data sources for quick access
http://www.ldodds.com/projects/twinkle/twinkle-2.0-src.zip
Redland RDF Libraries
Redland is a set of free software C libraries that provide support for the Resource Description Framework (RDF).
Modular, object based libraries and APIs for manipulating the RDF graph, triples, URIs and Literals.
Storage for graphs in memory and persistently with Sleepycat/Berkeley DB, MySQL 3-5, PostgreSQL, AKT Triplestore, SQLite, files or URIs.
Support for multiple syntaxes for reading and writing RDF as RDF/XML, N-Triples and Turtle Terse RDF Triple Language, RSS and Atom syntaxes via the Raptor RDF Parser Library.
Querying with SPARQL and RDQL using the Rasqal RDF Query Library.
Data aggregation and recording provenance support with Redland contexts.
Language Bindings in Perl, PHP, Python and Ruby via the Redland Bindings package.
Command line utility programs rdfproc (RDF), rapper (parsing) and roqet (query).
Portable, fast and with no known memory leaks.
The Redland library packages are:
1.4.20 release raptor-1.4.20.tar.gz (2009-11-28)
0.9.17 release rasqal-0.9.17.tar.gz (2009-12-16)
Redland RDF Library - librdf providing the RDF
API and triple stores. Requires: Raptor and Rasqal
1.0.10 release redland-1.0.10.tar.gz (2009-12-16)
1.0.10.1 release redland-bindings-1.0.10.1.tar.gz (2009-12-16)
These are mature RDF packages developed since 2000 used in several projects. Each library has its own documentation and status information in the form of a list of TODOs/bugs, general news, detailed release notes and file-by-file changes in the ChangeLog.
License
All Redland packages are free software / open source software and released under the LGPL 2.1, GPL 2 or Apache 2 licenses as alternatives. See the individual package license files for full details and any exceptions.
http://download.librdf.org/
ARQ
ARQ is a query engine for Jena that supports the SPARQL RDF Query language. SPARQL is the query language developed by the W3C RDF Data Access Working Group.
ARQ Features:
Standard SPARQL
Free text search via Lucene
SPARQL/Update
Access and extension of the SPARQL algebra
Support for custom filter functions
Property functions for custom processing of semantic relationships
Aggregation, GROUP BY and assignment as SPARQL extensions
Support for federated query
Support for extension to other storage systems
Client-support for remote access to any SPARQL endpoint
Jena storage engines that plug into ARQ include:
http://sourceforge.net/projects/jena/files/ARQ/
SWI-Prolog semantic Web serwer with sparql/serql
Introduction
The SWI-Prolog Semantic Web Server unifies the SWI-Prolog general Web support and Semantic Web support, providing both a starting point for dedicated applications and a platform for exchange of RDF-based data using a standardised language and protocol. An overview of the SWI-Prolog Web support libraries can be found in SWI-Prolog and the Web,1Submitted to Theory and Practice of Logic Programming
Query Languages
The current server supports two query languages: SeRQL and SPARQL. For both languages we provide an interactive service that presents the results as a human-readable HTML table, a service presenting its result as RDF/XML or XML that follows the HTTP protocol definition for the query language, the possibility to query the local database using a query language in Prolog and a Prolog client that can be used to query remote services supporting the query language and HTTP service.
For both query languages, queries are translated to a complex Prolog goal calling rdf/3 to resolve edges in the graph and calls to predicates from rdfql_runtime.pl that realise constraints imposed by the SeRQL WHERE clause and SPARQL FILTER clauses.
SPARQL Support
SPARQL support is based on the SPARQL specification, versioned April 6, 2006. Status:
No query optimization
Limited value-testing, notably on xsd:dateTime
Incomplete ORDER BY support. Only ascending and all values are compared lexically.
No support for named graphs
Passes current test-suite, except tests affected by the above or acknowledged as errornous.
SeRQL Support
SeRQL support and compatibility is based on development version 20040820, with additional support for the new 1.2 syntax and some of the built-in functions. Both SeRQL and the HTTP API are fully defined in the Sesame documentation.
Installation and Administration
Getting started
The file parms.pl contains a number of settings relevant to the server. Notable the port to connect to, where to store user information, etc. Persistent data kept by the server is a list of users and their access rights (default users.db) and a file-based backup of the in-memory store (default in the directory SeRQL-store). Please check the content of parms.pl and follow directions in the comments. On Unix-like systems, edit run.pl to adjust the location of SWI-Prolog on the !# line. Next, start run.pl and launch the server using the command below.
?- serql_server.
Now direct your browser to the server, using the default setup this is http://localhost:3020. If no users are defined the browser will prompt to enter the administrative password. After that the admin and anonymous users are created. Accounts can be created and modified by users with administrative rights through the List users … link on the sidebar.
To restart from scratch, stop the server, delete the users database file and/or the triple backup file and restart the server as described above.
Persistent store
The parms.pl setting persistent_store(Directory, Options) can be used to specify file-based persistent backup for the in-memory triple store. The store is a combination of quick-load triple databases and journal files that hold the modifications made to the triple store. Details of the persistent store are documented with the SWI-Prolog Semantic Web package
Roadmap
Query processing and entailment
The kernel of the system is formed by serql.pl and sparql, that implement the DCG parsers for the respective query languages as well as a compiler that translates this into a Prolog goal executing the query op top of the SWI-Prolog SemWeb package. The file rdfql_runtime.pl contains predicates that implement the constraints (SeRQL WHERE or SPARQL FILTER) and other constructs generated by the query-compiler.
Entailment reasoning is defined by rdf_entailment.pl. Specific entailments are in seperate files:
no_entailment.pl
Defines entailment none. Query explicitely stored triples only.
rdf_entailment.pl
Defines entailment rdf. Any resource appearing in a predicate position is of type rdf:Property. Any subject is an instance of rdf:Resource
rdfs_entailment.pl
Defines entailment rdfs. Adds class- and property-hierarchy reasoning to RDF reasoning, as well as reasoning on the basis of property domain and range.
rdfslite_entailment.pl
Defines entailment rdfslite. Only considers the class- and property-hierarchy. Using a backward chaining solver this is much faster, while normally keeping the intended meaning.
The query compiler and execution system can be called directly from Prolog.
serql_compile(+Query, -Compiled, +Options)
Compile Query, which is either an atom or a list of character codes and unify Compiled with an opaque term representing the query and suitable for passing to serql_run/2. Defined Options are:
entailment(Entailment)
Entailment to use. Default is rdfs. See section 4.1.
type(-Type)
Extract the type of query compiled and generally useful information on it. SeRQL defines the types construct and select(VarNames), where VarNames is a list of variables appearing in the projection.
optimise(Bool)
Whether or not to optimise the query. Default is defined by the setting optimise_query.
sparql_compile(+Query, -Compiled, +Options)
Similar to to serql_compile/3. Defined types are extended with describe and ask. Addional options are:
base_uri(-URI)
Base URI used to compile the query if not specified as part of the query.
ordered(-Bool)
Unify Bool with true if query contains an ORDER BY clause.
distinct(-Bool)
Unify Bool with true if query contains a DISTINCT modifier.
serql_run(+Compiled, -Answer)
Run a query compiled by serql_compile/3, returning terms row(Arg …) for select queries and terms rdf(Subject, Predicate, Object) for construct queries. Subsequent results are returned on backtracking.
sparql_run(+Compiled, -Answer)
Similar to serql_run/2. Queries of type describe return rdf-terms like construct. Queries of type ask return either true or false.
serql_query(+Query, -Answer, +Options)
Utility combining of serql_compile/3 and serql_run/2. Note this gives no access to the column-names.
sparql_query(+Query, -Answer, +Options)
Similar to serql_query/3.
Query optimisation
By default, but under control of the setting/1 option optimise_query(Bool), and the option optimise(Bool), the query compiler optimises initial goal obtained from naive translation of the query text. The optimiser is defined in rdf_optimise.pl. The optimiser is described in detail in An optimised Semantic Web query language implementation in Prolog. The optimiser reorders goals in the generated conjunction and prepares for independent execution of independent parts of the generated goal. With the optimiser enabled (default), the provided order of path-expressions on the query text is completely ignored and constraints are inserted at the earliest possible point.
The SeRQL LIKE operator applies to both resources and literals, while the SWI-Prolog RDF-DB module can only handle LIKE efficiently on literals. The optimiser can be made aware of this using WHERE label(X) LIKE „joe*”. Taking the label informs the optimiser that it only needs to consider literals. Likewise, equivalence tests where one of the arguments is used as subject or predicate or has the isResource(X) constraint tell the system it can do straight identifier comparison rather then the much more expensive general comparison.
Query optimisation is not yet supported for SPARQL.
Webserver
The webserver is realised by server.pl, merely loading both components: http_data.pl providing the Sesame HTTP API using the same paths and parameters and http_user.pl providing a browser-friendly frontend. Error messages are still very crude and almost all errors return a 500 server error page with a transcription of the Prolog exception.
The Sesame HTTP API deals with a large number of data formats, only part of which are realised by the current system. This realisation is achieved through rdf_result, providing an extensible API for reading and writing in different formats. rdf_html, rdf_write and xml_result provide some implementations thereof.
The Sesame client
The file sesame_client.pl, created by Maarten Menken provides an API to remote Sesame servers. Below is a brief documentation of the available primitives. All predicates take an option list. To simplify applications that communicate with a single server defauls for the server and reposititory locations can be specified using set_sesame_default/1.
set_sesame_default(+DefaultOrList)
This predicate can be used to specify defaults for the options available to the other Sesame interface predicates. A default is a term Option(Value). If a list of such options is provided all options are set in the order of appearance in the list. This implies options later in the list may overrule already set options. Defined options are:
host(Host)
Hostname running the Sesame server.
port(Port)
Por the sesame server listens on.
path(Path)
Path from the root to the Sesame server. For the SWI-Prolog Sesame client, this is normally the empty atom (''). For thte Java based Sesame this is normally '/sesame'.
repository(Repository)
Name of the repository to connect to. See also sesame_current_repository/3.
Below is a typical call to connect to a sesame server:
...,
set_sesame_default([ host(localhost),
port(8080),
path('/sesame'),
repository('mem-rdfs-db')
]).
sesame_current_repository(-Id, -Properties, +Options)
Enumerate the currently available Sesame repositories. Id is unified to the name of the repository. Properties is a list of Name(Value) terms providing title and access details. Options specifies the host, port and path of the server.
sesame_clear_repository(+Options)
Remove all content from the repository. Options specifies the host, port and path of the server as well as the target repository.
sesame_login(+User, +Password, +Options)
Login to a Sesame server. On success the returned cookie is stored and transmitted with each query on the same server. Options specifies the host, port and path of the server.
sesame_logout(+Options)
Options specifies the host, port and path of the server.
sesame_graph_query(+Query, -Triple, +Options)
Execute Query on the given server and return the resulting triples on backtracking. Options specifies the host, port and path of the server as well as the target repository. The example below extracts all type relations from the default server.
...,
sesame_graph_query('construct * from {s} <rdf:type> {o}',
rdf(S,P,O),
[]),
sesame_table_query(+Query, -Row, +Options)
Execute Query on the given server and return the resulting rows on backtracking. Each Row is a term of the format row(Col1, Col2, … ColN). Options specifies the host, port and path of the server as well as the target repository.
sesame_extract_rdf(-Triple, +Options)
Extract all content from an RDF repository. In addition to the server and repository options the following options are defined:
schema(OnOff)
Extract the schema information.
data(OnOff)
Extract the plain data
explicit_only(OnOff)
Determine whether or not entailed triples are returned. Default is off, returning both explicit and inferred triples.
sesame_upload_file(+File, +Options)
dd the content of File to the repository. In addition to the server and repository options the following options are defined:
data_format(+Format)
Format of the input file. Default is rdfxml.
base_uri(+BaseURI)
URI for resolving local names. Default is foo:bar.
verify_data(OnOff)
Do/do not verify the input. Default is off.
sesame_assert(+TripleOrList, +Options)
Assert a single rdf(Subject, Predicate, Object) or a list of such terms. In addition to the server and repository options the following options are defined:
base_uri(+BaseURI)
URI for resolving local names. Default is foo:bar.
sesame_retract(+Triple, +Options)
Remove a triple from the repository. Variables in Triple match all values for that field.
Prezentacja
Interesting documentation about SWI-Prolog and SPARQL
Important links