Source for file OntProperty.php

Documentation is available at OntProperty.php

  1. <?PHP
  2. /**
  3. * ----------------------------------------------------------------------------------
  4. * Class: OntProperty
  5. * ----------------------------------------------------------------------------------
  6. *
  7. * @package ontModel
  8. */
  9.  
  10.  
  11. /**
  12. * Class encapsulating a property in an ontology.
  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.  
  25. class OntProperty extends OntResource
  26. {
  27. /**
  28. * Constructor.
  29. * You can supply a URI.
  30. *
  31. * @param string $uri
  32. * @access public
  33. */
  34. function OntProperty($uri = null)
  35. {
  36. parent::OntResource($uri);
  37. }
  38. /**
  39. * Add a resource representing the domain of this property.
  40. *
  41. * @param object ResResource $resResource
  42. * @return boolean
  43. * @access public
  44. */
  45. function addDomain($resResource)
  46. {
  47. return $this->addProperty($this->vocabulary->DOMAIN(),$resResource);
  48. }
  49. /**
  50. * Add a resource representing the range of this property.
  51. *
  52. * @param object ResResource $resResource
  53. * @return boolean
  54. * @access public
  55. */
  56. function addRange($resResource)
  57. {
  58. return $this->addProperty($this->vocabulary->RANGE(),$resResource);
  59. }
  60. /**
  61. * Add a sub-property of this property.
  62. *
  63. * @param object ResProperty $resProperty
  64. * @return boolean
  65. * @access public
  66. */
  67. function addSubProperty($resProperty)
  68. {
  69. return $resProperty->addProperty($this->vocabulary->SUB_PROPERTY_OF(),$this);
  70. }
  71. /**
  72. * Add a super-property of this property.
  73. *
  74. * @param object ResProperty $resProperty
  75. * @return boolean
  76. * @access public
  77. */
  78. function addSuperProperty($resProperty)
  79. {
  80. return $this->addProperty($this->vocabulary->SUB_PROPERTY_OF(),$resProperty);
  81. }
  82. /**
  83. * Answer a OntClass that represents the domain class of this property.
  84. * If there is more than one such resource, an arbitrary selection is made.
  85. *
  86. * @return object OntClass
  87. * @access public
  88. */
  89. function getDomain()
  90. {
  91. return $this->getPropertyValue($this->vocabulary->DOMAIN(),'OntClass');
  92. }
  93.  
  94. /**
  95. * Answer a OntClass that represents the range class of this property.
  96. * If there is more than one such resource, an arbitrary selection is made.
  97. *
  98. * @return object OntClass
  99. * @access public
  100. */
  101. function getRange()
  102. {
  103. return $this->getPropertyValue($this->vocabulary->RANGE(),'OntClass');
  104. }
  105. /**
  106. * Answer a property that is the sub-property of this property.
  107. * If there is more than one such property, an arbitrary selection is made.
  108. *
  109. * @return object OntProperty
  110. * @access public
  111. */
  112. function getSubProperty()
  113. {
  114. $statement = $this->model->findFirstMatchingStatement(null,$this->vocabulary->SUB_PROPERTY_OF(),$this);
  115. if ($statement !== null)
  116. return new OntProperty($statement->getLabelSubject());
  117. return null;
  118. }
  119. /**
  120. * Answer a property that is the super-property of this property.
  121. * If there is more than one such property, an arbitrary selection is made.
  122. *
  123. * @return object OntProperty
  124. * @access public
  125. */
  126. function getSuperProperty()
  127. {
  128. return $this->getPropertyValue($this->vocabulary->SUB_PROPERTY_OF(),'OntProperty');
  129. }
  130. /**
  131. * Answer true if the given resource a class specifying the domain of this property.
  132. *
  133. * @param object ResResource $resResource
  134. * @return boolean
  135. * @access public
  136. */
  137. function hasDomain($resResource)
  138. {
  139. return $this->hasProperty($this->vocabulary->DOMAIN(),$resResource);
  140. }
  141. /**
  142. * Answer true if the given resource a class specifying the range of this property.
  143. *
  144. * @param object ResResource $resResource
  145. * @return boolean
  146. * @access public
  147. */
  148. function hasRange($resResource)
  149. {
  150. return $this->hasProperty($this->vocabulary->RANGE(),$resResource);
  151. }
  152. /**
  153. * Answer true if the given property is a sub-property of this property.
  154. * If $direct is set to true, only consider the direcly adjacent
  155. * properties in the property hierarchy
  156. *
  157. * @param object ResResource $resProperty
  158. * @param boolean $direct
  159. * @return boolean
  160. * @access public
  161. */
  162. function hasSubProperty($resProperty, $direct = true)
  163. {
  164. if ($direct)
  165. return $resProperty->hasProperty($this->vocabulary->SUB_PROPERTY_OF(),$this);
  166. $index=array();
  167. return ($this->_getSubAttributeStatementsRec($this,$this->vocabulary->SUB_PROPERTY_OF(),$index,$resProperty) === true);
  168. }
  169. /**
  170. * Answer true if the given property is a super-property of this property.
  171. * If $direct is set to true, only consider the direcly adjacent
  172. * properties in the property hierarchy
  173. *
  174. * @param object ResResource $resProperty
  175. * @param boolean $direct
  176. * @return boolean
  177. * @access public
  178. */
  179. function hasSuperProperty($resProperty, $direct = true)
  180. {
  181. if ($direct)
  182. return $this->hasProperty($this->vocabulary->SUB_PROPERTY_OF(),$resProperty);
  183. $index=array();
  184. return ($this->_getSuperAttributeStatementsRec($this,$this->vocabulary->SUB_PROPERTY_OF(),$index,$resProperty) === true);
  185. }
  186. /**
  187. * Answer an array of all of the declared domain classes of this property.
  188. * Each element of the iterator will be an OntClass.
  189. *
  190. * @return array of OntClasses
  191. * @access public
  192. */
  193. function listDomain()
  194. {
  195. return $this->listProperty($this->vocabulary->DOMAIN(),'OntClass');
  196. }
  197. /**
  198. * Answer an array of all of the declared range classes of this property.
  199. * Each element of the iterator will be an OntClass.
  200. *
  201. * @return array of OntClasses
  202. * @access public
  203. */
  204. function listRange()
  205. {
  206. return $this->listProperty($this->vocabulary->RANGE(),'OntClass');
  207. }
  208. /**
  209. * Answer an array of all the properties that are declared to be
  210. * sub-properties of this property. Each element of the iterator will be an
  211. * OntProperty.
  212. * If $direct is set to true, only consider the direcly adjacent
  213. * properties in the property hierarchy
  214. *
  215. * @param boolean $direct
  216. * @return array of OntProperties
  217. * @access public
  218. */
  219. function listSubProperties($direct = true)
  220. {
  221. $return = array();
  222. if ($direct)
  223. {
  224. $statements = $this->model->find(null,$this->vocabulary->SUB_PROPERTY_OF(),$this);
  225. } else
  226. {
  227. $index = array();
  228. $statements = $this->_getSubAttributeStatementsRec($this,$this->vocabulary->SUB_PROPERTY_OF(),$index);
  229. }
  230. $returnIndex=array();
  231. foreach ($statements as $statement)
  232. {
  233. $objectLabel=$statement->getLabelSubject();
  234. if (!in_array($objectLabel,$returnIndex))
  235. {
  236. $returnIndex[]=$objectLabel;
  237. $return[]=new OntProperty($statement->getLabelSubject());
  238. }
  239. }
  240. return $return;
  241. }
  242. /**
  243. * Answer an array of all the properties that are declared to be
  244. * super-properties of this property. Each element of the iterator will be an
  245. * OntProperty.
  246. * If $direct is set to true, only consider the direcly adjacent
  247. * properties in the property hierarchy
  248. *
  249. * @param boolean $direct
  250. * @return array of OntProperties
  251. * @access public
  252. */
  253. function listSuperProperties($direct = true)
  254. {
  255. $return = array();
  256. if ($direct)
  257. return $this->listProperty($this->vocabulary->SUB_PROPERTY_OF(),'OntProperty');
  258. $index=array();
  259. $statements = $this->_getSuperAttributeStatementsRec($this,$this->vocabulary->SUB_PROPERTY_OF(),$index);
  260. $returnIndex=array();
  261. foreach ($statements as $statement)
  262. {
  263. $objectLabel=$statement->getLabelObject();
  264. if (!in_array($objectLabel,$returnIndex))
  265. {
  266. $returnIndex[]=$objectLabel;
  267. $return[]=new OntProperty($statement->getLabelObject());
  268. }
  269. }
  270. return $return;
  271. }
  272. /**
  273. * Remove the given class from the stated domain(s) of this property.
  274. *
  275. * @param object ResResource $resResource
  276. * @return boolean
  277. * @access public
  278. */
  279. function removeDomain($resResource)
  280. {
  281. return $this->removeProperty($this->vocabulary->DOMAIN(),$resResource);
  282. }
  283. /**
  284. * Remove the given class from the stated range(es) of this property.
  285. *
  286. * @param object ResResource $resResource
  287. * @return boolean
  288. * @access public
  289. */
  290. function removeRange($resResource)
  291. {
  292. return $this->removeProperty($this->vocabulary->RANGE(),$resResource);
  293. }
  294. /**
  295. * Remove the given property from the sub-properties of this property.
  296. *
  297. * @param object ResProperty $resProperty
  298. * @return boolean
  299. * @access public
  300. */
  301. function removeSubProperty( )
  302. {
  303. return $this->model->remove(new Statement($resProperty,$this->vocabulary->SUB_PROPERTY_OF(),$this));
  304. }
  305. /**
  306. * Remove the given property from the super-properties of this property.
  307. *
  308. * @param object ResProperty $resProperty
  309. * @return boolean
  310. * @access public
  311. */
  312. function removeSuperProperty($resProperty)
  313. {
  314. return $this->removeProperty($this->vocabulary->SUB_PROPERTY_OF(),$resProperty);
  315. }
  316.  
  317. /**
  318. * Assert that the given resource represents the class of individuals
  319. * that form the domain of this property. Any existing domain statements
  320. * for this property are removed.
  321. *
  322. * @param object ResResource $resResource
  323. * @access public
  324. */
  325. function setDomain($resResource)
  326. {
  327. $this->setPropertyValue($this->vocabulary->DOMAIN(),$resResource);
  328. }
  329. /**
  330. * Assert that the given resource represents the class of individuals
  331. * that form the range of this property. Any existing range statements
  332. * for this property are removed.
  333. *
  334. * @param object ResResource $resResource
  335. * @access public
  336. */
  337. function setRange($resResource)
  338. {
  339. $this->setPropertyValue($this->vocabulary->RANGE(),$resResource);
  340. }
  341. /**
  342. * Assert that this property is super-property of the given property.
  343. * Any existing statements for superPropertyOf on prop will be removed.
  344. *
  345. * @param object ResProperty $resProperty
  346. * @access public
  347. */
  348. function setSubProperty($resProperty)
  349. {
  350. foreach ($this->listSubProperties() as $oldResProperty)
  351. {
  352. $this->removeSubProperty($oldResProperty);
  353. }
  354. $this->addSubProperty($resProperty);
  355. }
  356. /**
  357. * Assert that this property is sub-property of the given property.
  358. * Any existing statements for subPropertyOf on prop will be removed.
  359. *
  360. * @param object ResProperty $resProperty
  361. * @access public
  362. */
  363. function setSuperProperty($resProperty)
  364. {
  365. $this->setPropertyValue($this->vocabulary->SUB_PROPERTY_OF(),$resProperty);
  366. }
  367. }
  368. ?>

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