Source for file OntModel.php

Documentation is available at OntModel.php

  1. <?PHP
  2.  
  3. /**
  4. * ----------------------------------------------------------------------------------
  5. * Class: OntModel
  6. * ----------------------------------------------------------------------------------
  7. *
  8. * @package ontModel
  9. */
  10.  
  11.  
  12. /**
  13. * Enhanced view of the model that is known to contain ontology data, under a
  14. * given ontology vocabulary (such as RDFS). OntModel together with OntClass
  15. * and OntResource provide ontology specific methods like addSubClass(),
  16. * listSubClasses(), hasSuperProperty(), addDomain() and listInstances(). This class does not by
  17. * itself compute the deductive extension of the graph under the semantic
  18. * rules of the language. Instead, we wrap an underlying model with this
  19. * ontology interface, that presents a convenience syntax for accessing the
  20. * language elements. Depending on the inference capability of the underlying
  21. * model, the OntModel will appear to contain more or less triples.
  22. * For example, if this class is used to wrap a MemModel or DBModel, only the
  23. * relationships asserted by the document will be reported through this
  24. * convenience API.
  25. * Alternatively, if the OntModel wraps an InfModel (InfModelF / InfModelB),
  26. * the inferred triples from the extension will be reported as well.
  27. *
  28. * <BR><BR>History:
  29. * <LI>10-05-2004 : First version of this class.</LI>
  30. *
  31. * @version V0.9.1
  32. * @author Daniel Westphal <mail at d-westphal dot de>
  33. *
  34. *
  35. * @package ontModel
  36. * @access public
  37. ***/
  38. class OntModel extends ResModel
  39. {
  40. /**
  41. * Holds a reference to the assoiated vocabulary.
  42. * @var object
  43. * @access private
  44. */
  45. var $vocabulary;
  46. /**
  47. * Constructor.
  48. * You have to supply a memmodel/dbmodel/infmodel to save the statements and a vocabulary
  49. *
  50. * @param object Model $model
  51. * @access public
  52. */
  53. function OntModel(& $model,& $vocabulary)
  54. {
  55. parent::ResModel($model);
  56. $this->vocabulary = & $vocabulary;
  57. }
  58. /**
  59. * Answer a resource that represents a class description node in this model.
  60. * If a resource with the given uri exists in the model, it will be re-used.
  61. * If not, a new one is created in the updateable sub-model of the ontology model.
  62. *
  63. * @param string $uri
  64. * @return object OntClass
  65. * @access public
  66. */
  67. function createOntClass($uri = null)
  68. {
  69. $class = new OntClass($uri);
  70. $class->setAssociatedModel($this);
  71. $class->setVocabulary($this->vocabulary);
  72. $class->setInstanceRdfType($this->vocabulary->ONTCLASS());
  73. return $class;
  74. }
  75. /**
  76. * Answer a resource that represents an Individual node in this model.
  77. * If a resource with the given uri exists in the model, it will be re-used.
  78. * If not, a new one is created in the updateable sub-model of the ontology model.
  79. *
  80. * @param string $uri
  81. * @return object Individual
  82. * @access public
  83. */
  84. function createIndividual($uri = null)
  85. {
  86. $individual = new Individual($uri);
  87. $individual->setAssociatedModel($this);
  88. $individual->setVocabulary($this->vocabulary);
  89. return $individual;
  90. }
  91. /**
  92. * Answer a resource that represents an OntProperty node in this model.
  93. * If a resource with the given uri exists in the model, it will be re-used.
  94. * If not, a new one is created in the updateable sub-model of the ontology model.
  95. *
  96. * @param string $uri
  97. * @return object OntProperty
  98. * @access public
  99. */
  100. function createOntProperty($uri = null)
  101. {
  102. $ontProperty = new OntProperty($uri);
  103. $ontProperty->setAssociatedModel($this);
  104. $ontProperty->setVocabulary($this->vocabulary);
  105. $ontProperty->setInstanceRdfType($this->createResource(RDF_NAMESPACE_URI.RDF_PROPERTY));
  106. return $ontProperty;
  107. }
  108. /**
  109. * Answer an array that ranges over all of the various forms of class
  110. * description resource in this model.
  111. * Class descriptions include domain/range definitions, named classes and subClass constructs.
  112. *
  113. * @param string $uri
  114. * @return array of object ResResource
  115. * @access public
  116. */
  117. function listClasses()
  118. {
  119. //get all statements, with an rdf:type as property
  120. $statements= $this->find(null,$this->vocabulary->TYPE(),null);
  121. $return = array();
  122. $returnIndex=array();
  123. foreach ($statements as $statement)
  124. {
  125. $objectLabel=$statement->getLabelObject();
  126. //if it's about a typed Individual
  127. if ($objectLabel!=RDF_SCHEMA_URI.RDFS_CLASS)
  128. {
  129. if (!in_array($objectLabel,$returnIndex))
  130. {
  131. $returnIndex[]=$objectLabel;
  132. $return[]=$statement->getObject();
  133. }
  134. } else
  135. //if it's a "class1 rdf:type rdf:class" construct
  136. {
  137. $subjectLabel=$statement->getLabelSubject();
  138. if (!in_array($subjectLabel,$returnIndex))
  139. {
  140. $returnIndex[]=$subjectLabel;
  141. $return[]=$statement->getSubject();
  142. }
  143. }
  144. }
  145. //find all statements about SubClassConstructs
  146. $statements= $this->find(null,$this->vocabulary->SUB_CLASS_OF(),null);
  147. foreach ($statements as $statement)
  148. {
  149. //add the statements object to the result
  150. $objectLabel=$statement->getLabelObject();
  151. if (!in_array($objectLabel,$returnIndex))
  152. {
  153. $returnIndex[]=$objectLabel;
  154. $return[]=$statement->getObject();
  155. }
  156. }
  157. foreach ($statements as $statement)
  158. {
  159. //add the statements subject to the result
  160. $objectLabel=$statement->getLabelSubject();
  161. if (!in_array($objectLabel,$returnIndex))
  162. {
  163. $returnIndex[]=$objectLabel;
  164. $return[]=$statement->getSubject();
  165. }
  166. }
  167. return $return;
  168. }
  169. }
  170. ?>

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