Source for file custom_test.php
Documentation is available at custom_test.php
// ----------------------------------------------------------------------------------
// PHP Script: custom_test.php
// ----------------------------------------------------------------------------------
* This is an online demo of RDF API for PHP.
* 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.
* The size of your RDF code is limited to 10.000 characters, due to resource restrictions.
* @author Chris Bizer <chris@bizer.de>
* @autor Seairth Jacobs <seairth@seairth.com>
* @author Daniel Westphal <dawe@gmx.de>
<title>RAP - RDF API for PHP online demo</title>
<link href="phpdoc.css" rel="stylesheet" type="text/css">
<table width="100%" border="0">
<TD align=left vAlign=top>
<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>
<a href="http://www.php.net" target="_blank"><img src="php_logo.gif" width="120" height="64" border="0" alt="PHP Logo"></a></div>
<H1>Online API Demo</H1><BR>
// Function: Output a string with line numbers
$input_string = str_replace (" ", " ", $input_string);
for ($i = 0; $i < (count($data_lines)); $i++ ) {
$return .= '<TR><TD width="30" valign="top">' . ($i + 1 ) . '.</TD><TD>' . $data_lines[$i] . '</TD></TR>';
echo $return . '</TABLE>';
// Test if the form is submitted or the code is too long
if (!isset ($_POST['submit']) OR (strlen($_POST['RDF']) > 10000 )) {
<form method="post" action=" <?php echo $_SERVER['SCRIPT_NAME'];
<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>
<p>The size of your RDF code is limited to 10.000 characters, due to resource restrictions.</p>
<H3>Please paste RDF code here:</H3>
// Show error message if the rdf is too long
if ((isset ($_POST['submit']) AND (strlen($_POST['RDF']) > 10000 ))) {
echo "<center><h2>We're sorry, but your RDF is bigger than the allowed size</h2></center>";
// //////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////
<p><textarea cols="100" rows="20" name="RDF"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:ex="http://example.org/stuff/1.0/"
xmlns:s="http://description.org/schema/">
<rdf:Description rdf:about="http://www.w3.org/Home/Lassila">
<rdf:Description rdf:nodeID="b85740">
<rdf:type rdf:resource="http://description.org/schema/Person"/>
<ex:Name rdf:datatype="http://www.w3.org/TR/xmlschema-2#name">Ora Lassila</ex:Name>
<ex:Email rdf:datatype="http://www.w3.org/TR/xmlschema-2#string">lassila@w3.org</ex:Email>
<H3>Please choose the output format(s):</H3>
<table width="70%" border="0" cellspacing="0" cellpadding="0">
<td > <div align="center">
<input name="view_triple" type="checkbox" id="view_triple" value="1" checked>
<td><strong>Table with RDF triples.</strong></td>
<td> <div align="center">
<input name="serialize" type="checkbox" id="serialize" value="1" checked>
<td><strong>Serialize model back to RDF.</strong></td>
<input name="serial_attributes" type="checkbox" id="serial_attributes" value="1">
<td>Serialize to RDF using attributes for RDF properties whereever possible.</td>
<input name="serial_entities" type="checkbox" id="serial_entities" value="1">
<td>Serialize to RDF using XML entities for URIs.</td>
<input name="serial_wo_qnames" type="checkbox" id="serial_wo_qnames" value="1">
<td>Serialize to RDF without qnames for RDF tags.</td>
<input name="view_dump" type="checkbox" id="view_dump" value="1">
<td><strong>toSting: Output the model as text.</strong></td>
<input name="reify" type="checkbox" id="reify" value="1">
<td> <strong>Reify the input model before output.</strong></td>
<td><div align="center"> </div></td>
<td><strong>Query model ("blank" will match
<table width="99%" border="0" cellspacing="0" cellpadding="0">
<td width="21%" > <div align="left">Subject:</div></td>
<td width="79%"><input name="query_subject" type="text" id="query_subject2" size="50">
<select name="subject_kind" id="object_kind">
<option value="resource" selected>Resource</option>
<option value="bnode">BlankNode</option>
<td><input name="query_predicate" type="text" id="query_predicate2" size="50"></td>
<td><input name="query_object" type="text" id="query_object2" size="50">
<select name="object_kind" id="object_kind">
<option value="resource" selected>Resource</option>
<option value="literal">Literal</option>
<option value="bnode">BlankNode</option>
<br>Object datatype: <input name="query_object_datatype" type="text" id="query_object_datatype2" size="47">
<input type="submit" name="submit" value="submit me!">
// ///////////////////////////////////////////////////////////////
// (if submitted and RDF smaller than 10000 chars)
// ///////////////////////////////////////////////////////////////
require_once 'RDF/Model/Memory.php';
// Show the submitted RDF
echo "<BR><H3>Your original RDF input:</h3><BR>";
// Create a new Model_Memory
// Load and parse document
$model = & $parser->generateModel ($rdfInput);
// Set the base URI of the model
$model->setBaseURI ("http://www3.wiwiss.fu-berlin.de" . $_SERVER['SCRIPT_NAME'] . "/DemoModel#");
// Execute query on model if submitted
if ($_POST['query_subject'] != '' OR $_POST['query_predicate'] != '' OR $_POST['query_object'] != '') {
$comment_string = "<BR><H3>The following query has been executed:</H3><BR>";
if ($_POST['query_subject'] != '') {
if ($_POST['subject_kind'] == 'resource') {
$comment_string .= "Subject = " . $_POST['query_subject'] . "<BR>";
if ($_POST['query_predicate'] != '') {
$comment_string .= "Predicate = " . $_POST['query_predicate'] . "<BR>";
if ($_POST['query_object'] != '') {
if ($_POST['object_kind'] == 'resource') {
} elseif ($_POST['object_kind'] == 'literal') {
if ($_POST['query_object_datatype'] != '') {
$query_obj->setDatatype ($_POST['query_object_datatype']);
$comment_string .= "Object = " . $_POST['query_object'] . "<BR>";
// Execute query and display what has been done
$model = $model->find ($query_subj, $query_pred, $query_obj);
// Reify the model if checked in submitted form
if (isset ($_POST['reify']) and $_POST['reify'] == "1") {
$model = & $model->reify ();
echo "<BR><BR><h3>Your original model has been refied.</h3><BR>";
// Output Triples as Table if checked in submitted form
if ($_POST['view_triple'] == "1") {
echo "<BR><BR><h3>View input as HTML table:</h3><BR>";
// serialize model to RDF with default configuration if checked in submitted form
if ($_POST['serialize'] == '1') {
if (isset ($_POST['serial_attributes']) and $_POST['serial_attributes'] == '1') {
$ser->configUseAttributes (true );
$msg_string .= 'Use Attributes ';
if (isset ($_POST['serial_entities']) and $_POST['serial_entities'] == '1') {
$ser->configUseEntities (true );
$msg_string .= 'Use XML Entities ';
if (isset ($_POST['serial_wo_qnames']) and $_POST['serial_wo_qnames'] == '1') {
$ser->configUseQnames (false );
$msg_string .= 'Without Qnames ';
echo "<p><BR><h3>Serialization of input model";
if (isset ($msg_string)) echo " (Options: " . $msg_string . ")";
// Show dump of the model including triples if submitted in form
if (isset ($_POST['view_dump']) and $_POST['view_dump'] == '1') {
echo "<BR><BR><h3>Dump of the model including triples</h3>";
?> <center><a href=" <?php echo $_SERVER['SCRIPT_NAME'] ?>"><h2>Go back to input form.</h2></a></center> <?php
} // end of "form submitted"
<p>Please send bug reports and other comments to <a href="mailto:chris@bizer.de">Chris Bizer</a>.<br>
Documentation generated on Mon, 11 Mar 2019 15:39:28 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|