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

Source for file custom_test.php

Documentation is available at custom_test.php

  1. <?php 
  2. // ----------------------------------------------------------------------------------
  3. // PHP Script: custom_test.php
  4. // ----------------------------------------------------------------------------------
  5. /*
  6.  * This is an online demo of RDF API for PHP. 
  7.  * You can paste RDF code into the text field below and choose how the data should be 
  8.  * processed. It's possible to parse, serialize, reify and query the data.
  9.  * The size of your RDF code is limited to 10.000 characters, due to resource restrictions.
  10.  * 
  11.  * @author Chris Bizer <chris@bizer.de>
  12.  * @autor Seairth Jacobs <seairth@seairth.com>
  13.  * @author Daniel Westphal <dawe@gmx.de>
  14.  *
  15.  */
  16. ?>
  17.  
  18. <head>
  19.     <title>RAP - RDF API for PHP online demo</title>
  20.     <link href="phpdoc.css" rel="stylesheet" type="text/css">
  21. </head>
  22.  
  23. <body>
  24. <table width="100%" border="0">
  25. <TR> 
  26.   <TD align=left vAlign=top>
  27.    <DIV align="right"><BR>
  28.       &nbsp;<a href="http://www.w3.org/RDF/" target="_blank"><img src="rdf_metadata_button.gif" width="95" height="40" border="0" alt="RDF Logo"></a> 
  29.       &nbsp;<a href="http://www.php.net" target="_blank"><img src="php_logo.gif" width="120" height="64" border="0" alt="PHP Logo"></a></div>
  30.     <H3>RDF API for PHP</H3>
  31.     <H1>Online API Demo</H1><BR>
  32.      
  33. <?php 
  34. // Function: Output a string with line numbers
  35. function echo_string_with_linenumbers ($input_string)
  36. {
  37.     $input_string str_replace (" ""&nbsp;&nbsp;"$input_string);
  38.     $data_lines explode('&lt;br />'str_replace('<''&lt;'nl2br($input_string)));
  39.     $return '<table>';
  40.     for ($i = 0; $i (count($data_lines))$i++{
  41.         $return .= '<TR><TD width="30" valign="top">' ($i + 1'.</TD><TD>' $data_lines[$i'</TD></TR>';
  42.     ;
  43.     echo $return '</TABLE>';
  44. ;
  45. // Test if the form is submitted or the code is too long
  46. if (!isset($_POST['submit']OR (strlen($_POST['RDF']> 10000)) {
  47.     ?>
  48.  
  49. <form method="post" action="<?php echo $_SERVER['SCRIPT_NAME'];
  50.     ?>"> 
  51. <p>This is an online demo of <a href="http://www.wiwiss.fu-berlin.de/suhl/bizer/rdfapi/index.html">RAP - RDF API for PHP V0.8</a> . You can paste RDF code into the text field below and choose how the data should be processed. It's possible to parse, serialize, reify and query the data.</p>
  52. <p>The size of your RDF code is limited to 10.000 characters, due to resource restrictions.</p>
  53. <H3>Please paste RDF code here:</H3>
  54.  
  55. <?php 
  56.     // Show error message if the rdf is too long
  57.     if ((isset($_POST['submit']AND (strlen($_POST['RDF']> 10000))) {
  58.         echo "<center><h2>We're sorry, but your RDF is bigger than the allowed size</h2></center>";
  59.     
  60.     // //////////////////////////////////////////////////////////////////
  61.     // Show input form
  62.     // //////////////////////////////////////////////////////////////////
  63.     ?>
  64. <p><textarea cols="100" rows="20" name="RDF"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  65. xmlns:dc="http://purl.org/dc/elements/1.1/"
  66. xmlns:ex="http://example.org/stuff/1.0/"
  67. xmlns:s="http://description.org/schema/">
  68. <rdf:Description rdf:about="http://www.w3.org/Home/Lassila">
  69. <s:Creator>
  70. <rdf:Description rdf:nodeID="b85740">
  71. <rdf:type rdf:resource="http://description.org/schema/Person"/>
  72. <ex:Name rdf:datatype="http://www.w3.org/TR/xmlschema-2#name">Ora Lassila</ex:Name>
  73. <ex:Email rdf:datatype="http://www.w3.org/TR/xmlschema-2#string">lassila@w3.org</ex:Email>
  74. </rdf:Description>
  75. </s:Creator>
  76. </rdf:Description>
  77. </rdf:RDF></textarea>
  78.         <br />
  79.       </p>
  80.       <H3>Please choose the output format(s):</H3>
  81.       <table width="70%" border="0" cellspacing="0" cellpadding="0">
  82.         <tr> 
  83.           <td > <div align="center"> 
  84.               <input name="view_triple" type="checkbox" id="view_triple" value="1" checked>
  85.             </div></td>
  86.           <td><strong>Table with RDF triples.</strong></td>
  87.         </tr>
  88.         <tr> 
  89.           <td>&nbsp;</td>
  90.           <td>&nbsp;</td>
  91.         </tr>
  92.         <tr> 
  93.           <td> <div align="center"> 
  94.               <input name="serialize" type="checkbox" id="serialize" value="1" checked>
  95.             </div></td>
  96.           <td><strong>Serialize model back to RDF.</strong></td>
  97.         </tr>
  98.         <TR><TD></TD><TD><table>
  99.                 <tr> 
  100.           <td><div align="center"> 
  101.               <input name="serial_attributes" type="checkbox" id="serial_attributes" value="1">
  102.             </div></td>
  103.           <td>Serialize to RDF using attributes for RDF properties whereever possible.</td>
  104.         </tr>
  105.         <tr> 
  106.           <td><div align="center"> 
  107.               <input name="serial_entities" type="checkbox" id="serial_entities" value="1">
  108.             </div></td>
  109.           <td>Serialize to RDF using XML entities for URIs.</td>
  110.         </tr>
  111.         <tr> 
  112.           <td><div align="center"> 
  113.               <input name="serial_wo_qnames" type="checkbox" id="serial_wo_qnames" value="1">
  114.             </div></td>
  115.           <td>Serialize to RDF without qnames for RDF tags.</td>
  116.         </tr>
  117.         </table>        
  118.         </TD></TR>
  119.         <tr> 
  120.           <td>&nbsp;</td>
  121.           <td>&nbsp;</td>
  122.         </tr>
  123.         <tr> 
  124.           <td><div align="center">
  125.               <input name="view_dump" type="checkbox" id="view_dump" value="1">
  126.             </div></td>
  127.           <td><strong>toSting: Output the model as text.</strong></td>
  128.         </tr>
  129.         <tr> 
  130.           <td>&nbsp;</td>
  131.           <td>&nbsp;</td>
  132.         </tr>
  133.         <tr> 
  134.           <td><div align="center"> 
  135.               <input name="reify" type="checkbox" id="reify" value="1">
  136.             </div></td>
  137.           <td> <strong>Reify the input model before output.</strong></td>
  138.         </tr>
  139.         <tr> 
  140.           <td>&nbsp;</td>
  141.           <td>&nbsp;</td>
  142.         </tr>
  143.         <tr> 
  144.           <td><div align="center"> </div></td>
  145.           <td><strong>Query model (&quot;blank&quot; will match 
  146.             anything):</strong></td>
  147.         </tr>
  148.         <tr>
  149.           <td>&nbsp;</td>
  150.           <td><br>
  151.             <table width="99%" border="0" cellspacing="0" cellpadding="0">
  152.               <tr> 
  153.                 <td width="21%" > <div align="left">Subject:</div></td>
  154.                 <td width="79%"><input name="query_subject" type="text" id="query_subject2" size="50">
  155.                   <select name="subject_kind" id="object_kind">
  156.                     <option value="resource" selected>Resource</option>
  157.                     <option value="bnode">BlankNode</option>
  158.                   </select></td>
  159.               </tr>
  160.               <tr> 
  161.                 <td >Predicate:</td>
  162.                 <td><input name="query_predicate" type="text" id="query_predicate2" size="50"></td>
  163.               </tr>
  164.               <tr> 
  165.                 <td >Object:</td>
  166.                 <td><input name="query_object" type="text" id="query_object2" size="50">
  167.                   <select name="object_kind" id="object_kind">
  168.                     <option value="resource" selected>Resource</option>
  169.                     <option value="literal">Literal</option>
  170.                     <option value="bnode">BlankNode</option>
  171.                   </select>
  172.                   <br>Object datatype: <input name="query_object_datatype" type="text" id="query_object_datatype2" size="47">
  173.                   </td>
  174.               </tr>
  175.             </table></td>
  176.         </tr>
  177.       </table>
  178.       <p><br />
  179.         <br />        
  180.         <input type="submit" name="submit" value="submit me!">
  181.       </p>
  182.       </form>
  183. <?php
  184. else {
  185.     // ///////////////////////////////////////////////////////////////
  186.     // Process RDF
  187.     // (if submitted and RDF smaller than 10000 chars)
  188.     // ///////////////////////////////////////////////////////////////
  189.     require_once 'RDF.php';
  190.     require_once 'RDF/Model/Memory.php';
  191.     // Prepare RDF
  192.     $rdfInput stripslashes($_POST['RDF']);
  193.     // Show the submitted RDF
  194.     echo "<BR><H3>Your original RDF input:</h3><BR>";
  195.     echo_string_with_linenumbers($rdfInput);
  196.     // Create a new Model_Memory
  197.     $model =new RDF_Model_Memory();
  198.     // Load and parse document
  199.     $parser =new RDF_Parser();
  200.     $model =$parser->generateModel($rdfInput);
  201.     // Set the base URI of the model
  202.     $model->setBaseURI("http://www3.wiwiss.fu-berlin.de" $_SERVER['SCRIPT_NAME'"/DemoModel#");
  203.     // Execute query on model if submitted
  204.     if ($_POST['query_subject'!= '' OR $_POST['query_predicate'!= '' OR $_POST['query_object'!= ''{
  205.         $comment_string "<BR><H3>The following query has been executed:</H3><BR>";
  206.  
  207.         $query_subj = null;
  208.         $query_pred = null;
  209.         $query_obj = null;
  210.  
  211.         if ($_POST['query_subject'!= ''{
  212.             if ($_POST['subject_kind'== 'resource'{
  213.                 $query_subj =RDF_Resource::factory($_POST['query_subject']);
  214.             else {
  215.                 $query_subj =RDF_BlankNode::factory($_POST['query_subject']);
  216.             
  217.             $comment_string .= "Subject = " $_POST['query_subject'"<BR>";
  218.         ;
  219.  
  220.         if ($_POST['query_predicate'!= ''{
  221.             $query_pred =RDF_Resource::factory($_POST['query_predicate']);
  222.             $comment_string .= "Predicate = " $_POST['query_predicate'"<BR>";
  223.         ;
  224.  
  225.         if ($_POST['query_object'!= ''{
  226.             if ($_POST['object_kind'== 'resource'{
  227.                 $query_obj =RDF_Resource::factory($_POST['query_object']);
  228.             elseif ($_POST['object_kind'== 'literal'{
  229.                 $query_obj =RDF_Literal::factory($_POST['query_object']);
  230.                 if ($_POST['query_object_datatype'!= ''{
  231.                     $query_obj->setDatatype($_POST['query_object_datatype']);
  232.                 
  233.             else {
  234.                 $query_obj =RDF_BlankNode::factory($_POST['query_object']);
  235.             ;
  236.             $comment_string .= "Object = " $_POST['query_object'"<BR>";
  237.         
  238.         // Execute query and display what has been done
  239.         $model $model->find($query_subj$query_pred$query_obj);
  240.         echo $comment_string;
  241.     
  242.     // Reify the model if checked in submitted form
  243.     if (isset($_POST['reify']and $_POST['reify'== "1"{
  244.         $model =$model->reify();
  245.         echo "<BR><BR><h3>Your original model has been refied.</h3><BR>";
  246.     ;
  247.     // Output Triples as Table if checked in submitted form
  248.     if ($_POST['view_triple'== "1"{
  249.         echo "<BR><BR><h3>View input as HTML table:</h3><BR>";
  250.         RDF_Util::writeHTMLTable($model);
  251.         echo "<P>";
  252.     ;
  253.     // serialize model to RDF with default configuration if checked in submitted form
  254.     if ($_POST['serialize'== '1'{
  255.         // Create Serializer
  256.         $ser =new RDF_Serializer();
  257.         $msg_string '';
  258.         if (isset($_POST['serial_attributes']and $_POST['serial_attributes'== '1'{
  259.             $ser->configUseAttributes(true);
  260.             $msg_string .= 'Use Attributes ';
  261.         ;
  262.         if (isset($_POST['serial_entities']and $_POST['serial_entities'== '1'{
  263.             $ser->configUseEntities(true);
  264.             $msg_string .= 'Use XML Entities ';
  265.         ;
  266.         if (isset($_POST['serial_wo_qnames']and $_POST['serial_wo_qnames'== '1'{
  267.             $ser->configUseQnames(false);
  268.             $msg_string .= 'Without Qnames ';
  269.         ;
  270.         $rdf =$ser->serialize($model);
  271.         echo "<p><BR><h3>Serialization of input model";
  272.         if (isset($msg_string)) echo " (Options: " $msg_string ")";
  273.         echo ":</h3>";
  274.         echo_string_with_linenumbers($rdf);
  275.     ;
  276.     // Show dump of the model including triples if submitted in form
  277.     if (isset($_POST['view_dump']and $_POST['view_dump'== '1'{
  278.         echo "<BR><BR><h3>Dump of the model including triples</h3>";
  279.         echo_string_with_linenumbers($model->toStringIncludingTriples());
  280.     ;
  281.  
  282.     ?> <center><a href="<?php echo $_SERVER['SCRIPT_NAME'?>"><h2>Go back to input form.</h2></a></center><?php
  283. // end of "form submitted"
  284.  
  285. ?>
  286.  
  287. <BR><H1>Feedback</H1>
  288.  
  289. </p>
  290.     <p>Please send bug reports and other comments to <a href="mailto:chris@bizer.de">Chris Bizer</a>.<br>
  291. </p></body>
  292. </html>

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