/**
  * @Route("/create-person")
  */
 public function createPersonAction()
 {
     \EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Arc');
     \EasyRdf_Format::registerSerialiser('posh', 'EasyRdf_Serialiser_Arc');
     \EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Arc');
     \EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Arc');
     \EasyRdf_Namespace::set('foaf', 'http://xmlns.com/foaf/0.1/');
     $uri = 'http://www.example.com/emi#me';
     $name = 'Emi Berea';
     $emailStr = '*****@*****.**';
     $homepageStr = 'http://bereae.me/';
     $graph = new \EasyRdf_Graph();
     # 1st Technique
     $me = $graph->resource($uri, 'foaf:Person');
     $me->set('foaf:name', $name);
     if ($emailStr) {
         $email = $graph->resource("mailto:" . $emailStr);
         $me->add('foaf:mbox', $email);
     }
     if ($homepageStr) {
         $homepage = $graph->resource($homepageStr);
         $me->add('foaf:homepage', $homepage);
     }
     # Finally output the graph
     $data = $graph->serialise('rdfxml');
     if (!is_scalar($data)) {
         $data = var_export($data, true);
     }
     var_dump($data);
     die;
 }
 public function setUp()
 {
     EasyRdf_Http::setDefaultHttpClient($this->_client = new EasyRdf_Http_MockClient());
     $this->_graphStore = new EasyRdf_GraphStore('http://localhost:8080/data/');
     // Ensure that the built-in n-triples parser is used
     EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Ntriples');
 }
예제 #3
0
 public function __construct(EasyRdf_Graph $graph = null)
 {
     if ($graph === null) {
         $graph = new EasyRdf_Graph();
     }
     $this->graph = $graph;
     $this->uriGenerators = array();
     EasyRdf_Format::register('rdfxml', 'RDF/XML', 'http://www.w3.org/TR/rdf-syntax-grammar', 'application/rdf+xml');
     //EasyRdf_Format::registerParser( 'rdfxml', 'EasyRdf_Parser_RdfXml');
     EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_RdfXml');
 }
