RDF_RDQL
[ class tree: RDF_RDQL ] [ index: RDF_RDQL ] [ all elements ]

Source for file test_RdqlQuery.php

Documentation is available at test_RdqlQuery.php

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4.     <title>Test Traverse Model_Memory</title>
  5. </head>
  6. <body>
  7.  
  8. <?php
  9. include 'RDF.php';
  10. include 'RDF/Model/Memory.php';
  11. include 'RDF/RDQL.php';
  12. // Filename of an RDF document
  13. $base "employees.rdf";
  14. // Create a new Model_Memory
  15. $model =new RDF_Model_Memory();
  16. // Load and parse document
  17. $model->load($base);
  18. // Show input model
  19. $model->writeAsHtmlTable();
  20.  
  21. echo "<p>";
  22.  
  23. echo "<BR>show the age of all employees ,using the RdqlResultIterator<BR>";
  24. $rdql_query '
  25. SELECT ?givenName, ?age
  26. WHERE (?x, v:age, ?age),
  27.       (?x, vcard:N, ?blank),
  28.       (?blank, vcard:Given, ?givenName)
  29. USING vcard FOR <http://www.w3.org/2001/vcard-rdf/3.0#>
  30.       v FOR <http://sampleVocabulary.org/1.3/People#>';
  31. // query model, get RDQLResultIterator
  32. $rdqlIter = RDF_RDQL::RDQLQueryAsIterator($model$rdql_query);
  33.  
  34. // get different Result labels as array
  35. $result_labels $rdqlIter->getResultLabels();
  36.  
  37. echo "<BR><b>Result Label Names:</b> ";
  38. for ($i = 0; $i count($result_labels)$i++echo $result_labels[$i" ";
  39. echo "<BR><B>Number of results:</B> " $rdqlIter->countResults();
  40. echo "<BR><B>Result objects, serialized to string:</B><BR>"
  41. // serialize result to string
  42. while ($rdqlIter->hasNext()) {
  43.     $curren_result $rdqlIter->next();
  44.     echo "<BR>";
  45.     for ($j = 0; $j count($result_labels)$j++echo $curren_result[$result_labels[$j]]->toString("<BR> ";
  46. ;
  47.  
  48. echo "</p>";
  49. // show emails of all employees
  50. $rdql_query '
  51. SELECT ?givenName, ?familyName, ?email
  52. WHERE  (?person vcard:N ?blank1)
  53.        (?blank1 vcard:Given ?givenName)
  54.        (?blank1 vcard:Family ?familyName)
  55.        (?person vcard:EMAIL ?blank2)
  56.        (?blank2 rdf:value ?email)
  57. AND ?person ~~ "/example.com\/EMPLOYEES\//i"
  58. USING vcard FOR <http://www.w3.org/2001/vcard-rdf/3.0#>
  59.       v FOR <http://sampleVocabulary.org/1.3/People#>';
  60. $res = RDF_RDQL::RDQLQuery($model$rdql_query);
  61.  
  62. RDF_RDQL_Engine::writeQueryResultAsHtmlTable($res);
  63.  
  64. echo "<br>show all employees over 30 <BR>";
  65. // show all employees over 30
  66. $rdql_query '
  67. SELECT ?employee, ?age
  68. WHERE  (?x, vcard:FN, ?employee), (?x, v:age, ?age)
  69. AND ?age > 30
  70. USING vcard FOR <http://www.w3.org/2001/vcard-rdf/3.0#>
  71.       v FOR <http://sampleVocabulary.org/1.3/People#>';
  72.  
  73. $res = RDF_RDQL::RDQLQuery($model$rdql_query);
  74.  
  75. RDF_RDQL_Engine::writeQueryResultAsHtmlTable($res);
  76.  
  77. echo "<p>";
  78. // find out whose number is it: +1 111 2212 431
  79. $rdql_query '
  80. SELECT ?x, ?type
  81. WHERE  (?x, vcard:TEL, ?tel),
  82.        (?tel, rdf:value, ?telNumber)
  83.        (?tel, rdf:type, ?type)
  84. AND ?telNumber eq "+1 111 2212 431"
  85. USING vcard FOR <http://www.w3.org/2001/vcard-rdf/3.0#>
  86.       v FOR <http://sampleVocabulary.org/1.3/People#>';
  87. $res = RDF_RDQL::RDQLQuery($model$rdql_query);
  88. RDF_RDQL_Engine::writeQueryResultAsHtmlTable($res);
  89.  
  90. echo "</p>";
  91. // show office telephone numbers of all employees
  92. $rdql_query '
  93. SELECT ?givenName, ?familyName, ?telNumber
  94. WHERE  (?person vcard:N ?blank1)
  95.        (?blank1 vcard:Given ?givenName)
  96.        (?blank1 vcard:Family ?familyName)
  97.        (?person vcard:TEL ?blank2)
  98.        (?blank2 rdf:value ?telNumber)
  99.        (?blank2 rdf:type ?type)
  100. AND ?person ~~ "/example.com\/EMPLOYEES\//i" && ?type eq vcard:work
  101. USING vcard FOR <http://www.w3.org/2001/vcard-rdf/3.0#>
  102.       v FOR <http://sampleVocabulary.org/1.3/People#>';
  103. $res = RDF_RDQL::RDQLQuery($model$rdql_query);
  104. RDF_RDQL_Engine::writeQueryResultAsHtmlTable($res);
  105.  
  106. ?>
  107.  
  108.  
  109.  
  110. </body>
  111. </html>

Documentation generated on Mon, 11 Mar 2019 13:55:46 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.