The scope of this specification is to provide a way to query over quads, as defined in the RDF/JS: Data model specification. Similar to the RDF/JS: Data model specification, this is a low-level specification that provides only essential methods for working across query engine component. High-level querying interfaces can and should be using libraries that implement this interface.
The specification itself consists of a core-part that is the base for all other functions defined.
Low-level methods are using explicit parameters that cannot be omitted.
Additional high-level interfaces are outside of the scope of this specification and should be defined elsewhere.
This document provides a specification of an interface for RDF query engines in a JavaScript environment. The task force which defines this interface was formed by RDF JavaScript library developers with the wish to make existing and future libraries interoperable. This definition strives to provide the minimal necessary interface to enable interoperability of RDF querying libraries.
Currently, this specification only provides interfaces that enable filtering quads based on expressions. Additional interfaces for more general querying support will be defined in the future.
interface FilterableSource { FilterResult matchExpression ( optional Term? subject, optional Term? predicate, optional Term? obj, optional Term? graph, optional Expression? expression ); };
A FilterableSource
is an object that produces a FilterableSourceResult
that can emit quads.
The emitted quads can be directly contained in this FilterableSource
object, or they can be generated on the fly.
FilterableSource
is not necessarily an extension of the RDF/JS Source interface, but implementers MAY decide to implement both at the same time.
matchExpression() Returns a FilterableSourceResult
that contains a quad stream that processes all quads matching the quad pattern and the expression.
When a Term
parameter is defined, and is a NamedNode
, Literal
or BlankNode
,
it must match each produced quad, according to the Quad.equals
semantics.
When a Term
parameter is a Variable
,
or it is undefined, it acts as a wildcard, and can match with any Term
.
When matching with graph
set to undefined
or null
it MUST match all the graphs (sometimes called the union graph). To match only the default graph
set graph
to a DefaultGraph
When an Expression
parameter is defined, the complete quad stream is filtered according to this expression.
When it is undefined, no filter is applied.
If parameters of type Variable
with an equal variable name are in place,
then the corresponding quad components in the resulting quad stream MUST be equal.
Expression
's MAY contain Variable
Term
's.
If their variable names are equal to Variable
's in the given quad pattern,
then the Expression
MUST be instantiated for each variable's binding in the resulting quad stream when applying the Expression
filter.
interface FilterResult { Stream quads(); Promise<QueryResultMetadata> metadata(optional QueryResultMetadataOptions? options); Promise<boolean> isSupported(); };
A FilterResult
is an object that represents the result of a filter expression of FilterableSource
for a given quad pattern and expression.
It MAY create results lazily after one of its methods is invoked.
quads() Returns a Stream
containing all the quads that matched the given quad pattern and expression.
metadata() Asynchronously returns a QueryResultMetadata
, that contains the metadata of the current result.
isSupported() Asynchronously returns a boolean indicating if the requested expression is supported by the FilterableSource
.
If it returns true
, quads()
and metadata()
MAY produce a valid result.
If it returns false
, quads()
MUST return a stream emitting an error, and metadata()
MUST reject.
interface QueryResultMetadata { attribute QueryResultMetadataCount? count; };
A QueryResultMetadata
is an object that represents contains metadata bout a certain query result,
such as invoking FilterableSource.matchExpression
.
count is an optional field that contains metadata about the number of quads in the result stream.
interface QueryResultMetadataCount { attribute string type; attribute number value; };
QueryResultMetadataCount
is part of the QueryResultMetadata
interface
to represent metadata about the number of quads in the result stream.
type indicates the type of counting that was done, and MUST either be "estimate"
or "exact"
.
value indicates an estimate of the number of quads in the stream if type = "estimate"
,
or the exact number of quads in the stream if type = "exact"
.
interface QueryResultMetadataOptions { attribute string? count; };
A QueryResultMetadataOptions
is an object that gives suggestions on what type of metadata is desired,
such as when invoking FilterResult.metadata
.
count is an optional field that MAY either contain "estimate"
or "exact"
.
If defined, this type MUST correspond to the type in QueryResultMetadataCount
.
interface Expression { attribute string expressionType; };
QueryResultMetadataOptions
is an abstract interface that represents a generic expression over a stream of quads.
expressionType contains a value that identifies the concrete interface of the expression, since the Expression itself is not directly instantiated.
Possible values include "operator"
and "term"
.
interface OperatorExpression { attribute string expressionType; attribute string operator; attribute FrozenArray<Expression> args; };
An OperatorExpression
is represents an expression that applies a given operator on given sub-expressions.
expressionType contains the constant "operator"
.
operator contains a value that identifies an operator. Possible values can be found in the list of operators.
args contains an array of Expression
's on to which the given operator applies.
The length of this array depends on the operator.
interface TermExpression { attribute string expressionType; attribute Term term; };
A TermExpression
is an expression that contains a Term
.
expressionType contains the constant "term"
.
term contains a Term
.
interface ExpressionFactory { OperatorExpression operatorExpression(string operator, sequence<Expression> args); TermExpression termExpression(Term term); };
ExpressionFactory
enables expressions to be created in an idiomatic manner.
operatorExpression creates a new OperatorExpression
instance for the given operator and array of arguments.
termExpression creates a new TermExpression
instance for the given term.
This section introduces a non-exhaustive list of operators that MAY be used in OperatorExpression
.
Implementers MAY decide to support only a subset of these operators.
We omit any formal semantics behind these operators in this specification, and refer to their SPARQL 1.1. semantics.
Name | Input | Output | Description |
---|---|---|---|
! |
|
Literal (xsd:boolean) |
The inverse of the given boolean value. |
uplus |
|
Literal (numeric) |
The positive value of the given numeric value. |
uminus |
|
Literal (numeric) |
The negative value of the given numeric value. |
* |
|
Literal (numeric) |
The multiplication of the given values. |
/ |
|
Literal (numeric) |
The division of the given values. |
+ |
|
Literal (numeric) |
The addition of the given values. |
- |
|
Literal (numeric) |
The subtraction of the given values. |
= |
|
Literal (xsd:boolean) |
If the given values are equal. If the terms are Literal s, their lexical value is compared |
!= |
|
Literal (xsd:boolean) |
If the given values are not equal. If the terms are Literal s, their lexical value is compared |
< |
|
Literal (xsd:boolean) |
If the first value is lesser than the second value. If the terms are Literal s, their lexical value is compared |
> |
|
Literal (xsd:boolean) |
If the first value is greater than the second value. If the terms are Literal s, their lexical value is compared |
≤ |
|
Literal (xsd:boolean) |
If the first value is lesser than or equal to the second value. If the terms are Literal s, their lexical value is compared |
≥ |
|
Literal (xsd:boolean) |
If the first value is greater than or equal to the second value. If the terms are Literal s, their lexical value is compared |
Name | Input | Output | Description |
---|---|---|---|
isiri |
|
Literal (xsd:boolean) |
Returns true if term is a NamedNode . Returns false otherwise. |
isblank |
|
Literal (xsd:boolean) |
Returns true if term is a BlankNode . Returns false otherwise. |
isliteral |
|
Literal (xsd:boolean) |
Returns true if term is a Literal . Returns false otherwise. |
isnumeric |
|
Literal (xsd:boolean) |
Returns true if term is a Literal with a numeric datatype. Returns false otherwise. |
str |
|
Literal (xsd:string) |
Returns the (lexical) string representation of the given term. |
lang |
|
Literal (xsd:string) |
Returns the language tag of the given Literal , or the empty string if the Literal has no language tag. |
datatype |
|
NamedNode |
Returns the datatype of the given Literal . |
iri |
|
NamedNode |
Resolve the given IRI against the base IRI of the current context. |
bnode |
|
BlankNode |
Create a new blank node with the given label if provided. |
strdt |
|
Literal |
Returns a new Literal with the given datatype. |
strlang |
|
Literal |
Returns a new Literal with the given language tag. |
uuid |
/ | NamedNode |
Returns a new NamedNode following the UUID URN scheme. |
struuid |
/ | Literal (xsd:string) |
Returns a new Literal following the UUID URN scheme. |
Name | Input | Output | Description |
---|---|---|---|
strlen |
|
Literal (xsd:integer) |
Returns the number of characters of the given string. |
substr |
|
Literal (xsd:string) |
Returns the substring of the given string starting from the given position (second parameter) with the given length (third parameter). If no third parameter is provided, then the maximum length is taken. |
ucase |
|
Literal (xsd:string) |
Transform each character in the given string to upper case. |
lcase |
|
Literal (xsd:string) |
Transform each character in the given string to lower case. |
strstarts |
|
Literal (xsd:boolean) |
Check if the given string starts with the given second string. |
strends |
|
Literal (xsd:boolean) |
Check if the given string ends with the given second string. |
strcontains |
|
Literal (xsd:boolean) |
Check if the given string contains the given second string. |
strbefore |
|
Literal (xsd:string) |
From the given first string, find the full string that occurs before the given second string. |
strafter |
|
Literal (xsd:string) |
From the given first string, find the full string that occurs after the given second string. |
encode_for_uri |
|
Literal (xsd:string) |
Apply URI encoding on the given string. |
concat |
|
Literal (xsd:string) |
Concatenation of all the given strings. |
langmatches |
|
Literal (xsd:boolean) |
If the language tag of the first literal matches the second string. |
regex |
|
Literal (xsd:boolean) |
Check if on the given first string, the given second regular expression matches. The third parameter indicates optional regex flags. |
replace |
|
Literal (xsd:boolean) |
In the given first string, match the given second regular expression, and replace it with the given third string. The fourth parameter indicates optional regex flags. |
Name | Input | Output | Description |
---|---|---|---|
abs |
|
Literal (numeric) |
Returns the absolute value of the given numerical term. |
round |
|
Literal (numeric) |
Returns the number with no fractional part that is closest to the argument, with preference for rounding up. |
ceil |
|
Literal (numeric) |
Returns the smallest (closest to negative infinity) number with no fractional part that is not less than the value of arg. |
floor |
|
Literal (numeric) |
Returns the largest (closest to positive infinity) number with no fractional part that is not greater than the value of arg. |
rand |
/ | Literal (xsd:double) |
Returns a pseudo-random, number between 0 (inclusive) and 1.0e0 (exclusive). Different numbers can be produced every time this function is invoked. Numbers should be produced with approximately equal probability. |
Name | Input | Output | Description |
---|---|---|---|
now |
/ | Literal (xsd:dateTime) |
Returns an XSD dateTime value for the current query execution. All calls to this function in any one query execution must return the same value. |
year |
|
Literal (xsd:integer) |
Returns the year of the given date. |
month |
|
Literal (xsd:integer) |
Returns the month of the given date. |
day |
|
Literal (xsd:integer) |
Returns the day of the given date. |
hours |
|
Literal (xsd:integer) |
Returns the hours of the given date. |
minutes |
|
Literal (xsd:integer) |
Returns the minutes of the given date. |
seconds |
|
Literal (xsd:integer) |
Returns the seconds of the given date. |
timezone |
|
Literal (xsd:dayTimeDuration) |
Returns the timezone part of the given date. |
tz |
|
Literal (xsd:string) |
Returns the timezone part of the given date. |
Name | Input | Output | Description |
---|---|---|---|
md5 |
|
Literal (xsd:string) |
Returns the MD5 checksum of the given string. |
sha1 |
|
Literal (xsd:string) |
Returns the SHA1 checksum of the given string. |
sha256 |
|
Literal (xsd:string) |
Returns the SHA256 checksum of the given string. |
sha384 |
|
Literal (xsd:string) |
Returns the SHA384 checksum of the given string. |
sha512 |
|
Literal (xsd:string) |
Returns the SHA512 checksum of the given string. |
Name | Input | Output | Description |
---|---|---|---|
http://www.w3.org/2001/XMLSchema#string |
|
Literal (xsd:string) |
Cast the given term to xsd:string |
http://www.w3.org/2001/XMLSchema#float |
|
Literal (xsd:float) |
Cast the given term to xsd:float |
http://www.w3.org/2001/XMLSchema#double |
|
Literal (xsd:double) |
Cast the given term to xsd:double |
http://www.w3.org/2001/XMLSchema#decimal |
|
Literal (xsd:decimal) |
Cast the given term to xsd:decimal |
http://www.w3.org/2001/XMLSchema#integer |
|
Literal (xsd:integer) |
Cast the given term to xsd:integer |
http://www.w3.org/2001/XMLSchema#dateTime |
|
Literal (xsd:dateTime) |
Cast the given term to xsd:dateTime |
http://www.w3.org/2001/XMLSchema#date |
|
Literal (xsd:date) |
Cast the given term to xsd:date |
http://www.w3.org/2001/XMLSchema#boolean |
|
Literal (xsd:boolean) |
Cast the given term to xsd:boolean |
Name | Input | Output | Description |
---|---|---|---|
bound |
|
Literal (xsd:boolean) |
Returns true if the given variable is bound to a value. Returns false otherwise. |
if |
|
Term |
Evaluates the expression as effective boolean value. Returns the second argument if true, otherwise the third argument. |
coalesce |
|
Term |
Returns the first expression result that evaluates without an error. |
|| |
|
Literal (xsd:boolean) |
Returns a logical OR of left and right. Note that logical-or operates on the effective boolean value of its arguments. |
&& |
|
Literal (xsd:boolean) |
Returns a logical AND of left and right. Note that logical-or operates on the effective boolean value of its arguments. |
= |
|
Literal (xsd:boolean) |
Returns true if both terms are the same follow these rules. A type error is produced if both arguments are literals but not the same. |
sameterm |
|
Literal (xsd:boolean) |
Returns true if both terms are the same follow these rules. False is returned instead of type errors. |
in |
|
Literal (xsd:boolean) |
Tests whether the RDF term on the left-hand side is found in the values of list of expressions on the right-hand side. |
notin |
|
Literal (xsd:boolean) |
Tests whether the RDF term on the left-hand side is not found in the values of list of expressions on the right-hand side. |