コード例 #1
0
ファイル: Mssql.php プロジェクト: FTeichmann/Erfurt
 /** @see Erfurt_Store_Adapter_Interface */
 public function countWhereMatches($graphIris, $whereSpec, $countSpec, $distinct = false)
 {
     $query = new Erfurt_Sparql_SimpleQuery();
     if (!$distinct) {
         $query->setProloguePart("COUNT DISTINCT {$countSpec}");
         // old way: distinct has no effect !!!
     } else {
         $query->setProloguePart("COUNT-DISTINCT {$countSpec}");
         // i made a (unccol) hack to fix this, the "-" ist there because i didnt want to change tokenization
     }
     $query->setFrom($graphIris)->setWherePart($whereSpec);
     $result = $this->sparqlQuery($query);
     if ($result) {
         return $result;
     }
     return 0;
 }
コード例 #2
0
ファイル: Store.php プロジェクト: FTeichmann/Erfurt
 /**
  * Get the configuration for a graph.
  * @param string $graphUri to specity the graph
  * @return array
  */
 public function getGraphConfiguration($graphUri)
 {
     if (null === $this->_graphConfigurations) {
         $sysOntModelUri = $this->getOption('modelUri');
         // Fetch the graph configurations
         $queryObject = new Erfurt_Sparql_SimpleQuery();
         $queryObject->setProloguePart('SELECT ?s ?p ?o');
         $queryObject->setFrom(array($sysOntModelUri));
         $queryObject->setWherePart('WHERE { ?s ?p ?o . ?s a <http://ns.ontowiki.net/SysOnt/Model> }');
         $queryoptions = array('use_ac' => false, 'result_format' => Erfurt_Store::RESULTFORMAT_EXTENDED, 'use_additional_imports' => false);
         $stmtArray = array();
         if ($result = $this->sparqlQuery($queryObject, $queryoptions)) {
             $result = $result['results'];
             foreach ($result['bindings'] as $row) {
                 if (!isset($stmtArray[$row['s']['value']])) {
                     $stmtArray[$row['s']['value']] = array();
                 }
                 if (!isset($stmtArray[$row['s']['value']][$row['p']['value']])) {
                     $stmtArray[$row['s']['value']][$row['p']['value']] = array();
                 }
                 if ($row['o']['type'] === 'typed-literal') {
                     $row['o']['type'] = 'literal';
                 }
                 if (isset($row['o']['xml:lang'])) {
                     $row['o']['lang'] = $row['o']['xml:lang'];
                     unset($row['o']['xml:lang']);
                 }
                 $stmtArray[$row['s']['value']][$row['p']['value']][] = $row['o'];
             }
         }
         $this->_graphConfigurations = $stmtArray;
     }
     if (isset($this->_graphConfigurations[$graphUri])) {
         return $this->_graphConfigurations[$graphUri];
     }
     return array();
 }
コード例 #3
0
ファイル: Query.php プロジェクト: eschwert/cubeviz.ontowiki
 /**
  * Get all observations which fits to given DSD, DS and selected compontents.
  * @param $dataSetUrl URL of a data set
  * @param $selectedComponentDimensions
  */
 public function getObservations($dataSetUrl, $selectedComponentDimensions = array())
 {
     // generate unique hash using given result and model uri
     $objectId = md5($this->_model->getModelIri() . $dataSetUrl . json_encode($selectedComponentDimensions));
     // check there is already a cached object for this hash
     $result = $this->_objectCache->load($objectId);
     if (false === $result) {
         $this->_queryCache->startTransaction($objectId);
         /**
          * Fill SimpleQuery object with live!
          */
         $queryObject = new Erfurt_Sparql_SimpleQuery();
         // SELECT
         $queryObject->setProloguePart('SELECT ?s ?p ?o');
         // FROM
         $queryObject->setFrom(array($this->_model->getModelIri()));
         // WHERE
         $where = 'WHERE { ' . "\n" . '
             ?s ?p ?o .' . "\n" . '
             ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <' . DataCube_UriOf::Observation . '> .' . "\n" . '
             ?s <' . DataCube_UriOf::DataSetRelation . '> <' . $dataSetUrl . '> .' . "\n";
         // Set selected properties (e.g. ?s <http://data.lod2.eu/scoreboard/properties/year> ?d0 .)
         $i = 0;
         foreach ($selectedComponentDimensions as $dimension) {
             if (0 < count($dimension['__cv_elements'])) {
                 $where .= ' ?s <' . $dimension[DataCube_UriOf::Dimension] . '> ?d' . $i++ . ' .' . "\n";
             }
         }
         // Set FILTER
         // e.g.: FILTER (?d1 = "2003" OR ?d1 = "2001" OR ?d1 = "2002")
         // e.g. 2: FILTER ( ?d0 = <http://data.lod2.eu/scoreboard/indicators/bb_fcov_RURAL_POP__pop> OR
         //                  ?d0 = <http://data.lod2.eu/scoreboard/indicators/bb_lines_TOTAL_FBB_nbr_lines> )
         $i = 0;
         foreach ($selectedComponentDimensions as $dimension) {
             $dimensionElements = $dimension['__cv_elements'];
             if (0 < count($dimensionElements)) {
                 $filter = array();
                 foreach ($dimensionElements as $elementUri => $element) {
                     // If __cv_uri is set and an URL
                     if (true == Erfurt_Uri::check($element['__cv_uri'])) {
                         $value = '<' . $element['__cv_uri'] . '>';
                         $filter[] = ' ?d' . $i . ' = ' . $value . ' ';
                     } else {
                         $value = '"' . $element['__cv_niceLabel'] . '"';
                         $filter[] = ' xsd:string(?d' . $i . ') = xsd:string(' . $value . ') ';
                     }
                 }
                 $i++;
                 $where .= ' FILTER (' . implode('OR', $filter) . ') ' . "\n";
             }
         }
         $where .= '}';
         $queryObject->setWherePart($where);
         $result = $this->_model->sparqlQuery((string) $queryObject);
         // generate associative array out of given observation result
         $result = $this->generateAssocSPOArrayFromSparqlResult($result, 's', 'p', 'o');
         // limit the number of observations
         $result = array_slice($result, 0, 250);
         // enrich data with CubeViz sugar
         $result = $this->enrichResult($result, false);
         // close the object cache transaction
         $this->_queryCache->endTransaction($objectId);
         // save the result value in the object cache
         $this->_objectCache->save($result, $objectId);
     }
     return $result;
 }