DanNet can queried in a variety of ways. This plurality is intentional as explained in the rationale. The directly supported query methods include:

Furthermore, by importing DanNet into another RDF-supporting database, the query language of this database may also be used to query DanNet, e.g. Neo4j's Cypher query language.

Note: when querying Apache Jena's persisted TDB rather than an in-memory graph, you will need to wrap the querying code inside transactions. The dk.cst.dannet.db.query namespace contains functionality to help with this aspect of using Apache Jena. Transactions are always required for TDB 2, while they are only required for TDB 1 if at least one transaction has already occurred!


SPARQL is the official query language for querying RDF graphs. It is superficially similar to SQL, although queries take the form of dynamically joined sets of triples rather than the explicit table joins found in SQL.

SPARQL Algebra

SPARQL queries are compiled to an algebraic form before being run. This is similar to how SQL queries are also compiled to some form of relational algebra.

Although the algebraic form is mapped directly to Java classes in Apache Jena, this algebraic representation is usually illustrated using s-expressions - i.e. Lisp syntax - in the various documents on it. This makes it a suitable target for a DSL in a Lisp such as Clojure.

Important terms

  • bgp - i.e. Basic Graph Pattern, an expression enclosing a set of triples.

Aristotle queries

While Aristotle accepts regular SPARQL queries, its primary query language is based on Jena's SPARQL Algebra and superficially resembles Datomic-style Datalog.

Changes compared to SPARQL Algebra

  • Square brackets - i.e. Clojure vectors - are used rather than parentheses.
  • Triples are inferred from vectors, e.g. [?s ?p ?o] is equivalent to (triple ?s ?p ?o) in the SPARQL Algebra.

Relevant namespaces

The query language of Aristotle isn't well-specified, but its close relationship to the SPARQL Algebra can be gauged from the following namespaces:

  • arachne.aristotle.query.compiler
  • arachne.aristotle.query.spec

Graph traversal

Since RDF triples constitute a directed graph, this graph can be queried programmatically using graph traversal algorithms.

One way to do this is by invoking the igraph Clojure library which has Apache Jena integration.

Note that currently some functions available in igraph don't work well with models that perform triple inferencing, e.g. OWL-enabled graphs. They are too slow (in the realm of several minutes) for any production application to use them.