本文整理汇总了PHP中EasyRdf_Graph::load方法的典型用法代码示例。如果您正苦于以下问题:PHP EasyRdf_Graph::load方法的具体用法?PHP EasyRdf_Graph::load怎么用?PHP EasyRdf_Graph::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EasyRdf_Graph
的用法示例。
在下文中一共展示了EasyRdf_Graph::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createGraph
/**
* Creates an EasyRdf_Graph object from the given URI.
*
* @param string $uri
* URL of a web resource or path of the cached file.
* @param string $type
* Format of the document.
*
* @throws \Doctrine\Common\Proxy\Exception\InvalidArgumentException
* If invalid type or URL is passed as parameters.
*/
protected function createGraph($uri, $type) {
/*
* Initialize an EasyRdf_Graph object using
* _construct(string $uri = null, string $data = null,
* string $format = null)
*/
if (!is_string($type) or $type == NULL or $type == '') {
throw new InvalidArgumentException("\$type should be a string and cannot be null or empty");
}
if (!is_string($uri) or $uri == NULL or $uri == '') {
throw new InvalidArgumentException("\$uri should be a string and cannot be null or empty");
}
try {
if (preg_match('#^http#i', $uri) === 1) {
$this->graph = new \EasyRdf_Graph($uri, NULL, $type);
$this->graph->load();
}
else {
$this->graph = new \EasyRdf_Graph(NULL);
$this->graph->parseFile($uri);
}
$this->iterateGraph();
}
catch (\Exception $e) {
throw new InvalidArgumentException("Invalid uri + $e");
}
}
示例2: 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));
}
}
示例3: 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;
}
示例4: get
/** Fetch a named graph from the graph store
*
* The URI can either be a full absolute URI or
* a URI relative to the URI of the graph store.
*
* @param string $uriRef The URI of graph desired
* @return object EasyRdf_Graph The graph requested
*/
public function get($uriRef)
{
$graphUri = EasyRdf_Utils::resolveUriReference($this->_uri, $uriRef);
$dataUrl = $this->urlForGraph($graphUri);
$graph = new EasyRdf_Graph($graphUri);
$graph->load($dataUrl);
return $graph;
}
示例5: get
/** Fetch a named graph from the graph store
*
* The URI can either be a full absolute URI or
* a URI relative to the URI of the graph store.
*
* @param string $uriRef The URI of graph desired
* @return object EasyRdf_Graph The graph requested
*/
public function get($uriRef)
{
$graphUri = $this->_parsedUri->resolve($uriRef)->toString();
$dataUrl = $this->urlForGraph($graphUri);
$graph = new EasyRdf_Graph($graphUri);
$graph->load($dataUrl);
return $graph;
}
示例6: actionEasyRDF
public function actionEasyRDF()
{
$this->layout = "test";
$foaf = new EasyRdf_Graph("http://njh.me/foaf.rdf");
$foaf->load();
$me = $foaf->primaryTopic();
echo "My name is: " . $me->get('foaf:name') . "\n";
}
示例7: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$relations = [];
$schemaOrg = new \EasyRdf_Graph();
$schemaOrg->load(TypesGeneratorConfiguration::SCHEMA_ORG_RDFA_URL, 'rdfa');
$relations[] = $schemaOrg;
$goodRelations = [new \SimpleXMLElement(TypesGeneratorConfiguration::GOOD_RELATIONS_OWL_URL, 0, true)];
$goodRelationsBridge = new GoodRelationsBridge($goodRelations);
$cardinalitiesExtractor = new CardinalitiesExtractor($relations, $goodRelationsBridge);
$result = $cardinalitiesExtractor->extract();
$output->writeln(json_encode($result, JSON_PRETTY_PRINT));
}
示例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: queryWorldCatFromOCLC
public function queryWorldCatFromOCLC()
{
$oclc = (string) (int) $this->OCLC;
$url = 'http://www.worldcat.org/oclc/' . $oclc;
$rdf = new EasyRdf_Graph($url . '.rdf');
$rdf->load();
$resources = $rdf->resources();
$book = $resources[$url];
//Core info
$this->Title = (string) $book->getLiteral('schema:name');
$publisherData = $book->get('schema:publisher');
if ($publisherData) {
$this->Publisher = (string) $publisherData->get('schema:name');
}
//Publishing date
$date = (string) $book->getLiteral('schema:datePublished');
if (strlen($date) == 4) {
$this->YYYY = $date;
} else {
echo '<div class="alert-box">Publishing date: ', $date, " / check the template, the code doesn't know how to parse this format and only made a guess. ", '<a href="" class="close">×</a></div>';
$date = date_parse($date);
$this->YYYY = $date['year'];
$this->MM = $date['month'];
$this->DD = $date['day'];
}
//Authors
$this->Authors = [];
//TODO: look type mapping
$contributors = $book->allResources('schema:contributor');
foreach ($contributors as $contributor) {
$this->Authors[] = [(string) $contributor->get('schema:givenName'), (string) $contributor->get('schema:familyName')];
}
//Kludge for library:placeOfPublication
//We have generally two links, one for the city, one for the country.
//Only the city has a schema:name, the country is only a reference.
$rdf_content = file_get_contents($url . '.rdf');
if (preg_match_all('@<library:placeOfPublication rdf:resource="(.*)"/>@', $rdf_content, $matches)) {
foreach ($matches[1] as $place) {
if ($cityCandidate = (string) $resources[$place]->get('schema:name')) {
$this->Place = $cityCandidate;
break;
}
}
}
}
示例11: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$configArgument = $input->getArgument('config');
if ($configArgument) {
$parser = new Parser();
$config = $parser->parse(file_get_contents($configArgument));
unset($parser);
} else {
$config = [];
}
$processor = new Processor();
$configuration = new TypesGeneratorConfiguration();
$processedConfiguration = $processor->processConfiguration($configuration, [$config]);
$processedConfiguration['output'] = realpath($input->getArgument('output'));
if (!$processedConfiguration['output']) {
throw new \RuntimeException('The specified output is invalid');
}
$graphs = [];
foreach ($processedConfiguration['rdfa'] as $rdfa) {
$graph = new \EasyRdf_Graph();
if ('http://' === substr($rdfa['uri'], 0, 7) || 'https://' === substr($rdfa['uri'], 0, 8)) {
$graph->load($rdfa['uri'], $rdfa['format']);
} else {
$graph->parseFile($rdfa['uri'], $rdfa['format']);
}
$graphs[] = $graph;
}
$relations = [];
foreach ($processedConfiguration['relations'] as $relation) {
$relations[] = new \SimpleXMLElement($relation, 0, true);
}
$goodRelationsBridge = new GoodRelationsBridge($relations);
$cardinalitiesExtractor = new CardinalitiesExtractor($graphs, $goodRelationsBridge);
$ucfirstFilter = new \Twig_SimpleFilter('ucfirst', 'ucfirst');
$loader = new \Twig_Loader_Filesystem(__DIR__ . '/../../templates/');
$twig = new \Twig_Environment($loader, ['autoescape' => false, 'debug' => $processedConfiguration['debug']]);
$twig->addFilter($ucfirstFilter);
if ($processedConfiguration['debug']) {
$twig->addExtension(new \Twig_Extension_Debug());
}
$logger = new ConsoleLogger($output);
$entitiesGenerator = new TypesGenerator($twig, $logger, $graphs, $cardinalitiesExtractor, $goodRelationsBridge);
$entitiesGenerator->generate($processedConfiguration);
}
示例12: 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;
}
示例13: array
print "<div style='margin: 10px'>\n";
print form_tag();
print label_tag('data', 'Input Data: ') . '<br />' . text_area_tag('data', '', array('cols' => 80, 'rows' => 10)) . "<br />\n";
print label_tag('uri', 'or Uri: ') . text_field_tag('uri', 'http://www.dajobe.org/foaf.rdf', array('size' => 80)) . "<br />\n";
print label_tag('input_format', 'Input Format: ') . select_tag('input_format', $input_format_options) . "<br />\n";
print label_tag('output_format', 'Output Format: ') . select_tag('output_format', $output_format_options) . "<br />\n";
print label_tag('raw', 'Raw Output: ') . check_box_tag('raw') . "<br />\n";
print reset_tag() . submit_tag();
print form_end_tag();
print "</div>\n";
}
if (isset($_REQUEST['uri']) or isset($_REQUEST['data'])) {
// Parse the input
$graph = new EasyRdf_Graph($_REQUEST['uri']);
if (empty($_REQUEST['data'])) {
$graph->load($_REQUEST['uri'], $_REQUEST['input_format']);
} else {
$graph->parse($_REQUEST['data'], $_REQUEST['input_format'], $_REQUEST['uri']);
}
// Lookup the output format
$format = EasyRdf_Format::getFormat($_REQUEST['output_format']);
// Serialise to the new output format
$output = $graph->serialise($format);
if (!is_scalar($output)) {
$output = var_export($output, true);
}
// Send the output back to the client
if (isset($_REQUEST['raw'])) {
header('Content-Type: ' . $format->getDefaultMimeType());
print $output;
} else {
示例14: urldecode
function del_friend($uri, $format = 'rdfxml')
{
$uri = urldecode($uri);
$path = $this->get_local_path($this->webid);
// Create the new graph object in which we store data
$graph = new EasyRdf_Graph($this->webid);
$graph->load();
$person = $graph->resource($this->webid);
$graph->deleteResource($person, 'foaf:knows', $uri);
// write profile to file
$data = $graph->serialise($format);
if (!is_scalar($data)) {
$data = var_export($data, true);
} else {
$data = print_r($data, true);
}
$pf = fopen($path . '/foaf.rdf', 'w') or die('Cannot open profile RDF file!');
fwrite($pf, $data);
fclose($pf);
$pf = fopen($path . '/foaf.txt', 'w') or die('Cannot open profile TXT file!');
fwrite($pf, $data);
fclose($pf);
// get the user's name
$friend = new MyProfile($uri, $this->base_uri, SPARQL_ENDPOINT);
$friend->load();
// everything is fine
return success("You have just removed " . $friend->get_name() . " from your list of friends.");
}
示例15: getData
public function getData()
{
$graph = new EasyRdf_Graph($this->getUri());
$graph->load();
}