Source for file ModelFactory.php

Documentation is available at ModelFactory.php

  1. <?php 
  2.  
  3. // ----------------------------------------------------------------------------------
  4. // Class: ModelFactory
  5. // ----------------------------------------------------------------------------------
  6.  
  7.  
  8. /**
  9. * ModelFactory is a static class which provides methods for creating different
  10. * types of RAP models. RAP models have to be created trough a ModelFactory
  11. * instead of creating them directly with the 'new' operator because of RAP's
  12. * dynamic code inclusion mechanism.
  13. *
  14. @version  $Id: fsource_model__modelModelFactory.php.html,v 1.10 2006/06/26 12:34:12 tgauss Exp $
  15. @author Daniel Westphal <mail at d-westphal.de>
  16. @author Richard Cyganiak <richard@cyganiak.de>
  17. *
  18. *
  19. @package     model
  20. @access    public
  21. ***/
  22. {
  23.     /** 
  24.     * Returns a MemModel.
  25.     * You can supply a base URI
  26.     *
  27.     * @param   string  $baseURI 
  28.     * @return    object    MemModel 
  29.     * @access    public
  30.     */
  31.     function getDefaultModel($baseURI null)
  32.     {
  33.         return ModelFactory::getMemModel($baseURI);
  34.     }
  35.     
  36.     /** 
  37.     * Returns a NamedGraphSetMem.
  38.     * You can supply a GraphSet name.
  39.     *
  40.     * @param string $graphSetId 
  41.     * @param string $uri 
  42.     * @access    public
  43.     */
  44.     function getDatasetMem($graphSetId null)
  45.     {
  46.         include_once(RDFAPI_INCLUDE_DIR PACKAGE_DATASET);
  47.         return new DatasetMem($graphSetId);
  48.     }
  49.     
  50.     /** 
  51.     * Returns a MemModel.
  52.     * You can supply a base URI
  53.     *
  54.     * @param   string  $baseURI 
  55.     * @return    object    MemModel 
  56.     * @access    public
  57.     */
  58.     function getMemModel($baseURI null)
  59.     {
  60.         return new MemModel($baseURI);
  61.     }
  62.     
  63.     /**
  64.     * Returns a DbModel with the database connection
  65.     * defined in constants.php.
  66.     * You can supply a base URI. If a model with the given base
  67.     * URI exists in the DbStore, it'll be opened.
  68.     * If not, a new model will be created.
  69.     *
  70.     * @param   string  $baseURI 
  71.     * @return    object    DbModel 
  72.     * @access    public
  73.     */
  74.     function getDefaultDbModel($baseURI null)
  75.     {
  76.         $dbStore ModelFactory::getDbStore();
  77.         return ModelFactory::getDbModel($dbStore,$baseURI);
  78.     }
  79.     
  80.     /** 
  81.     * Returns a new DbModel using the database connection
  82.     * supplied by $dbStore.
  83.     * You can supply a base URI. If a model with the given base
  84.     * URI exists in the DbStore, it'll be opened.
  85.     * If not, a new model will be created.
  86.     *
  87.     * @param   object    DbStore  $dbStore 
  88.     * @param   string  $baseURI 
  89.     * @return    object    DbModel 
  90.     * @access    public
  91.     */
  92.     function getDbModel($dbStore$baseURI null)
  93.     {
  94.         if ($dbStore->modelExists($baseURI))
  95.             return $dbStore->getModel($baseURI);
  96.         
  97.         return $dbStore->getNewModel($baseURI);
  98.     }
  99.     
  100.     /** 
  101.     * Returns a database connection with the given parameters.
  102.     * Paramters, which are not defined are taken from the constants.php
  103.     *
  104.     * @param   string   $dbDriver 
  105.     * @param   string   $host 
  106.     * @param   string   $dbName 
  107.     * @param   string   $user 
  108.     * @param   string   $password 
  109.     * @return    object    DbStore 
  110.     * @access    public
  111.     */
  112.     function getDbStore($dbDriver=ADODB_DB_DRIVER$host=ADODB_DB_HOST$dbName=ADODB_DB_NAME,
  113.                            $user=ADODB_DB_USER$password=ADODB_DB_PASSWORD)
  114.     {
  115.         return new DbStore($dbDriver$host$dbName,$user$password);
  116.     }
  117.     
  118.     /** 
  119.     * Returns a InfModelF.
  120.     * (MemModel with forward chaining inference engine)
  121.     * Configurations can be done in constants.php
  122.     * You can supply a base URI
  123.     *
  124.     * @param   string  $baseURI 
  125.     * @return    object    MemModel 
  126.     * @access    public
  127.     */
  128.     function getInfModelF($baseURI null)
  129.     {
  130.         require_onceRDFAPI_INCLUDE_DIR PACKAGE_INFMODEL);
  131.         return new InfModelF($baseURI);
  132.     }
  133.     
  134.     /** 
  135.     * Returns a InfModelB.
  136.     * (MemModel with backward chaining inference engine)
  137.     * Configurations can be done in constants.php
  138.     * You can supply a base URI
  139.     *
  140.     * @param   string  $baseURI 
  141.     * @return    object    MemModel 
  142.     * @access    public
  143.     */
  144.     function getInfModelB($baseURI null)
  145.     {
  146.         require_onceRDFAPI_INCLUDE_DIR PACKAGE_INFMODEL);
  147.         return new InfModelB($baseURI);
  148.     }
  149.     
  150.     /** 
  151.     * Returns a ResModel.
  152.     * $modelType has to be one of the following constants:
  153.     * MEMMODEL,DBMODEL,INFMODELF,INFMODELB to create a resmodel with a new
  154.     * model from defined type.
  155.     * You can supply a base URI
  156.     *
  157.     * @param   constant  $modelType 
  158.     * @param   string  $baseURI 
  159.     * @return    object    ResModel 
  160.     * @access    public
  161.     */
  162.     function getResModel($modelType$baseURI null)
  163.     {
  164.         switch ($modelType{
  165.             case DBMODEL:
  166.                 $baseModel ModelFactory::getDefaultDbModel($baseURI);
  167.                 break;
  168.                 
  169.             case INFMODELF:
  170.                 $baseModel ModelFactory::getInfModelF($baseURI);
  171.                 break;
  172.                 
  173.             case INFMODELB:
  174.                 $baseModel ModelFactory::getInfModelB($baseURI);
  175.                 break;                
  176.                 
  177.             default:
  178.                 $baseModel ModelFactory::getMemModel($baseURI);
  179.                 break;
  180.         }
  181.         return ModelFactory::getResModelForBaseModel($baseModel);
  182.     }
  183.     
  184.     /** 
  185.     * Creates a ResModel that wraps an existing base model.
  186.     *
  187.     * @param       object  Model    $baseModel 
  188.     * @return    object    ResModel 
  189.     * @access    public
  190.     */
  191.     function &getResModelForBaseModel(&$baseModel{
  192.         require_onceRDFAPI_INCLUDE_DIR PACKAGE_RESMODEL);
  193.         return new ResModel($baseModel);
  194.     }
  195.  
  196.     /** 
  197.     * Returns an OntModel.
  198.     * $modelType has to be one of the following constants:
  199.     * MEMMODEL, DBMODEL, INFMODELF, INFMODELB to create a OntModel
  200.     * with a new model from defined type.
  201.     * $vocabulary defines the ontology language. Currently only
  202.     * RDFS_VOCABULARY is supported. You can supply a model base URI.
  203.     *
  204.     * @param       constant      $modelType 
  205.     * @param       constant      $vocabulary 
  206.     * @param       string      $baseURI 
  207.     * @return    object        OntModel 
  208.     * @access    public
  209.     */
  210.     function getOntModel($modelType,$vocabulary$baseURI null)
  211.     {
  212.         switch ($modelType
  213.         {
  214.             case DBMODEL:
  215.                 $baseModel ModelFactory::getDefaultDbModel($baseURI);
  216.                 break;
  217.                 
  218.             case INFMODELF:
  219.                 $baseModel ModelFactory::getInfModelF($baseURI);
  220.                 break;
  221.                 
  222.             case INFMODELB:
  223.                 $baseModel ModelFactory::getInfModelB($baseURI);
  224.                 break;                
  225.                 
  226.             default:
  227.                 $baseModel ModelFactory::getMemModel($baseURI);;
  228.         }
  229.         
  230.         return ModelFactory::getOntModelForBaseModel($baseModel$vocabulary);
  231.     }
  232.  
  233.     /** 
  234.     * Creates an OntModel that wraps an existing base model.
  235.     * $vocabulary defines the ontology language. Currently only
  236.     * RDFS_VOCABULARY is supported.
  237.     *
  238.     * @param       object  Model    $baseModel 
  239.     * @param       constant      $vocabulary 
  240.     * @return    object        OntModel 
  241.     * @access    public
  242.     */
  243.     function &getOntModelForBaseModel(&$baseModel$vocabulary)
  244.     {
  245.         require_onceRDFAPI_INCLUDE_DIR PACKAGE_ONTMODEL);
  246.         
  247.         switch ($vocabulary
  248.         {
  249.             case RDFS_VOCABULARY:
  250.                 require_once(RDFAPI_INCLUDE_DIR.'ontModel/'.RDFS_VOCABULARY);
  251.                 $vocab_object new RdfsVocabulary();
  252.                 break;            
  253.             default:
  254.                 trigger_error("Unknown vocabulary constant '$vocabulary'; only RDFS_VOCABULARY is supported"E_USER_WARNING);
  255.                 $vocab_object null;
  256.                 break;
  257.         }
  258.         return new OntModel($baseModel$vocab_object);
  259.     }
  260.     
  261.     
  262.     
  263.     /** 
  264.     * Creates a SparqlClient.
  265.     *
  266.     * @param       String  $server    Link to a SPARQL endpoint.
  267.     * @return    SparqlClient the SparqlClient object.
  268.     * @access    public
  269.     */
  270.     function getSparqlClient($server){
  271.         return new SparqlClient($server);
  272.     }
  273. }  
  274. ?>

Documentation generated on Mon, 26 Jun 2006 14:25:39 +0200 by phpDocumentor 1.3.0RC6