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


PHP EasyRdf_Graph::add方法代码示例

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


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

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

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

示例3: add

 /**
  * Create a new dataset
  *
  * @param array $config The config of the new dataset
  *
  * @return void
  */
 public function add($config)
 {
     // Create a auto-generated subject URI
     $id = $this->getIncrementalId();
     $uri = \URL::to('/users/' . $id);
     $context = $this->getContext();
     // Add the dataset resource
     $graph = new \EasyRdf_Graph();
     $user = $graph->resource($uri . '#agent');
     $user->addType('foaf:Agent');
     foreach ($this->getFields() as $field) {
         if ($field['domain'] == 'foaf:Agent') {
             if ($field['single_value'] && in_array($field['type'], ['string', 'text', 'list'])) {
                 if (filter_var(trim($config[$field['var_name']]), FILTER_VALIDATE_URL)) {
                     $graph->addResource($user, $field['sem_term'], trim($config[$field['var_name']]));
                 } else {
                     $graph->add($user, $field['sem_term'], trim($config[$field['var_name']]));
                 }
             } else {
                 if (!$field['single_value'] && in_array($field['type'], ['string', 'list'])) {
                     if (!empty($config[$field['var_name']])) {
                         foreach ($config[$field['var_name']] as $val) {
                             if (filter_var($val, FILTER_VALIDATE_URL)) {
                                 $graph->addResource(${$user}, $field['sem_term'], $val);
                             } else {
                                 $graph->add(${$user}, $field['sem_term'], $val);
                             }
                         }
                     }
                 }
             }
         }
     }
     $serializer = new \EasyRdf_Serialiser_JsonLd();
     $jsonld = $serializer->serialise($graph, 'jsonld');
     $compact_document = (array) JsonLD::compact($jsonld, $context);
     $serializer = new \EasyRdf_Serialiser_JsonLd();
     $jsonld = $serializer->serialise($graph, 'jsonld');
     $compact_document = (array) JsonLD::compact($jsonld, $context);
     $collection = $this->getMongoCollection();
     $collection->insert($compact_document);
 }
开发者ID:vanherba,项目名称:linda,代码行数:49,代码来源:UserRepository.php

示例4: add

 /**
  * Create a new dataset
  *
  * @param array $config The config of the new dataset
  *
  * @return void
  */
 public function add($config)
 {
     \EasyRdf_Namespace::set('odapps', 'http://semweb.mmlab.be/ns/odapps#');
     // Create a auto-generated subject URI
     $id = $this->getIncrementalId();
     $uri = \URL::to('/apps/' . $id);
     $context = $this->getContext();
     $graph = new \EasyRdf_Graph();
     $application = $graph->resource($uri . '#application');
     $application->addType('odapps:Application');
     foreach ($this->getFields() as $field) {
         if ($field['domain'] == 'odapps:Application') {
             if ($field['single_value'] && in_array($field['type'], ['string', 'text', 'list'])) {
                 if (filter_var(trim($config[$field['var_name']]), FILTER_VALIDATE_URL)) {
                     $graph->addResource($application, $field['sem_term'], trim($config[$field['var_name']]));
                 } else {
                     $graph->add($application, $field['sem_term'], trim($config[$field['var_name']]));
                 }
             } else {
                 if (!$field['single_value'] && in_array($field['type'], ['string', 'list'])) {
                     if (!empty($config[$field['var_name']])) {
                         foreach ($config[$field['var_name']] as $val) {
                             if (filter_var($val, FILTER_VALIDATE_URL)) {
                                 $graph->addResource($application, $field['sem_term'], $val);
                             } else {
                                 $graph->add($application, $field['sem_term'], $val);
                             }
                         }
                     }
                 }
             }
         }
     }
     $serializer = new \EasyRdf_Serialiser_JsonLd();
     $jsonld = $serializer->serialise($graph, 'jsonld');
     $compact_document = (array) JsonLD::compact($jsonld, $context);
     $serializer = new \EasyRdf_Serialiser_JsonLd();
     $jsonld = $serializer->serialise($graph, 'jsonld');
     $compact_document = (array) JsonLD::compact($jsonld, $context);
     $collection = $this->getMongoCollection();
     $collection->insert($compact_document);
 }
开发者ID:vanherba,项目名称:linda,代码行数:49,代码来源:AppRepository.php

