Source for file ResModel.php

Documentation is available at ResModel.php

  1. <?php
  2. // ----------------------------------------------------------------------------------
  3. // Class: ResModel
  4. // ----------------------------------------------------------------------------------
  5.  
  6. /**
  7. * A ResModel provides an resource centric view on an underlying RDF model.
  8. * ResModels show information not as statements but as resources with
  9. * properties, similar to Jena models. ResModels may create Resources [URI
  10. * nodes and bnodes]. Creating a Resource does not make the Resource visible to
  11. * the model; Resources are only "in" Models if Statements about them are added
  12. * to the Model. Similarly the only way to "remove" a Resource from a Model is
  13. * to remove all the Statements that mention it.
  14. * When a Resource or Literal is created by a Model, the Model is free to re-use an existing
  15. * Resource or Literal object with the correct values, or it may create a fresh one.
  16. *
  17. @version  $Id: fsource_resModel__resModelResModel.php.html 443 2007-06-01 16:25:38Z cax $
  18. @author Daniel Westphal <mail at d-westphal dot de>
  19. *
  20. *
  21. @package     resModel
  22. @access    public
  23. ***/
  24.  
  25. class ResModel
  26. {
  27.     
  28.     /**
  29.     * Holds a reference to the assoiated memmodel/dbmodel/infmodel
  30.     * @var        ResResource 
  31.     * @access    private
  32.     */
  33.     var $model;
  34.  
  35.     
  36.     /**
  37.     * Constructor
  38.     * You have to supply a memmodel/dbmodel/infmodel to save the statements.
  39.     *
  40.     * @param object model $model 
  41.     * @access    public
  42.     */    
  43.     function ResModel($model)
  44.     {
  45.         if (!is_a($model,'Model'))
  46.             trigger_error(RDFAPI_ERROR '(class: ResourceLayer; method: ResourceLayer): 
  47.                 $model has to be object of class Model'E_USER_ERROR);    
  48.         
  49.         $this->model =$model;            
  50.     }
  51.     
  52.     /**
  53.     * Create a new resource associated with this model.
  54.     * If the uri string isn't set, this creates a bnode.
  55.     * Otherwise it creates a URI node.
  56.     * A URI resource is .equals() to any other URI Resource with the same URI
  57.     * (even in a different model - be warned).
  58.     * 
  59.     * This method may return an existing Resource with the correct URI and model,
  60.     * or it may construct a fresh one, as it sees fit.
  61.     *
  62.     * Operations on the result Resource may change this model.
  63.     *
  64.        * @param    string    $uri 
  65.        * @return    object ResResource 
  66.        * @access    public
  67.        */
  68.     function createResource($uri null)
  69.     {
  70.         $resResource new ResResource($uri);
  71.         //associate the resource with this model, and get a unique identifier
  72.         //if it is bnode.
  73.         $resResource->setAssociatedModel($this);
  74.         
  75.         return $resResource;
  76.     
  77.     
  78.     /**
  79.     * Create a new Property associated with this model.
  80.     * This method may return an existing property with the correct URI and model,
  81.     * or it may construct a fresh one, as it sees fit.
  82.     *
  83.     * Subsequent operations on the returned property may modify this model.
  84.     *  
  85.     *
  86.        * @param    string    $uri 
  87.        * @return    object ResProperty 
  88.        * @access    public
  89.        */
  90.     function createProperty($uri null)
  91.     {
  92.         $resProperty new ResProperty($uri);
  93.         $resProperty->setAssociatedModel($this);
  94.             
  95.         return $resProperty;
  96.     }
  97.     
  98.     /**
  99.     * Create an untyped literal from a String value with a specified language.
  100.     *
  101.     * If you want to type this literal, you have to set a datatype before
  102.     * adding it to the model.
  103.     *  
  104.     *
  105.        * @param    string    $label 
  106.        * @param    string    $languageTag 
  107.        * @return    object ResLiteral 
  108.        * @access    public
  109.        */    
  110.     function createLiteral($label,$languageTag null)
  111.     {
  112.         $resLiteral new ResLiteral($label,$languageTag);
  113.         $resLiteral->setAssociatedModel($this);
  114.         
  115.         return $resLiteral;
  116.     }
  117.     
  118.     /**
  119.     * General method to search for triples.
  120.     * NULL input for any parameter will match anything.
  121.     * Example:  $result = $m->find( NULL, NULL, $node );
  122.     * Finds all Statements with $node as object.
  123.     * Returns an array of statements with ResResources.
  124.     *
  125.     * @param    object ResResource    $subject 
  126.     * @param    object ResResource    $predicate 
  127.     * @param    object ResResource    $object 
  128.     * @return    array 
  129.     * @access    public
  130.     * @throws    PhpError
  131.     */
  132.     function find($subject,$predicate$object)
  133.     {
  134.         $result=array();
  135.         //convert ResResources to Resources and Blanknodes
  136.         $resmodel=$this->model->find(    $this->_resNode2Node($subject),
  137.                                         $this->_resNode2Node($predicate),
  138.                                         $this->_resNode2Node($object)
  139.                                      );
  140.         //convert Resources, Blanknodes to ResResources                             
  141.         foreach ($resmodel->triples as $statement
  142.         {
  143.             $result[]=new Statement($this->_node2ResNode($statement->getSubject()),
  144.                                     $this->_node2ResNode($statement->getPredicate(),true),
  145.                                     $this->_node2ResNode($statement->getObject())
  146.                                     );
  147.         };
  148.         return $result;
  149.         
  150.     }
  151.     
  152.     /**
  153.     * Searches for triples and returns the first matching statement.
  154.     * NULL input for any parameter will match anything.
  155.     * Example:  $result = $m->findFirstMatchingStatement( NULL, NULL, $node );
  156.     * Returns the first statement with ResResources of the Model where the object equals $node.
  157.     * Returns an NULL if nothing is found.
  158.     * You can define an offset to search.
  159.     *
  160.     * @param    object Node    $subject 
  161.     * @param    object Node    $predicate 
  162.     * @param    object Node    $object 
  163.     * @param    integer $offset 
  164.     * @return    object Statement 
  165.     * @access    public
  166.     */
  167.     function findFirstMatchingStatement($subject,$predicate,$object,$offset 0)
  168.     {
  169.     
  170.         $statement $this->model->findFirstMatchingStatement(    $this->_resNode2Node($subject),
  171.                                                                 $this->_resNode2Node($predicate),
  172.                                                                 $this->_resNode2Node($object),
  173.                                                                 $offset
  174.                                                               );
  175.         if ($statement!==null)
  176.         {                                            
  177.             return new Statement(    $this->_node2ResNode($statement->getSubject()),
  178.                                     $this->_node2ResNode($statement->getPredicate(),true),
  179.                                     $this->_node2ResNode($statement->getObject())
  180.                                 );
  181.         else 
  182.         {
  183.             return null;
  184.         }
  185.     }
  186.     
  187.     /**
  188.     * Adds a new triple to the Model without checking if the statement is already in the Model.
  189.     * So if you want a duplicate free Model use the addWithoutDuplicates() function (which is slower then add())
  190.     * Expects a statements with ResResources(ResLiterals)
  191.     *
  192.     * @param    object Statement    $statement 
  193.     * @access    public
  194.     * @throws    PhpError
  195.     */
  196.     function add($statement)
  197.     {
  198.         return $this->model->add(new Statement(    $this->_resNode2Node($statement->getSubject()),
  199.                                                 $this->_resNode2Node($statement->getPredicate()),
  200.                                                 $this->_resNode2Node($statement->getObject()))
  201.                                                );        
  202.     }
  203.     /**
  204.     * Checks if a new statement is already in the Model and adds the statement, if it is not in the Model.
  205.     * addWithoutDuplicates() is significantly slower then add().
  206.     * Retruns TRUE if the statement is added.
  207.     * FALSE otherwise.
  208.     * Expects a statements with ResResources(ResLiterals)
  209.     *
  210.     * @param    object Statement    $statement 
  211.     * @return   boolean 
  212.     * @access    public
  213.     * @throws    PhpError
  214.     */
  215.     function addWithoutDuplicates($statement)
  216.     {
  217.         return $this->model->addWithoutDuplicates(new Statement($this->_resNode2Node($statement->getSubject()),
  218.                                                                 $this->_resNode2Node($statement->getPredicate()),
  219.                                                                 $this->_resNode2Node($statement->getObject()))
  220.                                                                 );    
  221.     }
  222.     
  223.     /**
  224.     * Tests if the Model contains the given statement.
  225.     * TRUE if the statement belongs to the model;
  226.     * FALSE otherwise.
  227.     * Expects a statement of ResResources(ResLiterals)
  228.     *
  229.     * @param    object Statement    $statement 
  230.     * @return    boolean 
  231.     * @access    public
  232.     */
  233.     function contains($statement)
  234.     {
  235.         
  236.         return $this->model->contains(new Statement($this->_resNode2Node($statement->getSubject()),
  237.                                                     $this->_resNode2Node($statement->getPredicate()),
  238.                                                     $this->_resNode2Node($statement->getObject()))
  239.                                                     );
  240.     }
  241.     
  242.     /**
  243.     * Determine if all of the statements in a model are also contained in this model.
  244.     * True if all of the statements in $model are also contained in this model and false otherwise.
  245.     *
  246.     * @param    object Model    &$model 
  247.     * @return    boolean 
  248.     * @access    public
  249.     */
  250.     function containsAll($model)
  251.     {
  252.         if (is_a($model,'ResModel'))
  253.             return $this->model->containsAll($model->getModel());
  254.         
  255.         return $this->model->containsAll($model);
  256.     }
  257.     
  258.     /**
  259.     * Determine if any of the statements in a model are also contained in this model.
  260.     * True if any of the statements in $model are also contained in this model and false otherwise.
  261.     *
  262.     * @param    object Model    &$model 
  263.     * @return    boolean 
  264.     * @access    public
  265.     */    
  266.     function containsAny($model)
  267.     {
  268.         if (is_a($model,'ResModel'))
  269.             return $this->model->containsAny($model->getModel());
  270.         return $this->model->containsAny($model);
  271.     }
  272.     
  273.     /**
  274.     * Determine if the node (ResResource / ResLiteral) $node appears in any statement of this model.
  275.     *
  276.     * @param    object Node    &$node 
  277.     * @return    boolean 
  278.     * @access    public
  279.     */    
  280.     function containsResource($node)
  281.     {
  282.         if ($this->findFirstMatchingStatement($node,null,null=== null)
  283.             if ($this->findFirstMatchingStatement(null,$node,null=== null)
  284.                 if ($this->findFirstMatchingStatement(null,null,$node=== null)
  285.                     return false;
  286.                     
  287.         return true;
  288.     }
  289.     
  290.     /**
  291.     * Create a literal from a String value with the $dtype Datatype
  292.     * An existing literal of the right value may be returned, or a fresh one created.
  293.     *
  294.     * @param    string    $value 
  295.     * @param    string     $dtype 
  296.     * @return     object ResLiteral 
  297.     * @access    public
  298.     */
  299.     function createTypedLiteral($value,$dtype)
  300.     {
  301.         $resLiteral new ResLiteral($value);
  302.         $resLiteral->setDatatype($dtype);
  303.         $resLiteral->setAssociatedModel($this);
  304.         
  305.         return $resLiteral;
  306.     }
  307.     
  308.     /**
  309.     * Checks if two models are equal.
  310.     * Two models are equal if and only if the two RDF graphs they represent are isomorphic.
  311.     * 
  312.     * Warning: This method doesn't work correct with models where the same blank node has different
  313.     * identifiers in the two models. We will correct this in a future version.
  314.     *
  315.     * @access    public
  316.     * @param    object    model &$that 
  317.     * @throws    phpErrpr
  318.     * @return    boolean 
  319.     */        
  320.     function equals($that)
  321.     {
  322.         if (is_a($that,'ResModel'))
  323.             return $this->model->equals($that->getModel());
  324.         return $this->model->equals($that);    
  325.     }
  326.     
  327.     /** 
  328.     * Returns a new model that is the subtraction of another model from this model.
  329.     *
  330.     * @param    object Model $model 
  331.     * @return    object MemModel 
  332.     * @access    public
  333.     * @throws phpErrpr
  334.     */ 
  335.     function subtract($model)
  336.     {
  337.         if (is_a($model,'ResModel'))
  338.             return $this->model->subtract($model->getModel());
  339.         return $this->model->subtract($model);
  340.     }
  341.     
  342.     /** 
  343.     * Answer a statement find(s, p, null) with ResResources(ResLiterals) from this model.
  344.     * If none exist, return null; if several exist, pick one arbitrarily.
  345.     *
  346.     * @param    object ResResource $subject 
  347.     * @param    object ResResource $property 
  348.     * @return    object Statement 
  349.     * @access    public
  350.     * @throws phpErrpr
  351.     */ 
  352.     function getProperty($subject,$property)
  353.     {
  354.     
  355.         $statement$this->model->findFirstMatchingStatement(    $this->_resNode2Node($subject),
  356.                                                                 $this->_resNode2Node($property),
  357.                                                                 null
  358.                                                             );
  359.         if ($statement === null)
  360.             return null;
  361.                                                                 
  362.         return new Statement($this->_node2ResNode($statement->getSubject()),
  363.                                     $this->_node2ResNode($statement->getPredicate(),true),
  364.                                     $this->_node2ResNode($statement->getObject())
  365.                             );
  366.                                                     
  367.     }
  368.     
  369.     /**
  370.     * Checks if MemModel is empty
  371.     *
  372.     * @return    boolean 
  373.     * @access    public
  374.     */
  375.     function isEmpty()
  376.     {
  377.         return $this->model->isEmpty();
  378.     }
  379.     
  380.     /** 
  381.     * Returns a ResIterator with all objects in a model.
  382.     *
  383.     * @return    object ResIterator 
  384.     * @access    public
  385.     * @throws phpErrpr
  386.     */
  387.     function listObjects()
  388.     {
  389.         return $this->listObjectsOfProperty(null);
  390.     }
  391.     
  392.     /** 
  393.     * Returns a ResIterator with all objects with a given property and property value.
  394.     *
  395.     * @param    object ResResource    $property 
  396.     * @param    object ResResource    $value 
  397.     * @return    object ResIterator 
  398.     * @access    public
  399.     */
  400.     function listObjectsOfProperty($property$value null)
  401.     {
  402.         return new ResIterator(null,$property,$value,'o',$this);
  403.     }
  404.  
  405.     
  406.     /** 
  407.     * Returns a ResIterator with all subjects in a model.
  408.     *
  409.     * @return    object ResIterator 
  410.     * @access    public
  411.     * @throws phpErrpr
  412.     */
  413.     function listSubjects()
  414.     {
  415.         return $this->listSubjectsWithProperty(null);
  416.     }
  417.     
  418.     /** 
  419.     * Returns a ResIterator with all subjects with a given property and property value.
  420.     *
  421.     * @param    object ResResource    $property 
  422.     * @param    object ResResource    $value 
  423.     * @return    object ResIterator 
  424.     * @access    public
  425.     * @throws phpErrpr
  426.     */
  427.     function listSubjectsWithProperty($property,$value null)
  428.     {
  429.         return new ResIterator(null,$property,$value,'s',$this);
  430.     }
  431.     
  432.     /**
  433.     * Removes the statement of ResResources(ResTriples) from the MemModel.
  434.     * TRUE if the statement is removed.
  435.     * FALSE otherwise.
  436.     *
  437.     * @param    object Statement    $statement 
  438.     * @return   boolean 
  439.     * @access    public
  440.     * @throws    PhpError
  441.     */    
  442.     function remove($statement)
  443.     {
  444.         return $this->model->remove(new Statement(    $this->_resNode2Node($statement->getSubject()),
  445.                                                     $this->_resNode2Node($statement->getPredicate()),
  446.                                                     $this->_resNode2Node($statement->getObject())
  447.                                                   ));
  448.     }
  449.     
  450.     /**
  451.     * Number of statements in the MemModel
  452.     *
  453.     * @return    integer 
  454.     * @access    public
  455.     */
  456.     function size()
  457.     {
  458.         return $this->model->size();
  459.     }
  460.     
  461.     /** 
  462.     * Returns a new Model that is the set-union of the model with another model.
  463.     * Duplicate statements are removed. If you want to allow duplicates, use addModel() which is much faster.
  464.     *
  465.     * The result of taking the set-union of two or more RDF graphs (i.e. sets of triples)
  466.     * is another graph, which we will call the merge of the graphs.
  467.     * Each of the original graphs is a subgraph of the merged graph. Notice that when forming
  468.     * a merged graph, two occurrences of a given uriref or literal as nodes in two different
  469.     * graphs become a single node in the union graph (since by definition they are the same
  470.     * uriref or literal) but blank nodes are not 'merged' in this way; and arcs are of course
  471.     * never merged. In particular, this means that every blank node in a merged graph can be
  472.     * identified as coming from one particular graph in the original set of graphs.
  473.     * 
  474.     * Notice that one does not, in general, obtain the merge of a set of graphs by concatenating
  475.     * their corresponding N-triples documents and constructing the graph described by the merged
  476.     * document, since if some of the documents use the same node identifiers, the merged document
  477.     * will describe a graph in which some of the blank nodes have been 'accidentally' merged.
  478.     * To merge Ntriples documents it is necessary to check if the same nodeID is used in two or
  479.     * more documents, and to replace it with a distinct nodeID in each of them, before merging the
  480.     * documents. (Not implemented yet !!!!!!!!!!!)
  481.     *
  482.     * @param    object Model    $model 
  483.     * @return    object MemModel 
  484.     * @access    public
  485.     * @throws phpErrpr
  486.     *
  487.     */
  488.     function unite($model)
  489.     {
  490.         if (is_a($model,'ResModel'))
  491.             return $this->model->unite($model->getModel());
  492.         return $this->model->unite($model);
  493.     }
  494.     
  495.     /** 
  496.     * Adds another model to this MemModel.
  497.     * Duplicate statements are not removed.
  498.     * If you don't want duplicates, use unite().
  499.     * If any statement of the model to be added to this model contains a blankNode
  500.     * with an identifier already existing in this model, a new blankNode is generated.
  501.     *
  502.     * @param    object Model    $model 
  503.     * @access    public
  504.     * @throws phpErrpr
  505.     *
  506.     */
  507.     function addModel(&$model)  
  508.     {
  509.         if (is_a($model,'ResModel'))
  510.             return $this->model->addModel($model->getModel());
  511.         return $this->model->addModel($model);
  512.     }
  513.     
  514.     /**
  515.     * Create a new RDF Container from type rdf:Alt
  516.     * This method may return an existing container with the correct URI and model,
  517.     * or it may construct a fresh one, as it sees fit.
  518.     *
  519.     * Subsequent operations on the returned Container may modify this model.
  520.     *  
  521.     *
  522.        * @param    string    $uri 
  523.        * @return    object ResProperty 
  524.        * @access    public
  525.        */
  526.     function createAlt($uri null)
  527.     {
  528.         $resAlt new ResAlt($uri);
  529.         $resAlt->setAssociatedModel($this);
  530.             
  531.         return $resAlt;        
  532.     }
  533.     
  534.     /**
  535.     * Create a new RDF Container from type rdf:Bag
  536.     * This method may return an existing container with the correct URI and model,
  537.     * or it may construct a fresh one, as it sees fit.
  538.     *
  539.     * Subsequent operations on the returned Container may modify this model.
  540.     *  
  541.     *
  542.        * @param    string    $uri 
  543.        * @return    object ResProperty 
  544.        * @access    public
  545.        */
  546.     function createBag($uri null)
  547.     {
  548.         $resBag new ResBag($uri);
  549.         $resBag->setAssociatedModel($this);
  550.             
  551.         return $resBag;
  552.     }
  553.     
  554.     /**
  555.     * Create a new RDF Container from type rdf:Seq
  556.     * This method may return an existing container with the correct URI and model,
  557.     * or it may construct a fresh one, as it sees fit.
  558.     *
  559.     * Subsequent operations on the returned Container may modify this model.
  560.     *  
  561.     *
  562.        * @param    string    $uri 
  563.        * @return    object ResProperty 
  564.        * @access    public
  565.        */
  566.     function createSeq($uri null)
  567.     {
  568.         $resSeq new ResSeq($uri);
  569.         $resSeq->setAssociatedModel($this);
  570.             
  571.         return $resSeq;
  572.     }    
  573.     
  574.     /**
  575.     * Create a new RDF Collection from type rdf:List
  576.     * This method may return an existing container with the correct URI and model,
  577.     * or it may construct a fresh one, as it sees fit.
  578.     *
  579.     * Subsequent operations on the returned Container may modify this model.
  580.     *  
  581.     *
  582.        * @param    string    $uri 
  583.        * @return    object ResProperty 
  584.        * @access    public
  585.        */
  586.     function createList($uri null)
  587.     {
  588.         $resList new ResList($uri);
  589.         $resList->setAssociatedModel($this);
  590.             
  591.         return $resList;    
  592.     }
  593.     
  594.     /**
  595.     * Returns a reference to the underlying model (Mem/DB/InfModel) that contains the statements
  596.     *  
  597.     *
  598.        * @return    object Model 
  599.        * @access    public
  600.        */    
  601.     function getModel()
  602.     {
  603.         return  $this->model;
  604.     }
  605.     
  606.     
  607.     /**
  608.     * Internal method, that returns a resource URI that is unique for the Model.
  609.     * URIs are generated using the base_uri of the Model, the prefix and a unique number.
  610.     * If no prefix is defined, the bNode prefix, defined in constants.php, is used.
  611.     *
  612.     * @param    string    $prefix 
  613.     * @return    string 
  614.     * @access    private
  615.     */
  616.     function getUniqueResourceURI($bnodePrefix)
  617.     {
  618.         return $this->model->getUniqueResourceURI($bnodePrefix);
  619.     }
  620.     
  621.     /**
  622.     * Load a model from a file containing RDF, N3 or N-Triples.
  623.     * This function recognizes the suffix of the filename (.n3 or .rdf) and
  624.     * calls a suitable parser, if no $type is given as string ("rdf" "n3" "nt");
  625.     * If the model is not empty, the contents of the file is added to this DbModel.
  626.     *
  627.     * @param     string     $filename 
  628.     * @param     string     $type 
  629.     * @param   boolean $stream 
  630.     * @access    public
  631.     */
  632.     function load($filename$type NULL$stream=false)
  633.     {
  634.         $this->model->load($filename$type NULL$stream=false);
  635.     }
  636.     
  637.     /**
  638.     * Return current baseURI.
  639.     *
  640.     * @return  string 
  641.     * @access    public
  642.     */
  643.     function getBaseURI()  
  644.     {
  645.         return $this->model->getBaseURI();
  646.     }
  647.  
  648.     /**
  649.     * Saves the RDF,N3 or N-Triple serialization of the MemModel to a file.
  650.     * You can decide to which format the model should be serialized by using a
  651.     * corresponding suffix-string as $type parameter. If no $type parameter
  652.     * is placed this method will serialize the model to XML/RDF format.
  653.     * Returns FALSE if the MemModel couldn't be saved to the file.
  654.     *
  655.     * @access    public
  656.     * @param     string     $filename 
  657.     * @param     string     $type 
  658.     * @throws   PhpError
  659.     * @return    boolean 
  660.     */  
  661.     function saveAs($filename$type ='rdf'
  662.     {
  663.         return $this->model->saveAs($filename$type ='rdf');
  664.     }
  665.     
  666.     /**
  667.     * Writes the RDF serialization of the MemModel as HTML table.
  668.     *
  669.     * @access    public
  670.     */  
  671.     function writeAsHTMLTable()
  672.     {
  673.         $this->model->writeAsHtmlTable();
  674.     }
  675.     
  676.     /** 
  677.     * Returns a new model containing all the statements which are in both this model and another.
  678.     *
  679.     * @param    object Model    $model 
  680.     * @return    object MemModel 
  681.     * @access    public
  682.     * @throws phpErrpr
  683.     */ 
  684.     function intersect($model)
  685.     {
  686.         if (is_a($model,'ResModel'))
  687.             return $this->model->intersect($model->getModel());
  688.         return $this->model->intersect($model);
  689.     }
  690.     
  691.     /** 
  692.     * converts a Resource,Blanknode,Literal into a ResResource, ResProperty, or ResLiteral
  693.     *
  694.     * @param    object Node    $node 
  695.     * @param    boolean        $isProperty 
  696.     * @return    object ResResource / ResProperty / ResLiteral
  697.     * @access    private
  698.     * @throws phpErrpr
  699.     */ 
  700.     function _node2ResNode($node$isProperty false)
  701.     {
  702.         if (is_a($node,'Literal'))
  703.         {
  704.             $returnnew ResLiteral($node->getLabel(),$node->getLanguage());
  705.             $return->setDatatype($node->getDatatype());
  706.             $return->setAssociatedModel($this);
  707.  
  708.             return $return;
  709.         }
  710.         if (is_a($node,'Resource'))
  711.         {
  712.             if ($isProperty)
  713.             {
  714.                 $resnew ResProperty($node->getLabel());
  715.             else 
  716.             {
  717.                 $resnew ResResource($node->getLabel());
  718.             }
  719.             $res->setAssociatedModel($this);
  720.             if (is_a($node,'Blanknode'))
  721.                 $res->setIsAnon(true);    
  722.         
  723.             return $res;
  724.         }
  725.     }
  726.     
  727.     /** 
  728.     * converts a ResResource, ResProperty, or ResLiteral into a Resource, Blanknode, or Literal
  729.     *
  730.     * @param    object ResNode    $resNode 
  731.     * @return    object Node 
  732.     * @access    private
  733.     * @throws phpErrpr
  734.     */ 
  735.     function _resNode2Node($resNode)
  736.     {
  737.         if (is_a($resNode,'ResResource'))
  738.         {
  739.             if ($resNode->getIsAnon())    
  740.             {
  741.                 $return=new BlankNode($resNode->getURI());
  742.             else 
  743.             {
  744.                 $return=new Resource($resNode->getURI());    
  745.             }    
  746.         return $return;    
  747.         }
  748.         
  749.         if (is_a($resNode,'ResLiteral'))
  750.         {
  751.             $literal=new Literal($resNode->getLabel(),$resNode->getLanguage());
  752.             if ($resNode->getDatatype(!= null)
  753.                 $literal->setDatatype($resNode->getDatatype());
  754.             return $literal;
  755.         }
  756.     }
  757.     
  758.     /**
  759.     * Set a base URI for the MemModel.
  760.     * Affects creating of new resources and serialization syntax.
  761.     * If the URI doesn't end with # : or /, then a # is added to the URI.
  762.     * @param    string    $uri 
  763.     * @access    public
  764.     */
  765.     function setBaseURI($uri
  766.     {
  767.         $this->model->setBaseURI($uri);
  768.     }
  769.     
  770.     /**
  771.     * Writes the RDF serialization of the MemModel as HTML table.
  772.     *
  773.     * @access    public
  774.     * @return    string 
  775.     */  
  776.     function writeRdfToString(
  777.     {
  778.         return $this->model->writeRdfToString();    
  779.     }
  780.     
  781.     /**
  782.     * Perform an RDQL query on this MemModel.
  783.     * This method returns an associative array of variable bindings.
  784.     * The values of the query variables can either be RAP's objects (instances of Node)
  785.     * if $returnNodes set to TRUE, or their string serialization.
  786.     *
  787.     * @access    public
  788.     * @param string $queryString 
  789.     * @param boolean $returnNodes 
  790.     * @return  array   [][?VARNAME] = object Node  (if $returnNodes = TRUE)
  791.     *       OR  array   [][?VARNAME] = string
  792.     *
  793.     */
  794.     function rdqlQuery($queryString$returnNodes TRUE
  795.     {
  796.         return $this->model->rdqlQuery($queryString$returnNodes);
  797.     }
  798.     
  799.     /**
  800.     * Perform an RDQL query on this MemModel.
  801.     * This method returns an RdqlResultIterator of variable bindings.
  802.     * The values of the query variables can either be RAP's objects (instances of Node)
  803.     * if $returnNodes set to TRUE, or their string serialization.
  804.     *
  805.     * @access    public
  806.     * @param string $queryString 
  807.     * @param boolean $returnNodes 
  808.     * @return  object RdqlResultIterator = with values as object Node  (if $returnNodes = TRUE)
  809.     *       OR  object RdqlResultIterator = with values as strings if (if $returnNodes = FALSE)
  810.     *
  811.     */
  812.     function rdqlQueryAsIterator($queryString$returnNodes TRUE
  813.     {
  814.         return $this->model->rdqlQueryAsIterator($queryString$returnNodes);
  815.     }
  816.     
  817.     
  818.     /**
  819.     * Returns the models namespaces.
  820.     *
  821.     * @author   Tobias Gauß <tobias.gauss@web.de>
  822.     * @access   public
  823.     * @return   Array 
  824.     */
  825.     function getParsedNamespaces(){
  826.         return $this->model->getParsedNamespaces();
  827.     }
  828.  
  829.  
  830.  
  831.     /**
  832.     * Adds the namespaces to the model. This method is called by
  833.     * the parser. !!!! addParsedNamespaces() not overwrites manual
  834.     * added namespaces in the model !!!!
  835.     *
  836.     * @author   Tobias Gauß <tobias.gauss@web.de>
  837.     * @access   public
  838.     * @param    Array $newNs 
  839.     */
  840.     function addParsedNamespaces($newNs){
  841.         $this->model->addParsedNamespaces($newNs);
  842.     }
  843.  
  844.  
  845.     /**
  846.     * Adds a namespace and prefix to the model.
  847.     *
  848.     * @author   Tobias Gauß <tobias.gauss@web.de>
  849.     * @access   public
  850.     * @param    String $prefix, String $nmsp
  851.     */
  852.     function addNamespace($prefix$namespace){
  853.         $this->model->addNamespace($prefix$namespace);
  854.     }
  855.     
  856.     /**
  857.     * removes a single namespace from the model
  858.     *
  859.     * @author   Tobias Gauß <tobias.gauss@web.de>
  860.     * @access   public
  861.     * @param    String $nmsp 
  862.     */
  863.     function removeNamespace($nmsp){
  864.         return $this->model->removeNamespace($nmsp);
  865.     }
  866.  
  867.     
  868.     
  869.     
  870.     
  871.     
  872. }

Documentation generated on Fri, 1 Jun 2007 16:51:35 +0200 by phpDocumentor 1.3.2