Source for file OntProperty.php

Documentation is available at OntProperty.php

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

Documentation generated on Fri, 1 Jun 2007 16:50:10 +0200 by phpDocumentor 1.3.2