There are several ways to extend ARQ:
Any system that implements the Jena Graph API or Jena Model API can be queried.
SPARQL allows custom functions in filter expressions so that queries can be used on domain-specific data. SPARQL defines a function by URI (or qname) in FILTER expressions. ARQ provides a function library and supports application-provided functions. There is a mechanism for dynamically loading.
Function name | Description |
---|---|
jfn:langeq(literal, lang) |
Compare the language tag of the literal with a language tag. Comparison reflects language tag rules so "foo"@en matches "EN-gb". |
jfn:now() |
Current time. Actually, the fixed time the query started. |
jfn:bnode(?x) |
Return the blank node label if ?x is a blank node. |
jfn:min(num1, num2) |
Return the minimum of two expressions evaluating to numbers. |
jfn:max(v1, v2) |
Return the maximum of two expressions evaluating to numbers. |
jfn:round(v) |
Return the nearest integer value to the argument. |
jfn:abs(v) |
Return the absolute value. |
jfn:floor(v) |
Return the greatest integer value less than the argument (as a double). |
jfn:ceiling(v) |
Return the smallest integer value than the argument (as a double). |
More functions will be added. Contributions welcome.
Writing a SPARQL custom function is implementation dependent and requires some understanding of the ARQ query engine being used. ARQ has a basic, general purpose query engine but it is possible to add new engines, or override functionality in the basic query engine. See ARQ Query Engine Design.
@@add details - see javadoc for now.
URIs for functions in the (fake) URI scheme java:
are
dynamically loaded. The class name forms the scheme specific part of the URI.
The ARQ function library uses this mechanism. The namespace of the ARQ function library
is <java:com.hp.hpl.jena.query.function.library.>
(note the trailing dot).
PREFIX jfn: <java:com.hp.hpl.jena.query.function.library.> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> SELECT ?v { ?x rdfs:label ?v . FILTER jfn:langeq(?v, "en" ) }
ARQ also provides the ability to write custom extensions. This not part of SPARQL; the application will need to use the ARQ query language (a superset of SPARQL). Unlike a value function, an extension can set variables and generate multiple solutions. An extensions can also query the dataset.
EXT q:name(?a, ?b, ?c)
Writing a an extension requires understanding of the ARQ query engine. See ARQ Query Engine Design.
@@ to be written. Extension is loaded like functions. Likely to change.
The DESCRIBE
result form in SPARQL does not define an exact form
of RDF to return. Instead, it allows the server or query processor to
return what it considers to be an appropriate description of the resources
located. This description will be specific to the domain, data modelling or
application.
ARQ comes with one built-in handler which calculates the blank node closure
of resources found. While suitable for many situations, it is not general (for
example, a FOAF file usually consists
of all blank nodes). ARQ allows the application to replace or add handlers for
producing DESCRIBE
result forms.
Application-specific handlers can be added to the
DescribeHandlerRegistry
. The handler will be called for each resource
(not literals) identified by the DESCRIBE
query.
URIs from with scheme name "_" (which is illegal) are created as blank node labels for directly accessing a blank node in the queried graph or dataset. This are constant terms in the query - not unnamed variables. Do not confuse these with the standard qname notation for blank nodes in queries. This is not portable - use with case.
<_:1234-5678-90> # A blank node in the data
_:b0 # A blank node in the query - a variable