当前位置: 首页>>代码示例>>PHP>>正文


PHP EasyRdf_Format::getFormat方法代码示例

本文整理汇总了PHP中EasyRdf_Format::getFormat方法的典型用法代码示例。如果您正苦于以下问题:PHP EasyRdf_Format::getFormat方法的具体用法?PHP EasyRdf_Format::getFormat怎么用?PHP EasyRdf_Format::getFormat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EasyRdf_Format的用法示例。


在下文中一共展示了EasyRdf_Format::getFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: createModel

 /**
  * @author "Lionel Lecaque, <lionel@taotesting.com>"
  * @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

示例3: 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

示例4: 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

示例5: 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

示例6: 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, <jerome.bogaerts@tudor.lu>
  * @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

示例7: 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

示例8: 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

示例9: 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

示例10: testRegisterSerialiserForUnknownFormat

 public function testRegisterSerialiserForUnknownFormat()
 {
     EasyRdf_Format::registerSerialiser('testRegisterSerialiser', 'MockSerialiserClass');
     $format = EasyRdf_Format::getFormat('testRegisterSerialiser');
     $this->assertNotNull($format);
     $this->assertEquals('MockSerialiserClass', $format->getSerialiserClass());
 }
开发者ID:nhukhanhdl,项目名称:easyrdf,代码行数:7,代码来源:FormatTest.php

示例11: 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

示例12: testParseFormatObject

 public function testParseFormatObject()
 {
     $format = EasyRdf_Format::getFormat('json');
     $this->assertTrue($this->_parser->parse($this->_graph, $this->_data, $format, null));
 }
开发者ID:nhukhanhdl,项目名称:easyrdf,代码行数:5,代码来源:ParserTest.php

示例13: 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

示例14: serialise

 /** Serialise the graph into RDF
  *
  * The $format parameter can be an EasyRdf_Format object, a
  * format name, a mime type or a file extension.
  *
  * Example:
  *   $turtle = $graph->serialise('turtle');
  *
  * @param  mixed $format  The format to serialise to
  * @param  array $options Serialiser-specific options, for fine-tuning the output
  * @return mixed  The serialised graph
  */
 public function serialise($format, array $options = array())
 {
     if (!$format instanceof EasyRdf_Format) {
         $format = EasyRdf_Format::getFormat($format);
     }
     $serialiser = $format->newSerialiser();
     return $serialiser->serialise($this, $format->getName(), $options);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:20,代码来源:Graph.php

示例15: testSerialiseFormatObject

 public function testSerialiseFormatObject()
 {
     $format = EasyRdf_Format::getFormat('json');
     $this->assertTrue($this->_serialiser->serialise($this->_graph, $format));
 }
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:5,代码来源:SerialiserTest.php


注:本文中的EasyRdf_Format::getFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。