Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
\section{Endpoints}
With ULO/RDF triplets imported into a database, in our case GraphDB,
we have all data available for querying. There are multiple approaches
to querying such triplet stores.
\subsection{SPARQL}
SPARQL~\cite{sparql} is a standardized query language for RDF triplet
data. The spec includes not just syntax and semantics of the language
itself, but also a standardized REST interface for querying databases.
Various implementations of this standard, e.g.~\cite{gosparql}, are
available so using SPARQL has the advantage of making us independent
of a specific programming language or environment.
SPARQL is inspired by SQL, a simple query that returns all triplets
in the store looks like
\begin{verbatim}
SELECT * WHERE { ?s ?p ?o }
\end{verbatim}
where \texttt{s}, \texttt{p} and \texttt{o} are query variables. The
result of a query are valid substitutions for the query variables. In
this case, the database would return a table of all triplets in the
store sorted by subject~\texttt{o}, predicate~\texttt{p} and
object~\texttt{o}.
Of course, queries might return a lot of data. Importing just the
Isabelle exports~\cite{uloisabelle} into GraphDB results in more than
200M triplets. This is solved with pagination
techniques~\cite{sparqlpagination}.
\subsection{RDF4J}
RDF4J~\cite{rdf4j} is a Java API for interacting with triplet stores,
implemented based on a superset of SPARQL. GraphDB supports RDF4J, in
fact it is the recommended way of interacting with GraphDB
repositories [6].
Instead of formulating textual queries, RDF4J allows developers to
query a repository by calling Java API methods. Above query that
returns all triplets in the store looks like
\begin{verbatim}
connection.getStatements(null, null, null);
\end{verbatim}
in RDF4J. Method \texttt{getStatements(s, p, o)} returns all triplets
that have matching subject~\texttt{s}, predicate~\texttt{p} and
object~\texttt{o}. If any of these arguments is \texttt{null}, it can
be any value, i.e.\ it is a query variable that is to be filled by the
call to \texttt{getStatements}.