Source for file OntClass.php

Documentation is available at OntClass.php

  1. <?PHP
  2. /**
  3. * ----------------------------------------------------------------------------------
  4. * Class: OntClass
  5. * ----------------------------------------------------------------------------------
  6. *
  7. * @package ontModel
  8. */
  9.  
  10.  
  11. /**
  12. * Class that represents an ontology node characterising a class description.
  13. *
  14. * <BR><BR>History:
  15. * <LI>10-05-2004 : First version of this class.</LI>
  16. *
  17. * @version V0.9.1
  18. * @author Daniel Westphal <mail at d-westphal dot de>
  19. *
  20. *
  21. * @package ontModel
  22. * @access public
  23. ***/
  24. class OntClass extends OntResource
  25. {
  26. /**
  27. * Constructor
  28. * You can supply a uri
  29. *
  30. * @param string $uri
  31. * @access public
  32. */
  33. function OntClass($uri = null)
  34. {
  35. parent::OntResource($uri);
  36. }
  37.  
  38. /**
  39. * Add a sub-class of this class.
  40. *
  41. * @param object ResResource $resResource
  42. * @return boolean
  43. * @access public
  44. */
  45. function addSubClass($resResource)
  46. {
  47. return $resResource->addProperty($this->vocabulary->SUB_CLASS_OF(),$this);
  48. }
  49. /**
  50. * Add a super-class of this class.
  51. *
  52. * @param object ResResource $resResource
  53. * @return boolean
  54. * @access public
  55. */
  56. function addSuperClass($resResource)
  57. {
  58. return $this->addProperty($this->vocabulary->SUB_CLASS_OF(),$resResource);
  59. }
  60. /**
  61. * Answer a class that is the sub-class of this class.
  62. * If there is more than one such class, an arbitrary selection is made.
  63. *
  64. * @return object OntClass or NULL
  65. * @access public
  66. */
  67. function getSubClass()
  68. {
  69. $statement = $this->model->findFirstMatchingStatement(null,$this->vocabulary->SUB_CLASS_OF(),$this);
  70. if ($statement !== null)
  71. return $this->model->createOntClass($statement->getLabelSubject());
  72. return null;
  73. }
  74. /**
  75. * Answer a class that is the super-class of this class.
  76. * If there is more than one such class, an arbitrary selection is made.
  77. *
  78. * @return object OntClass or NULL
  79. * @access public
  80. */
  81. function getSuperClass()
  82. {
  83. return $this->getPropertyValue($this->vocabulary->SUB_CLASS_OF(),'OntClass');
  84. }
  85. /**
  86. * Answer true if the given class is a sub-class of this class.
  87. * $direct - If true, only search the classes that are directly
  88. * adjacent to this class in the class hierarchy.
  89. *
  90. * @param object ResResource $resResource
  91. * @param boolean $direct
  92. * @return boolean
  93. * @access public
  94. */
  95. function hasSubclass($resResource, $direct = true)
  96. {
  97. if ($direct)
  98. return $resResource->hasProperty($this->vocabulary->SUB_CLASS_OF(),$this);
  99. $index=array();
  100. return ($this->_getSubAttributeStatementsRec($this,$this->vocabulary->SUB_CLASS_OF(),$index,$resResource) === true);
  101. }
  102. /**
  103. * Answer true if the given class is a super-class of this class.
  104. * $direct - If true, only search the classes that are directly
  105. * adjacent to this class in the class hierarchy.
  106. *
  107. * @param object ResResource $resResource
  108. * @param boolean $direct
  109. * @return boolean
  110. * @access public
  111. */
  112. function hasSuperClass($resResource, $direct = true)
  113. {
  114. if ($direct)
  115. return $this->hasProperty($this->vocabulary->SUB_CLASS_OF(),$resResource);
  116. $index=array();
  117. return ($this->_getSuperAttributeStatementsRec($this,$this->vocabulary->SUB_CLASS_OF(),$index,$resResource) === true);
  118. }
  119. /**
  120. * Answer an ResIterator over the individuals in the model that have this class
  121. * among their types.
  122. *
  123. * @return object ResIterator
  124. * @access public
  125. */
  126. function listInstances()
  127. {
  128. /*
  129. $statements= $this->model->find(null,$this->vocabulary->TYPE(),$this);
  130. $return = array();
  131. $returnIndex=array();
  132. foreach ($statements as $statement)
  133. {
  134. $subjectLabel=$statement->getLabelSubject();
  135. if (!in_array($subjectLabel,$returnIndex))
  136. {
  137. $returnIndex[]=$subjectLabel;
  138. $return[]=$statement->getSubject();
  139. }
  140. }
  141. return $return;
  142. */
  143. return new ResIterator(null,$this->vocabulary->TYPE(),$this,'s',$this->model,'Individual');
  144. }
  145. /**
  146. * Answer an array over the classes that are declared to be sub-classes of this class.
  147. * Each element of the array will be an OntClass.
  148. * $direct - If true, only search the classes that are directly
  149. * adjacent to this class in the class hierarchy.
  150. *
  151. * @param boolean $direct
  152. * @return array
  153. * @access public
  154. */
  155. function listSubClasses($direct = true)
  156. {
  157. $return = array();
  158. if ($direct)
  159. {
  160. $statements = $this->model->find(null,$this->vocabulary->SUB_CLASS_OF(),$this);
  161. } else
  162. {
  163. $index = array();
  164. $statements = $this->_getSubAttributeStatementsRec($this,$this->vocabulary->SUB_CLASS_OF(),$index);
  165. }
  166. $returnIndex=array();
  167. foreach ($statements as $statement)
  168. {
  169. $subjectLabel=$statement->getLabelSubject();
  170. if (!in_array($subjectLabel,$returnIndex))
  171. {
  172. $returnIndex[]=$subjectLabel;
  173. $return[]=$this->model->createOntClass($subjectLabel);
  174. }
  175. }
  176. return $return;
  177. }
  178. /**
  179. * Answer an array over the classes that are declared to be super-classes of this class.
  180. * Each element of the array will be an OntClass.
  181. * $direct - If true, only search the classes that are directly
  182. * adjacent to this class in the class hierarchy.
  183. *
  184. * @param boolean $direct
  185. * @return array
  186. * @access public
  187. */
  188. function listSuperClasses($direct = true)
  189. {
  190. $return = array();
  191. if ($direct)
  192. return $this->listProperty($this->vocabulary->SUB_CLASS_OF(),'OntClass');
  193. $index=array();
  194. $statements = $this->_getSuperAttributeStatementsRec($this,$this->vocabulary->SUB_CLASS_OF(),$index);
  195. $returnIndex=array();
  196. foreach ($statements as $statement)
  197. {
  198. $objectLabel=$statement->getLabelObject();
  199. if (!in_array($objectLabel,$returnIndex))
  200. {
  201. $returnIndex[]=$objectLabel;
  202. $return[]=$this->model->createOntClass($objectLabel);
  203. }
  204. }
  205. return $return;
  206. }
  207. /**
  208. * Remove the given class from the sub-classes of this class.
  209. *
  210. * @param object ResResource $resResource
  211. * @return boolean
  212. * @access public
  213. */
  214. function removeSubClass($resResource)
  215. {
  216. return $this->model->remove(new Statement($resResource,$this->vocabulary->SUB_CLASS_OF(),$this));
  217. }
  218. /**
  219. * Remove the given class from the super-classes of this class.
  220. *
  221. * @param object ResResource $resResource
  222. * @return boolean
  223. * @access public
  224. */
  225. function removeSuperClass($resResource)
  226. {
  227. return $this->removeProperty($this->vocabulary->SUB_CLASS_OF(),$resResource);
  228. }
  229. /**
  230. * Assert that this class is super-class of the given class.
  231. * Any existing statements for subClassOf on prop will be removed.
  232. *
  233. * @param object ResResource $resResource
  234. * @access public
  235. */
  236. function setSubClass($resResource)
  237. {
  238. foreach ($this->listSubClasses() as $oldRes)
  239. {
  240. $this->removeSubClass($oldRes);
  241. }
  242. $this->addSubClass($resResource);
  243. }
  244. /**
  245. * Assert that this class is sub-class of the given class.
  246. * Any existing statements for subClassOf on prop will be removed.
  247. *
  248. * @param object ResResource $resResource
  249. * @access public
  250. */
  251. function setSuperClass($resResource)
  252. {
  253. $this->setPropertyValue($this->vocabulary->SUB_CLASS_OF(),$resResource);
  254. }
  255. /**
  256. * Answer a resource that represents an instance of this OntClass and Individual
  257. * node in this model.
  258. * If a resource with the given uri exists in the model, it will be re-used.
  259. * If not, a new one is created in the updateable sub-model of the ontology model.
  260. *
  261. * @param string $uri
  262. * @return object Individual
  263. * @access public
  264. */
  265. function createInstance($uri = null)
  266. {
  267. $instance = $this->model->createIndividual($uri);
  268. $instance->setInstanceRdfType($this);
  269. return $instance;
  270. }
  271. }
  272. ?>

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