3 homepage: http://arc.semsol.org/
4 license: http://arc.semsol.org/license
6 class: ARC2 Store DESCRIBE Query Handler
7 author: Benjamin Nowack
8 version: 2008-01-09 (Tweak: label auto-detection is now optional)
11 ARC2::inc('StoreSelectQueryHandler');
13 class ARC2_StoreDescribeQueryHandler extends ARC2_StoreSelectQueryHandler {
15 function __construct($a = '', &$caller) {/* caller has to be a store */
16 parent::__construct($a, $caller);
19 function ARC2_StoreDescribeQueryHandler($a = '', &$caller) {
20 $this->__construct($a, $caller);
23 function __init() {/* db_con */
25 $this->store =& $this->caller;
26 $this->detect_labels = $this->v('detect_describe_query_labels', 0, $this->a);
31 function runQuery($infos) {
32 $ids = $infos['query']['result_uris'];
33 if ($vars = $infos['query']['result_vars']) {
34 $sub_r = parent::runQuery($infos);
35 $rf = $this->v('result_format', '', $infos);
36 if (in_array($rf, array('sql', 'structure', 'index'))) {
39 $rows = $this->v('rows', array(), $sub_r);
40 foreach ($rows as $row) {
41 foreach ($vars as $info) {
42 $val = isset($row[$info['var']]) ? $row[$info['var']] : '';
43 if ($val && ($row[$info['var'] . ' type'] != 'literal') && !in_array($val, $ids)) {
50 $this->described_ids = array();
52 $this->added_triples = array();
56 $this->described_ids[] = $id;
57 if ($this->detect_labels) {
61 ?o ?label_p ?o_label .
62 ?o <http://arc.semsol.org/ns/arc#label> ?o_label .
66 ?o ?label_p ?o_label .
67 FILTER REGEX(str(?label_p), "(name|label|title|summary|nick|fn)$", "i")
81 $sub_r = $this->store->query($q);
82 $sub_index = is_array($sub_r['result']) ? $sub_r['result'] : array();
83 $this->mergeSubResults($sub_index, $is_sub_describe);
91 function mergeSubResults($index, $is_sub_describe = 1) {
92 foreach ($index as $s => $ps) {
93 if (!isset($this->r[$s])) $this->r[$s] = array();
94 foreach ($ps as $p => $os) {
95 if (!isset($this->r[$s][$p])) $this->r[$s][$p] = array();
97 $id = md5($s . ' ' . $p . ' ' . serialize($o));
98 if (!isset($this->added_triples[$id])) {
99 if (1 || !$is_sub_describe) {
100 $this->r[$s][$p][] = $o;
101 if (is_array($o) && ($o['type'] == 'bnode') && !in_array($o['value'], $this->ids)) $this->ids[] = $o['value'];
103 elseif (!is_array($o) || ($o['type'] != 'bnode')) {
104 $this->r[$s][$p][] = $o;
106 $this->added_triples[$id] = 1;
113 $this->ids = array();
114 foreach ($ids as $id) {
115 if (!in_array($id, $this->described_ids)) $this->ids[] = $id;