本文整理汇总了PHP中ARC2::getTurtleSerializer方法的典型用法代码示例。如果您正苦于以下问题:PHP ARC2::getTurtleSerializer方法的具体用法?PHP ARC2::getTurtleSerializer怎么用?PHP ARC2::getTurtleSerializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ARC2
的用法示例。
在下文中一共展示了ARC2::getTurtleSerializer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct($a = '')
{
parent::__construct();
$this->a = $a;
/* parse the before and after graphs if necessary*/
foreach (array('before', 'after', 'before_rdfxml', 'after_rdfxml') as $rdf) {
if (!empty($a[$rdf])) {
if (is_string($a[$rdf])) {
/** @var \ARC2_RDFParser $parser */
$parser = \ARC2::getRDFParser();
$parser->parse(false, $a[$rdf]);
$a[$rdf] = $parser->getSimpleIndex(0);
} else {
if (is_array($a[$rdf]) and isset($a[$rdf][0]) and isset($a[$rdf][0]['s'])) {
//triples array
/** @var \ARC2_RDFSerializer $ser */
$ser = \ARC2::getTurtleSerializer();
/** @var string $turtle */
$turtle = $ser->getSerializedTriples($a[$rdf]);
/** @var \ARC2_RDFParser $parser */
$parser = \ARC2::getTurtleParser();
$parser->parse(false, $turtle);
$a[$rdf] = $parser->getSimpleIndex(0);
}
}
$nrdf = str_replace('_rdfxml', '', $rdf);
$this->{$nrdf} = $a[$rdf];
}
}
$this->__init();
}
示例2: printGraph
public function printGraph()
{
/* Serializer instantiation */
$ser = \ARC2::getTurtleSerializer();
foreach ($this->objectToPrint as $class => $prop) {
$triples = $prop->getTriples();
}
/* Serialize a triples array */
echo $ser->getSerializedTriples($triples);
}
示例3: getRdf
/**
* getRdf get the full BIBO RDF serialization of the collection of entries
* @param $format the serialization format
* @throws Exception if PHP_ZOTERO_ENTRIES_ARC_PATH is not defined
*/
public function getRdf($format = 'rdf/xml')
{
if (!defined('PHP_ZOTERO_ENTRIES_ARC_PATH')) {
throw new Exception('PHP_ZOTERO_ENTRIES_ARC_PATH must be defined and valid to use RDF methods');
}
require_once PHP_ZOTERO_ENTRIES_ARC_PATH;
switch ($format) {
case 'rdf/xml':
$ser = ARC2::getRDFXMLSerializer($this->arcConf);
break;
case 'rdf/json':
$ser = ARC2::getRDFJsonSerializer($this->arcConf);
break;
case 'turtle':
$ser = ARC2::getTurtleSerializer($this->arcConf);
break;
case 'ntriples':
$ser = ARC2::getNTriplesSerializer($this->arcConf);
break;
}
return $ser->getSerializedIndex($this->getArcIndex());
}
示例4: getTurtleDescribeResultDoc
function getTurtleDescribeResultDoc($r)
{
$this->setHeader('content-type', 'Content-Type: application/x-turtle');
$index = $r['result'];
$ser = ARC2::getTurtleSerializer($this->a);
$dur = $r['query_time'];
return '# query time: ' . $dur . "\n" . $ser->getSerializedIndex($index);
}
示例5: serializeRdf
public static function serializeRdf($data, $extension = 'rdf')
{
global $conf;
global $lodspk;
$ser;
$dPointer;
$docs = Utils::travelTree($data);
require_once $conf['home'] . 'lib/arc2/ARC2.php';
$parser = ARC2::getRDFParser();
$triples = array();
foreach ($docs as $d) {
$parser->parse($conf['basedir'], $d);
$t = $parser->getTriples();
$triples = array_merge($triples, $t);
}
if ($lodspk['mirror_external_uris']) {
global $uri;
global $localUri;
$t = array();
$t['s'] = $localUri;
$t['s_type'] = 'uri';
$t['p'] = "http://www.w3.org/2002/07/owl#sameAs";
$t['o'] = $uri;
$t['o_type'] = 'uri';
array_push($triples, $t);
$t['p'] = "http://www.w3.org/2000/10/swap/pim/contact#preferredURI";
array_push($triples, $t);
}
switch ($extension) {
case 'ttl':
$ser = ARC2::getTurtleSerializer();
break;
case 'nt':
$ser = ARC2::getNTriplesSerializer();
break;
case 'json':
$ser = ARC2::getRDFJSONSerializer();
break;
case 'rdf':
$ser = ARC2::getRDFXMLSerializer();
break;
case 'html':
return array("content" => $triples, "serialized" => false);
break;
default:
$ser = null;
}
if ($ser != null) {
$doc = $ser->getSerializedTriples($triples);
} else {
$doc = var_export($data, true);
}
return array("content" => $doc, "serialized" => true);
}
示例6: runQueryEvaluationTest
function runQueryEvaluationTest($id)
{
$nl = "\n";
$r = '';
/* get action */
$q = '
PREFIX mf: <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#> .
PREFIX qt: <http://www.w3.org/2001/sw/DataAccess/tests/test-query#> .
SELECT DISTINCT ?query ?data ?graph_data ?result WHERE {
<' . $id . '> mf:action ?action ;
mf:result ?result .
?action qt:query ?query .
OPTIONAL {
?action qt:data ?data .
}
OPTIONAL {
?action qt:graphData ?graph_data .
}
}
';
$qr = $this->store->query($q);
$rows = $qr['result']['rows'];
$infos = array();
foreach (array('query', 'data', 'result', 'graph_data') as $var) {
$infos[$var] = array();
$infos[$var . '_value'] = array();
foreach ($rows as $row) {
if (isset($row[$var])) {
if (!in_array($row[$var], $infos[$var])) {
$infos[$var][] = $row[$var];
$infos[$var . '_value'][] = $this->getFile($row[$var]);
}
}
}
${$var} = $infos[$var];
${$var . '_value'} = $infos[$var . '_value'];
if (count($infos[$var]) == 1) {
${$var} = $infos[$var][0];
${$var . '_value'} = $infos[$var . '_value'][0];
}
if (${$var} && $var != '-result') {
//echo '<pre>' . $$var . $nl . $nl . htmlspecialchars(${$var . '_value'}) . '</pre><hr />';
}
}
/* query infos */
ARC2::inc('SPARQLPlusParser');
$parser = new ARC2_SPARQLPlusParser($this->a, $this);
$parser->parse($query_value, $query);
$infos = $parser->getQueryInfos();
$rest = $parser->getUnparsedCode();
$errors = $parser->getErrors();
$q_type = !$errors ? $infos['query']['type'] : '';
/* add data */
$dsets = array();
$gdsets = array();
if ($data) {
$dsets = is_array($data) ? array_merge($dsets, $data) : array_merge($dsets, array($data));
}
if ($graph_data) {
$gdsets = is_array($graph_data) ? array_merge($gdsets, $graph_data) : array_merge($gdsets, array($graph_data));
}
if (!$dsets && !$gdsets) {
foreach ($infos['query']['dataset'] as $set) {
if ($set['named']) {
$gdsets[] = $set['graph'];
} else {
$dsets[] = $set['graph'];
}
}
}
$store = $this->data_store;
$store->reset();
foreach ($dsets as $graph) {
$qr = $store->query('LOAD <' . $graph . '>');
}
foreach ($gdsets as $graph) {
$qr = $store->query('LOAD <' . $graph . '> INTO <' . $graph . '>');
}
/* run query */
if ($query) {
$sql = $store->query($query_value, 'sql', $query);
$qr = $store->query($query_value, '', $query);
$qr_result = $qr['result'];
if ($q_type == 'select') {
$qr_result = $this->adjustBnodes($qr['result'], $id);
} elseif ($q_type == 'construct') {
$ser = ARC2::getTurtleSerializer($this->a);
$qr_result = $ser->getSerializedIndex($qr_result);
}
}
//echo '<pre>query result: ' . $nl . htmlspecialchars(print_r($qr_result, 1)) . '</pre>';
if (!$query || $errors || $rest) {
return array('pass' => 0, 'info' => 'query could not be parsed' . htmlspecialchars($query_value));
}
$m = 'isSame' . $q_type . 'Result';
$sub_r = $this->{$m}($qr_result, $result_value, $result, $id);
$pass = $sub_r['pass'];
if (in_array($id, array('http://www.w3.org/2001/sw/DataAccess/tests/data-r2/sort/manifest#dawg-sort-6', 'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/sort/manifest#dawg-sort-8', 'http://www.w3.org/2001/sw/DataAccess/tests/data-r2/sort/manifest#dawg-sort-builtin'))) {
$pass = 0;
/* manually checked 2007-09-18 */
//.........这里部分代码省略.........
示例7: switch
$ser = null;
switch ($outformat) {
case "turtle":
$ser = ARC2::getTurtleSerializer(array('ns' => $ns));
break;
case "rdfxml":
$ser = ARC2::getRDFXMLSerializer(array('ns' => $ns));
break;
case "json":
$ser = ARC2::getRDFJSONSerializer(array('ns' => $ns));
break;
case "ntriples":
$ser = ARC2::getNTriplesSerializer(array('ns' => $ns));
break;
default:
$ser = ARC2::getTurtleSerializer(array('ns' => $ns));
break;
}
$output = "";
if ($outformat == "turtle") {
$output = $ser->getSerializedTriples($triples);
header("Content-Type: text/turtle");
} else {
if ($outformat == "rdfxml") {
$output = $ser->getSerializedTriples($triples);
header("Content-Type: application/rdf+xml");
} else {
if ($outformat == "json") {
$ser = ARC2::getRDFJSONSerializer(array('ns' => $ns));
$output = $ser->getSerializedTriples($triples);
} else {
示例8: to_turtle
/**
* Serialise the graph to Turtle
* @see http://www.dajobe.org/2004/01/turtle/
* @return string the Turtle version of the graph
*/
function to_turtle()
{
$this->update_prefix_mappings();
$serializer = ARC2::getTurtleSerializer(array('ns' => $this->_labeller->get_ns()));
return $serializer->getSerializedIndex($this->_to_arc_index($this->_index));
}
示例9: execute
public function execute($service)
{
global $conf;
$this->serialization = "";
$this->graph = array();
header('Content-Type: text/plain');
define("CNT", "http://www.w3.org/2011/content#");
define("NSVIZON", "http://graves.cl/vizon/");
define("LS", "http://lodspeakr.org/lda/");
define("LDA", "http://tw.rpi.edu/lda/");
define("DC", "http://purl.org/dc/terms/");
define("RDF", "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
define("RDFS", "http://www.w3.org/2000/01/rdf-schema#");
define("OPMV", "http://openprovenance.org/ontology#");
define("SKOS", "http://www.w3.org/2004/02/skos/core#");
require $conf['home'] . 'lib/arc2/ARC2.php';
$ser = ARC2::getTurtleSerializer();
$triples = array();
$t = array();
$t['s'] = $conf['basedir'];
$t['s_type'] = 'uri';
$t['p'] = RDF . 'type';
$t['o'] = OPMV . 'Agent';
$t['o_type'] = 'uri';
array_push($triples, $t);
$t['o'] = SKOS . 'Concept';
array_push($triples, $t);
$t['o'] = LS . 'Application';
array_push($triples, $t);
if ($conf['parentApp'] != NULL) {
$t['p'] = OPMV . 'wasDerivedFrom';
$t['o'] = $conf['parentApp'];
array_push($triples, $t);
}
$sparqlComponent = $conf['basedir'] . 'sparqlComponent';
//uniqid("_:b");
$baseComponent = $conf['basedir'];
//uniqid("_:b");
$components = $this->getComponents($conf['home'] . $conf['view']['directory'] . "/" . $conf['service']['prefix'], '');
//var_dump($components);exit(0);
//Define Process
$t = array();
foreach ($components as $k => $m) {
$process = uniqid("_:b");
$t['s'] = $process;
$t['s_type'] = 'bnode';
$t['p'] = RDF . 'type';
$t['o'] = OPMV . 'Process';
$t['o_type'] = 'uri';
array_push($triples, $t);
//Controlled by
$component = $baseComponent . $conf['service']['prefix'] . "/" . $k;
$t['p'] = OPMV . 'wasControlledBy';
$t['o'] = $component;
$t['o_type'] = 'uri';
array_push($triples, $t);
//Associated Agent to this installation
$aux = $t['o'];
$t['s'] = $t['o'];
$t['p'] = RDF . 'type';
$t['o'] = OPMV . 'Component';
array_push($triples, $t);
$t['p'] = SKOS . 'broader';
$t['o'] = $conf['basedir'];
$t['o_type'] = 'uri';
array_push($triples, $t);
//$t['s'] = $process;
//$t['s_type'] = 'bnode';
$visualPart = uniqid("_:b");
$queryPart = uniqid("_:b");
$t['p'] = SKOS . 'broader';
$t['s'] = $queryPart;
$t['s_type'] = 'bnode';
$t['o'] = $component;
array_push($triples, $t);
$t['s'] = $visualPart;
array_push($triples, $t);
foreach ($m as $l => $v) {
if (strpos($l, "query") > -1) {
$t2['s'] = $queryPart;
$t2['p'] = RDF . 'type';
$t2['o'] = LS . 'LodspeakrDataComponent';
$t2['o_type'] = 'uri';
} else {
$t2['s'] = $visualPart;
$t2['p'] = RDF . 'type';
$t2['o'] = LS . 'LodspeakrVisualComponent';
$t2['o_type'] = 'uri';
}
array_push($triples, $t2);
$t2['p'] = NSVIZON . 'hasInput';
$t2['o'] = $baseComponent . $conf['service']['prefix'] . "/" . $k . "/" . $l;
$t2['o_type'] = 'uri';
array_push($triples, $t2);
$t2['s'] = $t2['o'];
$t2['p'] = DC . "hasFormat";
$t2['o'] = uniqid("_:b");
$t2['o_type'] = 'bnode';
array_push($triples, $t2);
$t2['s'] = $t2['o'];
//.........这里部分代码省略.........
示例10: toTurtle
function toTurtle()
{
$index = $this->toIndex();
$ser = ARC2::getTurtleSerializer(array('ns' => $this->ns));
return $ser->getSerializedIndex($index);
}
示例11: xml2turtle
function xml2turtle($file)
{
//Andrea Mazzocchi
include_once "semsol-arc2-c7c03da/ARC2.php";
//Leggo il database in una stringa
$string = file_get_contents($file);
//Interpreto una stringa XML in un oggetto
$obj = simplexml_load_string($string);
//Ritorna la rappresentazione JSON di un valore, prende una
//stringa JSON encoded e la converte in una variabile
$data = json_decode(json_encode((array) $obj), 1);
//Array associativo utile per la gestione dei prefix
$namespace = array(':' => 'http://www.essepuntato.it/resource/', 'vcard' => 'http://www.w3.org/2006/vcard/ns#', 'cs' => 'http://cs.unibo.it/ontology/', 'dcterms' => 'http://purl.org/dc/terms/', 'xsd' => 'http://www.w3.org/2001/XMLSchema#', 'this' => 'http://vitali.web.cs.unibo.it/twiki/pub/TechWeb12/DataSource2/posteBO2011.ttl');
$namespace2 = array("ns" => $namespace);
//Elimino "@attributes" creando nuove chiavi apposta per "id", "lat"
//e "long", salvandole dalla rimozione di "@attributes"
for ($i = 0; $i < count($data['location']); $i++) {
//Memorizzo le chiavi dell'array associativo
$attr = array_keys($data['location'][$i]['@attributes']);
for ($a = 0; $a < count($attr); $a++) {
$attr_temp = $attr[$a];
$data['location'][$i][$attr_temp] = $data['location'][$i]['@attributes'][$attr_temp];
}
//Cancello le posizioni, ormai inutili, dove
//"id", "lat" e "long" erano prima contenuti
unset($data['location'][$i]['@attributes']);
}
//Per la conversione in Turtle ho convertito da XML ad array associativo
//che memorizza il documento da convertire in Turtle
$newarray = array();
foreach ($data as $key => $value) {
//Codice per il riempimento del blocco "metadata"
if (strcasecmp($key, 'metadata') == 0) {
//Memorizzo le chiavi di $value...
$s = array_keys($value);
//...eseguendo un ciclo di riempimento
for ($j = 0; $j < count($value); $j++) {
//$deep memorizza i nomi dei tag XML del
//campo metadata (creator, created, ...)
$deep = $s[$j];
//Richiamo da $namespace i prefix per i metadata
$meta_subj = $namespace['this'];
$dcterms = $namespace['dcterms'];
$xsd = $namespace['xsd'];
//"created" e "valid" sono delle date e devono essere validati
//dal prefix xsd in modo da distinguerli da semplice stringhe
if (stristr($deep, 'created') or stristr($deep, 'valid')) {
$newarray[$meta_subj . 'metadata'][$dcterms . $deep] = array($data['metadata'][$deep], $xsd . 'date');
} else {
$newarray[$meta_subj . 'metadata'][$dcterms . $deep] = $data['metadata'][$deep];
}
}
}
//Codice per il riempimento del blocco "location"
if (strcasecmp($key, 'location') == 0) {
for ($z = 0; $z < count($value); $z++) {
//Richiamo i quattro prefix che serviranno per questo blocco
$n_this = $namespace['this'];
$loc_subj = $namespace[':'];
$v_card = $namespace['vcard'];
$cs = $namespace['cs'];
//$id memorizza i vari "id" (far0001, far0002, ...)
$id = $value[$z]['id'];
//Cancello "id" in modo da renderlo soggetto con ":",
//altrimenti sarebbe stato l'oggetto di "vcard"
unset($data['location'][$z]['id']);
//$keys_z contiene un'array associativo i cui valori sono
//i nomi dei tag XML (category, subcategory, name, ..)
$keys_z = array_keys($data['location'][$z]);
//Con questo ciclo for popolo l̈́'array da passare alla conversione
for ($kz = 0; $kz < count($keys_z); $kz++) {
$temp = $keys_z[$kz];
//I campi "opening" e "closing" sono oggetti del predicato "cs"...
if (stristr($temp, 'opening') or stristr($temp, 'closing')) {
$newarray[$loc_subj . $id][$cs . $temp] = $data['location'][$z][$temp];
} else {
$newarray[$loc_subj . $id][$v_card . $temp] = $data['location'][$z][$temp];
}
}
}
}
}
//Salvo in formato Turtle valido
$doc = ARC2::getTurtleSerializer($namespace2);
$fromXMLtoTTL = $doc->getSerializedIndex($newarray);
return $fromXMLtoTTL;
}
示例12: getItemAsRdf
/**
* getItemAsRdf returns the BIBO RDF for the entire Zotero Item
* @param $format default 'rdf/xml' the rdf serialization to use
* @return string the RDF serialization
* @throw Exception if PHP_ZOTERO_ENTRIES_ARC_PATH is not defined
*/
public function getItemAsRdf($format = 'rdf/xml')
{
if (!defined('PHP_ZOTERO_ENTRIES_ARC_PATH')) {
throw new Exception('PHP_ZOTERO_ENTRIES_ARC_PATH must be defined and valid to use RDF methods');
}
if (!$this->arcIndex) {
$this->setRdf();
}
switch ($format) {
case 'rdf/xml':
$ser = ARC2::getRDFXMLSerializer($this->arcConf);
break;
case 'rdf/json':
$ser = ARC2::getRDFJsonSerializer($this->arcConf);
break;
case 'turtle':
$ser = ARC2::getTurtleSerializer($this->arcConf);
break;
case 'ntriples':
$ser = ARC2::getNTriplesSerializer($this->arcConf);
break;
}
return $ser->getSerializedIndex(array($this->itemUri => $this->arcIndex[$this->itemUri]));
}
示例13: to_turtle
/**
* Serialise the graph to Turtle
* @see http://www.dajobe.org/2004/01/turtle/
* @return string the Turtle version of the graph
*/
public function to_turtle()
{
/** @var \ARC2_RDFSerializer $serializer */
$serializer = \ARC2::getTurtleSerializer(array('ns' => $this->_labeller->get_ns()));
return $serializer->getSerializedIndex($this->_to_arc_index($this->_index));
}
示例14: error_log
$store = ARC2::getStore($arc_config);
if (!$store->isSetUp()) {
$store->setUp();
/* create MySQL tables */
}
/* query handling */
$query = $argv[1];
$result = $store->query($query);
/* error handling */
if ($errors = $store->getErrors()) {
error_log("arc2sparql error:\n" . join("\n", $errors));
exit(10);
}
/* result handling */
if ($result["query_type"] == "construct" || $result["query_type"] == "describe") {
$ser = ARC2::getTurtleSerializer();
print $ser->getSerializedIndex($result["result"]);
print "\n";
} else {
if ($result["query_type"] == "select") {
$vars = $result['result']['variables'];
$rows = $result['result']['rows'];
foreach ($vars as $var) {
print $var . " ";
}
print "\n";
foreach ($rows as $row) {
foreach ($vars as $var) {
print $row[$var] . " ";
}
print "\n";
示例15: run
//.........这里部分代码省略.........
$t['o_type'] = 'bnode';
array_push($triples, $t);
$t2 = array();
$t2['s'] = $t['o'];
$t2['s_type'] = 'uri';
$t2['p'] = RDF . 'type';
$t2['o'] = LS . "Parameter";
$t2['o_type'] = 'uri';
array_push($triples, $t2);
$t2['p'] = RDFS . 'label';
$t2['o'] = $k;
$t2['o_type'] = 'literal';
array_push($triples, $t2);
$t2['p'] = DC . 'hasFormat';
$t2['o'] = uniqid("_:b");
$t2['o_type'] = 'bnode';
array_push($triples, $t2);
$t2['s'] = $t2['o'];
$t2['s_type'] = 'bnode';
$t2['p'] = RDF . 'type';
$t2['o'] = CNT . "ContentAsText";
$t2['o_type'] = 'uri';
array_push($triples, $t2);
$t2['p'] = CNT . 'chars';
$t2['o'] = $v;
$t2['o_type'] = 'literal';
array_push($triples, $t2);
$t2['p'] = DC . 'format';
$t2['o'] = 'text/plain;charset=utf-8';
$t2['o_type'] = 'literal';
array_push($triples, $t2);
}
require $conf['home'] . 'lib/arc2/ARC2.php';
$ser = ARC2::getTurtleSerializer();
$sparqlComponent = $conf['basedir'] . 'sparqlComponent';
//uniqid("_:b");
//echo $ser->getSerializedTriples($triples);
//var_dump($this->getComponents($conf['home'].$conf['view']['directory']));
$models = $this->getComponents($conf['home'] . $conf['model']['directory'], '');
//Define Process
$t = array();
$t['s'] = uniqid("_:b");
$t['s_type'] = 'bnode';
$t['p'] = RDF . 'type';
$t['o'] = OPMV . 'Process';
$t['o_type'] = 'uri';
array_push($triples, $t);
foreach ($models as $k => $m) {
//Controlled by
$t['p'] = OPMV . 'wasControlledBy';
$t['o'] = $sparqlComponent;
$t['o_type'] = 'bnode';
array_push($triples, $t);
//Associated Agent to this installation
$aux = $t['o'];
$t['s'] = $t['o'];
$t['p'] = SKOS . 'broader';
$t['o'] = $conf['basedir'];
$t['o_type'] = 'uri';
array_push($triples, $t);
//Return object for later triple
$t['o'] = $sparqlComponent;
// Type of query
$t2 = array();
$t2['s'] = $t['o'];
$t2['s_type'] = 'bnode';