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


PHP EasyRdf_Format类代码示例

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


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

示例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 = 'emi.berea@gmail.com';
     $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, <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

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


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