*/ echo "

RAP Tutorial

"; // Include all RAP classes // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!! This should reflect your own installation !!!!!!!!!!!!!!!!!!! // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! define("RDFAPI_INCLUDE_DIR", "C:/Apache/htdocs/rdf_api/api/"); include(RDFAPI_INCLUDE_DIR . "RdfAPI.php"); include(RDFAPI_INCLUDE_DIR . PACKAGE_VOCABULARY); // Create subject and predicate of $statement1 $someDoc = new Resource ("http://www.example.org/someDocument.html"); $creator = new Resource ("http://www.purl.org/dc/elements/1.1/creator"); // Create and instance of object Statement with subject, predicate and object // passed to the creator function. $statement1 = new Statement ($someDoc, $creator, new Literal ("Radoslaw Oldakowski")); // Create a new MemModel $model1 = ModelFactory::getDefaultModel(); // Add the statement $statement1 to the model $model1 $model1->add($statement1); // Create second MemModel $model2 = new MemModel(); // Add two statements to $model2 $model2->add(new Statement($someDoc, new Resource("http://www.example.org/myVocabulary/title"), new Literal("RAP tutorial"))); $model2->add(new Statement($someDoc, new Resource("http://www.example.org/myVocabulary/language"), new Literal("English"))); // Add the second model ($model2) to the first one ($model1) $model1->addModel($model2); // Check the size of $model1 echo "

Section 3, output the size of the MemModel:

"; echo "\$model1 contains " .$model1->size() ." statements
"; echo "
"; // Output $model1 as HTML table echo "


Section 4, output the MemModel as HTML table:

"; $model1->writeAsHtmlTable(); // Output the string serialization of $model1 echo "


Section 4, output the plain text serialization of the MemModel:

"; echo $model1->toStringIncludingTriples(); // Output the RDF/XML serialization of $model1 echo "


Section 4, output the RDF/XML serialization of the MemModel:

"; echo $model1->writeAsHtml(); echo "

"; // Save the model to file in RDF/XML and N3 $model1->saveAs("model1.rdf", "rdf"); $model1->saveAs("model1.n3", "n3"); // Replace the Literal for a BlankNode $bNode = new BlankNode($model1); $model1->replace(NULL, NULL, new Literal("Radoslaw Oldakowski"), $bNode); // Add statements describing the BlankNode using pre-defined vCard vocabulary $model1->add(new Statement($bNode, $VCARD_FN, new Literal("Radoslaw Oldakowski"))); $model1->add(new Statement($bNode, $VCARD_EMAIL, new Literal("radol@gmx.de"))); // Create a new literal, its datatype and then add it to the MemModel $model1 $age = new Literal("26"); $age->setDatatype("http://www.w3.org/TR/xmlschema-2/integer"); $model1->add(new Statement ($bNode, new Resource("http://www.example.org/myVocabulary/age"), $age)); // Create a statement iterator for $model1 $it = $model2->getStatementIterator(); // Use the iterator to output the string serialization of all statements // Traverse model and output statements echo "


Section 8, traverse the Model:

"; while ($it->hasNext()) { $statement = $it->next(); echo "Statement number: " . $it->getCurrentPosition() . "
"; echo "Subject: " . $statement->getLabelSubject() . "
"; echo "Predicate: " . $statement->getLabelPredicate() . "
"; echo "Object: " . $statement->getLabelObject() . "

"; } echo "
"; // Find all statements having subject equal $someDoc and print the result as HTML table echo "


Section 10, find statements:

"; $result = $model1->find($someDoc, NULL, NULL); $result->writeAsHtmlTable(); echo "

"; // Reify all statements of $model2 and show the corresponding reified model as HTML table echo "


Section 11, output the reified Model:

"; $reified = $model2->reify(); $reified->writeAsHtmlTable(); // Close all MemModels used in this tutorial $model1->close(); $model2->close(); $result->close(); $reified->close(); ?>