May 02, 2015 .. currentmodule:: rdfextras.sparql.operators

operators - SPARQL Operators

$Date: 2005/11/04 14:06:36 $, by $Author: ivan $, $Revision: 1.1 $

API for the SPARQL operators.

The operators (eg, ‘lt’) return a function that can be added to the AND clause of a query. The parameters are either regular values or query strings.

The resulting function has one parameter (the binding directory), it can be combined with others or be plugged to into an array of constraints.

For example:

constraints = [lt("?m", 42)]

for checking whether ”?m” is smaller than the (integer) value 42. It can be combined using the lambda function, for example:

constraints = [lambda(b): lt("?m", 42")(b) or lt("?n", 134)(b)]

is the expression for:

AND ?m < 42 || ?n < 134

(Clearly, the relative complexity is only on the API level; a SPARQL language parser that starts with a SPARQL expression can map on this API).

rdfextras.sparql.operators.queryString(v)[source]

Boolean test whether this is a a query string or not :param v: the value to be checked :returns: True if it is a query string

rdfextras.sparql.operators.getLiteralValue(v)[source]

Return the value in a literal, making on the fly conversion on datatype (using the datatypes that are implemented) :param v: the Literal to be converted :returns: the result of the conversion.

rdfextras.sparql.operators.getValue(param)[source]

Returns a value retrieval function. The return value can be plugged in a query; it would return the value of param directly if param is a real value, and the run-time value if param is a query string of the type ”?xxx”. If no binding is defined at the time of call, the return value is None.

Parameters:param – query string, Unbound instance, or real value
Returns:a function taking one parameter (the binding directory)
rdfextras.sparql.operators.lt(a, b)[source]

Operator for ‘&lt;’ :param a: value or query string :param b: value or query string :returns: comparison method

rdfextras.sparql.operators.le(a, b)[source]
rdfextras.sparql.operators.gt(a, b)[source]

Operator for ‘&gt;’ :param a: value or query string :param b: value or query string :returns: comparison method

rdfextras.sparql.operators.ge(a, b)[source]

Operator for ‘&gt;=’ :param a: value or query string :param b: value or query string :returns: comparison method

rdfextras.sparql.operators.eq(a, b)[source]

Operator for ‘=’ :param a: value or query string :param b: value or query string :returns: comparison method

rdfextras.sparql.operators.neq(a, b)[source]

Operator for ‘!=’ :param a: value or query string :param b: value or query string :returns: comparison method

rdfextras.sparql.operators.bound(a)[source]

Is the variable bound :param a: value or query string :returns: check method

rdfextras.sparql.operators.isURI(a)[source]

Is the variable bound to a URIRef :param a: value or query string :returns: check method

rdfextras.sparql.operators.isIRI(a)[source]

Is the variable bound to a IRIRef (this is just an alias for URIRef) :param a: value or query string :returns: check method

rdfextras.sparql.operators.isBlank(a)[source]

Is the variable bound to a Blank Node :param a: value or query string :returns: check method

rdfextras.sparql.operators.isLiteral(a)[source]

Is the variable bound to a Literal :param a: value or query string :returns: check method

rdfextras.sparql.operators.str(a)[source]

Return the string version of a resource :param a: value or query string :returns: check method

rdfextras.sparql.operators.lang(a)[source]

Return the lang value of a literal :param a: value or query string :returns: check method

rdfextras.sparql.operators.datatype(a)[source]

Return the datatype URI of a literal :param a: value or query string :returns: check method

rdfextras.sparql.operators.isOnCollection(collection, item, triplets)[source]

Generate a method that can be used as a global constaint in sparql to check whether the ‘item’ is an element of the ‘collection’ (a.k.a. list). Both collection and item can be a real resource or a query string. Furthermore, item might be a plain string, that is then turned into a literal run-time. The method returns an adapted method.

Is a resource on a collection?

The operator can be used to check whether the ‘item’ is an element of the ‘collection’ (a.k.a. list). Both collection and item can be a real resource or a query string.

Parameters:
  • collection – is either a query string (that has to be bound by the query) or an RDFLib Resource representing the collection
  • item – is either a query string (that has to be bound by the query), an RDFLib Resource, or a data type value that is turned into a corresponding Literal (with possible datatype) that must be tested to be part of the collection
Returns:

a function

rdfextras.sparql.operators.addOperator(args, combinationArg)[source]

SPARQL numeric + operator implemented via Python

rdfextras.sparql.operators.XSDCast(source, target=None)[source]

XSD Casting/Construction Support For now (this may be an issue since Literal doesn’t override comparisons) it simply creates a Literal with the target datatype using the ‘lexical’ value of the source

rdfextras.sparql.operators.regex(item, pattern, flag=None)[source]

Invokes the XPath fn:matches function to match text against a regular expression pattern. The regular expression language is defined in XQuery 1.0 and XPath 2.0 Functions and Operators section 7.6.1 Regular Expression Syntax

rdfextras.sparql.operators.EBV(a)[source]
  • If the argument is a typed literal with a datatype of xsd:boolean, the EBV is the value of that argument.
  • If the argument is a plain literal or a typed literal with a datatype of xsd:string, the EBV is false if the operand value has zero length; otherwise the EBV is true.
  • If the argument is a numeric type or a typed literal with a datatype derived from a numeric type, the EBV is false if the operand value is NaN or is numerically equal to zero; otherwise the EBV is true.
  • All other arguments, including unbound arguments, produce a type error.

Table Of Contents

Previous topic

graph - SPARQL Graph

Next topic

parser - SPARQL parser