NAME

RDF::Query - An RDF query implementation of SPARQL/RDQL in Perl for use with RDF::Redland and RDF::Core.

VERSION

This document describes RDF::Query version 1.034.

SYNOPSIS

my $query = new RDF::Query ( $rdql, undef, undef, 'rdql' );
my @rows = $query->execute( $model );

my $query = new RDF::Query ( $sparql, undef, undef, 'sparql' );
my $iterator = $query->execute( $model );
while (my $row = $iterator->()) {
  ...
}

DESCRIPTION

RDF::Query allows RDQL and SPARQL queries to be run against an RDF model, returning rows of matching results.

See http://www.w3.org/TR/rdf-sparql-query/ for more information on SPARQL. See http://www.w3.org/Submission/2004/SUBM-RDQL-20040109/ for more information on RDQL.

REQUIRES

RDF::Redland or RDF::Core

Parse::RecDescent (for RDF::Core)

LWP::Simple

DateTime::Format::W3CDTF

Scalar::Util

METHODS

new ( $query, $baseuri, $languri, $lang )

Returns a new RDF::Query object for the query specified. The query language used will be set if $languri or $lang is passed as the URI or name of the query language, otherwise the query defaults to SPARQL.

get ( $model )

Executes the query using the specified model, and returns the first row found.

execute ( $model, %args )

Executes the query using the specified model. If called in a list context, returns an array of rows, otherwise returns an iterator.

describe ( $stream )

Takes a stream of matching statements and constructs a DESCRIBE graph.

construct ( $stream )

Takes a stream of matching statements and constructs a result graph matching the uery's CONSTRUCT graph patterns.

ask ( $stream )

Takes a stream of matching statements and returns a boolean query result stream.

supports ( $model, $feature )

Returns a boolean value representing the support of $feature for the given model.

set_named_graph_query ()

Makes appropriate changes for the current query to use named graphs. This entails creating a new context-aware bridge (and model) object.

new_bridge ()

Returns a new bridge object representing a new, empty model.

get_bridge ( $model )

Returns a bridge object for the specified model object.

fixup ()

Does last-minute fix-up on the parse tree. This involves:

* Loading any external files into the model.
* Converting URIs and strings to model-specific objects.
* Fixing variable list in the case of 'SELECT *' queries.
fixup_triple_bridge_variables ()

Called by fixup() to replace URIs and strings with model-specific objects.

query_more ( bound = $bound, triples => \@triples )>

Internal recursive query function to bind pivot variables until only result variables are left and found from the RDF store. Called from query.

union ( bound = \%bound, triples => \@triples )>

Called by query_more() to handle UNION queries. Calls query_more() with each UNION branch, and returns an aggregated data stream.

optional ( bound = \%bound, triples => \@triples )>

Called by query_more() to handle OPTIONAL query patterns. Calls query_more() with the OPTIONAL pattern, binding variables if the pattern succeeds. Returns by calling query_more() with any remaining triples.

named_graph ( bound = \%bound, triples => \@triples )>

Called by query_more() to handle NAMED graph query patterns. Matches graph context (binding the graph to a variable if applicable). Returns by calling query_more() with any remaining triples.

qualify_uri ( [ 'URI', [ $prefix, $localPart ] ] )
qualify_uri ( [ 'URI', $uri )

Returns a full URI given the URI data structure passed as an argument. For already-qualified URIs, simply returns the URI. For QNames, looks up the QName prefix in the parse-tree namespaces, and concatenates with the QName local part.

check_constraints ( \%bound, \@data )

Returns the value returned by evaluating the expression structures in @data with the bound variables in %bound.

get_value ( $value )

Returns the scalar value (string literal, URI value, or blank node identifier) for the specified model-specific node object.

add_function ( $uri, $function )

Associates the custom function $function (a CODE reference) with the specified URI, allowing the function to be called by query FILTERs.

ncmp ( $value )

General-purpose sorting function for both numbers and strings.

sort_rows ( $nodes, $parsed )

Called by execute to handle result forms including: * Sorting results * Distinct results * Limiting result count * Offset in result set

parse_url ( $url, $named )

Retrieve a remote file by URL, and parse RDF into the RDF store. If $named is TRUE, associate all parsed triples with a named graph.

variables ()

Returns a list of the ordered variables the query is selecting.

error ()

Returns the last error the parser experienced.

set_error ( $error )

Sets the object's error variable.

clear_error ()

Clears the object's error variable.

_debug_closure ( $code )

Debugging function to print out a deparsed (textual) version of a closure.

_debug ( $message, $level, $trace )

Debugging function to print out $message at or above the specified debugging $level, with an optional stack $trace.

Supported Built-in Operators and Functions

  • REGEX, BOUND, ISURI, ISBLANK, ISLITERAL

  • Data-typed literals: DATATYPE(string)

  • Language-typed literals: LANG(string), LANGMATCHES(string, lang)

  • Casting functions: xsd:dateTime, xsd:string

  • dateTime-equal, dateTime-greater-than

TODO

  • Built-in Operators and Functions

    http://www.w3.org/TR/rdf-sparql-query/#StandardOperations

    Casting functions: xsd:{boolean,double,float,decimal,integer}, rdf:{URIRef,Literal}, STR

    XPath functions: numeric-equal, numeric-less-than, numeric-greater-than, numeric-multiply, numeric-divide, numeric-add, numeric-subtract, not, matches

    SPARQL operators: sop:RDFterm-equal, sop:bound, sop:isURI, sop:isBlank, sop:isLiteral, sop:str, sop:lang, sop:datatype, sop:logical-or, sop:logical-and

AUTHOR

Gregory Todd Williams <greg@evilfunhouse.com>

24 POD Errors

The following errors were encountered while parsing the POD:

Around line 222:

=end for without matching =begin. (Stack: =over)

Around line 271:

=end for without matching =begin. (Stack: =over)

Around line 334:

=end for without matching =begin. (Stack: =over)

Around line 352:

=end for without matching =begin. (Stack: =over)

Around line 370:

=end for without matching =begin. (Stack: =over)

Around line 387:

=end for without matching =begin. (Stack: =over)

Around line 415:

=end for without matching =begin. (Stack: =over)

Around line 456:

=end for without matching =begin. (Stack: =over)

Around line 562:

=end for without matching =begin. (Stack: =over)

Around line 608:

=end private without matching =begin. (Stack: =over)

Around line 849:

=end for without matching =begin. (Stack: =over)

Around line 893:

=end for without matching =begin. (Stack: =over)

Around line 985:

=end for without matching =begin. (Stack: =over)

Around line 1063:

=end for without matching =begin. (Stack: =over)

Around line 1093:

=end for without matching =begin. (Stack: =over)

Around line 1197:

=end for without matching =begin. (Stack: =over)

Around line 1247:

=end for without matching =begin. (Stack: =over)

Around line 1272:

=end for without matching =begin. (Stack: =over)

Around line 1363:

=end private without matching =begin. (Stack: =over)

Around line 1381:

=end for without matching =begin. (Stack: =over)

Around line 1414:

=end for without matching =begin. (Stack: =over)

Around line 1430:

=end for without matching =begin. (Stack: =over)

Around line 1446:

=end for without matching =begin. (Stack: =over)

Around line 1467:

=end for without matching =begin. (Stack: =over)