Esempio n. 1
0
 /**
  * fetches all titles according the given array if Uris
  *
  * @param array resourceUris
  */
 private function _fetchTitlesFromResourcePool($resourceUris)
 {
     $resourcePool = $this->_erfurtApp->getResourcePool();
     $resources = array();
     if (!empty($this->_model)) {
         $modelUri = $this->_model->getModelIri();
         $resources = $resourcePool->getResources($resourceUris, $modelUri);
     } else {
         $resources = $resourcePool->getResources($resourceUris);
     }
     $memoryModel = new Erfurt_Rdf_MemoryModel();
     foreach ($resources as $resourceUri => $resource) {
         $resourceDescription = $resource->getDescription();
         $memoryModel->addStatements($resourceDescription);
         $found = false;
         foreach ($this->_titleProperties as $titleProperty) {
             $values = $memoryModel->getValues($resourceUri, $titleProperty);
             foreach ($values as $value) {
                 if (!empty($value['lang'])) {
                     $language = $value['lang'];
                 } else {
                     $language = '';
                 }
                 $this->_resources[$resourceUri][$titleProperty][$language] = $value['value'];
             }
         }
     }
 }
 /**
  * Method that counts already existing distinct datasets for given uri
  *
  * @param $uri uri string
  *
  * @return int distinct existing datasets
  */
 private function countUriPattern($uri)
 {
     $query = new Erfurt_Sparql_Query2();
     $query->setDistinct(true);
     $unions = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
     $subjectVar = new Erfurt_Sparql_Query2_Var('s');
     $query->addProjectionVar($subjectVar);
     // create six temporary vars (not selected in query)
     $tempVars = array();
     for ($i = 0; $i < 6; $i++) {
         $tempVars[] = new Erfurt_Sparql_Query2_Var('var' . $i);
     }
     $singlePattern = new Erfurt_Sparql_Query2_GroupGraphPattern();
     $singlePattern->addTriple($subjectVar, $tempVars[0], $tempVars[1]);
     $unions->addElement($singlePattern);
     $singlePattern = new Erfurt_Sparql_Query2_GroupGraphPattern();
     $singlePattern->addTriple($tempVars[2], $subjectVar, $tempVars[3]);
     $unions->addElement($singlePattern);
     $singlePattern = new Erfurt_Sparql_Query2_GroupGraphPattern();
     $singlePattern->addTriple($tempVars[4], $tempVars[5], $subjectVar);
     $unions->addElement($singlePattern);
     $query->getWhere()->addElement($unions);
     $filter = new Erfurt_Sparql_Query2_ConditionalOrExpression();
     $filter->addElement(new Erfurt_Sparql_Query2_Regex($subjectVar, new Erfurt_Sparql_Query2_RDFLiteral('^' . $uri), new Erfurt_Sparql_Query2_RDFLiteral('i')));
     $query->addFilter($filter);
     $result = $this->_owApp->erfurt->getStore()->countWhereMatches($this->_model->getModelIri(), $query->getWhere(), 's', true);
     return $result;
 }
Esempio n. 3
0
 /**
  * Constructor
  */
 public function __construct(Erfurt_Store $store, Erfurt_Rdf_Model $graph)
 {
     // system variables
     $this->_store = $store;
     $this->_config = OntoWiki::getInstance()->config;
     $this->_logger = OntoWiki::getInstance()->logger;
     $this->_eventDispatcher = Erfurt_Event_Dispatcher::getInstance();
     if (isset($this->_config->system->inference) && !(bool) $this->_config->system->inference) {
         $this->_inference = false;
     }
     // data variables
     $this->_graph = $graph->getModelIri();
     $this->_model = $graph;
     $this->_titleHelper = new OntoWiki_Model_TitleHelper($this->_model, $store);
     // $this->_titleProperties = array_flip($this->_config->properties->title->toArray());
     $this->_titleProperties = array_flip($graph->getTitleProperties());
 }
Esempio n. 4
0
 protected function _fetchDescription($maxDepth)
 {
     $query = new Erfurt_Sparql_SimpleQuery();
     $query->setProloguePart('SELECT ?p ?o')->setWherePart(sprintf('{<%s> ?p ?o . }', $this->getIri()));
     $description = array();
     $result = null;
     if ($this->_model) {
         $result = $this->_model->sparqlQuery($query, array('result_format' => 'extended'));
     } else {
         $result = Erfurt_App::getInstance()->getStore()->sparqlQuery($query, array('result_format' => 'extended'));
     }
     if ($maxDepth > 0 && $result) {
         foreach ($result['results']['bindings'] as $row) {
             $property = $row['p']['value'];
             $this->_descriptionResource($property);
             $currentValue = array('type' => $row['o']['type'], 'value' => $row['o']['value']);
             if ($row['o']['type'] == 'uri') {
                 $this->_descriptionResource($row['o']['value']);
             } else {
                 if ($row['o']['type'] == 'typed-literal') {
                     $currentValue['type'] = 'literal';
                     $currentValue['datatype'] = $row['o']['datatype'];
                 } else {
                     if (isset($row['o']['xml:lang'])) {
                         $currentValue['lang'] = $row['o']['xml:lang'];
                     }
                 }
             }
             if (!array_key_exists($property, $description)) {
                 $description[$property] = array();
             }
             array_push($description[$property], $currentValue);
             if ($row['o']['type'] === 'bnode') {
                 $nodeId = $row['o']['value'];
                 $bNode = self::initWithBlankNode($nodeId, $this->_model);
                 $nodeKey = sprintf('_:%s', $nodeId);
                 $description[$nodeKey] = $bNode->getDescription($maxDepth - 1);
             }
         }
     }
     return array($this->getIri() => $description);
 }
Esempio n. 5
0
 /**
  * Transform a given string to full URI using the models namespaces if it 
  * is a qname or check the uri if it is not a qname
  *
  * @param $qname the input qname or uri candidate
  * @param $model the Erfurt model which is used to check for namespaces
  */
 public static function getFromQnameOrUri($qnameOrUri, Erfurt_Rdf_Model $model)
 {
     // test for qname
     if (preg_match(self::$_regExpQname, (string) $qnameOrUri) == 0) {
         // input is not a qname so test for Uri-ness and return uri
         if (!self::check($qnameOrUri)) {
             throw new Erfurt_Uri_Exception('The supplied string is neither a valid Qname nor Uri by syntax.');
         } else {
             // return checked Uri
             return $qnameOrUri;
         }
     } else {
         // input is qname so split it and build Uri from namespace if possible
         $parts = explode(':', $qnameOrUri);
         if (count($parts) > 1) {
             $prefix = $parts[0];
             $localName = $parts[1];
             $namespace = $model->getNamespaceByPrefix($prefix);
         } else {
             // it is a local name only
             $localName = $qnameOrUri;
             $namespace = $model->getBaseIri();
         }
         $uri = $namespace . $localName;
         if (!self::check($uri)) {
             throw new Erfurt_Uri_Exception('The given qname "' . $qnameOrUri . '" results in an invalid Uri "' . $uri . '".');
         } else {
             // return constructed and checked Uri
             return $uri;
         }
     }
 }
Esempio n. 6
0
 public function testGetBaseIriWithEmptyBaseReturnsModelIri()
 {
     $this->markTestNeedsTestConfig();
     $model1 = new Erfurt_Rdf_Model('http://example.org/');
     $model2 = new Erfurt_Rdf_Model('http://example.org/', 'http://example.org/resources/');
     $this->assertSame('http://example.org/', $model1->getBaseIri());
     $this->assertSame('http://example.org/resources/', $model2->getBaseIri());
 }