예제 #4
0
파일: Format.php 프로젝트: ASDAFF/myprofile
EasyRdf_Format::register('turtle', 'Turtle Terse RDF Triple Language', 'http://www.dajobe.org/2004/01/turtle', array('text/turtle' => 0.8, 'application/turtle' => 0.7, 'application/x-turtle' => 0.7), array('ttl'));
EasyRdf_Format::register('rdfxml', 'RDF/XML', 'http://www.w3.org/TR/rdf-syntax-grammar', array('application/rdf+xml' => 0.8), array('rdf', 'xrdf'));
EasyRdf_Format::register('dot', 'Graphviz', 'http://www.graphviz.org/doc/info/lang.html', array('text/vnd.graphviz' => 0.8), array('gv', 'dot'));
EasyRdf_Format::register('json-triples', 'RDF/JSON Triples');
EasyRdf_Format::register('n3', 'Notation3', 'http://www.w3.org/2000/10/swap/grammar/n3#', array('text/n3' => 0.5, 'text/rdf+n3' => 0.5), array('n3'));
EasyRdf_Format::register('rdfa', 'RDFa', 'http://www.w3.org/TR/rdfa-core/', array('text/html' => 0.4, 'application/xhtml+xml' => 0.4), array('html'));
EasyRdf_Format::register('sparql-xml', 'SPARQL XML Query Results', 'http://www.w3.org/TR/rdf-sparql-XMLres/', array('application/sparql-results+xml' => 1.0));
EasyRdf_Format::register('sparql-json', 'SPARQL JSON Query Results', 'http://www.w3.org/TR/rdf-sparql-json-res/', array('application/sparql-results+json' => 1.0));
EasyRdf_Format::register('png', 'Portable Network Graphics (PNG)', 'http://www.w3.org/TR/PNG/', array('image/png' => 0.3), array('png'));
EasyRdf_Format::register('gif', 'Graphics Interchange Format (GIF)', 'http://www.w3.org/Graphics/GIF/spec-gif89a.txt', array('image/gif' => 0.2), array('gif'));
EasyRdf_Format::register('svg', 'Scalable Vector Graphics (SVG)', 'http://www.w3.org/TR/SVG/', array('image/svg+xml' => 0.3), array('svg'));
/*
   Register default set of parsers and serialisers
*/
EasyRdf_Format::registerParser('json', 'EasyRdf_Parser_Json');
EasyRdf_Format::registerParser('ntriples', 'EasyRdf_Parser_Ntriples');
EasyRdf_Format::registerParser('php', 'EasyRdf_Parser_RdfPhp');
EasyRdf_Format::registerParser('rdfxml', 'EasyRdf_Parser_RdfXml');
EasyRdf_Format::registerParser('turtle', 'EasyRdf_Parser_Turtle');
EasyRdf_Format::registerParser('rdfa', 'EasyRdf_Parser_Rdfa');
EasyRdf_Format::registerSerialiser('json', 'EasyRdf_Serialiser_Json');
EasyRdf_Format::registerSerialiser('n3', 'EasyRdf_Serialiser_Turtle');
EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Ntriples');
EasyRdf_Format::registerSerialiser('php', 'EasyRdf_Serialiser_RdfPhp');
EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_RdfXml');
EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Turtle');
EasyRdf_Format::registerSerialiser('dot', 'EasyRdf_Serialiser_GraphViz');
EasyRdf_Format::registerSerialiser('gif', 'EasyRdf_Serialiser_GraphViz');
EasyRdf_Format::registerSerialiser('png', 'EasyRdf_Serialiser_GraphViz');
EasyRdf_Format::registerSerialiser('svg', 'EasyRdf_Serialiser_GraphViz');
        /* not defined => ignore */
    }
    /**
     * Serialise an EasyRdf_Graph into N-Triples
     *
     * @param object EasyRdf_Graph $graph   An EasyRdf_Graph object.
     * @param string  $format               The name of the format to convert to.
     * @return string                       The RDF in the new desired format.
     */
    public function serialise($graph, $format)
    {
        parent::checkSerialiseParams($graph, $format);
        if ($format != 'ntriples') {
            throw new EasyRdf_Exception("EasyRdf_Serialiser_Ntriples does not support: {$format}");
        }
        $nt = '';
        foreach ($graph->resources() as $resource) {
            foreach ($resource->propertyUris() as $property) {
                $objects = $resource->all($property);
                foreach ($objects as $object) {
                    $nt .= $this->ntriplesResource($resource) . " ";
                    $nt .= "<" . $this->escape($property) . "> ";
                    $nt .= $this->ntriplesObject($object) . " .\n";
                }
            }
        }
        return $nt;
    }
}
EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Ntriples');
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
require_once "html_tag_helpers.php";
if (isset($_REQUEST['enable_arc']) && $_REQUEST['enable_arc']) {
    require_once "EasyRdf/Serialiser/Arc.php";
    EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Arc');
    EasyRdf_Format::registerSerialiser('posh', 'EasyRdf_Serialiser_Arc');
    EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Arc');
    EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Arc');
}
if (isset($_REQUEST['enable_rapper']) && $_REQUEST['enable_rapper']) {
    require_once "EasyRdf/Serialiser/Rapper.php";
    EasyRdf_Format::registerSerialiser('dot', 'EasyRdf_Serialiser_Rapper');
    EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Rapper');
    EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Rapper');
}
$format_options = array();
foreach (EasyRdf_Format::getFormats() as $format) {
    if ($format->getSerialiserClass()) {
        $format_options[$format->getLabel()] = $format->getName();
    }
}
?>
<html>
<head><title>EasyRdf FOAF Maker Example</title></head>
<body>
<h1>EasyRdf FOAF Maker Example</h1>

<?php 
echo form_tag(null, array('method' => 'POST'));
예제 #7
0
파일: Arc.php 프로젝트: Tjorriemorrie/app
    }
    /**
     * Serialise an EasyRdf_Graph into RDF format of choice.
     *
     * @param object EasyRdf_Graph $graph   An EasyRdf_Graph object.
     * @param string               $format  The name of the format to convert to.
     * @return string              The RDF in the new desired format.
     */
    public function serialise($graph, $format)
    {
        parent::checkSerialiseParams($graph, $format);
        if (array_key_exists($format, self::$_supportedTypes)) {
            $className = self::$_supportedTypes[$format];
        } else {
            throw new EasyRdf_Exception("EasyRdf_Serialiser_Arc does not support: {$format}");
        }
        $serialiser = ARC2::getSer($className);
        if ($serialiser) {
            return $serialiser->getSerializedIndex(parent::serialise($graph, 'php'));
        } else {
            throw new EasyRdf_Exception("ARC2 failed to get a {$className} serialiser.");
        }
    }
}
# FIXME: to this automatically
EasyRdf_Format::register('posh', 'poshRDF');
EasyRdf_Format::registerSerialiser('ntriples', 'EasyRdf_Serialiser_Arc');
EasyRdf_Format::registerSerialiser('posh', 'EasyRdf_Serialiser_Arc');
EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Arc');
EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Arc');
 */
