/usr/share/php/arc/parsers/ARC2_SPARQLXMLResultParser.php is in libarc-php 2.2.5-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | <?php
/*
homepage: http://arc.semsol.org/
license: http://arc.semsol.org/license
class: ARC2 SPARQL Result XML Parser
author: Benjamin Nowack
version: 2010-11-16
*/
ARC2::inc('LegacyXMLParser');
class ARC2_SPARQLXMLResultParser extends ARC2_LegacyXMLParser {
function __construct($a, &$caller) {
parent::__construct($a, $caller);
}
function __init() {/* reader */
parent::__init();
$this->srx = 'http://www.w3.org/2005/sparql-results#';
$this->nsp[$this->srx] = 'srx';
$this->allowCDataNodes = 0;
}
/* */
function done() {
}
/* */
function getVariables() {
$r = array();
foreach ($this->nodes as $node) {
if ($node['tag'] == $this->srx . 'variable') {
$r[] = $node['a']['name'];
}
}
return $r;
}
function getRows() {
$r = array();
$index = $this->getNodeIndex();
foreach ($this->nodes as $node) {
if ($node['tag'] == $this->srx . 'result') {
$row = array();
$row_id = $node['id'];
$bindings = isset($index[$row_id])? $index[$row_id] : array();
foreach ($bindings as $binding) {
$row = array_merge($row, $this->getBinding($binding));
}
if ($row) {
$r[] = $row;
}
}
}
return $r;
}
function getBinding($node) {
$r = array();
$index = $this->getNodeIndex();
$var = $node['a']['name'];
$term = $index[$node['id']][0];
$r[$var . ' type'] = preg_replace('/^uri$/', 'uri', substr($term['tag'], strlen($this->srx)));
$r[$var] = ($r[$var . ' type'] == 'bnode') ? '_:' . $term['cdata'] : $term['cdata'];
if (isset($term['a']['datatype'])) {
$r[$var . ' datatype'] = $term['a']['datatype'];
}
elseif (isset($term['a'][$this->xml . 'lang'])) {
$r[$var . ' lang'] = $term['a'][$this->xml . 'lang'];
}
return $r;
}
function getBooleanInsertedDeleted() {
foreach ($this->nodes as $node) {
if ($node['tag'] == $this->srx . 'boolean') {
return ($node['cdata'] == 'true') ? array('boolean' => true) : array('boolean' => false);
}
elseif ($node['tag'] == $this->srx . 'inserted') {
return array('inserted' => $node['cdata']);
}
elseif ($node['tag'] == $this->srx . 'deleted') {
return array('deleted' => $node['cdata']);
}
elseif ($node['tag'] == $this->srx . 'results') {
return '';
}
}
return '';
}
/* */
function getStructure() {
$r = array('variables' => $this->getVariables(), 'rows' => $this->getRows());
/* boolean|inserted|deleted */
if ($sub_r = $this->getBooleanInsertedDeleted()) {
foreach ($sub_r as $k => $v) {
$r[$k] = $v;
}
}
return $r;
}
/* */
}
|