本文整理汇总了PHP中EasyRdf_Format类的典型用法代码示例。如果您正苦于以下问题:PHP EasyRdf_Format类的具体用法?PHP EasyRdf_Format怎么用?PHP EasyRdf_Format使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EasyRdf_Format类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: testParseWithFormatObject
public function testParseWithFormatObject()
{
$format = EasyRdf_Format::getFormat('json');
$this->_parser->parse($this->_graph, $this->_data, $format, null);
$joe = $this->_graph->resource('http://www.example.com/joe#me');
$this->assertStringEquals('Joe Bloggs', $joe->get('foaf:name'));
}
开发者ID:nhukhanhdl,项目名称:easyrdf,代码行数:7,代码来源:JsonTest.php
示例2: setUp
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');
}
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:7,代码来源:GraphStoreTest.php
示例3: getTriples
protected function getTriples($file)
{
if (!file_exists($file)) {
throw new Exception($file . ' not found');
}
// validate the file to import
$parser = new tao_models_classes_Parser($file, array('extension' => 'rdf'));
$parser->validate();
if (!$parser->isValid()) {
throw new common_Exception('Invalid RDF file ' . $file);
}
$modelDefinition = new EasyRdf_Graph();
$modelDefinition->parseFile($file);
/*
$graph = $modelDefinition->toRdfPhp();
$resources = $modelDefinition->resources();
*/
$format = EasyRdf_Format::getFormat('php');
$data = $modelDefinition->serialise($format);
$triples = array();
foreach ($data as $subjectUri => $propertiesValues) {
foreach ($propertiesValues as $prop => $values) {
foreach ($values as $k => $v) {
$triples[] = array('s' => $subjectUri, 'p' => $prop, 'o' => $v['value'], 'l' => isset($v['lang']) ? $v['lang'] : '');
}
}
}
return $triples;
}
开发者ID:oat-sa,项目名称:extension-tao-devtools,代码行数:29,代码来源:class.RdfDiff.php
示例4: createModel
/**
* @author "Lionel Lecaque, <[email protected]>"
* @param string $namespace
* @param string $data xml content
*/
public function createModel($namespace, $data)
{
$modelId = $this->getModelId($namespace);
if ($modelId === false) {
common_Logger::d('modelId not found, need to add namespace ' . $namespace);
$this->addNewModel($namespace);
//TODO bad way, need to find better
$modelId = $this->getModelId($namespace);
}
$modelDefinition = new EasyRdf_Graph($namespace);
if (is_file($data)) {
$modelDefinition->parseFile($data);
} else {
$modelDefinition->parse($data);
}
$graph = $modelDefinition->toRdfPhp();
$resources = $modelDefinition->resources();
$format = EasyRdf_Format::getFormat('php');
$data = $modelDefinition->serialise($format);
foreach ($data as $subjectUri => $propertiesValues) {
foreach ($propertiesValues as $prop => $values) {
foreach ($values as $k => $v) {
$this->addStatement($modelId, $subjectUri, $prop, $v['value'], isset($v['lang']) ? $v['lang'] : null);
}
}
}
return true;
}
开发者ID:nagyist,项目名称:generis,代码行数:33,代码来源:class.ModelFactory.php
示例5: getJSONVersionOfSchema
/**
* Retrieve the latest RDFA version of schema.org and converts it to JSON-LD.
*
* Note: caches the file in data and retrieves it from there as long as it exists.
*/
private function getJSONVersionOfSchema()
{
// Set cachefile
$cacheFile = dirname(dirname(__DIR__)) . '/data/schemaorg.cache';
if (!file_exists($cacheFile)) {
// Create dir
if (!file_exists(dirname($cacheFile))) {
mkdir(dirname($cacheFile), 0777, true);
}
// Load RDFA Schema
$graph = new \EasyRdf_Graph(self::RDFA_SCHEMA);
$graph->load(self::RDFA_SCHEMA, 'rdfa');
// Lookup the output format
$format = \EasyRdf_Format::getFormat('jsonld');
// Serialise to the new output format
$output = $graph->serialise($format);
if (!is_scalar($output)) {
$output = var_export($output, true);
}
$this->schema = \ML\JsonLD\JsonLD::compact($graph->serialise($format), 'http://schema.org/');
// Write cache file
file_put_contents($cacheFile, serialize($this->schema));
} else {
$this->schema = unserialize(file_get_contents($cacheFile));
}
}
开发者ID:lengthofrope,项目名称:create-jsonld,代码行数:31,代码来源:Build.php
示例6: setup
public function setup()
{
// Reset to built-in parsers
EasyRdf_Format::registerParser('ntriples', 'EasyRdf_Parser_Ntriples');
EasyRdf_Format::registerParser('rdfxml', 'EasyRdf_Parser_RdfXml');
EasyRdf_Format::registerParser('turtle', 'EasyRdf_Parser_Turtle');
}
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:7,代码来源:HexBinaryTest.php
示例7: createPersonAction
/**
* @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 = '[email protected]';
$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;
}
开发者ID:emiberea,项目名称:wade-phos-server,代码行数:34,代码来源:DefaultController.php
示例8: testParseWithFormatObject
public function testParseWithFormatObject()
{
$data = readFixture('foaf.jsonld');
$format = EasyRdf_Format::getFormat('jsonld');
$count = $this->parser->parse($this->graph, $data, $format, null);
$this->assertSame(14, $count);
$joe = $this->graph->resource('http://www.example.com/joe#me');
$this->assertStringEquals('Joe Bloggs', $joe->get('foaf:name'));
}
开发者ID:takin,项目名称:workshop-semantic-web,代码行数:9,代码来源:JsonLdTest.php
示例9: __construct
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');
}
开发者ID:Tjoosten,项目名称:kvd,代码行数:11,代码来源:AbstractSerialiser.class.php
示例10: toFile
public static function toFile($filePath, $triples)
{
$graph = new \EasyRdf_Graph();
foreach ($triples as $triple) {
if (!empty($triple->lg)) {
$graph->addLiteral($triple->subject, $triple->predicate, $triple->object, $triple->lg);
} elseif (\common_Utils::isUri($triple->object)) {
$graph->add($triple->subject, $triple->predicate, $triple->object);
} else {
$graph->addLiteral($triple->subject, $triple->predicate, $triple->object);
}
}
$format = \EasyRdf_Format::getFormat('rdfxml');
return file_put_contents($filePath, $graph->serialise($format));
}
开发者ID:nagyist,项目名称:generis,代码行数:15,代码来源:FileModel.php
示例11: export
/**
* Export to xml-rdf the ontology of the Class in parameter.
* All the ontologies are exported if the class is not set
*
* @access public
* @author Jerome Bogaerts, <[email protected]>
* @param Class source
* @return string
*/
public function export(core_kernel_classes_Class $source = null)
{
$rdf = '';
if (is_null($source)) {
return core_kernel_api_ModelExporter::exportAll();
}
$graph = new EasyRdf_Graph();
if ($source->isClass()) {
$this->addClass($graph, $source);
} else {
$this->addResource($graph, $source);
}
$format = EasyRdf_Format::getFormat('rdfxml');
return $graph->serialise($format);
}
开发者ID:nagyist,项目名称:tao-core,代码行数:24,代码来源:class.GenerisAdapterRdf.php
示例12: statement2rdf
/**
* @ignore
*/
private static function statement2rdf(PDOStatement $statement)
{
$graph = new EasyRdf_Graph();
while ($r = $statement->fetch()) {
if (isset($r['l_language']) && !empty($r['l_language'])) {
$graph->addLiteral($r['subject'], $r['predicate'], $r['object'], $r['l_language']);
} elseif (common_Utils::isUri($r['object'])) {
$graph->add($r['subject'], $r['predicate'], $r['object']);
} else {
$graph->addLiteral($r['subject'], $r['predicate'], $r['object']);
}
}
$format = EasyRdf_Format::getFormat('rdfxml');
return $graph->serialise($format);
}
开发者ID:nagyist,项目名称:generis,代码行数:18,代码来源:class.ModelExporter.php
示例13: flatImport
/**
* Imports the rdf file into the selected class
*
* @param string $file
* @param core_kernel_classes_Class $class
* @return common_report_Report
*/
private function flatImport($file, core_kernel_classes_Class $class)
{
$report = common_report_Report::createSuccess(__('Data imported successfully'));
$graph = new EasyRdf_Graph();
$graph->parseFile($file);
// keep type property
$map = array(RDF_PROPERTY => RDF_PROPERTY);
foreach ($graph->resources() as $resource) {
$map[$resource->getUri()] = common_Utils::getNewUri();
}
$format = EasyRdf_Format::getFormat('php');
$data = $graph->serialise($format);
foreach ($data as $subjectUri => $propertiesValues) {
$resource = new core_kernel_classes_Resource($map[$subjectUri]);
$subreport = $this->importProperties($resource, $propertiesValues, $map, $class);
$report->add($subreport);
}
return $report;
}
开发者ID:nagyist,项目名称:tao-core,代码行数:26,代码来源:class.RdfImporter.php
示例14: addMock
public function addMock($method, $uri, $body, $options = array())
{
$match = array();
$match['method'] = $method;
$match['uri'] = array();
if (isset($options['callback'])) {
$match['callback'] = $options['callback'];
if (isset($options['callbackArgs'])) {
$match['callbackArgs'] = $options['callbackArgs'];
} else {
$match['callbackArgs'] = array();
}
}
if (!isset($uri)) {
$match['uri'] = null;
} else {
$match['uri'] = strval($uri);
}
if ($body instanceof EasyRdf_Http_Response) {
$response = $body;
} else {
if (isset($options['status'])) {
$status = $options['status'];
} else {
$status = 200;
}
if (isset($options['headers'])) {
$headers = $options['headers'];
} else {
$headers = array();
$format = EasyRdf_Format::guessFormat($body);
if (isset($format)) {
$headers['Content-Type'] = $format->getDefaultMimeType();
}
if (isset($body)) {
$headers['Content-Length'] = strlen($body);
}
}
$response = new EasyRdf_Http_Response($status, $headers, $body);
}
$once = isset($options['once']) ? $options['once'] : false;
$this->_mocks[] = array($match, $response, $once);
}
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:43,代码来源:MockClient.php
示例15: sendGraph
/** Send some graph data to the graph store
*
* This method is used by insert() and replace()
*
* @ignore
*/
protected function sendGraph($method, $graph, $uriRef, $format)
{
if (is_object($graph) and $graph instanceof EasyRdf_Graph) {
if ($uriRef == null) {
$uriRef = $graph->getUri();
}
$data = $graph->serialise($format);
} else {
$data = $graph;
}
$formatObj = EasyRdf_Format::getFormat($format);
$mimeType = $formatObj->getDefaultMimeType();
$graphUri = $this->_parsedUri->resolve($uriRef)->toString();
$dataUrl = $this->urlForGraph($graphUri);
$client = EasyRdf_Http::getDefaultHttpClient();
$client->resetParameters(true);
$client->setUri($dataUrl);
$client->setMethod($method);
$client->setRawData($data);
$client->setHeaders('Content-Type', $mimeType);
$client->setHeaders('Content-Length', strlen($data));
$response = $client->request();
if (!$response->isSuccessful()) {
throw new EasyRdf_Exception("HTTP request for {$dataUrl} failed: " . $response->getMessage());
}
return $response;
}
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:33,代码来源:GraphStore.php
示例16: parse
*
* @param object EasyRdf_Graph $graph the graph to load the data into
* @param string $data the RDF document data
* @param string $format the format of the input data
* @param string $baseUri the base URI of the data being parsed
* @return boolean true if parsing was successful
*/
public function parse($graph, $data, $format, $baseUri)
{
parent::checkParseParams($graph, $data, $format, $baseUri);
if (array_key_exists($format, self::$_supportedTypes)) {
$className = self::$_supportedTypes[$format];
} else {
throw new EasyRdf_Exception("EasyRdf_Parser_Arc does not support: {$format}");
}
$parser = ARC2::getParser($className);
if ($parser) {
$parser->parse($baseUri, $data);
$rdfphp = $parser->getSimpleIndex(false);
return parent::parse($graph, $rdfphp, 'php', $baseUri);
} else {
throw new EasyRdf_Exception("ARC2 failed to get a {$className} parser.");
}
}
}
## FIXME: do this automatically
EasyRdf_Format::registerParser('rdfxml', 'EasyRdf_Parser_Arc');
EasyRdf_Format::registerParser('turtle', 'EasyRdf_Parser_Arc');
EasyRdf_Format::registerParser('ntriples', 'EasyRdf_Parser_Arc');
EasyRdf_Format::registerParser('rdfa', 'EasyRdf_Parser_Arc');
开发者ID:Tjorriemorrie,项目名称:app,代码行数:30,代码来源:Arc.php
示例17: array
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');
开发者ID:ASDAFF,项目名称:myprofile,代码行数:30,代码来源:Format.php
示例18: parse
}
/**
* Parse an RDF/XML document into an EasyRdf_Graph
*
* @param object EasyRdf_Graph $graph the graph to load the data into
* @param string $data the RDF document data
* @param string $format the format of the input data
* @param string $baseUri the base URI of the data being parsed
* @return boolean true if parsing was successful
*/
public function parse($graph, $data, $format, $baseUri)
{
parent::checkParseParams($graph, $data, $format, $baseUri);
if ($format != 'rdfxml') {
throw new EasyRdf_Exception("EasyRdf_Parser_RdfXml does not support: {$format}");
}
$this->init($graph, $baseUri);
$this->resetBnodeMap();
/* xml parser */
$this->initXMLParser();
/* parse */
if (!xml_parse($this->_xmlParser, $data, false)) {
throw new EasyRdf_Exception('XML error: "' . xml_error_string(xml_get_error_code($this->_xmlParser)) . '" at line ' . xml_get_current_line_number($this->_xmlParser));
}
xml_parser_free($this->_xmlParser);
// Success
return true;
}
}
EasyRdf_Format::registerParser('rdfxml', 'EasyRdf_Parser_RdfXml');
开发者ID:Tjorriemorrie,项目名称:app,代码行数:30,代码来源:RdfXml.php
示例19: set_include_path
* can have resource URIs replaced with text based labels and using
* 'Only Labelled' option, only the resources and properties with
* a label will be displayed.
*
* Rending a graph to an image will only work if you have the
* GraphViz 'dot' command installed.
*
* @package EasyRdf
* @copyright Copyright (c) 2012-2013 Nicholas J Humfrey
* @license http://unlicense.org/
*/
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
require_once "html_tag_helpers.php";
$formats = array('PNG' => 'png', 'GIF' => 'gif', 'SVG' => 'svg');
$format = EasyRdf_Format::getFormat(isset($_REQUEST['format']) ? $_REQUEST['format'] : 'png');
// Construct a graph of three people
$graph = new EasyRdf_Graph();
$graph->set('foaf:knows', 'rdfs:label', 'knows');
$bob = $graph->resource('http://www.example.com/bob', 'foaf:Person');
$alice = $graph->resource('http://www.example.com/alice', 'foaf:Person');
$carol = $graph->resource('http://www.example.com/carol', 'foaf:Person');
$bob->set('foaf:name', 'Bob');
$alice->set('foaf:name', 'Alice');
$carol->set('foaf:name', 'Carol');
$bob->add('foaf:knows', $alice);
$bob->add('foaf:knows', $carol);
$alice->add('foaf:knows', $bob);
$alice->add('foaf:knows', $carol);
// Create a GraphViz serialiser
$gv = new EasyRdf_Serialiser_GraphViz();
开发者ID:gitter-badger,项目名称:mexproject,代码行数:31,代码来源:graphviz.php
示例20: parse
public function parse($graph, $data, $format, $baseUri)
{
parent::checkParseParams($graph, $data, $format, $baseUri);
if ($format != 'php') {
throw new EasyRdf_Exception("EasyRdf_Parser_RdfPhp does not support: {$format}");
}
// Reset the bnode mapping
$this->resetBnodeMap();
foreach ($data as $subject => $properties) {
if (substr($subject, 0, 2) === '_:') {
$subject = $this->remapBnode($graph, $subject);
} elseif (preg_match('/^\\w+$/', $subject)) {
# Cope with invalid RDF/JSON serialisations that
# put the node name in, without the _: prefix
# (such as net.fortytwo.sesametools.rdfjson)
$subject = $this->remapBnode($graph, $subject);
}
foreach ($properties as $property => $objects) {
foreach ($objects as $object) {
if ($object['type'] === 'bnode') {
$object['value'] = $this->remapBnode($graph, $object['value']);
}
$graph->add($subject, $property, $object);
}
}
}
return true;
}
}
EasyRdf_Format::registerParser('php', 'EasyRdf_Parser_RdfPhp');
开发者ID:rowanthorpe,项目名称:myprofile,代码行数:30,代码来源:RdfPhp.php
注:本文中的EasyRdf_Format类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论