本文整理汇总了PHP中EasyRdf_Graph::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP EasyRdf_Graph::parse方法的具体用法?PHP EasyRdf_Graph::parse怎么用?PHP EasyRdf_Graph::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EasyRdf_Graph
的用法示例。
在下文中一共展示了EasyRdf_Graph::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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());
}
示例3: saveAdditionalRdf
public function saveAdditionalRdf($userId)
{
try {
$serializedRdf = trim(stripslashes($_POST['additionalRdf']));
if (!empty($serializedRdf)) {
$graph = new \EasyRdf_Graph();
$graph->parse($serializedRdf);
// parsing if done to check if syntax is valid
update_user_meta($userId, 'additionalRdf', $serializedRdf);
} else {
update_user_meta($userId, 'additionalRdf', '');
}
} catch (\Exception $ex) {
wp_die('Addtional RDF Triples could not be saved. Cause: ' . $ex->getMessage());
}
}
示例4: get
/**
* Get a certain dataset
*
* @param string $id The id of the dataset
*
* @return EasyRdf_Resource
*/
public function get($id)
{
$uri = \URL::to('/users/' . $id);
$collection = $this->getMongoCollection();
$cursor = $collection->find(['@id' => $uri]);
if ($cursor->hasNext()) {
$jsonLd = $cursor->getNext();
unset($jsonLd['_id']);
$expand = JsonLD::expand(json_encode($jsonLd));
$jsonLd = (array) $expand;
$graph = new \EasyRdf_Graph();
$json_ld = json_encode($jsonLd);
$graph->parse($json_ld, 'jsonld');
return $graph;
} else {
return [];
}
}
示例5: mergeGraph
/**
* Merge two graphs and return the resulting merged graph
*
* @param EasyRdf_Graph $graph
* @param EasyRdf_Graph $input_graph
*
* @return EasyRdf_Graph
*/
private function mergeGraph($graph, $input_graph)
{
$turtle_graph = $input_graph->serialise('turtle');
$graph->parse($turtle_graph, 'turtle');
return $graph;
}
示例6: testIssue115
/**
* @see https://github.com/njh/easyrdf/issues/115
*/
public function testIssue115()
{
$triples = <<<RDF
<http://example.com/id/1> <http://www.w3.org/2000/01/rdf-schema#type> <http://example.com/ns/animals/dog> .
<http://example.com/id/2> <http://www.w3.org/2000/01/rdf-schema#type> <http://example.com/ns/animals/cat> .
<http://example.com/id/3> <http://www.w3.org/2000/01/rdf-schema#type> <http://example.com/ns/animals/bird> .
<http://example.com/id/4> <http://www.w3.org/2000/01/rdf-schema#type> <http://example.com/ns/animals/reptiles/snake> .
RDF;
EasyRdf_Namespace::set('id', 'http://example.com/id/');
EasyRdf_Namespace::set('animals', 'http://example.com/ns/animals/');
// parse graph
$graph = new EasyRdf_Graph();
$graph->parse($triples, 'ntriples');
// dump as text/turtle
$turtle = $graph->serialise('turtle');
$this->assertEquals(readFixture('turtle/gh115-nested-namespaces.ttl'), $turtle);
}
示例7: json_encode
foreach (EasyRdf_Format::getFormats() as $format) {
if ($format->getSerialiserClass()) {
$output_format_options[$format->getLabel()] = $format->getName();
}
if ($format->getParserClass()) {
$input_format_options[$format->getLabel()] = $format->getName();
}
}
if (get_magic_quotes_gpc() and isset($fileContent)) {
$fileContent = stripslashes($fileContent);
}
$_REQUEST['output_format'] = 'dot';
$_REQUEST['input_format'] = 'guess';
$graph = new EasyRdf_Graph();
$returnValue = array();
try {
$graph->parse($fileContent, $_REQUEST['input_format']);
} catch (EasyRdf_Exception $e) {
$returnValue['status'] = "failure";
$returnValue['message'] = $e->getMessage();
echo json_encode($returnValue);
return;
}
$format = EasyRdf_Format::getFormat($_REQUEST['output_format']);
$output = $graph->serialise($format);
if (!is_scalar($output)) {
$output = var_export($output, true);
}
$returnValue['status'] = "success";
$returnValue['content'] = $output;
echo json_encode($returnValue);
示例8: testParseDataGuess
public function testParseDataGuess()
{
$graph = new EasyRdf_Graph();
$data = readFixture('foaf.json');
$graph->parse($data, 'guess');
$name = $graph->get('http://www.example.com/joe#me', 'foaf:name');
$this->assertEquals('EasyRdf_Literal', get_class($name));
$this->assertEquals('Joe Bloggs', $name->getValue());
$this->assertEquals('en', $name->getLang());
$this->assertEquals(null, $name->getDatatype());
}
示例9: specificTrain
/**
* Shows a train or train data, based on the accept-header.
* @param $station_id
* @param $liveboard_id
* @return array
* @throws EasyRdf_Exception
*/
public function specificTrain($station_id, $liveboard_id)
{
$negotiator = new \Negotiation\FormatNegotiator();
$acceptHeader = Request::header('accept');
$priorities = array('application/json', 'text/html', '*/*');
$result = $negotiator->getBest($acceptHeader, $priorities);
$val = $result->getValue();
//get the right date-time to query
$datetime = substr($liveboard_id, 0, 12);
$datetime = strtotime($datetime);
$archived = false;
if ($datetime < strtotime("now")) {
$archived = true;
}
switch ($val) {
case "text/html":
// Convert id to string for interpretation by old API
$stationStringName = \hyperRail\StationString::convertToString($station_id);
if (!$archived) {
// Set up path to old api
$URL = "http://api.irail.be/liveboard/?station=" . urlencode($stationStringName->name) . "&date=" . date("mmddyy", $datetime) . "&time=" . date("Hi", $datetime) . "&fast=true&lang=nl&format=json";
// Get the contents of this path
$data = file_get_contents($URL);
// Convert the data to the new liveboard object
$newData = \hyperRail\FormatConverter::convertLiveboardData($data, $station_id);
// Read new liveboard object and return the page but load data
foreach ($newData['@graph'] as $graph) {
if (strpos($graph['@id'], $liveboard_id) !== false) {
return View::make('stations.departuredetail')->with('station', $graph)->with('departureStation', $stationStringName);
}
}
App::abort(404);
} else {
// If no match is found, attempt to look in the archive
// Fetch file using curl
$ch = curl_init("http://archive.irail.be/" . 'irail?subject=' . urlencode('http://irail.be/stations/NMBS/' . $station_id . '/departures/' . $liveboard_id));
curl_setopt($ch, CURLOPT_HEADER, 0);
$request_headers[] = 'Accept: text/turtle';
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$turtle = curl_exec($ch);
curl_close($ch);
// Convert turtle to json-ld
// Create a new graph
$graph = new EasyRdf_Graph();
if (empty($_REQUEST['data'])) {
// Load the sample information
$graph->parse($turtle, 'turtle');
}
// Export to JSON LD
$format = EasyRdf_Format::getFormat('jsonld');
$output = $graph->serialise($format);
if (!is_scalar($output)) {
$output = var_export($output, true);
}
// First, define the context
$context = array("delay" => "http://semweb.mmlab.be/ns/rplod/delay", "platform" => "http://semweb.mmlab.be/ns/rplod/platform", "scheduledDepartureTime" => "http://semweb.mmlab.be/ns/rplod/scheduledDepartureTime", "headsign" => "http://vocab.org/transit/terms/headsign", "routeLabel" => "http://semweb.mmlab.be/ns/rplod/routeLabel", "stop" => array("@id" => "http://semweb.mmlab.be/ns/rplod/stop", "@type" => "@id"), "seeAlso" => array("@id" => "http://www.w3.org/2000/01/rdf-schema#seeAlso", "@type" => "@id"));
// Next, encode the context as JSON
$jsonContext = json_encode($context);
// Compact the JsonLD by using @context
$compacted = JsonLD::compact($output, $jsonContext);
// Print the resulting JSON-LD!
$urlToFind = 'NMBS/' . $station_id . '/departures/' . $liveboard_id;
$stationDataFallback = json_decode(JsonLD::toString($compacted, true));
foreach ($stationDataFallback->{'@graph'} as $graph) {
if (strpos($graph->{'@id'}, $urlToFind) !== false) {
return View::make('stations.departurearchive')->with('station', $graph)->with('departureStation', $stationStringName);
}
}
App::abort(404);
}
break;
case "application/json":
case "application/ld+json":
default:
$stationStringName = \hyperRail\StationString::convertToString($station_id);
if (!$archived) {
$URL = "http://api.irail.be/liveboard/?station=" . urlencode($stationStringName->name) . "&date=" . date("mmddyy", $datetime) . "&time=" . date("Hi", $datetime) . "&fast=true&lang=nl&format=json";
$data = file_get_contents($URL);
$newData = \hyperRail\FormatConverter::convertLiveboardData($data, $station_id);
foreach ($newData['@graph'] as $graph) {
if (strpos($graph['@id'], $liveboard_id) !== false) {
$context = array("delay" => "http://semweb.mmlab.be/ns/rplod/delay", "platform" => "http://semweb.mmlab.be/ns/rplod/platform", "scheduledDepartureTime" => "http://semweb.mmlab.be/ns/rplod/scheduledDepartureTime", "headsign" => "http://vocab.org/transit/terms/headsign", "routeLabel" => "http://semweb.mmlab.be/ns/rplod/routeLabel", "stop" => array("@id" => "http://semweb.mmlab.be/ns/rplod/stop", "@type" => "@id"));
return array("@context" => $context, "@graph" => $graph);
}
}
App::abort(404);
} else {
// If no match is found, attempt to look in the archive
// Fetch file using curl
$ch = curl_init("http://archive.irail.be/" . 'irail?subject=' . urlencode('http://irail.be/stations/NMBS/' . $station_id . '/departures/' . $liveboard_id));
curl_setopt($ch, CURLOPT_HEADER, 0);
$request_headers[] = 'Accept: text/turtle';
//.........这里部分代码省略.........
示例10: returnHttpError
break;
default:
returnHttpError(300);
break;
}
}
}
EasyRdf_Namespace::set('adms', 'http://www.w3.org/ns/adms#');
EasyRdf_Namespace::set('cnt', 'http://www.w3.org/2011/content#');
EasyRdf_Namespace::set('dc', 'http://purl.org/dc/elements/1.1/');
EasyRdf_Namespace::set('dcat', 'http://www.w3.org/ns/dcat#');
EasyRdf_Namespace::set('gsp', 'http://www.opengis.net/ont/geosparql#');
EasyRdf_Namespace::set('locn', 'http://www.w3.org/ns/locn#');
EasyRdf_Namespace::set('prov', 'http://www.w3.org/ns/prov#');
$graph = new EasyRdf_Graph();
$graph->parse($rdf, "rdfxml", $rdfxmlURL);
header("Content-type: " . $outputFormat);
echo $graph->serialise($outputFormats[$outputFormat][1]);
exit;
/*
if ($outputFormat == 'text/html') {
$xml = new DOMDocument;
$xml->loadXML($rdf) or die();
$xsl = new DOMDocument;
$xsl->load("");
$proc = new XSLTProcessor();
$proc->importStyleSheet($xsl);
echo $proc->transformToXML($xml);
exit;
}
else {
示例11: testMockParser
public function testMockParser()
{
EasyRdf_Format::registerParser('mock', 'Mock_RdfParser');
$graph = new EasyRdf_Graph();
$graph->parse('data', 'mock');
$this->assertStringEquals('Joseph Bloggs', $graph->get('http://www.example.com/joe#me', 'foaf:name'));
}
示例12: mergeGraph
/**
* Merge two graphs and return the result
*
* @param EasyRdf_Graph $graph
* @param EasyRdf_Graph $input_graph
*
* @return EasyRdf_Graph
*/
private function mergeGraph($graph, $input_graph)
{
$rdfxml_string = $input_graph->serialise('rdfxml');
$graph->parse($rdfxml_string, 'rdfxml');
return $graph;
}
示例13: getGraph
/**
* Gets RDF metadata from Fedora.
*
* @param string $uri Resource URI
* @param array $headers HTTP Headers
* @param string $transaction Transaction id
*
* @return EasyRdf_Graph
*/
public function getGraph($uri = "", $headers = [], $transaction = "")
{
$headers['Accept'] = 'application/ld+json';
$rdf = (string) $this->getResource($uri, $headers, $transaction);
if (empty($rdf)) {
return null;
}
$graph = new \EasyRdf_Graph();
$graph->parse($rdf, 'jsonld');
return $graph;
}
示例14: reset_tag
?>
<br />
<?php
echo reset_tag();
?>
<?php
echo submit_tag();
?>
<?php
echo form_end_tag();
?>
</div>
<?php
if (isset($_REQUEST['uri']) or isset($_REQUEST['data'])) {
$graph = new EasyRdf_Graph($_REQUEST['uri']);
if (empty($_REQUEST['data'])) {
$graph->load();
} else {
$graph->parse($_REQUEST['data'], $_REQUEST['input_format'], $_REQUEST['uri']);
}
$output = $graph->serialise($_REQUEST['output_format']);
if (!is_scalar($output)) {
$output = var_export($output, true);
}
print "<pre>" . htmlspecialchars($output) . "</pre>";
}
?>
</body>
</html>
示例15: testGetRDFShouldIncludeLists
/**
* @covers Model::getRDF
* @depends testConstructorWithConfig
*/
public function testGetRDFShouldIncludeLists()
{
$model = new Model(new GlobalConfig('/../tests/testconfig.inc'));
$result = $model->getRDF('test', 'http://www.skosmos.skos/test/ta124', 'text/turtle');
$resultGraph = new EasyRdf_Graph();
$resultGraph->parse($result, "turtle");
$expected = '@prefix test: <http://www.skosmos.skos/test/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix mads: <http://www.loc.gov/mads/rdf/v1#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
skos:prefLabel rdfs:label "preferred label"@en .
test:ta124
a mads:ComplexSubject, skos:Concept ;
skos:prefLabel "Vadefugler : Europa"@nb ;
mads:componentList ( test:ta125 test:ta126 ) .
test:ta125
a mads:Topic, skos:Concept ;
skos:prefLabel "Vadefugler"@nb .
test:ta126
a mads:Geographic, skos:Concept ;
skos:prefLabel "Europa"@nb .
';
$expectedGraph = new EasyRdf_Graph();
$expectedGraph->parse($expected, "turtle");
$this->assertTrue(EasyRdf_Isomorphic::isomorphic($resultGraph, $expectedGraph));
}