comparison sites/all/libraries/ARC2/arc/parsers/ARC2_SGAJSONParser.php @ 4:ce11bbd8f642

added modules
author danieleb <danielebarchiesi@me.com>
date Thu, 19 Sep 2013 10:38:44 +0100
parents
children
comparison
equal deleted inserted replaced
3:b28be78d8160 4:ce11bbd8f642
1 <?php
2 /*
3 homepage: http://arc.semsol.org/
4 license: http://arc.semsol.org/license
5
6 class: ARC2 SG API JSON Parser
7 author: Benjamin Nowack
8 version: 2010-11-16
9 */
10
11 ARC2::inc('JSONParser');
12
13 class ARC2_SGAJSONParser extends ARC2_JSONParser {
14
15 function __construct($a, &$caller) {
16 parent::__construct($a, $caller);
17 }
18
19 function __init() {/* reader */
20 parent::__init();
21 $this->rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
22 $this->nsp = array($this->rdf => 'rdf');
23 }
24
25 /* */
26
27 function done() {
28 $this->extractRDF();
29 }
30
31 function extractRDF() {
32 $s = $this->getContext();
33 $os = $this->getURLs($this->struct);
34 foreach ($os as $o) {
35 if ($o != $s) $this->addT($s, 'http://www.w3.org/2000/01/rdf-schema#seeAlso', $o, 'uri', 'uri');
36 }
37 }
38
39 function getContext() {
40 if (!isset($this->struct['canonical_mapping'])) return '';
41 foreach ($this->struct['canonical_mapping'] as $k => $v) return $v;
42 }
43
44 function getURLs($struct) {
45 $r =array();
46 if (is_array($struct)) {
47 foreach ($struct as $k => $v) {
48 if (preg_match('/^http:\/\//', $k) && !in_array($k, $r)) $r[] = $k;
49 $sub_r = $this->getURLs($v);
50 foreach ($sub_r as $sub_v) {
51 if (!in_array($sub_v, $r)) $r[] = $sub_v;
52 }
53 }
54 }
55 elseif (preg_match('/^http:\/\//', $struct) && !in_array($struct, $r)) {
56 $r[] = $struct;
57 }
58 return $r;
59 }
60
61 /* */
62
63 }