示例5: testDumpResource

 public function testDumpResource()
 {
     $graph = new EasyRdf_Graph();
     $graph->addResource('http://example.com/joe#me', 'rdf:type', 'foaf:Person');
     $graph->addResource('http://example.com/joe#me', 'foaf:homepage', 'http://example.com/');
     $graph->add('http://example.com/joe#me', 'foaf:knows', $graph->newBnode());
     $text = $graph->dumpResource('http://example.com/joe#me', false);
     $this->assertContains('http://example.com/joe#me', $text);
     $this->assertContains('-> rdf:type -> foaf:Person', $text);
     $this->assertContains('-> foaf:homepage -> http://example.com/', $text);
     $this->assertContains('-> foaf:knows -> _:genid1', $text);
     $html = $graph->dumpResource('http://example.com/joe#me', true);
     $this->assertContains('http://example.com/joe#me', $html);
     $this->assertContains('>rdf:type</span>', $html);
     $this->assertContains('>foaf:Person</a>', $html);
     $this->assertContains('>foaf:homepage</span>', $html);
     $this->assertContains('>http://example.com/</a>', $html);
     $this->assertContains('>foaf:knows</span>', $html);
     $this->assertContains('>_:genid1</a>', $html);
 }
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:20,代码来源:GraphTest.php

示例6: serializeIteratorToStream

 /**
  * Transforms the statements of a StatementIterator instance into a stream, a file for instance.
  *
  * @param StatementIterator $statements   The StatementIterator containing all the Statements which
  *                                        should be serialized by the serializer.
  * @param string|resource   $outputStream Filename or file pointer to the stream to where the serialization
  *                                        should be written.
  * @throws \Exception if unknown serilaization was given.
  */
 public function serializeIteratorToStream(StatementIterator $statements, $outputStream)
 {
     /*
      * check parameter $outputStream
      */
     if (is_resource($outputStream)) {
         // use it as it is
     } elseif (is_string($outputStream)) {
         $outputStream = fopen($outputStream, 'w');
     } else {
         throw new \Exception('Parameter $outputStream is neither a string nor resource.');
     }
     $graph = new \EasyRdf_Graph();
     // go through all statements
     foreach ($statements as $statement) {
         /*
          * Handle subject
          */
         $stmtSubject = $statement->getSubject();
         if ($stmtSubject->isNamed()) {
             $s = $stmtSubject->getUri();
         } elseif ($stmtSubject->isBlank()) {
             $s = $stmtSubject->getBlankId();
         } else {
             throw new \Exception('Subject can either be a blank node or an URI.');
         }
         /*
          * Handle predicate
          */
         $stmtPredicate = $statement->getPredicate();
         if ($stmtPredicate->isNamed()) {
             $p = $stmtPredicate->getUri();
         } else {
             throw new \Exception('Predicate can only be an URI.');
         }
         /*
          * Handle object
          */
         $stmtObject = $statement->getObject();
         if ($stmtObject->isNamed()) {
             $o = array('type' => 'uri', 'value' => $stmtObject->getUri());
         } elseif ($stmtObject->isBlank()) {
             $o = array('type' => 'bnode', 'value' => $stmtObject->getBlankId());
         } elseif ($stmtObject->isLiteral()) {
             $o = array('type' => 'literal', 'value' => $stmtObject->getValue());
         } else {
             throw new \Exception('Object can either be a blank node, an URI or literal.');
         }
         $graph->add($s, $p, $o);
     }
     fwrite($outputStream, $graph->serialise($this->serialization) . PHP_EOL);
 }
开发者ID:SaftIng,项目名称:Saft.easyrdf,代码行数:61,代码来源:SerializerEasyRdf.php

示例7: testReplaceDirectJson

 public function testReplaceDirectJson()
 {
     $graph = new EasyRdf_Graph('http://localhost:8080/data/new.rdf');
     $graph->add('urn:subject', 'urn:predicate', 'object');
     $this->_client->addMock('PUT', '/data/?graph=http%3A%2F%2Ffoo.com%2Fbar.rdf', 'OK', array('callback' => array($this, 'checkTurtleRequest')));
     $response = $this->_graphStore->replace($graph, "http://foo.com/bar.rdf", 'json');
     $this->assertEquals('200', $response->getStatus());
 }
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:8,代码来源:GraphStoreTest.php

