Source for file ModelFactory.php

Documentation is available at ModelFactory.php

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

Documentation generated on Fri, 1 Jun 2007 16:49:54 +0200 by phpDocumentor 1.3.2