本文整理汇总了PHP中EasyRdf_Graph::newAndLoad方法的典型用法代码示例。如果您正苦于以下问题:PHP EasyRdf_Graph::newAndLoad方法的具体用法?PHP EasyRdf_Graph::newAndLoad怎么用?PHP EasyRdf_Graph::newAndLoad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EasyRdf_Graph
的用法示例。
在下文中一共展示了EasyRdf_Graph::newAndLoad方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: seedThemes
/**
* Seed the themes
*
* return @void
*/
private function seedThemes()
{
$this->info('---- Seeding new themes ----');
$base_uri = $this->argument('uri');
$taxonomy_uri = $this->argument('taxonomy_uri');
if (empty($taxonomy_uri)) {
$taxonomy_uri = $base_uri;
}
// Try to get the themes from the ns.thedatatank.com (semantic data)
try {
$this->info('Trying to fetch triples from the uri: ' . $base_uri);
$themes_graph = \EasyRdf_Graph::newAndLoad($base_uri);
if ($themes_graph->isEmpty()) {
$this->info('We could not reach the online themes.');
} else {
$this->info('Found new themes online, removing the old ones.');
// Empty the themes table
\Theme::truncate();
}
// Fetch the resources with a skos:conceptScheme relationship
$resources = $themes_graph->allOfType('skos:ConceptScheme');
$taxonomy_uris = array();
foreach ($resources as $r) {
array_push($taxonomy_uris, $r->getUri());
}
if (!empty($taxonomy_uris)) {
if (count($taxonomy_uris) == 1) {
$taxonomy_uri = $taxonomy_uris[0];
} else {
// Check if one of the possible taxonomy uris compares to the uri of the document
foreach ($taxonomy_uris as $tax_uri) {
if ($base_uri == $tax_uri) {
$taxonomy_uri = $tax_uri;
break;
}
$this->error('None of the URIs that have the skos:ConceptScheme property matched the URI of the document, please specify the taxonomy URI as a second parameter.');
}
}
} else {
$this->error('No resource has been found with a property of skos:ConceptScheme.');
}
// Fetch all of the themes
foreach ($themes_graph->resourcesMatching('skos:inScheme') as $theme) {
if ($theme->get('skos:inScheme')->getUri() == $taxonomy_uri) {
$uri = $theme->getUri();
$label = $theme->getLiteral('rdfs:label');
if (!empty($label) && !empty($uri)) {
$label = $label->getValue();
$this->info('Added ' . $uri . ' with label ' . $label);
\Theme::create(array('uri' => $uri, 'label' => $label));
}
}
}
$this->info('Added new themes.');
} catch (EasyRdf_Exception $ex) {
$this->info('An error occurred when we tried to fetch online themes.');
}
}
示例2: indexAction
public function indexAction()
{
$foaf = \EasyRdf_Graph::newAndLoad('http://njh.me/foaf.rdf');
$me = $foaf->primaryTopic();
\EasyRdf_Namespace::set('category', 'http://dbpedia.org/resource/Category:');
\EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/resource/');
\EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
\EasyRdf_Namespace::set('dbp', 'http://dbpedia.org/property/');
$sparql = new \EasyRdf_Sparql_Client('http://dbpedia.org/sparql');
$result = $sparql->query('SELECT * WHERE {' . ' ?country rdf:type dbo:Country .' . ' ?country rdfs:label ?label .' . ' ?country dc:subject category:Member_states_of_the_United_Nations .' . ' FILTER ( lang(?label) = "en" )' . '} ORDER BY ?label');
return $this->render('MyAppBlogBundle:Default:index.html.twig', array('name' => $result, 'count' => $result->numRows()));
}
示例3: seedThemes
/**
* Seed the themes
*
* return @void
*/
private function seedThemes()
{
$this->command->info('---- DCAT Themes ----');
$uri = 'http://ns.thedatatank.com/dcat/themes#Taxonomy';
$themes_fetched = false;
// Try to get the themes from the ns.thedatatank.com (semantic data)
try {
$this->command->info('Trying to fetch new themes online.');
$themes_graph = \EasyRdf_Graph::newAndLoad($uri);
if ($themes_graph->isEmpty()) {
$this->command->info('We could not reach the online themes.');
} else {
$themes_fetched = true;
$this->command->info('Found new themes online, removing the old ones.');
// Empty the themes table
\Theme::truncate();
}
// Fetch all of the themes
foreach ($themes_graph->resourcesMatching('skos:inScheme') as $theme) {
if ($theme->get('skos:inScheme')->getUri() == $uri) {
$theme_uri = $theme->getUri();
$label = $theme->getLiteral('rdfs:label');
if (!empty($label) && !empty($theme_uri)) {
$label = $label->getValue();
$this->command->info('Added ' . $uri . ' with label ' . $label);
\Theme::create(array('uri' => $theme_uri, 'label' => $label));
}
}
}
$this->command->info('Added new themes.');
} catch (EasyRdf_Exception $ex) {
$this->command->info('An error occurred when we tried to fetch online themes.');
}
// If it's not available, get them from a file (json)
if (!$themes_fetched) {
$this->command->info('Trying to fetch the themes from the local json file containing a default set of themes.');
$themes = json_decode(file_get_contents(app_path() . '/database/seeds/data/themes.json'));
if (!empty($themes)) {
$this->command->info('Found new themes, removing the old ones.');
// Empty the themes table
\Theme::truncate();
foreach ($themes as $theme) {
\Theme::create(array('uri' => $theme->uri, 'label' => $theme->label));
}
if (!empty($themes)) {
$this->command->info('Added themes from the local json file.');
}
} else {
$this->command->info('No themes were found in the local json file, the old ones will not be replaced.');
}
}
}
示例4: makeSemanticResponse
private function makeSemanticResponse($uri)
{
try {
$graph = new \EasyRdf_Graph();
if (substr($uri, 0, 4) == "http") {
$graph = \EasyRdf_Graph::newAndLoad($uri);
} else {
$graph->parseFile($uri, 'jsonld');
}
} catch (\Exception $ex) {
\App::abort(500, "The JSON-LD reader couldn't parse the document, the exception message we got is: " . $ex->getMessage());
}
// Return the data object with the graph
$data = new Data();
$data->data = $graph;
$data->is_semantic = true;
$data->preferred_formats = ['jsonld', 'ttl', 'rdf'];
return $data;
}
示例5: readData
public function readData($source_definition, $rest_parameters = array())
{
$uri = $source_definition['uri'];
// If the parsing in the document fails, a JsonLdException is thrown
try {
$graph = new \EasyRdf_Graph();
if (substr($uri, 0, 4) == "http") {
$graph = \EasyRdf_Graph::newAndLoad($uri);
} else {
$graph->parseFile($uri, 'jsonld');
}
} catch (\Exception $ex) {
\App::abort(500, "The JSON LD reader couldn't parse the document, the exception message we got is: " . $ex->getMessage());
}
// Return the data object with the graph
$data = new Data();
$data->data = $graph;
$data->is_semantic = true;
$data->preferred_formats = $this->getPreferredFormats();
return $data;
}
示例6: indexAction
public function indexAction()
{
$product = new Product();
for ($i = 0; $i < 100; $i++) {
$product->setName('Foo Bar : ' . rand(0, 100));
$product->setPrice(rand(0, 1000));
$dm = $this->get('doctrine_mongodb')->getManager();
$dm->persist($product);
$dm->flush();
}
$foaf = \EasyRdf_Graph::newAndLoad('http://njh.me/foaf.rdf');
$me = $foaf->primaryTopic();
\EasyRdf_Namespace::set('category', 'http://dbpedia.org/resource/Category:');
\EasyRdf_Namespace::set('dbpedia', 'http://dbpedia.org/resource/');
\EasyRdf_Namespace::set('dbo', 'http://dbpedia.org/ontology/');
\EasyRdf_Namespace::set('dbp', 'http://dbpedia.org/property/');
$sparql = new \EasyRdf_Sparql_Client('http://dbpedia.org/sparql');
$result = $sparql->query('SELECT * WHERE {' . ' ?country rdf:type dbo:Country .' . ' ?country rdfs:label ?label .' . ' ?country dc:subject category:Member_states_of_the_United_Nations .' . ' FILTER ( lang(?label) = "en" )' . '} ORDER BY ?label');
$repository = $this->get('doctrine_mongodb')->getManager()->getRepository('MyAppBlogBundle:Product');
return $this->render('MyAppBlogBundle:Default:index.html.twig', array('name' => $result, 'count' => $result->numRows(), 'products' => $repository->findAll()));
}
示例7: set_include_path
* Script to update test cases from rdfa.info
*
* @package EasyRdf
* @copyright Copyright (c) 2012-2013 Nicholas J Humfrey
* @license http://www.opensource.org/licenses/bsd-license.php
*/
set_include_path(get_include_path() . PATH_SEPARATOR . './lib/');
require_once "EasyRdf.php";
$RDFA_VERSION = 'rdfa1.1';
$HOST_LANGUAGE = 'xhtml5';
$REFERENCE_DISTILLER = 'http://www.w3.org/2012/pyRdfa/extract?format=nt&rdfagraph=output&uri=';
$FIXTURE_DIR = dirname(__FILE__);
EasyRdf_Namespace::set('test', 'http://www.w3.org/2006/03/test-description#');
EasyRdf_Namespace::set('rdfatest', 'http://rdfa.info/vocabs/rdfa-test#');
$client = new EasyRdf_Http_Client();
$manifest = EasyRdf_Graph::newAndLoad('http://rdfa.info/test-suite/manifest.ttl');
foreach ($manifest->allOfType('test:TestCase') as $test) {
if (!in_array($RDFA_VERSION, $test->all('rdfatest:rdfaVersion'))) {
continue;
}
if (!in_array($HOST_LANGUAGE, $test->all('rdfatest:hostLanguage'))) {
continue;
}
if ($test->get('test:classification')->shorten() != 'test:required') {
continue;
}
$id = $test->localName();
$title = $test->get('dc:title');
$escapedTitle = addcslashes($title, '\'');
# Download the test input
$inputUri = "http://rdfa.info/test-suite/test-cases/{$RDFA_VERSION}/{$HOST_LANGUAGE}/{$id}.xhtml";
示例8: set_include_path
* A new EasyRdf_Graph object is created and then the contents
* of my FOAF profile is loaded from the web. An EasyRdf_Resource for
* the primary topic of the document (me, Nicholas Humfrey) is returned
* and then used to display my name.
*
* @package EasyRdf
* @copyright Copyright (c) 2009-2013 Nicholas J Humfrey
* @license http://unlicense.org/
*/
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "./lib/EasyRdf.php";
?>
<html>
<head>
<title>Basic FOAF example</title>
</head>
<body>
<?php
$foaf = EasyRdf_Graph::newAndLoad('http://njh.me/foaf.rdf');
$me = $foaf->primaryTopic();
?>
<p>
My name is: <?php
echo $me->get('foaf:name');
?>
</p>
</body>
</html>
示例9: fetchResourceFromUri
private function fetchResourceFromUri($uri)
{
try {
// change the timeout setting for external requests
$httpclient = EasyRdf_Http::getDefaultHttpClient();
$httpclient->setConfig(array('timeout' => $this->getConfig()->getHttpTimeout()));
EasyRdf_Http::setDefaultHttpClient($httpclient);
$client = EasyRdf_Graph::newAndLoad(EasyRdf_Utils::removeFragmentFromUri($uri));
return $client->resource($uri);
} catch (Exception $e) {
return null;
}
}
示例10: fetchDefaultGraph
/**
* Fetch the default licenses
*
* @return \EasyRdf_Graph
*/
private function fetchDefaultGraph()
{
$license_uri = $this->licenses_uri . $this->DEFAULT_LICENSE . '.json';
return \EasyRdf_Graph::newAndLoad($license_uri, 'jsonld');
}
示例11: form_tag
<html>
<head>
<title>EasyRdf RSS 1.0 Parsing example</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>EasyRdf RSS 1.0 Parsing example</h1>
<?php
echo form_tag();
echo text_field_tag('uri', 'http://planetrdf.com/index.rdf', array('size' => 50));
echo submit_tag();
echo form_end_tag();
?>
<?php
if (isset($_REQUEST['uri'])) {
$graph = EasyRdf_Graph::newAndLoad($_REQUEST['uri'], 'rdfxml');
$channel = $graph->get('rss:channel', '^rdf:type');
print "<p>Channel: " . link_to($channel->label(), $channel->get('rss:link')) . "</p>\n";
print "<p>Description: " . $channel->get('rss:description') . "</p>\n";
print "<ol>\n";
foreach ($channel->get('rss:items') as $item) {
print "<li>" . link_to($item->get('rss:title'), $item) . "</li>\n";
}
print "</ol>\n";
}
?>
</body>
</html>
示例12: str_replace
<hr/>
<section class="content-box">
<!-- metadata about the RDF document/record that describes the resource -->
<h2>Provenance of record</h2>
<?php
$record = $graph->resource('http://jacobshelby.org/examples/linkedData/catalog_001.rdf');
$creator = $record->get('dcterms:creator');
?>
<ul>
<li><strong>Creator</strong></li>
<?php
$creatorResource = str_replace("/me", "/jacobShelby.rdf", $creator);
$creatorGraph = EasyRdf_Graph::newAndLoad($creatorResource);
$creatorRecord = $creatorGraph->resource($creator);
$creatorName = $creatorRecord->get('schema:name');
echo "<li><a href='" . "{$creator}" . "'>{$creatorName}</a>";
?>
<details><ul>
<?php
$creatorEmployer = $creatorRecord->get('schema:worksFor');
$employerRecord = $creatorGraph->resource($creatorEmployer);
$employerName = $employerRecord->get('schema:name');
echo "<li><strong>Works for</strong></li>";
echo "<li><a href='" . "{$creatorEmployer}" . "'>{$employerName}</a></li>";
$creatorTitle = $creatorRecord->get('schema:jobTitle');
echo "<li><strong>Job title</strong></li>";
echo "<li>{$creatorTitle}</li>";
$creatorEmail = $creatorRecord->get('schema:email');
示例13: set_include_path
* @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";
EasyRdf_Namespace::setDefault('dc11');
?>
<html>
<head>
<title>Open Graph Protocol example</title>
</head>
<body>
<?php
$doc = EasyRdf_Graph::newAndLoad('http://www.rottentomatoes.com/m/10011268-oceans/');
?>
<p>
Title: <?php
echo $doc->title;
?>
<br />
Creator: <?php
echo $doc->creator;
?>
<br />
</p>
</body>
</html>
示例14: set_include_path
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib/');
require_once "EasyRdf.php";
## Add namespaces
EasyRdf_Namespace::set('vitro', 'http://vitro.mannlib.cornell.edu/ns/vitro/public#');
EasyRdf_Namespace::set('vivo', 'http://vivoweb.org/ontology/core#');
$uri = 'http://54.235.146.115:8080/vivo/individual/n5642';
$graph = EasyRdf_Graph::newAndLoad($uri);
$person = $graph->resource($uri);
?>
<html>
<head><title>Vivo Reader</title></head>
<body>
<h1>Vivo Reader</h1>
<p>
<b>First Name</b>: <?php
echo $person->get('foaf:firstName');
?>
<br />
<b>Last Name</b>: <?php
echo $person->get('foaf:lastName');
?>
<br />
<b>Title</b>: <?php
echo $person->get('vivo:preferredTitle');
?>
<br />
</p>
示例15:
<?php
require 'vendor/autoload.php';
$graph = EasyRdf_Graph::newAndLoad("http://localhost:8080/orbeon/nomisma/id/rome.rdf");
$objects = $graph->resources();
foreach ($objects as $object) {
var_dump($object->types());
}