示例8: addResource

 /**
  * Add a resource to the graph
  * 
  * @param EasyRdf_Graph $graph
  * @param core_kernel_classes_Resource $resource
  * @ignore
  */
 private function addResource(EasyRdf_Graph $graph, core_kernel_classes_Resource $resource)
 {
     foreach ($resource->getRdfTriples() 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);
         }
     }
 }
开发者ID:nagyist,项目名称:tao-core,代码行数:19,代码来源:class.GenerisAdapterRdf.php

示例9: rebaseGraph

 /**
  * Rebase the graph on triples with the start fragment to our own base URI
  *
  * @param string        $start_fragment
  * @param EasyRdf_Graph $graph
  *
  * @return EasyRdf_Graph
  */
 private function rebaseGraph($start_fragment, $graph)
 {
     // Filter out the #dataset meta-data (if present) and change the URI's to our base URI
     $collections = $graph->allOfType('hydra:Collection');
     // Fetch all of the subject URI's that bring forth hydra meta-data (and are thus irrelevant)
     $ignore_subjects = array();
     if (empty($collection)) {
         $collections = $graph->allOfType('hydra:PagedCollection');
     }
     if (!empty($collections)) {
         foreach ($collections as $collection) {
             array_push($ignore_subjects, $collection->getUri());
         }
     }
     // Fetch the bnode of the hydra mapping (property is hydra:search)
     $hydra_mapping = $graph->getResource($start_fragment . '#dataset', 'hydra:search');
     if (!empty($hydra_mapping)) {
         // Hydra mapping's will be a bnode structure
         array_push($ignore_subjects, '_:' . $hydra_mapping->getBNodeId());
         $mapping_nodes = $hydra_mapping->all('hydra:mapping');
         foreach ($mapping_nodes as $mapping_node) {
             if ($mapping_node->isBNode()) {
                 array_push($ignore_subjects, '_:' . $mapping_node->getBNodeId());
             }
         }
         $graph->deleteResource($start_fragment . '#dataset', 'hydra:search', '_:genid1');
         $graph->deleteResource('_:genid1', 'hydra:mapping', '_:genid2');
         // Delete all of the mapping related resources
         $triples = $graph->toRdfPhp();
     } else {
         // Change all of the base (startfragment) URI's to our own base URI
         $triples = $graph->toRdfPhp();
     }
     // Unset the #dataset
     unset($triples[$start_fragment . '#dataset']);
     foreach ($ignore_subjects as $ignore_subject) {
         unset($triples[$ignore_subject]);
     }
     $adjusted_graph = new \EasyRdf_Graph();
     foreach ($triples as $subject => $triple) {
         foreach ($triple as $predicate => $objects) {
             foreach ($objects as $object) {
                 $adjusted_graph->add($subject, $predicate, $object['value']);
             }
         }
     }
     return $adjusted_graph;
 }
开发者ID:tdt,项目名称:triples,代码行数:56,代码来源:LDFHandler.php

示例10: time

 * running on your local machine in order to test this example.
 *
 * @package    EasyRdf
 * @copyright  Copyright (c) 2009-2011 Nicholas J Humfrey
 * @license    http://unlicense.org/
 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
?>
<html>
<head>
  <title>GraphStore example</title>
</head>
<body>

<?php 
// Use a local SPARQL 1.1 Graph Store (eg RedStore)
$gs = new EasyRdf_GraphStore('http://localhost:8080/data/');
// Add the current time in a graph
$graph1 = new EasyRdf_Graph();
$graph1->add('http://example.com/test', 'rdfs:label', 'Test');
$graph1->add('http://example.com/test', 'dc:date', time());
$gs->insert($graph1, 'time.rdf');
// Get the graph back out of the graph store and display it
$graph2 = $gs->get('time.rdf');
print $graph2->dump();
?>

</body>
</html>
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:30,代码来源:graphstore.php

示例11: testIssue209

 /**
  * @see https://github.com/njh/easyrdf/issues/209
  */
 public function testIssue209()
 {
     $g = new EasyRdf_Graph();
     $g->add('http://example.com/resource', 'rdf:type', new EasyRdf_Resource('foaf:Person'));
     $g->add('http://example.com/resource', 'rdf:type', new EasyRdf_Resource('http://example.com/TypeA'));
     $xml = $g->serialise('rdfxml');
     $g2 = new EasyRdf_Graph('http://example.com/', $xml, 'rdfxml');
     $types = $g2->resource('http://example.com/resource')->typesAsResources();
     $expected = array('http://example.com/TypeA', 'http://xmlns.com/foaf/0.1/Person');
     $this->assertCount(2, $types);
     $this->assertContains($types[0]->getUri(), $expected);
     $this->assertContains($types[1]->getUri(), $expected);
 }
