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