server-php-xml-class-rdql-class-rdql.htm / htm
<html> <head> <title>RDQL (class_rdql.php)</title> <link rel="stylesheet" href="main.css" type="text/css"> </head> <body> <div align="center"> <table border="0" width="80%" cellpadding="0" cellspacing="0"> <tr> <td bgcolor="#aaaaee" class="text" align="center"><a href="http://phpxmlclasses.sourceforge.net/">PHP XML Classes</a></td> </tr> </table> <table border="0" width="80%" cellpadding="0" cellspacing="0"> <tr> <td bgcolor="#aaaaee" class="textblbl" align="center">RDQL (class_rdql.php)</td> </tr> </table> <br/> <table border="0" width="80%"> <tr> <td bgcolor="#eeeeff" class="text">Description: This class is a PHP implementation of the <a href="rdql.html">RDQL language</a>, a language to query RDF documents. This class can be used to query RDF documents from local files or URLs. There's a RDQL tutorial describing this RDQL implementation <a href="rdql.html">here</a>. </td> </tr> </table> <br/> <table border="0" bgcolor="ddddff" width="80%"> <tr> <td valign="top" class="text" width="50%"><b>NEWS:</b> <ul> <li> 2002-06-30 First version of this class released. </ul> </td> <td valign="top" width="50%" class="text"> This class code as well as the documentation are hosted at <a href="http://www.sourceforge.net">SourceForge</a> please visit our <a href="http://phpxmlclasses.sourceforge.net/">SourceForge page</a> for releases, documentation, bug-tracking, support forums and mailing lists. </td> </tr> </table> <br/> <table border="0" width="80%" cellpadding="0" cellspacing="0"> <tr> <td class="textbl" bgcolor="aaaaee" width="50%">Resources</td> <td class="textbl" bgcolor="aaaaee" width="50%">Requirements</td> </tr> </table> <table border="1" width="80%" cellpadding="0" cellspacing="0"> <tr> <td valign="top" bgcolor="eeeeff" class="text" width="50%"> <ul> <li><a class="textbl" href="http://www.sourceforge.net/projects/phpxmlclasses">Downloads</a> <li><a class="textbl" href="http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpxmlclasses/rdql/">Browse CVS</a> <li><a class="textbl" href="http://sourceforge.net/tracker/?atid=470965&group_id=53613&func=browse">Report Bugs</a> <li><a class="textbl" href="http://phpxmlclasses.sourceforge.net/rdql.html">RDQL Tutorial (html)</a> </ul> </td> <td valign="top" bgcolor="eeeeff" class="text" width="50%"> <ul> <li>PHP 4.0.5+ </ul> </td> </tr> </table> <br/> <table border="0" width="80%" cellpadding="0" cellspacing="0"> <tr> <td class="textbl" bgcolor="aaaaee" width="50%">Features</td> <td class="textbl" bgcolor="aaaaee" width="50%">To-dos</td> </tr> </table> <table border="1" width="80%" cellpadding="0" cellspacing="0"> <tr> <td valign="top" bgcolor="eeeeff" class="text" width="50%"> <ul> <li>RDQL queries can be applied to documents in the local file systems, URLs or combinations. <li>Multiple documents can be queried </ul> </td> <td valign="top" bgcolor="ddddff" class="text" width="50%"> <ul> <li> We have to add error handling to this class. <li> Errors are not handled, if your RDQL query has an error then a PHP error will appear. </ul> </td> </tr> </table> <br/> <table border="0" bgcolor="ddddff" width="80%"> <tr> <!-- <td valign="top" class="text" width="50%"><b>To-do/future releases:</b> <ul> <li>Class <li>Class <li>Class </ul> </td> --> <td valign="top" width="100%" class="text"> Contact: <a href="mailto:lrargerich@yahoo.com">;Luis Argerich</a> </td> </tr> </table> <br/> <table border="0" bgcolor="ddddff" width="80%"> <tr> <!-- <td valign="top" class="text" width="50%"><b>To-do/future releases:</b> <ul> <li>Class <li>Class <li>Class </ul> </td> --> <td valign="top" width="100%" class="text"> Detailed description and usage:<br/> <b>Using the class:</b><br/><br/> The best way to use the class is using the rdql_query_url method of the RDQL_query_document class. For example: <pre> a_query); </pre> The result is an array of asociative arrays, you can use a print_r(<br/><br/> 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). <br/> <h3>Documentation</h3> </div> <h2>Classes</h2> <ul> <li><a href="#class32">RDQL_query_document</a></li> <li><a href="#class33">RDF_iterator</a></li> <li><a href="#class34">RDQL_query</a></li> <li><a href="#class35">RDF_document_iterator</a></li> </ul> <a name="class32"></a> <h3>RDQL_query_document</h3> 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.
<br> <!-- METHOD SUMMARY --> <A NAME="pDomNode_method_summary"><!-- --></A> <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=2><FONT SIZE="+2"> <B>Method Summary</B></FONT></TD> </TR> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> Array</CODE></FONT></TD> <TD><CODE><B><A HREF="#class32method1">rdql_query_url</A></B>(string query)</CODE> <BR> Queries a URL or pathname</TD> </TR> <!-- A ROW --> </TABLE> <P> <!-- METHOD SUMMARY --> <!-- ============ METHOD DETAIL ========== --> <A NAME="method_detail"><!-- --></A> <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=1><FONT SIZE="+2"> <B>Method Detail</B></FONT></TD> </TR> </TABLE> <!-- method --> <A NAME="class32method1"><!-- --></A> <H3>rdql_query_url</H3> <PRE> Array <B>rdql_query_url</B>(string query - The RDQL query to be executed<br><DT><B>Returns:</B><DD>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<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- ============ METHOD DETAIL ========== --> <a name="class33"></a> <h3>RDF_iterator</h3> 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)
<br> <!-- METHOD SUMMARY --> <A NAME="pDomNode_method_summary"><!-- --></A> <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=2><FONT SIZE="+2"> <B>Method Summary</B></FONT></TD> </TR> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> boolean</CODE></FONT></TD> <TD><CODE><B><A HREF="#class33method1">tuple_match</A></B>(array tuple)</CODE> <BR> Indicates if a tuple matches a condition</TD> </TR> <!-- A ROW --> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> array</CODE></FONT></TD> <TD><CODE><B><A HREF="#class33method2">find_tuples</A></B>(array tuple)</CODE> <BR> Find tuples matching the values passed as arguments</TD> </TR> <!-- A ROW --> </TABLE> <P> <!-- METHOD SUMMARY --> <!-- ============ METHOD DETAIL ========== --> <A NAME="method_detail"><!-- --></A> <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=1><FONT SIZE="+2"> <B>Method Detail</B></FONT></TD> </TR> </TABLE> <!-- method --> <A NAME="class33method1"><!-- --></A> <H3>tuple_match</H3> <PRE> boolean <B>tuple_match</B>(array tuple)</PRE> <DL> <DD>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.<DD> <DL> <DT><B>Parameters:</B><DD> <br>tuple - This is an array with the RDF tuple being compared in the form (subject, predicate, object)<br><DT><B>Returns:</B><DD>True if the tuple matches the condition, false if not<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class33method2"><!-- --></A> <H3>find_tuples</H3> <PRE> array <B>find_tuples</B>(array tuple)</PRE> <DL> <DD>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)<DD> <DL> <DT><B>Parameters:</B><DD> <DT><B>Returns:</B><DD>An array of asocs.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- ============ METHOD DETAIL ========== --> <a name="class34"></a> <h3>RDQL_query</h3> 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.
<br> <!-- METHOD SUMMARY --> <A NAME="pDomNode_method_summary"><!-- --></A> <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=2><FONT SIZE="+2"> <B>Method Summary</B></FONT></TD> </TR> <!-- A ROW --> <TR BGCOLOR="white" CLASS="TableRowColor"> <TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"> <CODE> void</CODE></FONT></TD> <TD><CODE><B><A HREF="#class34method1">RDQL_query</A></B>(RDF_iterator <br><DT><B>Returns:</B><DD>Nothing<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method2"><!-- --></A> <H3>parse_query</H3> <PRE> array <B>parse_query</B>(string query)</PRE> <DL> <DD>This is the method that process a RDQL query and returns an array with the query results.<DD> <DL> <DT><B>Parameters:</B><DD>query - The RDQL query to be processed <br><DT><B>Returns:</B><DD>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.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method3"><!-- --></A> <H3>tokenize</H3> <PRE> array <B>tokenize</B>(string exp)</PRE> <DL> <DD>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)<DD> <DL> <DT><B>Parameters:</B><DD>exp - An RDQL expression <br><DT><B>Returns:</B><DD>An array whith parts of the RDQL query.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method4"><!-- --></A> <H3>array_sql_join</H3> <PRE> array <B>array_sql_join</B>(array v1, arrayv2)</PRE> <DL> <DD>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.<DD> <DL> <DT><B>Parameters:</B><DD> v1 - An array of asociative array<br>v2 - An array of asociative array <br><DT><B>Returns:</B><DD>An array with the result of the join between the arrays passed as arguments.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method5"><!-- --></A> <H3>array_join_elems</H3> <PRE> array <B>array_join_elems</B>(array v1, arrayv2)</PRE> <DL> <DD>Computes the join between two asociative arrays<DD> <DL> <DT><B>Parameters:</B><DD> v1 - An asociative array<br>v2 - An asociative array <br><DT><B>Returns:</B><DD>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)<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method6"><!-- --></A> <H3>parse_select</H3> <PRE> array <B>parse_select</B>(string exp)</PRE> <DL> <DD>Parses the select part of an RDQL query<DD> <DL> <DT><B>Parameters:</B><DD>exp - The select part of an RDQL sentence <br><DT><B>Returns:</B><DD>An array where each element of the array is a RDQL var to be selected.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method7"><!-- --></A> <H3>parse_from</H3> <PRE> array <B>parse_from</B>(string exp)</PRE> <DL> <DD>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.<DD> <DL> <DT><B>Parameters:</B><DD>exp - The from part of an RDQL query <br><DT><B>Returns:</B><DD>An array of RDF sources to be queried.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method8"><!-- --></A> <H3>parse_where</H3> <PRE> array <B>parse_where</B>(string exp)</PRE> <DL> <DD>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.<DD> <DL> <DT><B>Parameters:</B><DD>exp - The where part of a RDQL query <br><DT><B>Returns:</B><DD>An array of conditions that RDF triplets must follow.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method9"><!-- --></A> <H3>parse_and</H3> <PRE> array <B>parse_and</B>(string exp)</PRE> <DL> <DD>This method parses the and part of an RDQL query returning an array of expressions that RDQL variables must match.<DD> <DL> <DT><B>Parameters:</B><DD>exp - The and part of an RDQL query <br><DT><B>Returns:</B><DD>An array of PHP expressions where RDQL variables will be replaced by their values.<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method10"><!-- --></A> <H3>parse_using</H3> <PRE> array <B>parse_using</B>(string exp)</PRE> <DL> <DD>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<DD> <DL> <DT><B>Parameters:</B><DD>exp - The using section of an RDQL query <br><DT><B>Returns:</B><DD>An asociative array mapping namespace prefixes to URIs<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method11"><!-- --></A> <H3>filter_tuples</H3> <PRE> array <B>filter_tuples</B>(Reference to array &tuples, stringfilter)</PRE> <DL> <DD>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.<DD> <DL> <DT><B>Parameters:</B><DD> &tuples - A reference to an array of tuples mapping RDQL variables to values<br>filter - This is an expression as any PHP expression BUT using RDQL variables instead of PHP variables. <br><DT><B>Returns:</B><DD>An array containing tuples that matched the filter<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- method --> <A NAME="class34method12"><!-- --></A> <H3>find_matching_tuples</H3> <PRE> array <B>find_matching_tuples</B>(array sources, arrrayconditions, array ns)</PRE> <DL> <DD>This method returns an array of RDF tuples that match all the conditions from the RDQL query<DD> <DL> <DT><B>Parameters:</B><DD>sources - An array of RDF soures to be queried <br>conditions - An array of RDQL conditions that tuples must follow, each condition is a condition from the where part of an RDQL query.<br>ns - An asociative array mapping namespace prefixes to URIs, this array was obtained as a result of the parse_using method <br><DT><B>Returns:</B><DD>An array of tuples mapping RDQL variables to values<DT><B>Throws:</B><DD><CODE>None</CODE> </DL> </DD> </DL> <HR> <!-- a method --> <!-- ============ METHOD DETAIL ========== --> <a name="class35"></a> <h3>RDF_document_iterator</h3> 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.
<br> <!-- METHOD SUMMARY --> <A NAME="pDomNode_method_summary"><!-- --></A> <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=2><FONT SIZE="+2"> <B>Method Summary</B></FONT></TD> </TR> <tr><td><p align=center>This class doesn�t have any method</p></td></tr></TABLE> <P> <!-- METHOD SUMMARY --> <!-- ============ METHOD DETAIL ========== --> <A NAME="method_detail"><!-- --></A> <TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"> <TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"> <TD COLSPAN=1><FONT SIZE="+2"> <B>Method Detail</B></FONT></TD> </TR> </TABLE> <tr><td><p align=center>This class doesn�t have any method</p></td></tr><!-- ============ METHOD DETAIL ========== --> </td> </tr> </table> </body> </html>
(C) Æliens 20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.