PropertyHierarchy.php
Go to the documentation of this file.00001 <?php
00002
00005
00028 class PropertyHierarchy
00029 {
00031 public $properties = array();
00032
00043 function __construct($rootProperty) { $this->properties[$rootProperty] = new PropertyNode($rootProperty, ""); }
00044
00045 function __destruct() { }
00046
00058 public function addPropertyRelationship($property, $subPropertyOf)
00059 {
00060
00061
00062 if(isset($this->properties[$property]->subPropertyOf))
00063 {
00064 foreach($this->properties[$property]->subPropertyOf as $sp)
00065 {
00066 if($sp->name == $subPropertyOf)
00067 {
00068 return;
00069 }
00070 }
00071 }
00072
00073
00074 if(!isset($this->properties[$subPropertyOf]))
00075 {
00076 $this->addPropertyRelationship($subPropertyOf, "http://www.w3.org/2002/07/owl#Thing");
00077 }
00078
00079
00080 if(isset($this->properties[$property]))
00081 {
00082 $target = $this->properties[$property];
00083
00084 $superProperty = $this->properties[$subPropertyOf];
00085
00086 array_push($superProperty->superPropertyOf, $target);
00087
00088 array_push($target->subPropertyOf, $superProperty);
00089
00090
00091
00093 $newSubpropertyArray = array();
00094
00095 foreach($target->subPropertyOf as $sp)
00096 {
00097 if($sp->name != "http://www.w3.org/2002/07/owl#Thing")
00098 {
00099 array_push($newSubpropertyArray, $sp);
00100 }
00101 else
00102 {
00103
00104 $newSuperPropertyArray = array();
00105
00106 $owlThing = $this->properties["http://www.w3.org/2002/07/owl#Thing"];
00107
00108 foreach($owlThing->superPropertyOf as $sp)
00109 {
00110 if($sp->name != $target->name)
00111 {
00112 array_push($newSuperPropertyArray, $sp);
00113 }
00114 }
00115
00116 $owlThing->superPropertyOf = $newSuperPropertyArray;
00117 }
00118 }
00119
00120 $target->subPropertyOf = $newSubpropertyArray;
00122 }
00123 else
00124 {
00125
00126 $newProperty = new PropertyNode($property, $superProperty);
00127 $this->properties[$property] = $newProperty;
00128
00129 $superProperty = $this->properties[$subPropertyOf];
00130
00131 array_push($superProperty->superPropertyOf, &$newProperty);
00132
00133 array_push($newProperty->subPropertyOf, $superProperty);
00134 }
00135 }
00136
00149 public function getSuperProperties($property)
00150 {
00151 $superProperties = array();
00152 $stack = array();
00153
00154 if(isset($this->properties[$property]))
00155 {
00156
00157 foreach($this->properties[$property]->subPropertyOf as $sp)
00158 {
00159 if(array_search($sp, $stack) === FALSE)
00160 {
00161 array_push($stack, $sp);
00162 }
00163 }
00164
00165 while(count($stack) > 0)
00166 {
00167 $target = array_pop($stack);
00168
00169 array_push($superProperties, $target);
00170
00171 if(isset($target->subPropertyOf))
00172 {
00173 foreach($target->subPropertyOf as $sp)
00174 {
00175 if(array_search($sp, $stack) === FALSE)
00176 {
00177 array_push($stack, $sp);
00178 }
00179 }
00180 }
00181 }
00182 }
00183
00184 return $superProperties;
00185 }
00186
00199 public function getSubproperties($property)
00200 {
00201 $subproperties = array();
00202 $stack = array();
00203
00204 if(isset($this->properties[$property]))
00205 {
00206
00207 foreach($this->properties[$property]->superPropertyOf as $sp)
00208 {
00209 if(array_search($sp, $stack) === FALSE)
00210 {
00211 array_push($stack, $sp);
00212 }
00213 }
00214
00215 while(count($stack) > 0)
00216 {
00217 $target = array_pop($stack);
00218
00219 array_push($subproperties, $target);
00220
00221 if(isset($target->superPropertyOf))
00222 {
00223 foreach($target->superPropertyOf as $sp)
00224 {
00225 if(array_search($sp, $stack) === FALSE)
00226 {
00227 array_push($stack, $sp);
00228 }
00229 }
00230 }
00231 }
00232 }
00233
00234 return $subproperties;
00235 }
00236
00250 public function isSubPropertyOf($subproperty, $superProperty)
00251 {
00252 $superProperties = $this->getsuperProperties($subproperty);
00253
00254 foreach($superProperties as $sp)
00255 {
00256 if($sp->name == $superProperty)
00257 {
00258 return (TRUE);
00259 }
00260 }
00261
00262 return (FALSE);
00263 }
00264 }
00265
00266
00275 class propertyNode
00276 {
00278 public $name = "";
00279
00281 public $label = "";
00282
00284 public $description = "";
00285
00287 public $subPropertyOf = array();
00288
00290 public $superPropertyOf = array();
00291
00303 function __construct($name, $subPropertyOf)
00304 {
00305 $this->name = $name;
00306
00307 if(isset($subPropertyOf->name) && $subPropertyOf->name != "")
00308 {
00309 $this->subPropertyOf[$subPropertyOf->name] = $subPropertyOf;
00310 }
00311 }
00312
00313 function __destruct() { }
00314 }
00315 ?>
Copyright © 2009.
Structured Dynamics LLC. All rights reserved.