PageRenderTime 58ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tdt/core/model/semantics/rdfapi-php/api/syntax/RdfParser.php

https://github.com/oSoc13/tdt-core
PHP | 1823 lines | 1219 code | 230 blank | 374 comment | 594 complexity | 2d90e0d8610fd36dcead8f91321be0ba MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // ----------------------------------------------------------------------------------
  3. // Class: RdfParser
  4. // ----------------------------------------------------------------------------------
  5. /**
  6. * An RDF paser.
  7. * This class reads RDF data from files or URIs and generates models out of it. All valid
  8. * RDF XML syntaxes defined by the W3C in RDF/XML Syntax Specification (Revised)
  9. * - W3C Working Draft 10 October 2003
  10. * (http://www.w3.org/TR/2003/WD-rdf-syntax-grammar-20031010/) are supported.
  11. * The parser is based on the PHP version of repat
  12. * (http://phpxmlclasses.sourceforge.net/show_doc.php?class=class_rdf_parser.html)
  13. * by Luis Argerich (lrargerich@yahoo.com).
  14. *
  15. * @version $Id: RdfParser.php 493 2007-08-12 17:43:07Z cweiske $
  16. * @author Luis Argerich <lrargerich@yahoo.com>,
  17. * Chris Bizer <chris@bizer.de>,
  18. * Radoslaw Oldakowski <radol@gmx.de>
  19. * Daniel Westphal <mail@d-westphal.de>
  20. * @package syntax
  21. * @access public
  22. *
  23. */
  24. class RdfParser extends Object {
  25. private $rdf_parser;
  26. private $model;
  27. /* Private Methods */
  28. /**
  29. * converts a string to its unicode NFC form (e.g. uHHHH or UHHHHHHHH).
  30. *
  31. * @param String $str
  32. * @return String
  33. * @access private
  34. *
  35. */
  36. private function str2unicode_nfc($str = "") {
  37. $result = "";
  38. /* try to detect encoding */
  39. $tmp = str_replace("?", "", $str);
  40. if (strpos(utf8_decode($tmp), "?") === false) {
  41. $str = utf8_decode($str);
  42. }
  43. for ($i = 0, $i_max = strlen($str); $i < $i_max; $i++) {
  44. $nr = 0; /* unicode dec nr */
  45. /* char */
  46. $char = $str[$i];
  47. /* utf8 binary */
  48. $utf8_char = utf8_encode($char);
  49. $bytes = strlen($utf8_char);
  50. if ($bytes == 1) {
  51. /* 0####### (0-127) */
  52. $nr = ord($utf8_char);
  53. } elseif ($bytes == 2) {
  54. /* 110##### 10###### = 192+x 128+x */
  55. $nr = ((ord($utf8_char[0]) - 192) * 64) + (ord($utf8_char[1]) - 128);
  56. } elseif ($bytes == 3) {
  57. /* 1110#### 10###### 10###### = 224+x 128+x 128+x */
  58. $nr = ((ord($utf8_char[0]) - 224) * 4096) + ((ord($utf8_char[1]) - 128) * 64) + (ord($utf8_char[2]) - 128);
  59. } elseif ($bytes == 4) {
  60. /* 1111#### 10###### 10###### 10###### = 240+x 128+x 128+x 128+x */
  61. $nr = ((ord($utf8_char[0]) - 240) * 262144) + ((ord($utf8_char[1]) - 128) * 4096) + ((ord($utf8_char[2]) - 128) * 64) + (ord($utf8_char[3]) - 128);
  62. }
  63. /* result (see http://www.w3.org/TR/rdf-testcases/#ntrip_strings) */
  64. if ($nr < 9) {/* #x0-#x8 (0-8) */
  65. $result.="u" . sprintf("%04X", $nr);
  66. } elseif ($nr == 9) {/* #x9 (9) */
  67. $result.='t';
  68. } elseif ($nr == 10) {/* #xA (10) */
  69. $result.='n';
  70. } elseif ($nr < 13) {/* #xB-#xC (11-12) */
  71. $result.="u" . sprintf("%04X", $nr);
  72. } elseif ($nr == 13) {/* #xD (13) */
  73. $result.='t';
  74. } elseif ($nr < 32) {/* #xE-#x1F (14-31) */
  75. $result.="u" . sprintf("%04X", $nr);
  76. } elseif ($nr < 34) {/* #x20-#x21 (32-33) */
  77. $result.=$char;
  78. } elseif ($nr == 34) {/* #x22 (34) */
  79. $result.='"';
  80. } elseif ($nr < 92) {/* #x23-#x5B (35-91) */
  81. $result.=$char;
  82. } elseif ($nr == 92) {/* #x5C (92) */
  83. $result.='';
  84. } elseif ($nr < 127) {/* #x5D-#x7E (93-126) */
  85. $result.=$char;
  86. } elseif ($nr < 65536) {/* #x7F-#xFFFF (128-65535) */
  87. $result.="u" . sprintf("%04X", $nr);
  88. } elseif ($nr < 1114112) {/* #x10000-#x10FFFF (65536-1114111) */
  89. $result.="U" . sprintf("%08X", $nr);
  90. } else {
  91. /* other chars are not defined => ignore */
  92. }
  93. }
  94. return $result;
  95. }
  96. /**
  97. * @access private
  98. */
  99. private function _new_element() {
  100. $e['parent'] = Array(); // Parent is a blank Array
  101. $e['state'] = 0;
  102. $e['has_property_atributes'] = 0;
  103. $e['has_member_attributes'] = 0;
  104. $e['subject_type'] = 0;
  105. $e['subject'] = '';
  106. $e['predicate'] = '';
  107. $e['ordinal'] = 0;
  108. $e['members'] = 0;
  109. $e['data'] = '';
  110. $e['xml_lang'] = '';
  111. $e['bag_id'] = '';
  112. $e['statements'] = 0;
  113. $e['statement_id'] = '';
  114. $e['datatype'] = '';
  115. $e['element_base_uri'] = '';
  116. return $e;
  117. }
  118. /**
  119. * @param string $source
  120. * @param string &$destination
  121. *
  122. * @access private
  123. */
  124. private function _copy_element($source, &$destination) {
  125. if ($source) {
  126. $destination['parent'] = $source;
  127. $destination['state'] = $source['state'];
  128. $destination['xml_lang'] = $source['xml_lang'];
  129. $destination['element_base_uri'] = $source['element_base_uri'];
  130. }
  131. }
  132. /**
  133. * @param string &$e
  134. * @access private
  135. */
  136. private function _clear_element(&$e) {
  137. $e['subject'] = '';
  138. $e['predicate'] = '';
  139. $e['data'] = '';
  140. $e['bag_id'] = '';
  141. $e['statement_id'] = '';
  142. if (isset($e['parent'])) {
  143. if ($e['parent']) {
  144. if ($e['parent']['xml_lang'] != $e['xml_lang']) {
  145. $e['xml_lang'] = '';
  146. }
  147. } else {
  148. $e['xml_lang'] = '';
  149. }
  150. } else {
  151. $e['xml_lang'] = '';
  152. }
  153. $e['parent'] = Array();
  154. $e['state'] = 0;
  155. $e['has_property_attributes'] = 0;
  156. $e['has_member_attributes'] = 0;
  157. $e['subject_type'] = 0;
  158. $e['subject'] = '';
  159. $e['predicate'] = '';
  160. $e['ordinal'] = 0;
  161. $e['members'] = 0;
  162. $e['data'] = '';
  163. $e['xml_lang'] = '';
  164. $e['bag_id'] = '';
  165. $e['statements'] = 0;
  166. $e['statement_id'] = '';
  167. $e['datatype'] = '';
  168. $e['element_base_uri'] = '';
  169. }
  170. /**
  171. * @access private
  172. */
  173. private function _push_element() {
  174. if (!isset($this->rdf_parser['free'])) {
  175. $this->rdf_parser['free'] = Array();
  176. }
  177. if (count($this->rdf_parser['free']) > 0) {
  178. $e = $this->rdf_parser['free'];
  179. if (isset($e['parent'])) {
  180. $this->rdf_parser['free'] = $e['parent'];
  181. } else {
  182. $this->rdf_parser['free'] = $this->_new_element();
  183. }
  184. } else {
  185. $e = $this->_new_element();
  186. }
  187. if (!isset($this->rdf_parser['top'])) {
  188. $this->rdf_parser['top'] = Array();
  189. }
  190. $this->_copy_element($this->rdf_parser['top'], $e);
  191. $this->rdf_parser['top'] = $e;
  192. }
  193. /**
  194. * @access private
  195. */
  196. private function _pop_element() {
  197. $e = $this->rdf_parser['top'];
  198. $this->rdf_parser['top'] = $e['parent'];
  199. $this->_clear_element($e);
  200. $this->rdf_parser['free'] = $e;
  201. }
  202. /**
  203. * @param string $local_name
  204. * @access private
  205. */
  206. private function _is_rdf_property_attribute_resource($local_name) {
  207. return ( $local_name == RDF_TYPE );
  208. }
  209. /**
  210. * @param string $local_name
  211. * @access private
  212. */
  213. private function _is_rdf_property_attribute_literal($local_name) {
  214. return ( $local_name == RDF_VALUE )
  215. || ( $local_name == RDF_BAG )
  216. || ( $local_name == RDF_SEQ )
  217. || ( $local_name == RDF_ALT )
  218. || ( $local_name == RDF_STATEMENT )
  219. || ( $local_name == RDF_PROPERTY )
  220. || ( $local_name == RDF_LIST );
  221. }
  222. /**
  223. * @param string $local_name
  224. * @access private
  225. */
  226. private function _is_rdf_ordinal($local_name) {
  227. $ordinal = -1;
  228. if ($local_name{0} == '_') {
  229. $ordinal = substr($local_name, 1) + 1;
  230. }
  231. return ( $ordinal > 0 ) ? $ordinal : 0;
  232. }
  233. /**
  234. * @param string $local_name
  235. * @access private
  236. */
  237. private function _is_rdf_property_attribute($local_name) {
  238. return $this->_is_rdf_property_attribute_resource($local_name)
  239. || $this->_is_rdf_property_attribute_literal($local_name);
  240. }
  241. private function _is_forbidden_rdf_property_attribute($local_name) {
  242. return ( $local_name == RDF_RDF )
  243. || ( $local_name == RDF_DESCRIPTION)
  244. || ( $local_name == RDF_ID)
  245. || ( $local_name == RDF_ABOUT )
  246. || ( $local_name == RDF_BAG_ID )
  247. || ( $local_name == RDF_PARSE_TYPE )
  248. || ( $local_name == RDF_RESOURCE )
  249. || ( $local_name == RDF_NODEID )
  250. || ( $local_name == RDF_LI )
  251. || ( $local_name == RDF_ABOUT_EACH )
  252. || ( $local_name == RDF_ABOUT_EACH_PREFIX )
  253. || ( $local_name == RDF_DATATYPE );
  254. }
  255. /**
  256. * @param string $local_name
  257. * @access private
  258. */
  259. private function _is_rdf_property_element($local_name) {
  260. return ( $local_name == RDF_TYPE )
  261. || ( $local_name == RDF_SUBJECT )
  262. || ( $local_name == RDF_PREDICATE )
  263. || ( $local_name == RDF_OBJECT )
  264. || ( $local_name == RDF_VALUE )
  265. || ( $local_name == RDF_LI )
  266. || ( $local_name == RDF_SEEALSO )
  267. || ( $local_name == RDF_BAG )
  268. || ( $local_name == RDF_SEQ )
  269. || ( $local_name == RDF_ALT )
  270. || ( $local_name == RDF_STATEMENT )
  271. || ( $local_name == RDF_PROPERTY )
  272. || ( $local_name == RDF_LIST )
  273. || ( $local_name == RDF_FIRST )
  274. || ( $local_name == RDF_REST )
  275. || ( $local_name{0} == '_' );
  276. }
  277. /**
  278. * @param string $local_name
  279. * @access private
  280. */
  281. private function _is_forbidden_rdf_property_element($local_name) {
  282. return ( $local_name == RDF_RDF )
  283. || ( $local_name == RDF_DESCRIPTION)
  284. || ( $local_name == RDF_ID)
  285. || ( $local_name == RDF_ABOUT )
  286. || ( $local_name == RDF_BAG_ID )
  287. || ( $local_name == RDF_PARSE_TYPE )
  288. || ( $local_name == RDF_RESOURCE )
  289. || ( $local_name == RDF_NODEID )
  290. || ( $local_name == RDF_ABOUT_EACH )
  291. || ( $local_name == RDF_ABOUT_EACH_PREFIX )
  292. || ( $local_name == RDF_DATATYPE );
  293. }
  294. /**
  295. * @param string $local_name
  296. * @access private
  297. */
  298. private function _is_rdf_node_element($local_name) {
  299. return ( $local_name == RDF_DESCRIPTION )
  300. || ( $local_name == RDF_STATEMENT )
  301. || ( $local_name == RDF_SUBJECT )
  302. || ( $local_name == RDF_PREDICATE )
  303. || ( $local_name == RDF_OBJECT )
  304. || ( $local_name == RDF_PROPERTY )
  305. || ( $local_name == RDF_TYPE )
  306. || ( $local_name == RDF_VALUE )
  307. || ( $local_name == RDF_BAG )
  308. || ( $local_name == RDF_SEQ )
  309. || ( $local_name == RDF_ALT )
  310. || ( $local_name == RDF_SEEALSO )
  311. || ( $local_name == RDF_LIST )
  312. || ( $local_name == RDF_FIRST )
  313. || ( $local_name == RDF_REST )
  314. || ( $local_name == RDF_NIL )
  315. || ( $local_name{0} == '_' );
  316. }
  317. /**
  318. * @param string $local_name
  319. * @access private
  320. */
  321. private function _is_forbidden_rdf_node_element($local_name) {
  322. return ( $local_name == RDF_RDF )
  323. || ( $local_name == RDF_ID)
  324. || ( $local_name == RDF_ABOUT )
  325. || ( $local_name == RDF_BAG_ID )
  326. || ( $local_name == RDF_PARSE_TYPE )
  327. || ( $local_name == RDF_RESOURCE )
  328. || ( $local_name == RDF_NODEID )
  329. || ( $local_name == RDF_LI )
  330. || ( $local_name == RDF_ABOUT_EACH )
  331. || ( $local_name == RDF_ABOUT_EACH_PREFIX )
  332. || ( $local_name == RDF_DATATYPE );
  333. }
  334. /**
  335. * @param string $val
  336. * @access private
  337. */
  338. private function _istalnum($val) {
  339. return ereg("[A-Za-z0-9]", $val);
  340. }
  341. /**
  342. * @param string $val
  343. * @access private
  344. */
  345. public function _istalpha($val) {
  346. return ereg("[A-Za-z]", $val);
  347. }
  348. /**
  349. * @param string $uri
  350. * @access private
  351. */
  352. private function _is_absolute_uri($uri) {
  353. $result = false;
  354. $uri_p = 0;
  355. if ($uri && $this->_istalpha($uri{$uri_p})) {
  356. ++$uri_p;
  357. while (($uri_p < strlen($uri))
  358. && ( $this->_istalnum($uri{$uri_p})
  359. || ( $uri{$uri_p} == '+' )
  360. || ( $uri{$uri_p} == '-' )
  361. || ( $uri{$uri_p} == '.' ) )) {
  362. ++$uri_p;
  363. }
  364. $result = ( $uri{$uri_p} == ':' );
  365. }
  366. return $result;
  367. }
  368. /**
  369. * This function returns an associative array returning any of the various components of the URL that are present. This includes the
  370. * $arr=parse_url($url)
  371. * scheme - e.g. http
  372. * host
  373. * port
  374. * user
  375. * pass
  376. * path
  377. * query - after the question mark ?
  378. * fragment - after the hashmark #
  379. *
  380. * @param string $uri
  381. * @param string $buffer
  382. * @param string &$scheme
  383. * @param string &$authority
  384. * @param string &$path
  385. * @param string &$query
  386. * @param string &$fragment
  387. * @access private
  388. */
  389. private function _parse_uri($uri, $buffer, &$scheme, &$authority, &$path, &$query, &$fragment) {
  390. $parsed = parse_url($uri);
  391. if (isset($parsed['scheme'])) {
  392. $scheme = $parsed['scheme'];
  393. } else {
  394. $scheme = '';
  395. }
  396. if (isset($parsed['host'])) {
  397. $host = $parsed['host'];
  398. } else {
  399. $host = '';
  400. }
  401. if (isset($parsed['host'])) {
  402. $authority = $parsed['host'];
  403. } else {
  404. $authority = '';
  405. }
  406. if (isset($parsed['path'])) {
  407. $path = $parsed['path'];
  408. } else {
  409. $path = '';
  410. }
  411. if (isset($parsed['query'])) {
  412. $query = $parsed['query'];
  413. } else {
  414. $query = '';
  415. }
  416. if (isset($parsed['fragment'])) {
  417. $fragment = $parsed['fragment'];
  418. } else {
  419. $fragment = '';
  420. }
  421. }
  422. /**
  423. * @param string $base_uri
  424. * @param string $reference_uri
  425. * @param string &$buffer
  426. * @access private
  427. */
  428. private function _resolve_uri_reference($base_uri, $reference_uri, &$buffer) {
  429. if ($reference_uri == '')
  430. return ($buffer = preg_replace("/#/]*$/", '', $base_uri));
  431. $base_buffer = '';
  432. $reference_buffer = '';
  433. $path_buffer = '';
  434. $buffer = '';
  435. $this->_parse_uri($reference_uri, $reference_buffer, $reference_scheme, $reference_authority, $reference_path, $reference_query, $reference_fragment);
  436. $this->_parse_uri($base_uri, $base_buffer, $base_scheme, $base_authority, $base_path, $base_query, $base_fragment);
  437. if ($reference_scheme == ''
  438. && $reference_authority == ''
  439. && $reference_path == ''
  440. && $reference_query == '') {
  441. $buffer = $base_uri;
  442. if ($reference_fragment != '') {
  443. if ($base_path == '' || $base_path == '/' || $base_path == "") {
  444. $buffer = $this->rdf_parser['document_base_uri'];
  445. } else {
  446. $buffer = preg_replace("/#/]*$/", '', $base_uri);
  447. }
  448. // CB: Changed for base URI
  449. $c = substr($buffer, strlen($buffer) - 1, 1);
  450. if (!($c == '#' || $c == ':' || $c == '/' || $c == ""))
  451. $buffer.= '#';
  452. $buffer.=$reference_fragment;
  453. }
  454. }
  455. else if ($reference_scheme != '') {
  456. $buffer = $reference_uri;
  457. } else {
  458. $result_scheme = $base_scheme;
  459. $result_path = '';
  460. if ($reference_authority != '') {
  461. $result_authority = $reference_authority;
  462. } else {
  463. $result_authority = $base_authority;
  464. if ($reference_path != '') {
  465. if ($reference_path{0} == '/' || $reference_path{0} == "") {
  466. if ($reference_path{1} == '/' || $reference_path{1} == "") {
  467. $result_authority = '';
  468. $result_path = $reference_path;
  469. }
  470. else
  471. $result_path = $reference_path;
  472. }
  473. elseif (substr($reference_path, 0, 3) == '../' ||
  474. substr($reference_path, 0, 3) == '..') {
  475. $slash = $reference_path{2};
  476. while ($base_path != '' && ( substr($reference_path, 0, 3) == '../'
  477. || substr($reference_path, 0, 3) == '..')) {
  478. $base_path = preg_replace("/((/)|())/]*$/", '', $base_path);
  479. if ($base_path != '') {
  480. $base_path = preg_replace("/((/)|())/]*$/", '', $base_path);
  481. $reference_path = substr($reference_path, 3);
  482. }
  483. }
  484. $result_path = $base_path . $slash . $reference_path;
  485. } else {
  486. if ($base_path)
  487. $result_path = preg_replace("//]*$/", $reference_path, $base_path, 1);
  488. else
  489. $result_path = '/' . $reference_path;
  490. }
  491. }
  492. }
  493. if ($result_scheme != '') {
  494. $buffer = $result_scheme;
  495. $buffer.=':';
  496. }
  497. if ($result_authority != '') {
  498. $buffer.="//";
  499. $buffer.=$result_authority;
  500. }
  501. if ($result_path != '') {
  502. $buffer.=$result_path;
  503. }
  504. if ($reference_query != '') {
  505. $buffer.='?';
  506. $buffer.=$reference_query;
  507. }
  508. if ($reference_fragment != '') {
  509. $buffer.='#';
  510. $buffer.=$reference_fragment;
  511. }
  512. }
  513. }
  514. /**
  515. * IDs which contain CombiningChars or Extenders
  516. * (see http://www.w3.org/TR/REC-xml-names/#NT-NCName) are assumed to be invalid.
  517. * If you want to use IDs containing these characters you can turn off
  518. * the validating by setting the constant VALIDATE_IDS to FALSE (see constants.php).
  519. *
  520. * @param string $id
  521. * @access private
  522. */
  523. private function is_valid_id($id) {
  524. if (!VALIDATE_IDS)
  525. return TRUE;
  526. $result = FALSE;
  527. if ($id) {
  528. if ($this->_istalpha($id{0}) || $id{0} == '_') {
  529. $result = TRUE;
  530. $i = 0;
  531. $len = strlen($id);
  532. while ($result != FALSE && ++$i < $len) {
  533. if (!($this->_istalnum($id{$i})
  534. || $id{$i} == '.'
  535. || $id{$i} == '-'
  536. || $id{$i} == '_')) {
  537. $result = FALSE;
  538. }
  539. }
  540. }
  541. }
  542. if (!$result)
  543. $this->_report_error('illegal ID, nodeID or bagID attribute value');
  544. else
  545. return TRUE;
  546. }
  547. /**
  548. * @param string $id
  549. * @param string &$buffer
  550. * @access private
  551. */
  552. private function _resolve_id($id, &$buffer) {
  553. $id_buffer = '';
  554. if ($this->is_valid_id($id)) {
  555. $id_buffer = "#$id";
  556. }
  557. $this->_resolve_uri_reference($this->rdf_get_base(), $id_buffer, $buffer);
  558. }
  559. /**
  560. * @param string $name
  561. * @param string &$buffer
  562. * @param string &$namespace_uri
  563. * @param string &$local_name
  564. * @access private
  565. */
  566. private function _split_name($name, &$buffer, &$namespace_uri, &$local_name) {
  567. static $nul = 0;
  568. $buffer = $name;
  569. if (strstr($buffer, NAMESPACE_SEPARATOR_CHAR)) {
  570. $cosas = explode(NAMESPACE_SEPARATOR_CHAR, $buffer);
  571. $namespace_uri = $cosas[0];
  572. $local_name = $cosas[1];
  573. } else {
  574. if (( $buffer{ 0 } == 'x' )
  575. && ( $buffer{ 1 } == 'm' )
  576. && ( $buffer{ 2 } == 'l' )
  577. && ( $buffer{ 3 } == ':' )) {
  578. $namespace_uri = XML_NAMESPACE_URI;
  579. $local_name = substr($buffer, 4);
  580. } else {
  581. $namespace_uri = '';
  582. $local_name = $buffer;
  583. }
  584. }
  585. }
  586. /**
  587. * @param string &$buf
  588. * @access private
  589. */
  590. private function _generate_anonymous_uri(&$buf) {
  591. $id = '';
  592. if (!isset($this->rdf_parser['anonymous_id'])) {
  593. $this->rdf_parser['anonymous_id'] = 0;
  594. }
  595. $this->rdf_parser['anonymous_id']++;
  596. $buf = BNODE_PREFIX . $this->rdf_parser['anonymous_id'];
  597. }
  598. /**
  599. * @param string $subject_type
  600. * @param string $subject
  601. * @param string $predicate
  602. * @param string $ordinal
  603. * @param string $object_type
  604. * @param string $object
  605. * @param string $xml_lang
  606. * @param string $bag_id
  607. * @param string $statements
  608. * @param string $statement_id
  609. * @access private
  610. */
  611. private function _report_statement($subject_type, $subject, $predicate, $ordinal, $object_type, $object, $xml_lang, $bag_id, $statements, $statement_id, $datatype) {
  612. $statement_id_type = RDF_SUBJECT_TYPE_URI;
  613. $statement_id_buffer = '';
  614. $predicate_buffer = '';
  615. if (!$xml_lang && $object_type == RDF_OBJECT_TYPE_LITERAL && isset($this->rdf_parser['document_xml_lang']))
  616. $xml_lang = $this->rdf_parser['document_xml_lang'];
  617. // call add statement
  618. $this->add_statement_to_model($this->rdf_parser['user_data'], $subject_type, $subject, $predicate, $ordinal, $object_type, $object, $xml_lang, $datatype);
  619. if ($bag_id) {
  620. if ($statements == '') {
  621. $this->_report_statement(RDF_SUBJECT_TYPE_URI, $bag_id, RDF_NAMESPACE_URI . RDF_TYPE, 0, RDF_OBJECT_TYPE_RESOURCE, RDF_NAMESPACE_URI . RDF_BAG, '', '', '', '', $datatype);
  622. }
  623. if (!$statement_id) {
  624. $statement_id_type = RDF_SUBJECT_TYPE_BNODE;
  625. $this->_generate_anonymous_uri($statement_id_buffer);
  626. $statement_id = $statement_id_buffer;
  627. }
  628. $statements++;
  629. $predicate_buffer = 'RDF_NAMESPACE_URI_' . $statements;
  630. $this->_report_statement(
  631. RDF_SUBJECT_TYPE_URI, $bag_id, $predicate_buffer, $statements, RDF_OBJECT_TYPE_BNODE, $statement_id, '', '', '', '', $datatype);
  632. }
  633. if ($statement_id) {
  634. // rdf:type = rdf:Statement
  635. $this->_report_statement(
  636. $statement_id_type, $statement_id, RDF_NAMESPACE_URI . RDF_TYPE, 0, RDF_OBJECT_TYPE_RESOURCE, RDF_NAMESPACE_URI . RDF_STATEMENT, '', '', '', '', $datatype);
  637. if ($subject_type == RDF_SUBJECT_TYPE_BNODE)
  638. $obj_type = RDF_OBJECT_TYPE_BNODE;
  639. else
  640. $obj_type = RDF_OBJECT_TYPE_RESOURCE;
  641. // rdf:subject
  642. $this->_report_statement(
  643. $statement_id_type, $statement_id, RDF_NAMESPACE_URI . RDF_SUBJECT, 0, $obj_type, $subject, '', '', '', '', $datatype);
  644. // rdf:predicate
  645. $this->_report_statement(
  646. $statement_id_type, $statement_id, RDF_NAMESPACE_URI . RDF_PREDICATE, 0, RDF_OBJECT_TYPE_RESOURCE, $predicate, '', '', '', '', $datatype);
  647. // rdf:object
  648. $this->_report_statement(
  649. $statement_id_type, $statement_id, RDF_NAMESPACE_URI . RDF_OBJECT, 0, $object_type, $object, '', '', '', '', $datatype);
  650. }
  651. }
  652. /**
  653. * @param string $subject_type
  654. * @param string $subject
  655. * @param string $attributes
  656. * @param string $xml_lang
  657. * @param string $bag_id
  658. * @param string $statements
  659. * @access private
  660. */
  661. private function _handle_property_attributes($subject_type, $subject, $attributes, $xml_lang, $bag_id, $statements) {
  662. $i = 0;
  663. $attribute = '';
  664. $predicate = '';
  665. $attribute_namespace_uri = '';
  666. $attribute_local_name = '';
  667. $attribute_value = '';
  668. $ordinal = 0;
  669. for ($i = 0; isset($attributes[$i]); $i += 2) {
  670. $this->_split_name(
  671. $attributes[$i], $attribute, $attribute_namespace_uri, $attribute_local_name);
  672. $attribute_value = $attributes[$i + 1];
  673. $predicate = $attribute_namespace_uri;
  674. $predicate.=$attribute_local_name;
  675. if (RDF_NAMESPACE_URI == $attribute_namespace_uri) {
  676. if ($this->_is_rdf_property_attribute_literal($attribute_local_name)) {
  677. $this->_report_statement(
  678. $subject_type, $subject, $predicate, 0, RDF_OBJECT_TYPE_LITERAL, $attribute_value, $xml_lang, $bag_id, $statements, '', '');
  679. } else if ($this->_is_rdf_property_attribute_resource($attribute_local_name)) {
  680. $this->_report_statement(
  681. $subject_type, $subject, $predicate, 0, RDF_OBJECT_TYPE_RESOURCE, $attribute_value, '', $bag_id, $statements, '', '');
  682. } else if (( $ordinal = $this->_is_rdf_ordinal($attribute_local_name) ) != 0) {
  683. $this->_report_statement(
  684. $subject_type, $subject, $predicate, $ordinal, RDF_OBJECT_TYPE_LITERAL, $attribute_value, $xml_lang, $bag_id, $statements, '', '');
  685. } else if (($attribute_local_name != RDF_ABOUT)
  686. && ($attribute_local_name != RDF_RDF)
  687. && ($attribute_local_name != RDF_DESCRIPTION)
  688. && ($attribute_local_name != RDF_ID)
  689. && ($attribute_local_name != RDF_ABOUT_EACH)
  690. && ($attribute_local_name != RDF_ABOUT_EACH_PREFIX)
  691. && ($attribute_local_name != RDF_BAG_ID)
  692. && ($attribute_local_name != RDF_RESOURCE)
  693. && ($attribute_local_name != RDF_PARSE_TYPE)
  694. && ($attribute_local_name != RDF_PARSE_TYPE_LITERAL)
  695. && ($attribute_local_name != RDF_PARSE_TYPE_RESOURCE)
  696. && ($attribute_local_name != RDF_LI)
  697. && ($attribute_local_name != RDF_SUBJECT)
  698. && ($attribute_local_name != RDF_PREDICATE)
  699. && ($attribute_local_name != RDF_OBJECT)
  700. && ($attribute_local_name != RDF_NODEID)
  701. && ($attribute_local_name != RDF_DATATYPE)
  702. && ($attribute_local_name != RDF_SEEALSO)
  703. && ($attribute_local_name != RDF_NIL)
  704. && ($attribute_local_name != RDF_REST)
  705. && ($attribute_local_name != RDF_FIRST)
  706. ) {
  707. $this->_report_statement(
  708. $subject_type, $subject, $predicate, 0, RDF_OBJECT_TYPE_LITERAL, $attribute_value, $xml_lang, $bag_id, $statements, '', '');
  709. }
  710. } else if (XML_NAMESPACE_URI == $attribute_namespace_uri) {
  711. if ($attribute_local_name == 'base') {
  712. $this->rdf_parser['top']['element_base_uri'] = $attribute_value;
  713. }
  714. } else if ($attribute_namespace_uri) {
  715. // is it required that property attributes be in an explicit namespace?
  716. $this->_report_statement(
  717. $subject_type, $subject, $predicate, 0, RDF_OBJECT_TYPE_LITERAL, $attribute_value, $xml_lang, $bag_id, $statements, '', '');
  718. }
  719. }
  720. }
  721. /**
  722. * @param string $warning
  723. * @access private
  724. */
  725. private function _report_warning($warning) {
  726. $errmsg = RDFAPI_ERROR . '(class: parser): ' . $warning . '.';
  727. trigger_error($errmsg, E_USER_WARNING);
  728. }
  729. private function _report_error($error) {
  730. $errmsg = RDFAPI_ERROR . '(class: parser): ' . $error . '.';
  731. trigger_error($errmsg, E_USER_ERROR);
  732. }
  733. /**
  734. * @param string $namespace_uri
  735. * @param string $local_name
  736. * @param string $attributes
  737. * @param string $parent
  738. * @access private
  739. */
  740. private function _handle_resource_element($namespace_uri, $local_name, $attributes, $parent) {
  741. $subjects_found = 0;
  742. $aux = $attributes;
  743. $aux2 = Array();
  744. foreach ($attributes as $atkey => $atvalue) {
  745. $aux2[] = $atkey;
  746. $aux2[] = $atvalue;
  747. }
  748. $attributes = $aux2;
  749. $id = '';
  750. $about = '';
  751. $bag_id = '';
  752. $node_id = '';
  753. $datatype = '';
  754. $i = 0;
  755. $attribute = '';
  756. $attribute_namespace_uri = '';
  757. $attribute_local_name = '';
  758. $attribute_value = '';
  759. $id_buffer = '';
  760. $type = '';
  761. $this->rdf_parser['top']['has_property_attributes'] = false;
  762. $this->rdf_parser['top']['has_member_attributes'] = false;
  763. if ($namespace_uri == RDF_NAMESPACE_URI) {
  764. if (!$this->_is_rdf_node_element($local_name)) {
  765. $msg = 'unknown or out of context rdf node element: ' . $local_name;
  766. if ($this->_is_forbidden_rdf_node_element($local_name))
  767. $this->_report_error($msg);
  768. else
  769. $this->_report_warning($msg);
  770. }
  771. }
  772. // examine each attribute for the standard RDF "keywords"
  773. for ($i = 0; isset($attributes[$i]); $i += 2) {
  774. $this->_split_name(
  775. $attributes[$i], $attribute, $attribute_namespace_uri, $attribute_local_name);
  776. $attribute_value = $attributes[$i + 1];
  777. // if the attribute is not in any namespace
  778. // or the attribute is in the RDF namespace
  779. if (( $attribute_namespace_uri == '' )
  780. || ( $attribute_namespace_uri == RDF_NAMESPACE_URI )) {
  781. if ($attribute_local_name == RDF_ID) {
  782. $id = $attribute_value;
  783. ++$subjects_found;
  784. } else if ($attribute_local_name == RDF_ABOUT) {
  785. $about = '_' . $attribute_value;
  786. ++$subjects_found;
  787. } else if ($attribute_local_name == RDF_NODEID) {
  788. $node_id = $attribute_value;
  789. ++$subjects_found;
  790. } else if ($attribute_local_name == RDF_ABOUT_EACH) {
  791. $error = 'aboutEach has been removed from the RDF specifications';
  792. $this->_report_error($error);
  793. } else if ($attribute_local_name == RDF_ABOUT_EACH_PREFIX) {
  794. $error = 'aboutEachPrefix has been removed from the RDF specifications';
  795. $this->_report_error($error);
  796. } else if ($attribute_local_name == RDF_BAG_ID) {
  797. $bag_id = $attribute_value;
  798. } else if ($attribute_local_name == RDF_DATATYPE) {
  799. $datatype = $attribute_value;
  800. } else if ($this->_is_rdf_property_attribute($attribute_local_name)) {
  801. $this->rdf_parser['top']['has_property_attributes'] = true;
  802. } else if ($this->_is_rdf_ordinal($attribute_local_name)) {
  803. $this->rdf_parser['top']['has_property_attributes'] = true;
  804. $this->rdf_parser['top']['has_member_attributes'] = true;
  805. } else {
  806. $this->rdf_parser['top']['has_property_attributes'] = true;
  807. $msg = 'unknown or out of context rdf attribute: ' . $attribute_local_name;
  808. if ($this->_is_forbidden_rdf_property_attribute($attribute_local_name))
  809. $this->_report_error($msg);
  810. else
  811. $this->_report_warning($msg);
  812. }
  813. }
  814. else if ($attribute_namespace_uri == XML_NAMESPACE_URI) {
  815. if ($attribute_local_name == XML_LANG) {
  816. $this->rdf_parser['top']['xml_lang'] = $attribute_value;
  817. } elseif ($attribute_local_name == 'base') {
  818. $this->rdf_parser['top']['element_base_uri'] = $attribute_value;
  819. }
  820. } else if ($attribute_namespace_uri) {
  821. $this->rdf_parser['top']['has_property_attributes'] = true;
  822. }
  823. }
  824. // if no subjects were found, generate one.
  825. if ($subjects_found == 0) {
  826. $this->_generate_anonymous_uri($id_buffer);
  827. $this->rdf_parser['top']['subject'] = $id_buffer;
  828. $this->rdf_parser['top']['subject_type'] = RDF_SUBJECT_TYPE_BNODE;
  829. } else if ($subjects_found > 1) {
  830. $this->_report_error('ID, about and nodeID are mutually exclusive');
  831. } else if ($id) {
  832. $this->_resolve_id($id, $id_buffer);
  833. $this->rdf_parser['top']['subject_type'] = RDF_SUBJECT_TYPE_URI;
  834. $this->rdf_parser['top']['subject'] = $id_buffer;
  835. } else if ($about) {
  836. $this->_resolve_uri_reference($this->rdf_get_base(), substr($about, 1), $id_buffer);
  837. $this->rdf_parser['top']['subject_type'] = RDF_SUBJECT_TYPE_URI;
  838. $this->rdf_parser['top']['subject'] = $id_buffer;
  839. } else if ($node_id) {
  840. $this->is_valid_id($node_id);
  841. $this->rdf_parser['top']['subject_type'] = RDF_SUBJECT_TYPE_BNODE;
  842. $this->rdf_parser['top']['subject'] = $node_id;
  843. }
  844. // if the subject is empty, assign it the document uri
  845. if ($this->rdf_parser['top']['subject'] == '') {
  846. $this->rdf_parser['top']['subject'] = $this->rdf_get_base();
  847. }
  848. if ($bag_id) {
  849. $this->_resolve_id($bag_id, $id_buffer);
  850. $this->rdf_parser['top']['bag_id'] = $id_buffer;
  851. }
  852. // only report the type for non-rdf:Description elements.
  853. if (($local_name != RDF_DESCRIPTION )
  854. || ( $namespace_uri != RDF_NAMESPACE_URI )) {
  855. $type = $namespace_uri;
  856. $type.=$local_name;
  857. $this->_report_statement(
  858. $this->rdf_parser['top']['subject_type'], $this->rdf_parser['top']['subject'], RDF_NAMESPACE_URI . RDF_TYPE, 0, RDF_OBJECT_TYPE_RESOURCE, $type, '', $this->rdf_parser['top']['bag_id'], $this->rdf_parser['top']['statements'], '', $datatype);
  859. }
  860. // if this element is the child of some property,
  861. // report the appropriate statement.
  862. if ($parent) {
  863. if ($this->rdf_parser['top']['subject_type'] == RDF_SUBJECT_TYPE_BNODE)
  864. $objtype = RDF_OBJECT_TYPE_BNODE;
  865. else
  866. $objtype = RDF_OBJECT_TYPE_RESOURCE;
  867. $this->_report_statement(
  868. $parent['parent']['subject_type'], $parent['parent']['subject'], $parent['predicate'], $parent['ordinal'], $objtype, $this->rdf_parser['top']['subject'], '', $parent['parent']['bag_id'], $parent['parent']['statements'], $parent['statement_id'], $parent['datatype']);
  869. }
  870. if ($this->rdf_parser['top']['has_property_attributes']) {
  871. $this->_handle_property_attributes(
  872. $this->rdf_parser['top']['subject_type'], $this->rdf_parser['top']['subject'], $attributes, $this->rdf_parser['top']['xml_lang'], $this->rdf_parser['top']['bag_id'], $this->rdf_parser['top']['statements']);
  873. }
  874. }
  875. /**
  876. * @param string &$namespace_uri
  877. * @param string &$local_name
  878. * @param string &$attributes
  879. * @access private
  880. */
  881. private function _handle_property_element(&$namespace_uri, &$local_name, &$attributes) {
  882. $buffer = '';
  883. $i = 0;
  884. $aux = $attributes;
  885. $aux2 = Array();
  886. foreach ($attributes as $atkey => $atvalue) {
  887. $aux2[] = $atkey;
  888. $aux2[] = $atvalue;
  889. }
  890. $attributes = $aux2;
  891. $attribute_namespace_uri = '';
  892. $attribute_local_name = '';
  893. $attribute_value = '';
  894. $resource = NULL;
  895. $statement_id = '';
  896. $bag_id = '';
  897. $parse_type = '';
  898. $node_id = '';
  899. $datatype = '';
  900. $this->rdf_parser['top']['ordinal'] = 0;
  901. if ($namespace_uri == RDF_NAMESPACE_URI) {
  902. if (!$this->_is_rdf_property_element($local_name)) {
  903. $msg = 'unknown or out of context rdf property element: ' . $local_name;
  904. if ($this->_is_forbidden_rdf_property_element($local_name))
  905. $this->_report_error($msg);
  906. else
  907. $this->_report_warning($msg);
  908. }
  909. }
  910. $buffer = $namespace_uri;
  911. if (( $namespace_uri == RDF_NAMESPACE_URI )
  912. && ( $local_name == RDF_LI )) {
  913. $this->rdf_parser['top']['parent']['members']++;
  914. $this->rdf_parser['top']['ordinal'] = $this->rdf_parser['top']['parent']['members'];
  915. $this->rdf_parser['top']['ordinal'] = $this->rdf_parser['top']['ordinal'];
  916. $buffer.='_' . $this->rdf_parser['top']['ordinal'];
  917. } else {
  918. $buffer.=$local_name;
  919. }
  920. $this->rdf_parser['top']['predicate'] = $buffer;
  921. $this->rdf_parser['top']['has_property_attributes'] = false;
  922. $this->rdf_parser['top']['has_member_attributes'] = false;
  923. for ($i = 0; isset($attributes[$i]); $i += 2) {
  924. $this->_split_name(
  925. $attributes[$i], $buffer, $attribute_namespace_uri, $attribute_local_name);
  926. $attribute_value = $attributes[$i + 1];
  927. // if the attribute is not in any namespace
  928. // or the attribute is in the RDF namespace
  929. if (( $attribute_namespace_uri == '' )
  930. || ( $attribute_namespace_uri == RDF_NAMESPACE_URI )) {
  931. if (( $attribute_local_name == RDF_ID)) {
  932. $statement_id = $attribute_value;
  933. } else if ($attribute_local_name == RDF_PARSE_TYPE) {
  934. $parse_type = $attribute_value;
  935. } else if ($attribute_local_name == RDF_RESOURCE) {
  936. $resource = $attribute_value;
  937. } else if ($attribute_local_name == RDF_NODEID) {
  938. $node_id = $attribute_value;
  939. } else if ($attribute_local_name == RDF_BAG_ID) {
  940. $bag_id = $attribute_value;
  941. } else if ($attribute_local_name == RDF_DATATYPE) {
  942. $datatype = $attribute_value;
  943. $this->rdf_parser['top']['datatype'] = $attribute_value;
  944. } else if ($this->_is_rdf_property_attribute($attribute_local_name)) {
  945. $this->rdf_parser['top']['has_property_attributes'] = true;
  946. } else {
  947. $this->_report_warning('unknown rdf attribute: ' . $attribute_local_name);
  948. return;
  949. }
  950. } else if ($attribute_namespace_uri == XML_NAMESPACE_URI) {
  951. if ($attribute_local_name == XML_LANG) {
  952. $this->rdf_parser['top']['xml_lang'] = $attribute_value;
  953. } elseif ($attribute_local_name == 'base') {
  954. $this->rdf_parser['top']['element_base_uri'] = $attribute_value;
  955. }
  956. } else if ($attribute_namespace_uri) {
  957. $this->rdf_parser['top']['has_property_attributes'] = true;
  958. }
  959. }
  960. if ($statement_id) {
  961. $this->_resolve_id($statement_id, $buffer);
  962. $this->rdf_parser['top']['statement_id'] = $buffer;
  963. }
  964. if ($node_id) {
  965. $this->is_valid_id($node_id);
  966. if ($resource) {
  967. $this->_report_error('nodeID and resource are mutually exclusive');
  968. }
  969. if ($statement_id) {
  970. // reify statement
  971. $this->_report_statement(
  972. $this->rdf_parser['top']['parent']['subject_type'], $this->rdf_parser['top']['parent']['subject'], $this->rdf_parser['top']['predicate'], $this->rdf_parser['top']['ordinal'], RDF_OBJECT_TYPE_BNODE, $node_id, '', $this->rdf_parser['top']['parent']['bag_id'], $this->rdf_parser['top']['parent']['statements'], $this->rdf_parser['top']['statement_id'], '');
  973. $statement_id = '';
  974. } else {
  975. $this->_report_statement(
  976. $this->rdf_parser['top']['parent']['subject_type'], $this->rdf_parser['top']['parent']['subject'], $this->rdf_parser['top']['predicate'], $this->rdf_parser['top']['ordinal'], RDF_OBJECT_TYPE_BNODE, $node_id, '', $this->rdf_parser['top']['parent']['bag_id'], $this->rdf_parser['top']['parent']['statements'], '', $datatype);
  977. }
  978. $this->rdf_parser['top']['state'] = IN_PROPERTY_EMPTY_RESOURCE;
  979. }
  980. if ($parse_type) {
  981. if ($resource) {
  982. $this->_report_error('property elements with rdf:parseType do not allow rdf:resource');
  983. }
  984. if ($bag_id) {
  985. $this->_report_warning('property elements with rdf:parseType do not allow rdf:bagID');
  986. return;
  987. }
  988. if ($this->rdf_parser['top']['has_property_attributes']) {
  989. $this->_report_error('property elements with rdf:parseType do not allow property attributes');
  990. return;
  991. }
  992. if ($attribute_value == RDF_PARSE_TYPE_RESOURCE) {
  993. $this->_generate_anonymous_uri($buffer);
  994. // since we are sure that this is now a resource property we can report it
  995. $this->_report_statement(
  996. $this->rdf_parser['top']['parent']['subject_type'], $this->rdf_parser['top']['parent']['subject'], $this->rdf_parser['top']['predicate'], 0, RDF_OBJECT_TYPE_BNODE, $buffer, '', $this->rdf_parser['top']['parent']['bag_id'], $this->rdf_parser['top']['parent']['statements'], $this->rdf_parser['top']['statement_id'], $datatype);
  997. $this->_push_element();
  998. $this->rdf_parser['top']['state'] = IN_PROPERTY_PARSE_TYPE_RESOURCE;
  999. $this->rdf_parser['top']['subject_type'] = RDF_SUBJECT_TYPE_BNODE;
  1000. $this->rdf_parser['top']['subject'] = $buffer;
  1001. $this->rdf_parser['top']['bag_id'] = '';
  1002. $this->rdf_parser['top']['datatype'] = $datatype;
  1003. } elseif ($attribute_value == RDF_PARSE_TYPE_LITERAL) {
  1004. $this->rdf_parser['top']['state'] = IN_PROPERTY_PARSE_TYPE_LITERAL;
  1005. $this->rdf_parser['top']['datatype'] = RDF_NAMESPACE_URI . RDF_XMLLITERAL;
  1006. $this->rdf_parser['xml_literal']['buffer'] = '';
  1007. $this->rdf_parser['xml_literal']['depth'] = 0;
  1008. } elseif ($attribute_value == RDF_PARSE_TYPE_COLLECTION) {
  1009. $this->_generate_anonymous_uri($buffer);
  1010. $this->_report_statement(
  1011. $this->rdf_parser['top']['parent']['subject_type'], $this->rdf_parser['top']['parent']['subject'], $this->rdf_parser['top']['predicate'], 0, RDF_OBJECT_TYPE_BNODE, $buffer, '', $this->rdf_parser['top']['parent']['bag_id'], $this->rdf_parser['top']['parent']['statements'], $this->rdf_parser['top']['statement_id'], $datatype);
  1012. $this->rdf_parser['top']['state'] = IN_PROPERTY_PARSE_TYPE_COLLECTION;
  1013. $this->rdf_parser['top']['collection']['first_blank_node_id'] = $buffer;
  1014. } else {
  1015. $this->_report_statement(
  1016. $this->rdf_parser['top']['parent']['subject_type'], $this->rdf_parser['top']['parent']['subject'], $this->rdf_parser['top']['predicate'], 0, RDF_OBJECT_TYPE_XML, '', '', $this->rdf_parser['top']['parent']['bag_id'], $this->rdf_parser['top']['parent']['statements'], $this->rdf_parser['top']['statement_id'], $datatype);
  1017. $this->rdf_parser['top']['state'] = IN_PROPERTY_PARSE_TYPE_LITERAL;
  1018. }
  1019. } else if ($resource !== NULL || $bag_id || $this->rdf_parser['top']['has_property_attributes']) {
  1020. if ($resource !== NULL) {
  1021. $subject_type = RDF_SUBJECT_TYPE_URI;
  1022. $this->_resolve_uri_reference($this->rdf_get_base(), $resource, $buffer);
  1023. $object_type = RDF_OBJECT_TYPE_RESOURCE;
  1024. } else {
  1025. $subject_type = RDF_SUBJECT_TYPE_BNODE;
  1026. $this->_generate_anonymous_uri($buffer);
  1027. $object_type = RDF_OBJECT_TYPE_BNODE;
  1028. }
  1029. $this->rdf_parser['top']['state'] = IN_PROPERTY_EMPTY_RESOURCE;
  1030. // since we are sure that this is now a resource property we can report it.
  1031. $this->_report_statement(
  1032. $this->rdf_parser['top']['parent']['subject_type'], $this->rdf_parser['top']['parent']['subject'], $this->rdf_parser['top']['predicate'], $this->rdf_parser['top']['ordinal'], $object_type, $buffer, '', $this->rdf_parser['top']['parent']['bag_id'], $this->rdf_parser['top']['parent']['statements'], $this->rdf_parser['top']['statement_id'], $datatype); // should we allow IDs?
  1033. if ($bag_id) {
  1034. $this->_resolve_id($bag_id, $buffer);
  1035. $this->rdf_parser['top']['bag_id'] = $buffer;
  1036. }
  1037. if ($this->rdf_parser['top']['has_property_attributes']) {
  1038. $this->_handle_property_attributes(
  1039. $subject_type, $buffer, $attributes, $this->rdf_parser['top']['xml_lang'], $this->rdf_parser['top']['bag_id'], $this->rdf_parser['top']['statements']);
  1040. }
  1041. }
  1042. }
  1043. /**
  1044. * @param string &$namespace_uri
  1045. * @param string &$local_name
  1046. * @param string &$attributes
  1047. * @access private
  1048. */
  1049. private function _handle_collection_element(&$namespace_uri, &$local_name, &$attributes) {
  1050. $aux2 = Array();
  1051. foreach ($attributes as $atkey => $atvalue) {
  1052. $aux2[] = $atkey;
  1053. $aux2[] = $atvalue;
  1054. }
  1055. $attributes = $aux2;
  1056. /* collection construction site
  1057. // old:
  1058. if ( ($namespace_uri == RDF_NAMESPACE_URI || $namespace_uri == '')
  1059. && ($local_name == RDF_DESCRIPTION || $local_name == RDF_LI) )
  1060. {
  1061. for( $i = 0; isset($attributes[$i]); $i += 2 )
  1062. {
  1063. $this->_split_name(
  1064. $attributes[ $i ],
  1065. $attribute,
  1066. $attribute_namespace_uri,
  1067. $attribute_local_name );
  1068. $attribute_value = $attributes[ $i + 1 ];
  1069. if( $attribute_namespace_uri == '' || $attribute_namespace_uri == RDF_NAMESPACE_URI )
  1070. {
  1071. if( $attribute_local_name == RDF_ABOUT ||
  1072. $attribute_local_name == RDF_RESOURCE)
  1073. {
  1074. $this->rdf_parser['top']['parent']['collection']['object_type'][] = RDF_OBJECT_TYPE_RESOURCE;
  1075. }
  1076. elseif ( $attribute_local_name == RDF_NODEID ) {
  1077. $this->rdf_parser['top']['parent']['collection']['object_type'][] = RDF_OBJECT_TYPE_BNODE;
  1078. }
  1079. $this->rdf_parser['top']['parent']['collection']['object_label'][] = $attribute_value;
  1080. }
  1081. }
  1082. }
  1083. */
  1084. // new
  1085. for ($i = 0; isset($attributes[$i]); $i += 2) {
  1086. $this->_split_name(
  1087. $attributes[$i], $attribute, $attribute_namespace_uri, $attribute_local_name);
  1088. $attribute_value = $attributes[$i + 1];
  1089. if ($attribute_namespace_uri == '' || $attribute_namespace_uri == RDF_NAMESPACE_URI) {
  1090. $tmp_subject_type = RDF_SUBJECT_TYPE_URI;
  1091. if ($attribute_local_name == RDF_ABOUT ||
  1092. $attribute_local_name == RDF_RESOURCE) {
  1093. $this->rdf_parser['top']['parent']['collection']['object_type'][] = RDF_OBJECT_TYPE_RESOURCE;
  1094. } elseif ($attribute_local_name == RDF_NODEID) {
  1095. $this->rdf_parser['top']['parent']['collection']['object_type'][] = RDF_OBJECT_TYPE_BNODE;
  1096. $tmp_subject_type = RDF_SUBJECT_TYPE_BNODE;
  1097. }
  1098. $id_buffer = '';
  1099. $this->_resolve_uri_reference($this->rdf_get_base(), $attribute_value, $id_buffer);
  1100. $this->rdf_parser['top']['parent']['collection']['object_label'][] = $id_buffer;
  1101. if (!( ($namespace_uri == RDF_NAMESPACE_URI || $namespace_uri == '')
  1102. && ($local_name == RDF_DESCRIPTION || $local_name == RDF_LI) )) {
  1103. $this->_report_statement(
  1104. $tmp_subject_type, $id_buffer, RDF_NAMESPACE_URI . RDF_TYPE, '', RDF_OBJECT_TYPE_RESOURCE, $namespace_uri . $local_name, '', '', '', '', '');
  1105. }
  1106. }
  1107. }
  1108. // collection construction site
  1109. }
  1110. /**
  1111. * @param string &$namespace_uri

Large files files are truncated, but you can click here to view the full file