本文整理汇总了PHP中EasyRdf_Graph::serialise方法的典型用法代码示例。如果您正苦于以下问题:PHP EasyRdf_Graph::serialise方法的具体用法?PHP EasyRdf_Graph::serialise怎么用?PHP EasyRdf_Graph::serialise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EasyRdf_Graph
的用法示例。
在下文中一共展示了EasyRdf_Graph::serialise方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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));
}
}
示例2: execute
/**
* Perform the load.
*
* @param EasyRdf_Graph $chunk
* @return void
*/
public function execute(&$chunk)
{
if (!$chunk->isEmpty()) {
// Don't use EasyRdf's ntriple serializer, as something might be wrong with its unicode byte characters
// After serializing with semsol/arc and easyrdf, the output looks the same (with unicode characters), but after a
// binary utf-8 conversion (see $this->serialize()) the outcome is very different, leaving easyrdf's encoding completely different
// from the original utf-8 characters, and the semsol/arc encoding correct as the original.
$ttl = $chunk->serialise('turtle');
$arc_parser = \ARC2::getTurtleParser();
$ser = \ARC2::getNTriplesSerializer();
$arc_parser->parse('', $ttl);
$triples = $ser->getSerializedTriples($arc_parser->getTriples());
preg_match_all("/(<.*\\.)/", $triples, $matches);
if ($matches[0]) {
$this->buffer = array_merge($this->buffer, $matches[0]);
}
$triple_count = count($matches[0]);
$this->log("Added {$triple_count} triples to the load buffer.");
while (count($this->buffer) >= $this->loader->buffer_size) {
// Log the time it takes to load the triples into the store
$start = microtime(true);
$buffer_size = $this->loader->buffer_size;
$triples_to_send = array_slice($this->buffer, 0, $buffer_size);
$this->addTriples($triples_to_send);
$this->buffer = array_slice($this->buffer, $buffer_size);
$duration = round((microtime(true) - $start) * 1000, 2);
$this->log("Took {$buffer_size} triples from the load buffer, loading them took {$duration} ms.");
}
}
}
示例3: 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;
}
示例4: getTriples
protected function getTriples($file)
{
if (!file_exists($file)) {
throw new Exception($file . ' not found');
}
// validate the file to import
$parser = new tao_models_classes_Parser($file, array('extension' => 'rdf'));
$parser->validate();
if (!$parser->isValid()) {
throw new common_Exception('Invalid RDF file ' . $file);
}
$modelDefinition = new EasyRdf_Graph();
$modelDefinition->parseFile($file);
/*
$graph = $modelDefinition->toRdfPhp();
$resources = $modelDefinition->resources();
*/
$format = EasyRdf_Format::getFormat('php');
$data = $modelDefinition->serialise($format);
$triples = array();
foreach ($data as $subjectUri => $propertiesValues) {
foreach ($propertiesValues as $prop => $values) {
foreach ($values as $k => $v) {
$triples[] = array('s' => $subjectUri, 'p' => $prop, 'o' => $v['value'], 'l' => isset($v['lang']) ? $v['lang'] : '');
}
}
}
return $triples;
}
示例5: preRun
protected function preRun()
{
$data = parent::getData();
$resourceUri = JURI::base() . "index.php?com_content&view=article&id=" . $data["articleID"];
$annotation = new EasyRdf_Graph($resourceUri);
foreach ($data["entityIDs"] as $entityID) {
$annotation->addResource($resourceUri, "sioc:about", "http://www.mni.thm.de/user/" . $entityID);
}
parent::setData($annotation->serialise("rdfxml"));
}
示例6: 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);
}
示例7: 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));
}
示例8: flatImport
/**
* Imports the rdf file into the selected class
*
* @param string $file
* @param core_kernel_classes_Class $class
* @return common_report_Report
*/
private function flatImport($file, core_kernel_classes_Class $class)
{
$report = common_report_Report::createSuccess(__('Data imported successfully'));
$graph = new EasyRdf_Graph();
$graph->parseFile($file);
// keep type property
$map = array(RDF_PROPERTY => RDF_PROPERTY);
foreach ($graph->resources() as $resource) {
$map[$resource->getUri()] = common_Utils::getNewUri();
}
$format = EasyRdf_Format::getFormat('php');
$data = $graph->serialise($format);
foreach ($data as $subjectUri => $propertiesValues) {
$resource = new core_kernel_classes_Resource($map[$subjectUri]);
$subreport = $this->importProperties($resource, $propertiesValues, $map, $class);
$report->add($subreport);
}
return $report;
}
示例9: 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;
}
示例10: form_tag
<?php
echo form_tag();
?>
<?php
echo label_tag('uri') . text_field_tag('uri', 'http://www.dajobe.org/foaf.rdf', array('size' => 80));
?>
<br />
<?php
echo label_tag('format') . select_tag('format', $format_options, 'rdfxml');
?>
<?php
echo submit_tag();
?>
<?php
echo form_end_tag();
?>
</div>
<?php
if (isset($_REQUEST['uri'])) {
$graph = new EasyRdf_Graph($_REQUEST['uri']);
$data = $graph->serialise($_REQUEST['format']);
if (!is_scalar($data)) {
$data = var_export($data, true);
}
print "<pre>" . htmlspecialchars($data) . "</pre>";
}
?>
</body>
</html>
示例11: 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);
}
示例12: substr
} else {
mysql_free_result($result);
}
// autmatically subscribe to local services
$tiny = substr(md5(uniqid(microtime(true), true)), 0, 8);
$user_hash = substr(sha1($webid), 0, 20);
$query = "INSERT INTO pingback SET webid='" . $webid . "', feed_hash='" . $tiny . "', user_hash='" . $user_hash . "'";
$result = mysql_query($query);
if (!$result) {
$alert .= error('Unable to write to the database!');
} else {
mysql_free_result($result);
}
}
// write profile to file
$data = $graph->serialise('rdfxml');
if (!is_scalar($data)) {
$data = var_export($data, true);
}
$pf = fopen($user_dir . '/foaf.rdf', 'w') or die('Cannot create profile RDF file in ' . $user_dir . '!');
fwrite($pf, $data);
fclose($pf);
$pf = fopen($user_dir . '/foaf.txt', 'w') or die('Cannot create profile PHP file!');
fwrite($pf, $data);
fclose($pf);
// everything is fine
$ok = true;
// Send the X.509 SSL certificate to the script caller (user) as a file transfer
if ($_REQUEST['action'] == 'new' || $_REQUEST['action'] == 'import') {
download_identity_x509($x509, $webid);
} else {
示例13: returnHttpError
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 {
echo $graph->serialise($outputFormats[$outputFormat][1]);
exit;
示例14: 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;
}
示例15: 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>