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

Documentation generated on Mon, 11 Mar 2019 15:39:50 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.