开发者ID:takin,项目名称:workshop-semantic-web,代码行数:16,代码来源:RdfXmlTest.php

示例12:

 */
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
?>
<html>
<head>
  <title>Example of using EasyRdf_Graph directly</title>
</head>
<body>

<?php 
$graph = new EasyRdf_Graph();
$graph->addResource("http://example.com/joe", "rdf:type", "foaf:Person");
$graph->addLiteral("http://example.com/joe", "foaf:name", "Joe Bloggs");
$graph->addLiteral("http://example.com/joe", "foaf:name", "Joseph Bloggs");
$graph->add("http://example.com/joe", "rdfs:label", "Joe");
$graph->setType("http://njh.me/", "foaf:Person");
$graph->add("http://njh.me/", "rdfs:label", "Nick");
$graph->addLiteral("http://njh.me/", "foaf:name", "Nicholas Humfrey");
$graph->addResource("http://njh.me/", "foaf:homepage", "http://www.aelius.com/njh/");
?>

<p>
  <b>Name:</b> <?php 
echo $graph->get("http://example.com/joe", "foaf:name");
?>
 <br />
  <b>Names:</b> <?php 
echo $graph->join("http://example.com/joe", "foaf:name");
?>
 <br />
开发者ID:gitter-badger,项目名称:mexproject,代码行数:31,代码来源:graph_direct.php

示例13: add

 /**
  * Create a new dataset
  *
  * @param array $config The config of the new dataset
  *
  * @return void
  */
 public function add($config)
 {
     // Create a auto-generated subject URI
     $id = $this->getIncrementalId();
     $uri = \URL::to('/datasets/' . $id);
     $context = $this->getContext();
     // Add the dataset resource
     $graph = new \EasyRdf_Graph();
     $dataset = $graph->resource($uri . '#dataset');
     $dataset->addType('dcat:Dataset');
     foreach ($this->getFields() as $field) {
         if ($field['domain'] == 'dcat:Dataset') {
             if ($field['single_value'] && in_array($field['type'], ['string', 'text', 'list'])) {
                 $graph->add($dataset, $field['sem_term'], trim($config[$field['var_name']]));
             } elseif (!$field['single_value'] && in_array($field['type'], ['string', 'list'])) {
                 if (!empty($config[$field['var_name']])) {
                     foreach ($config[$field['var_name']] as $val) {
                         $graph->add($dataset, $field['sem_term'], $val);
                     }
                 }
             }
         }
     }
     $serializer = new \EasyRdf_Serialiser_JsonLd();
     $jsonld = $serializer->serialise($graph, 'jsonld');
     $compact_document = (array) JsonLD::compact($jsonld, $context);
     // Add the datarecord resource
     $datarecord = $graph->resource($uri);
     $datarecord->addType('dcat:CatalogRecord');
     $created = time();
     $datarecord->addLiteral('http://purl.org/dc/terms/issued', $created);
     $datarecord->addLiteral('http://purl.org/dc/terms/modified', $created);
     $datarecord->addResource('http://purl.org/dc/terms/creator', \URL::to('/users/' . strtolower(str_replace(" ", "", $config['user']))));
     foreach ($this->getFields() as $field) {
         if ($field['domain'] == 'dcat:CatalogRecord') {
             if ($field['single_value'] && in_array($field['type'], ['string', 'text', 'list'])) {
                 if (filter_var(trim($config[$field['var_name']]), FILTER_VALIDATE_URL)) {
                     $graph->addResource($datarecord, $field['sem_term'], trim($config[$field['var_name']]));
                 } else {
                     $graph->add($datarecord, $field['sem_term'], trim($config[$field['var_name']]));
                 }
             } elseif (!$field['single_value'] && in_array($field['type'], ['string', 'list'])) {
                 if (!empty($config[$field['var_name']])) {
                     foreach ($config[$field['var_name']] as $val) {
                         if (filter_var($val, FILTER_VALIDATE_URL)) {
                             $graph->addResource($datarecord, $field['sem_term'], $val);
                         } else {
                             $graph->add($datarecord, $field['sem_term'], $val);
                         }
                     }
                 }
             }
         }
     }
     // Add the relationship with the dataset
     $graph->addResource($datarecord, 'http://xmlns.com/foaf/spec/primaryTopic', $uri . '#dataset');
     // Add the distribution resource
     foreach ($config['distributions'] as $distribution) {
         $id = $this->getIncrementalId();
         $distr_uri = $uri . '#distribution' . $id;
         $distributionResource = $graph->resource($distr_uri);
         $distributionResource->addType('dcat:Distribution');
         if (!empty($distribution['license'])) {
             $graph->addResource($distributionResource, 'dct:license', $distribution['license']);
         }
         if (!empty($distribution['usecases'])) {
             foreach ($distribution['usecases'] as $usecase) {
                 $graph->addResource($distributionResource, 'linda:useFor', $usecase);
             }
         }
         // Add the distribution to the dataset
         $graph->addResource($dataset, 'dcat:distribution', $distr_uri);
     }
     $serializer = new \EasyRdf_Serialiser_JsonLd();
     $jsonld = $serializer->serialise($graph, 'jsonld');
     $compact_document = (array) JsonLD::compact($jsonld, $context);
     $collection = $this->getMongoCollection();
     $collection->insert($compact_document);
 }
