Source for file Resource.php

Documentation is available at Resource.php

  1. <?php
  2.  
  3. // ----------------------------------------------------------------------------------
  4. // Class: Resource
  5. // ----------------------------------------------------------------------------------
  6.  
  7.  
  8.  
  9. /**
  10. * An RDF resource.
  11. * Every RDF resource must have a URIref.
  12. * URIrefs are treated as logical constants, i.e. as names which denote something
  13. * (the things are called 'resources', but no assumptions are made about the nature of resources.)
  14. * Many RDF resources are pieces of vocabulary. They typically have a namespace
  15. * and a local name. In this case, a URI is composed as a
  16. * concatenation of the namespace and the local name.
  17. *
  18. * <BR><BR>History:<UL>
  19. * <LI>11-09-2003 : Fixed bug in equals() <radol@gmx.de></LI>
  20. * <LI>09-30-2002 : Fixed bug in getNamespace() and getLocalName().</LI>
  21. * <LI>09-10-2002 : First version of this class.</LI>
  22. * </UL>
  23. *
  24. * @version V0.9.1
  25. * @author Chris Bizer <chris@bizer.de>
  26. *
  27. * @package model
  28. * @todo nothing
  29. * @access public
  30. *
  31. */
  32. class Resource extends Node {
  33.  
  34. /**
  35. * URIref to the resource
  36. * @var string
  37. * @access private
  38. */
  39. var $uri;
  40. /**
  41. * Constructor
  42. * Takes an URI or a namespace/localname combination
  43. *
  44. * @param string $namespace_or_uri
  45. * @param string $localName
  46. * @access public
  47. */
  48. function Resource($namespace_or_uri , $localName = NULL) {
  49. if ($localName == NULL) {
  50. $this->uri = $namespace_or_uri;
  51. } else {
  52. $this->uri = $namespace_or_uri . $localName;
  53. }
  54. }
  55.  
  56. /**
  57. * Returns the URI of the resource.
  58. * @return string
  59. * @access public
  60. */
  61. function getURI() {
  62. return $this->uri;
  63. }
  64.  
  65. /**
  66. * Returns the label of the resource, which is the URI of the resource.
  67. * @access public
  68. * @return string
  69. */
  70. function getLabel() {
  71. return $this->getURI();
  72. }
  73. /**
  74. * Returns the namespace of the resource. May return null.
  75. * @access public
  76. * @return string
  77. */
  78. function getNamespace() {
  79. // Import Package Utility
  80. include_once(RDFAPI_INCLUDE_DIR.PACKAGE_UTILITY);
  81. return RDFUtil::guessNamespace($this->uri);
  82. }
  83.  
  84. /**
  85. * Returns the local name of the resource.
  86. * @access public
  87. * @return string
  88. */
  89. function getLocalName() {
  90. // Import Package Utility
  91. include_once(RDFAPI_INCLUDE_DIR.PACKAGE_UTILITY);
  92. return RDFUtil::guessName($this->uri);
  93. }
  94. /**
  95. * Dumps resource.
  96. * @access public
  97. * @return string
  98. */
  99. function toString() {
  100. return 'Resource("' . $this->uri .'")';
  101. }
  102.  
  103. /**
  104. * Checks if the resource equals another resource.
  105. * Two resources are equal, if they have the same URI
  106. *
  107. * @access public
  108. * @param object resource $that
  109. * @return boolean
  110. */
  111. function equals ($that) {
  112. if ($this == $that) {
  113. return true;
  114. }
  115. if (($that == NULL) or !(is_a($that, 'Resource')) or (is_a($that, 'BlankNode'))) {
  116. return false;
  117. }
  118. if ($this->getURI() == $that->getURI()) {
  119. return true;
  120. }
  121. return false;
  122. }
  123.  
  124. }
  125.  
  126. ?>

Documentation generated on Fri, 17 Dec 2004 16:18:01 +0100 by phpDocumentor 1.3.0RC3