PageRenderTime 35ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/rdfapi-php/rap-pubby/RAPpubbyDataset.php

https://github.com/koja13/DSi2.0
PHP | 143 lines | 71 code | 44 blank | 28 comment | 11 complexity | fd919f9042175d622b5e7f903bccb880 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?PHP
  2. // ----------------------------------------------------------------------------------
  3. // RAP_Pubby - A Linked Data Frontend for RAP
  4. // ----------------------------------------------------------------------------------
  5. /**
  6. * Installation information is found in the RAP_Pubby documentation.
  7. *
  8. * @author Radoslaw Oldakowski <radol@gmx.de>
  9. * @version 1.0, 19.12.2007
  10. * @package rap-pubby
  11. */
  12. // toDo: delete this
  13. include_once('RAPpubbyURIrewriter.php');
  14. Class RAPpubbyDataset extends Object {
  15. var $m;
  16. var $ns = array();
  17. var $metadata;
  18. function RAPpubbyDataset() {
  19. global $_PUBBY_DATASET;
  20. $this->loadModel($_PUBBY_DATASET['loadRDF']);
  21. $this->loadNamespaces($_PUBBY_DATASET['usePrefixesFrom']);
  22. $this->loadMetadata($_PUBBY_DATASET['rdfDocumentMetadata']);
  23. }
  24. /**
  25. *
  26. */
  27. function & getResDescr ($resURI, $attach_metadata = false) {
  28. global $_PUBBY_DATASET;
  29. $r = new Resource(RAPpubbyURIrewriter::pubbyURItoDatasetURI($resURI));
  30. $rd_m = new MemModel();
  31. $rd_m = $this->m->find($r, NULL, NULL);
  32. $backlinks = $this->m->find(NULL, NULL, $r);
  33. $rd_m->addModel($backlinks);
  34. $rew_rd_m = & RAPpubbyURIrewriter::rewriteURIsInResDescrModel($rd_m);
  35. if (!$rew_rd_m->isEmpty() && $_PUBBY_DATASET['addSameAsStatements']) {
  36. $rew_rd_m->add(new Statement(new Resource($resURI), new Resource(OWL_NS. "sameAs"), $r));
  37. }
  38. $rew_rd_m->addParsedNamespaces($this->ns);
  39. $rd = new RAPpubbyResDescr($resURI, $rew_rd_m);
  40. if ($attach_metadata && !$rd->isEmpty()) {
  41. $rd->attachMetadata($this->getMetadata($resURI));
  42. }
  43. return $rd;
  44. }
  45. // private -----------------------------------------------------
  46. /**
  47. * @return RAP model with metadata, blank node replaced with resource URI
  48. */
  49. function & getMetadata ($resURI) {
  50. $dataURI = RAPpubbyURIrewriter::resURItoDataURI($resURI);
  51. $metaData = $this->metadata;
  52. $metaData->replace(new BlankNode(BNODE_PREFIX .'1'), NULL, NULL, new Resource($dataURI));
  53. return $metaData;
  54. }
  55. /**
  56. *
  57. */
  58. function loadModel($url) {
  59. // load model from file
  60. if ($url) {
  61. $this->m = new MemModel();
  62. $this->m->load($url);
  63. }
  64. else {
  65. $db = new DbStore(PUBBY_DB_DRIVER, PUBBY_DB_HOST, PUBBY_DB_DB, PUBBY_DB_USER, PUBBY_DB_PASS);
  66. $this->m = $db->getModel(PUBBY_DBMODEL);
  67. }
  68. }
  69. /**
  70. * loads namespaces from file or rewrites from configuration model
  71. */
  72. function loadNamespaces($url) {
  73. if ($url) {
  74. $nmsp_m = new MemModel();
  75. $nmsp_m->load($url);
  76. $this->ns = $nmsp_m->getParsedNamespaces();
  77. if (!$this->ns) {
  78. trigger_error("The file:" .$url ."does not contain any namespace declarations."
  79. ."The prefixes from the configuration model will be used instead");
  80. }
  81. }
  82. else {
  83. $nmsp = $this->m->getParsedNamespaces();
  84. if ($nmsp) {
  85. $this->ns = RAPpubbyURIrewriter::rewrNamespaces($nmsp);
  86. }
  87. }
  88. }
  89. /**
  90. *
  91. */
  92. function loadMetadata($url) {
  93. if ($url) {
  94. $this->metadata = new MemModel();
  95. $this->metadata->load($url);
  96. }
  97. }
  98. }
  99. ?>