开发者ID:vanherba,项目名称:linda,代码行数:86,代码来源:DatasetRepository.php

示例14: array

<?php 
if (isset($_REQUEST['uri'])) {
    $graph = new EasyRdf_Graph();
    # 1st Technique
    $me = $graph->resource($_REQUEST['uri'], 'foaf:Person');
    $me->set('foaf:name', $_REQUEST['title'] . ' ' . $_REQUEST['given_name'] . ' ' . $_REQUEST['family_name']);
    if ($_REQUEST['email']) {
        $email = $graph->resource("mailto:" . $_REQUEST['email']);
        $me->add('foaf:mbox', $email);
    }
    if ($_REQUEST['homepage']) {
        $homepage = $graph->resource($_REQUEST['homepage']);
        $me->add('foaf:homepage', $homepage);
    }
    # 2nd Technique
    $graph->add($_REQUEST['uri'], array('foaf:title' => $_REQUEST['title'], 'foaf:givenname' => $_REQUEST['given_name'], 'foaf:family_name' => $_REQUEST['family_name'], 'foaf:nick' => $_REQUEST['nickname']));
    # Add friends
    for ($i = 1; $i <= 4; $i++) {
        if ($_REQUEST["person_{$i}"]) {
            $person = $graph->resource($_REQUEST["person_{$i}"]);
            $graph->add($me, 'foaf:knows', $person);
        }
    }
    # Finally output the graph
    $data = $graph->serialise($_REQUEST['format']);
    if (!is_scalar($data)) {
        $data = var_export($data, true);
    }
    print "<pre>" . htmlspecialchars($data) . "</pre>";
}
?>
开发者ID:nhukhanhdl,项目名称:easyrdf,代码行数:31,代码来源:foafmaker.php

示例15: htmlspecialchars

        $email = $graph->resource("mailto:" . $_REQUEST['email']);
        $me->add('foaf:mbox', $email);
    }
    if ($_REQUEST['homepage']) {
        $homepage = $graph->resource($_REQUEST['homepage']);
        $me->add('foaf:homepage', $homepage);
    }
    # 2nd Technique
    $graph->addLiteral($_REQUEST['uri'], 'foaf:title', $_REQUEST['title']);
    $graph->addLiteral($_REQUEST['uri'], 'foaf:givenname', $_REQUEST['given_name']);
    $graph->addLiteral($_REQUEST['uri'], 'foaf:family_name', $_REQUEST['family_name']);
    $graph->addLiteral($_REQUEST['uri'], 'foaf:nick', $_REQUEST['nickname']);
    # Add friends
    for ($i = 1; $i <= 4; $i++) {
        if ($_REQUEST["person_{$i}"]) {
            $person = $graph->resource($_REQUEST["person_{$i}"]);
            $graph->add($me, 'foaf:knows', $person);
        }
    }
    # Finally output the graph
    $data = $graph->serialise($_REQUEST['format']);
    if (!is_scalar($data)) {
        $data = var_export($data, true);
    }
    print "<pre>" . htmlspecialchars($data) . "</pre>";
}
?>

</body>
</html>
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:30,代码来源:foafmaker.php


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