本文整理汇总了PHP中EasyRdf_Graph::resource方法的典型用法代码示例。如果您正苦于以下问题:PHP EasyRdf_Graph::resource方法的具体用法?PHP EasyRdf_Graph::resource怎么用?PHP EasyRdf_Graph::resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EasyRdf_Graph
的用法示例。
在下文中一共展示了EasyRdf_Graph::resource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: getInfo
/** Get the data for reuse based off sparql endpoint
* @access public
* @return array $data
* */
public function getInfo($identifier)
{
$key = md5($identifier . 'ocre');
$uri = self::CRRO . $identifier;
if (!$this->getCache()->test($key)) {
EasyRdf_Namespace::set('nm', 'http://nomisma.org/id/');
EasyRdf_Namespace::set('nmo', 'http://nomisma.org/ontology#');
EasyRdf_Namespace::set('skos', 'http://www.w3.org/2004/02/skos/core#');
EasyRdf_Namespace::set('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#');
$request = new EasyRdf_Http_Client();
$request->setUri($uri);
$response = $request->request()->getStatus();
if ($response == 200) {
$graph = new EasyRdf_Graph($uri);
$graph->load();
$data = $graph->resource($uri);
$this->getCache()->save($data);
} else {
$data = NULL;
}
} else {
$data = $this->getCache()->load($key);
}
return $data;
}
示例3: setUp
public function setUp()
{
if (PHP_MAJOR_VERSION < 5 or PHP_MAJOR_VERSION >= 5 and PHP_MINOR_VERSION < 3) {
$this->markTestSkipped("JSON-LD support requires PHP 5.3+");
}
if (!class_exists('\\ML\\JsonLD\\JsonLD')) {
$this->markTestSkipped('"ml/json-ld" dependency is not installed');
}
$this->graph = new EasyRdf_Graph('http://example.com/');
$this->serialiser = new EasyRdf_Serialiser_JsonLd();
$joe = $this->graph->resource('http://www.example.com/joe#me', 'foaf:Person');
$joe->set('foaf:name', new EasyRdf_Literal('Joe Bloggs', 'en'));
$joe->set('foaf:age', 59);
$project = $this->graph->newBNode();
$project->add('foaf:name', 'Project Name');
$joe->add('foaf:project', $project);
}
示例4: testParseQuery
public function testParseQuery()
{
$graph = new EasyRdf_Graph();
$graph->parse(readFixture('query/describe.ttl'), 'turtle');
$query = $graph->resource('test:describe');
$this->assertClass('EasySpinRdf_Query_Describe', $query);
$this->assertStringEquals("DESCRIBE ?value WHERE { ?this test:uncle ?value }", $query->getSparql());
}
示例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'));
}
示例6: testParseWebId
public function testParseWebId()
{
$graph = new EasyRdf_Graph();
$graph->parseFile(fixturePath('webid.ttl'), 'turtle');
$me = $graph->resource('http://www.example.com/myfoaf#me');
$modulus = $me->get('cert:key')->get('cert:modulus');
$this->assertStringEquals('CB24ED85D64D794B69C701C186ACC059501E856000F661C93204D8380E07191C' . '5C8B368D2AC32A428ACB970398664368DC2A867320220F755E99CA2EECDAE62E' . '8D15FB58E1B76AE59CB7ACE8838394D59E7250B449176E51A494951A1C366C62' . '17D8768D682DDE78DD4D55E613F8839CF275D4C8403743E7862601F3C49A6366' . 'E12BB8F498262C3C77DE19BCE40B32F89AE62C3780F5B6275BE337E2B3153AE2' . 'BA72A9975AE71AB724649497066B660FCF774B7543D980952D2E8586200EDA41' . '58B014E75465D91ECF93EFC7AC170C11FC7246FC6DED79C37780000AC4E079F6' . '71FD4F207AD770809E0E2D7B0EF5493BEFE73544D8E1BE3DDDB52455C61391A1', $modulus);
$this->assertInternalType('string', $modulus->getValue());
$this->assertSame(NULL, $modulus->getLang());
$this->assertSame('xsd:hexBinary', $modulus->getDatatype());
}
示例7: setUp
public function setUp()
{
if (PHP_MAJOR_VERSION < 5 or PHP_MAJOR_VERSION == 5 and PHP_MINOR_VERSION < 3) {
$this->markTestSkipped("JSON-LD support requires PHP 5.3+");
}
if (!class_exists('\\ML\\JsonLD\\JsonLD')) {
$this->markTestSkipped('"ml/json-ld" dependency is not installed');
}
$this->graph = new EasyRdf_Graph('http://example.com/');
$this->serialiser = new EasyRdf_Serialiser_JsonLd();
$joe = $this->graph->resource('http://www.example.com/joe#me', 'foaf:Person');
$joe->set('foaf:name', new EasyRdf_Literal('Joe Bloggs', 'en'));
$joe->set('foaf:age', 59);
$joe->set('foaf:homepage', $this->graph->resource('http://foo/bar/me'));
$project = $this->graph->newBNode();
$project->add('foaf:name', 'Project Name');
$joe->add('foaf:project', $project);
EasyRdf_Namespace::set('dc', 'http://purl.org/dc/elements/1.1/');
EasyRdf_Namespace::set('ex', 'http://example.org/vocab#');
EasyRdf_Namespace::set('xsd', 'http://www.w3.org/2001/XMLSchema#');
EasyRdf_Namespace::set('', 'http://foo/bar/');
$chapter = $this->graph->resource('http://example.org/library/the-republic#introduction', 'ex:Chapter');
$chapter->set('dc:description', new EasyRdf_Literal('An introductory chapter on The Republic.'));
$chapter->set('dc:title', new EasyRdf_Literal('The Introduction'));
$book = $this->graph->resource('http://example.org/library/the-republic', 'ex:Book');
$book->set('dc:creator', new EasyRdf_Literal('Plato'));
$book->set('dc:title', new EasyRdf_Literal('The Republic'));
$book->addResource('ex:contains', $chapter);
$library = $this->graph->resource('http://example.org/library', 'ex:Library');
$library->addResource('ex:contains', $book);
}
示例8: getData
/** Get data from the endpoint
* @access protected
* @return string
*/
protected function getData()
{
$key = md5($this->_uri);
if (!$this->_cache->test($key)) {
$graph = new EasyRdf_Graph(self::URI . $this->_uri . self::SUFFIX);
$graph->load();
$data = $graph->resource(self::URI . $this->_uri);
$this->_cache->save($data);
} else {
$data = $this->_cache->load($key);
}
EasyRdf_Namespace::set('dcterms', 'http://purl.org/dc/terms/');
EasyRdf_Namespace::set('pleiades', 'http://pleiades.stoa.org/places/vocab#');
return $data;
}
示例9: getData
/** Get the graph to parse
* @access protected
* @returns object
*/
protected function getData()
{
$key = md5($this->_uri);
if (!$this->_cache->test($key)) {
$graph = new EasyRdf_Graph($this->_uri);
$graph->load();
$data = $graph->resource($this->_uri);
$this->_cache->save($data);
} else {
$data = $this->_cache->load($key);
}
EasyRdf_Namespace::set('dbpediaowl', 'http://dbpedia.org/ontology/');
EasyRdf_Namespace::set('dbpprop', 'http://dbpedia.org/property/');
EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/resource/');
return $data;
}
示例10: index
public function index()
{
Auth::requirePermissions('catalog.view');
$uri = \URL::to('/catalog#dcat');
$graph = new \EasyRdf_Graph();
$catalogR = $graph->resource($uri);
$catalogR->addLiteral('dc:title', \Config::get('catalog.title'));
$catalogR->addLiteral('dc:description', \Config::get('catalog.description'));
$catalogR->addType('dcat:Catalog');
$datasetRepo = new DatasetRepository();
foreach ($datasetRepo->getAll() as $datasetGraph) {
foreach ($datasetGraph->allOfType('dcat:Dataset') as $datasetR) {
$graph->addResource($catalogR, 'dcat:dataset', $datasetR);
}
}
$serializer = new \EasyRdf_Serialiser_Turtle();
$turtle = $serializer->serialise($graph, 'turtle');
return \View::make('catalog.detail')->with('title', 'Catalog | Linda')->with('turtle', $turtle);
}
示例11: 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);
}
示例12: 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);
}
示例13: getData
/** Get the data for rendering
* @access public
* @return
* */
public function getData()
{
$key = md5($this->getUri());
if (!$this->getCache()->test($key)) {
$request = new EasyRdf_Http_Client();
$request->setUri($this->getUri());
$response = $request->request()->getStatus();
if ($response == 200) {
$graph = new EasyRdf_Graph($this->_uri);
$graph->load();
$data = $graph->resource($this->_uri);
} else {
$data = NULL;
}
$this->getCache()->save($data);
} else {
$data = $this->getCache()->load($key);
}
return $data;
}
示例14: array
* 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();
$gv->setUseLabels(isset($_REQUEST['ul']));
$gv->setOnlyLabelled(isset($_REQUEST['ol']));
// If this is a request for the image, just render it and exit
if (isset($_REQUEST['image'])) {
示例15: label_tag
<?php
echo label_tag('format') . select_tag('format', $format_options, 'rdfxml');
?>
<br />
<?php
echo submit_tag();
echo form_end_tag();
?>
<?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->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