예제 #1
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');
 }
예제 #2
0
파일: Format.php 프로젝트: ASDAFF/myprofile
   NOTE: they are ordered by preference
*/
EasyRdf_Format::register('php', 'RDF/PHP', 'http://n2.talis.com/wiki/RDF_PHP_Specification');
EasyRdf_Format::register('json', 'RDF/JSON Resource-Centric', 'http://n2.talis.com/wiki/RDF_JSON_Specification', array('application/json' => 1.0, 'text/json' => 0.9, 'application/rdf+json' => 0.9), array('json'));
EasyRdf_Format::register('ntriples', 'N-Triples', 'http://www.w3.org/TR/rdf-testcases/#ntriples', array('text/plain' => 1.0, 'text/ntriples' => 0.9, 'application/ntriples' => 0.9, 'application/x-ntriples' => 0.9), array('nt'));
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');
예제 #3
0
        <>  a ldp:DirectContainer, foaf:Document ;
            foaf:primaryTopic :dataset ;
            ldp:membershipResource :dataset ;
            ldp:hasMemberRelation void:dataDump ;
            ldp:insertedContentRelation foaf:primaryTopic ;
            
        .
        :dataset a void:Dataset, prov:Entity ;
            prov:wasGeneratedBy [
                a prov:Activity ;
                prov:used <{queryResource}> ;
                prov:wasAssociatedWith :sparqlServerUser
            ]
        .
        :sparqlServerUser a foaf:Agent;
            foaf:account [
                a foaf:OnlineAccount ;
                foaf:accountServiceHomepage <{endpoint}> ;
                foaf:accountname "{username}" ;
            ]
        .
     ';
}
// fix a bug of Easy RDF
EasyRdf_Format::register('turtle', 'Turtle Terse RDF Triple Language', 'http://www.w3.org/TR/turtle/', array('text/turtle' => 1.0, 'application/turtle' => 0.7, 'application/x-turtle' => 0.7), array('ttl'));
$errorManager = BOTK\Core\ErrorManager::getInstance()->registerErrorHandler();
try {
    echo BOTK\Core\EndPointFactory::make('MyRouter')->run();
} catch (Exception $e) {
    echo $errorManager->render($e);
}
예제 #4
0
파일: Arc.php 프로젝트: aWEBoLabs/taxi
    public function __construct()
    {
        require_once 'arc/ARC2.php';
    }
    /**
     * Serialise an EasyRdf_Graph into RDF format of choice.
     *
     * @param EasyRdf_Graph $graph   An EasyRdf_Graph object.
     * @param string        $format  The name of the format to convert to.
     * @param array         $options
     * @throws EasyRdf_Exception
     * @return string              The RDF in the new desired format.
     */
    public function serialise($graph, $format, array $options = array())
    {
        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.");
        }
    }
}
EasyRdf_Format::register('posh', 'poshRDF');
 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'));
 }
        $process = proc_open(escapeshellcmd($this->_rapperCmd) . " --quiet " . " --input ntriples " . " --output " . escapeshellarg($format) . " - " . 'unknown://', $descriptorspec, $pipes, '/tmp', null);
        if (is_resource($process)) {
            // $pipes now looks like this:
            // 0 => writeable handle connected to child stdin
            // 1 => readable handle connected to child stdout
            // 2 => readable handle connected to child stderr
            fwrite($pipes[0], $ntriples);
            fclose($pipes[0]);
            $output = stream_get_contents($pipes[1]);
            fclose($pipes[1]);
            $error = stream_get_contents($pipes[2]);
            fclose($pipes[2]);
            // It is important that you close any pipes before calling
            // proc_close in order to avoid a deadlock
            $returnValue = proc_close($process);
            if ($returnValue) {
                throw new EasyRdf_Exception("Failed to convert RDF: " . $error);
            }
        } else {
            throw new EasyRdf_Exception("Failed to execute rapper command.");
        }
        return $output;
    }
}
// FIXME: do this automatically
EasyRdf_Format::register('dot', 'Graphviz');
EasyRdf_Format::register('json-triples', 'RDF/JSON Triples');
EasyRdf_Format::registerSerialiser('dot', 'EasyRdf_Serialiser_Rapper');
EasyRdf_Format::registerSerialiser('json-triples', 'EasyRdf_Serialiser_Rapper');
EasyRdf_Format::registerSerialiser('rdfxml', 'EasyRdf_Serialiser_Rapper');
EasyRdf_Format::registerSerialiser('turtle', 'EasyRdf_Serialiser_Rapper');
    public function newSerialiser()
    {
        $serialiserClass = $this->_serialiserClass;
        if (!$serialiserClass) {
            throw new EasyRdf_Exception("No serialiser class available for format: " . $this->getName());
        }
        return new $serialiserClass();
    }
    /** Magic method to return the name of the format when casted to string
     *
     * @return string The name of the format
     */
    public function __toString()
    {
        return $this->_name;
    }
}
/*
   Register default set of supported formats
   NOTE: they are ordered by preference
*/
EasyRdf_Format::register('php', 'RDF/PHP', 'http://n2.talis.com/wiki/RDF_PHP_Specification');
EasyRdf_Format::register('json', 'RDF/JSON Resource-Centric', 'http://n2.talis.com/wiki/RDF_JSON_Specification', array('application/json' => 1.0, 'text/json' => 0.9, 'application/rdf+json' => 0.9));
EasyRdf_Format::register('ntriples', 'N-Triples', 'http://www.w3.org/TR/rdf-testcases/#ntriples', array('text/plain' => 1.0, 'text/ntriples' => 0.9, 'application/ntriples' => 0.9, 'application/x-ntriples' => 0.9));
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));
EasyRdf_Format::register('rdfxml', 'RDF/XML', 'http://www.w3.org/TR/rdf-syntax-grammar', array('application/rdf+xml' => 0.8));
EasyRdf_Format::register('n3', 'Notation3', 'http://www.w3.org/2000/10/swap/grammar/n3#', array('text/n3' => 0.5, 'text/rdf+n3' => 0.5));
EasyRdf_Format::register('rdfa', 'RDF/A', 'http://www.w3.org/TR/rdfa/', array('text/html' => 0.4, 'application/xhtml+xml' => 0.4));
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));
        } elseif ($a['o'] != $b['o']) {
            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');
예제 #9
0
 public function testRegisterNameNonString()
 {
     $this->setExpectedException('InvalidArgumentException');
     EasyRdf_Format::register(array());
 }
예제 #10
0
     * @return object The new serialiser object
     */
    public function newSerialiser()
    {
        $serialiserClass = $this->_serialiserClass;
        if (!$serialiserClass) {
            throw new EasyRdf_Exception("No serialiser class available for: " . $this->getName());
        }
        return new $serialiserClass();
    }
    /** Magic method to return the name of the format when casted to string
     *
     * @return string The name of the format
     */
    public function __toString()
    {
        return $this->_name;
    }
}
/*
   Register default set of supported formats
   NOTE: they are ordered by preference
*/
EasyRdf_Format::register('php', 'RDF/PHP', 'http://n2.talis.com/wiki/RDF_PHP_Specification');
EasyRdf_Format::register('json', 'RDF/JSON Resource-Centric', 'http://n2.talis.com/wiki/RDF_JSON_Specification', array('application/json', 'text/json', 'application/rdf+json'));
EasyRdf_Format::register('ntriples', 'N-Triples', 'http://www.w3.org/TR/rdf-testcases/#ntriples', array('text/plain', 'text/ntriples', 'application/ntriples', 'application/x-ntriples'));
EasyRdf_Format::register('turtle', 'Turtle Terse RDF Triple Language', 'http://www.dajobe.org/2004/01/turtle', array('text/turtle', 'application/turtle', 'application/x-turtle'));
EasyRdf_Format::register('rdfxml', 'RDF/XML', 'http://www.w3.org/TR/rdf-syntax-grammar', 'application/rdf+xml');
EasyRdf_Format::register('n3', 'Notation3', 'http://www.w3.org/2000/10/swap/grammar/n3#', array('text/n3'));
EasyRdf_Format::register('rdfa', 'RDF/A', 'http://www.w3.org/TR/rdfa/', array('text/html', 'application/xhtml+xml'));
 public function testRegisterNameNonString()
 {
     $this->setExpectedException('InvalidArgumentException', '$name should be a string and cannot be null or empty');
     EasyRdf_Format::register(array());
 }
 public function testSerialiseByFormatObject()
 {
     $format = EasyRdf_Format::register('mock', 'Mock Format');
     $format->setSerialiserClass('Mock_RdfSerialiser');
     $graph = new EasyRdf_Graph();
     $this->assertSame("<rdf></rdf>", $graph->serialise($format));
 }
예제 #13
0
 public function testGetExtensionNoDefault()
 {
     $format2 = EasyRdf_Format::register('my2', 'Other Format');
     $this->assertNull($format2->getDefaultExtension());
 }