Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
easyrdf/examples/graph_direct.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
48 lines (41 sloc)
1.71 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Using EasyRdf\Graph directly without EasyRdf\Resource | |
* | |
* Triple data is inserted and retrieved directly from a graph object, | |
* where it is stored internally as an associative array. | |
* | |
* @package EasyRdf | |
* @copyright Copyright (c) 2009-2014 Nicholas J Humfrey | |
* @license http://unlicense.org/ | |
*/ | |
require_once realpath(__DIR__.'/..')."/vendor/autoload.php"; | |
?> | |
<html> | |
<head> | |
<title>Example of using EasyRdf\Graph directly</title> | |
</head> | |
<body> | |
<?php | |
$graph = new \EasyRdf\Graph(); | |
$graph->addResource("http://example.com/joe", "rdf:type", "foaf:Person"); | |
$graph->addLiteral("http://example.com/joe", "foaf:name", "Joe Bloggs"); | |
$graph->addLiteral("http://example.com/joe", "foaf:name", "Joseph Bloggs"); | |
$graph->add("http://example.com/joe", "rdfs:label", "Joe"); | |
$graph->setType("http://njh.me/", "foaf:Person"); | |
$graph->add("http://njh.me/", "rdfs:label", "Nick"); | |
$graph->addLiteral("http://njh.me/", "foaf:name", "Nicholas Humfrey"); | |
$graph->addResource("http://njh.me/", "foaf:homepage", "http://www.aelius.com/njh/"); | |
?> | |
<p> | |
<b>Name:</b> <?= $graph->get("http://example.com/joe", "foaf:name") ?> <br /> | |
<b>Names:</b> <?= $graph->join("http://example.com/joe", "foaf:name") ?> <br /> | |
<b>Label:</b> <?= $graph->label("http://njh.me/") ?> <br /> | |
<b>Properties:</b> <?= join(', ', $graph->properties("http://example.com/joe")) ?> <br /> | |
<b>PropertyUris:</b> <?= join(', ', $graph->propertyUris("http://example.com/joe")) ?> <br /> | |
<b>People:</b> <?= join(', ', $graph->allOfType('foaf:Person')) ?> <br /> | |
<b>Unknown:</b> <?= $graph->get("http://example.com/joe", "unknown:property") ?> <br /> | |
</p> | |
<?= $graph->dump() ?> | |
</body> | |
</html> |