Detailed description and usage:
Using the class:
The best way to use the class is using the rdql_query_url method of the
RDQL_query_document class. For example:
$rows = RDQL_query_document::rdql_query_url($a_query);
The result is an array of asociative arrays, you can use a print_r($rows) to see
the structure or take a look at the rdql_test.php script to see how the result
can be processed.
If you want to parse documents from a database, repository or similar you have
to implement a class extending RDF_iterator where you have to implement just one
method: find_tuples, then you can create RDQL_query_mysource by copying the way
in which RDQL_query_document was implemented (it's quite easy).
Documentation
Classes
RDQL_query_document
Extends: None
Description: This class implements a RDQL engine for RDF documents that can be indicated in the RDQL query as URLs or pathnames for RDF documents local to the machine.
Method Summary |
Array |
rdql_query_url(string $query)
Queries a URL or pathname |
rdql_query_url
Array rdql_query_url(string $query)
- This method can be used to perform a RDQL query where the FROM part of the query is a list of URLs or pathnames enclosed in angle brackets and sepparated by commas.
-
- Parameters:
-
$query - The RDQL query to be executed
- Returns:
- An array of asociative arrays. Each member of the array is a row of the RDQL result. Each row is an asociative array in the form RDQL_VAR_NAME => value
- Throws:
None
RDF_iterator
Extends: None
Description: The RDQL engine receives an RDF iterator object when constructed, the iterator is the object that knows how to access and traverse an RDF document indicated in the FROM part of the RDQL query. This allows the implementation of a RDQL engine accessing RDF documents from different sources (files, a database, etc)
Method Summary |
boolean |
tuple_match(array $condition, array $tuple)
Indicates if a tuple matches a condition |
array |
find_tuples(array $condition, array $tuple)
Find tuples matching the values passed as arguments |
tuple_match
boolean tuple_match(array $condition, array $tuple)
- This method is implemented in the abstract RDF_iterator match, classes extending this class can use tuple_match to check if an RDF tuple matches a condition.
-
- Parameters:
-
$condition - This array contains the conditions that subject, predicate and object must follow, they can be ?x if any value matches asigning the value to the ?x RDQL variable.
$tuple - This is an array with the RDF tuple being compared in the form (subject, predicate, object)
- Returns:
- True if the tuple matches the condition, false if not
- Throws:
None
find_tuples
array find_tuples(array $condition, array $tuple)
- This method must be implemented in classes extendin the RDF_iterator class. The method must return an array where each member of the array is an asoc array matching RDQL variables with values found in triplets of the RDF document. You can use the tuple_match method defined in this class to compare a tuple against a condition. (This method receives the condition for subject, predicate and object)
-
- Parameters:
-
- Returns:
- An array of asocs.
- Throws:
None
RDQL_query
Extends: None
Description: This class implements a generic RDQL engine that can be used to process RDQL queries against RDF documents from different data-sources.
Method Summary |
void |
RDQL_query(RDF_iterator $iterator)
Constructor receiving an RDF_iterator object |
array |
parse_query(string $query)
Parses an RDQL query returning the result |
array |
tokenize(string $exp)
Tokenizes a RDQL expression |
array |
array_sql_join(array $v1, array $v2)
Computes the join of two asociative arrays |
array |
array_join_elems(array $v1, array $v2)
Computes the join between two asociative arrays |
array |
parse_select(string $exp)
Parses the select part of an RDQL query |
array |
parse_from(string $exp)
Parses the from part of an RDQL query |
array |
parse_where(string $exp)
Parses the where part of an RDQL query |
array |
parse_and(string $exp)
Parses the and part of an RDQL query |
array |
parse_using(string $exp)
Parses the using part of an RDQL query |
array |
filter_tuples(Reference to array $&tuples, string $filter)
Filters the tuples according to the filter |
array |
find_matching_tuples(array $sources, arrray $conditions, array $ns)
Find tuples matching conditions |
RDQL_query
void RDQL_query(RDF_iterator $iterator)
- This is the constructor of the class it receives an RDF_iterator object that will be used to access RDF tuples in the RDF documents (the iterator is the object that knows how to access and parse RDF documents)
-
- Parameters:
-
$iterator - An object from a class extending RDF_iterator. This object implements the find_tuples method where tuples from the RDF sources indicated in the query are scanned to see if they match a condition. The object knows how to access and parse RDF documents indicated in the FROM part of the RDQL query.
- Returns:
- Nothing
- Throws:
None
parse_query
array parse_query(string $query)
- This is the method that process a RDQL query and returns an array with the query results.
-
- Parameters:
-
$query - The RDQL query to be processed
- Returns:
- An array where each member of the array is a row of the query result. Each row is an asociative array asociating RDQL variables from the SELECT part of the query with their values.
- Throws:
None
tokenize
array tokenize(string $exp)
- This method tokenizes a RDQL expression returning an array where each member of the array is a part of an RDQL expression (SELECT, FROM, WHERE, AND or USING)
-
- Parameters:
-
$exp - An RDQL expression
- Returns:
- An array whith parts of the RDQL query.
- Throws:
None
array_sql_join
array array_sql_join(array $v1, array $v2)
- This method computes a join between two arrays of asociative arrays, first the cartesian product between the arrays is performed then for each row if theres a key in v1 and v2 then if the values are the same in both arrays the row survives if not it is discarded. If no keys are equal then the row survives.
-
- Parameters:
-
$v1 - An array of asociative array
$v2 - An array of asociative array
- Returns:
- An array with the result of the join between the arrays passed as arguments.
- Throws:
None
array_join_elems
array array_join_elems(array $v1, array $v2)
- Computes the join between two asociative arrays
-
- Parameters:
-
$v1 - An asociative array
$v2 - An asociative array
- Returns:
- An asociative array with the elements in v1 and v2 if the keys in v1 and v2 where different or the repeated keys had the same value (then only one key is present in the result)
- Throws:
None
parse_select
array parse_select(string $exp)
- Parses the select part of an RDQL query
-
- Parameters:
-
$exp - The select part of an RDQL sentence
- Returns:
- An array where each element of the array is a RDQL var to be selected.
- Throws:
None
parse_from
array parse_from(string $exp)
- This method parses the from part of an RDQL query returning an array where each member of the array is an RDF source to be queired.
-
- Parameters:
-
$exp - The from part of an RDQL query
- Returns:
- An array of RDF sources to be queried.
- Throws:
None
parse_where
array parse_where(string $exp)
- This method parses the where section of a RDQL query returning an array where each member of the array is a condition that the RDF triplets must follow.
-
- Parameters:
-
$exp - The where part of a RDQL query
- Returns:
- An array of conditions that RDF triplets must follow.
- Throws:
None
parse_and
array parse_and(string $exp)
- This method parses the and part of an RDQL query returning an array of expressions that RDQL variables must match.
-
- Parameters:
-
$exp - The and part of an RDQL query
- Returns:
- An array of PHP expressions where RDQL variables will be replaced by their values.
- Throws:
None
parse_using
array parse_using(string $exp)
- This method is used to parse the using section of an RDQL query returning an asociative array where keys are namespace prefixes and the values are URIs
-
- Parameters:
-
$exp - The using section of an RDQL query
- Returns:
- An asociative array mapping namespace prefixes to URIs
- Throws:
None
filter_tuples
array filter_tuples(Reference to array $&tuples, string $filter)
- This method receives an array of tuples where each tuple is an asociative array mapping RDQL variables to values. The RDQL variables are replaced in the filter and if the expression returns false the tuple is eliminated from the array.
-
- Parameters:
-
$&tuples - A reference to an array of tuples mapping RDQL variables to values
$filter - This is an expression as any PHP expression BUT using RDQL variables instead of PHP variables.
- Returns:
- An array containing tuples that matched the filter
- Throws:
None
find_matching_tuples
array find_matching_tuples(array $sources, arrray $conditions, array $ns)
- This method returns an array of RDF tuples that match all the conditions from the RDQL query
-
- Parameters:
-
$sources - An array of RDF soures to be queried
$conditions - An array of RDQL conditions that tuples must follow, each condition is a condition from the where part of an RDQL query. $ns - An asociative array mapping namespace prefixes to URIs, this array was obtained as a result of the parse_using method
- Returns:
- An array of tuples mapping RDQL variables to values
- Throws:
None
RDF_document_iterator
Extends: RDF_iterator
Description: This is an iterator for RDF documents contained in files or URLs. The iterator is used to construct RDQL queries where the FROM part of the query can indicate URLs or paths.
Method Summary |
This class doesn´t have any method |
|