class EasyRdf_Serialiser_RdfPhp extends EasyRdf_Serialiser
{
    /**
     * Serialise an EasyRdf_Graph into RDF format of choice.
     *
     * @param string $graph An EasyRdf_Graph object.
     * @param string $format The name of the format to convert to.
     * @return string The RDF in the new desired format.
     */
    /**
     * Method to serialise an EasyRdf_Graph to RDF/PHP
     *
     * http://n2.talis.com/wiki/RDF_PHP_Specification
     *
     * @param object EasyRdf_Graph $graph   An EasyRdf_Graph object.
     * @param string  $format               The name of the format to convert to.
     * @return string                       The RDF in the new desired format.
     */
    public function serialise($graph, $format)
    {
        parent::checkSerialiseParams($graph, $format);
        if ($format != 'php') {
            throw new EasyRdf_Exception("EasyRdf_Serialiser_RdfPhp does not support: {$format}");
        }
        // Graph is already stored an RDF/PHP resource-centric array internally within the EasyRdf_Graph object
        return $graph->toArray();
    }
}
EasyRdf_Format::registerSerialiser('php', 'EasyRdf_Serialiser_RdfPhp');
 public function testSerialiseByMime()
 {
     EasyRdf_Format::registerSerialiser('mock', 'Mock_RdfSerialiser');
     EasyRdf_Format::register('mock', 'Mock', null, array('mock/mime' => 1.0));
     $graph = new EasyRdf_Graph();
     $this->assertEquals("<rdf></rdf>", $graph->serialise('mock/mime'));
 }
            return strcmp($a['o'], $b['o']);
        } else {
            return 0;
        }
    }
    /**
     * Serialise an EasyRdf_Graph into an array of N-Triples objects
     *
     * @param object EasyRdf_Graph $graph   An EasyRdf_Graph object.
     * @param string  $format               The name of the format to convert to.
     * @return string                       The RDF in the new desired format.
     */
    public function serialise($graph, $format)
    {
        parent::checkSerialiseParams($graph, $format);
        $triples = array();
        foreach ($graph->toArray() as $resource => $properties) {
            foreach ($properties as $property => $values) {
                foreach ($values as $value) {
                    array_push($triples, array('s' => $this->ntriplesResource($resource), 'p' => "<" . $this->escapeString($property) . ">", 'o' => $this->ntriplesValue($value)));
                }
            }
        }
        // Sort the triples into a consistent order
        usort($triples, array($this, 'compareTriples'));
        return $triples;
    }
}
EasyRdf_Format::register('ntriples-array', 'PHP Array of Triples');
EasyRdf_Format::registerSerialiser('ntriples-array', 'EasyRdf_Serialiser_NtriplesArray');
예제 #11
0
 public function testRegisterSerialiserForUnknownFormat()
 {
     EasyRdf_Format::registerSerialiser('testRegisterSerialiser', 'MockSerialiserClass');
     $format = EasyRdf_Format::getFormat('testRegisterSerialiser');
     $this->assertNotNull($format);
     $this->assertEquals('MockSerialiserClass', $format->getSerialiserClass());
 }
예제 #12
0
파일: Json.php 프로젝트: Tjorriemorrie/app
 */
/**
 * Class to serialise an EasyRdf_Graph to RDF/JSON
 * with no external dependancies.
 *
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2010 Nicholas J Humfrey
 * @license    http://www.opensource.org/licenses/bsd-license.php
 */
class EasyRdf_Serialiser_Json extends EasyRdf_Serialiser_RdfPhp
{
    /**
     * Method to serialise an EasyRdf_Graph to RDF/JSON
     *
     * http://n2.talis.com/wiki/RDF_JSON_Specification
     *
     * @param object EasyRdf_Graph $graph   An EasyRdf_Graph object.
     * @param string  $format               The name of the format to convert to.
     * @return string                       The RDF in the new desired format.
     */
    public function serialise($graph, $format)
    {
        parent::checkSerialiseParams($graph, $format);
        if ($format != 'json') {
            throw new EasyRdf_Exception("EasyRdf_Serialiser_Json does not support: {$format}");
        }
        return json_encode(parent::serialise($graph, 'php'));
    }
}
EasyRdf_Format::registerSerialiser('json', 'EasyRdf_Serialiser_Json');
예제 #13
0
     * @param string  $format               The name of the format to convert to.
     * @return string                       The RDF in the new desired format.
     */
    public function serialise($graph, $format)
    {
        parent::checkSerialiseParams($graph, $format);
        if ($format != 'rdfxml') {
            throw new EasyRdf_Exception("EasyRdf_Serialiser_RdfXml does not support: {$format}");
        }
        // store of namespaces to be appended to the rdf:RDF tag
        $this->_prefixes = array('rdf' => true);
        // store of the resource URIs we have serialised
        $this->_outputtedResources = array();
        $xml = '';
        foreach ($graph->resources() as $resource) {
            $xml .= $this->rdfxmlResource($resource, true, 1);
        }
        // iterate through namepsaces array prefix and output a string.
        $namespaceStr = '';
        foreach ($this->_prefixes as $prefix => $count) {
            $url = EasyRdf_Namespace::get($prefix);
            if (strlen($namespaceStr)) {
                $namespaceStr .= "\n        ";
            }
            $namespaceStr .= ' xmlns:' . $prefix . '="' . htmlspecialchars($url) . '"';
        }
        return "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" . "<rdf:RDF" . $namespaceStr . ">\n" . $xml . "\n</rdf:RDF>\n";
    }
}
EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_RdfXml');