PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/s3db3.5.10/pearlib/arc/parsers/ARC2_RDFParser.php

https://code.google.com/p/s3db/
PHP | 111 lines | 73 code | 21 blank | 17 comment | 5 complexity | 9fbc7f64fad1c60210f90af775bc2c79 MD5 | raw file
  1. <?php
  2. /*
  3. homepage: http://arc.semsol.org/
  4. license: http://arc.semsol.org/license
  5. class: ARC2 RDF Parser (generic)
  6. author: Benjamin Nowack
  7. version: 2008-07-15 (Addition: SG API JSON support)
  8. */
  9. ARC2::inc('Class');
  10. class ARC2_RDFParser extends ARC2_Class {
  11. function __construct($a = '', &$caller) {
  12. parent::__construct($a, $caller);
  13. }
  14. function ARC2_RDFParser($a = '', &$caller) {
  15. $this->__construct($a, $caller);
  16. }
  17. function __init() {/* proxy_host, proxy_port, proxy_skip, http_accept_header, http_user_agent_header, max_redirects, reader, skip_dupes */
  18. parent::__init();
  19. $this->a['format'] = $this->v('format', false, $this->a);
  20. $this->triples = array();
  21. $this->t_count = 0;
  22. $this->added_triples = array();
  23. $this->skip_dupes = $this->v('skip_dupes', false, $this->a);
  24. $this->bnode_prefix = $this->v('bnode_prefix', 'arc'.substr(md5(uniqid(rand())), 0, 4).'b', $this->a);
  25. $this->bnode_id = 0;
  26. }
  27. /* */
  28. function setReader(&$reader) {
  29. $this->reader =& $reader;
  30. }
  31. function parse($path, $data = '') {
  32. /* reader */
  33. if (!isset($this->reader)) {
  34. ARC2::inc('Reader');
  35. $this->reader = & new ARC2_Reader($this->a, $this);
  36. }
  37. $this->reader->activate($path, $data) ;
  38. /* format detection */
  39. $mappings = array(
  40. 'rdfxml' => 'RDFXML',
  41. 'turtle' => 'Turtle',
  42. 'sparqlxml' => 'SPOG',
  43. 'ntriples' => 'Turtle',
  44. 'html' => 'SemHTML',
  45. 'rss' => 'RSS',
  46. 'sgajson' => 'SGAJSON'
  47. );
  48. $format = $this->reader->getFormat();
  49. if (!$format || !isset($mappings[$format])) {
  50. return $this->addError('No parser available for "' . $format . '".');
  51. }
  52. /* format parser */
  53. $suffix = $mappings[$format] . 'Parser';
  54. ARC2::inc($suffix);
  55. $cls = 'ARC2_' . $suffix;
  56. $this->parser =& new $cls($this->a, $this);
  57. $this->parser->setReader($this->reader);
  58. return $this->parser->parse($path, $data);
  59. }
  60. function parseData($data) {
  61. return $this->parse(ARC2::getScriptURI(), $data);
  62. }
  63. /* */
  64. function done() {
  65. }
  66. /* */
  67. function getTriples() {
  68. return $this->v('parser') ? $this->m('getTriples', false, array(), $this->v('parser')) : array();
  69. }
  70. function countTriples() {
  71. return $this->v('parser') ? $this->m('countTriples', false, 0, $this->v('parser')) : 0;
  72. }
  73. function getSimpleIndex($flatten_objects = 1, $vals = '') {
  74. return ARC2::getSimpleIndex($this->getTriples(), $flatten_objects, $vals);
  75. }
  76. /* */
  77. function extractRDF($formats = '') {
  78. if (method_exists($this->parser, 'extractRDF')) {
  79. return $this->parser->extractRDF($formats);
  80. }
  81. }
  82. /* */
  83. function getEncoding($src = 'config') {
  84. if (method_exists($this->parser, 'getEncoding')) {
  85. return $this->parser->getEncoding($src);
  86. }
  87. }
  88. /* */
  89. }