示例#1
0
 public function groupOrUnionGraphPattern()
 {
     $value = null;
     $v1 = null;
     $v2 = null;
     $value = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
     try {
         $this->pushFollow(self::$FOLLOW_groupGraphPattern_in_groupOrUnionGraphPattern935);
         $v1 = $this->groupGraphPattern();
         $this->state->_fsp--;
         $value->addElement($v1);
         // Sparql10.g:161:62: ( UNION v2= groupGraphPattern )*
         //loop33:
         do {
             $alt33 = 2;
             $alt33 = $this->dfa33->predict($this->input);
             switch ($alt33) {
                 case 1:
                     $this->match($this->input, $this->getToken('UNION'), self::$FOLLOW_UNION_in_groupOrUnionGraphPattern941);
                     $this->pushFollow(self::$FOLLOW_groupGraphPattern_in_groupOrUnionGraphPattern945);
                     $v2 = $this->groupGraphPattern();
                     $this->state->_fsp--;
                     $value->addElement($v2);
                     break;
                 default:
                     break 2;
                     //loop33;
             }
         } while (true);
     } catch (RecognitionException $re) {
         $this->reportError($re);
         $this->recover($this->input, $re);
     } catch (Exception $e) {
         throw $e;
     }
     return $value;
 }
示例#2
0
 public function addDisjunctiveTypeFilters(array $types, $id = null, array $options = array())
 {
     if (!$id) {
         $id = 'type' . count($this->_filter);
     } else {
         if (isset($this->_filter[$id])) {
             $this->removeFilter($id);
         }
     }
     // Create UNION of all types
     $union = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
     foreach ($types as $type) {
         $union->addElement(new Erfurt_Sparql_Query2_GroupGraphPattern(new Erfurt_Sparql_Query2_Triple($this->_resourceVar, new Erfurt_Sparql_Query2_IriRef(EF_RDF_TYPE), new Erfurt_Sparql_Query2_IriRef($type))));
     }
     // Add UNION element
     $this->_resourceQuery->addElement($union);
     // Remove default ?s ?p ?o pattern
     $this->_allTriple->remove($this->_resourceQuery);
 }
 public static function getSearchTriples($setup, $forImplicit = false, $backend = 'zenddb')
 {
     $searchVar = new Erfurt_Sparql_Query2_Var('resourceUri');
     $classVar = new Erfurt_Sparql_Query2_Var('classUri');
     $subVar = new Erfurt_Sparql_Query2_Var('subResourceUri');
     $elements = array();
     // if deeper query
     if (isset($setup->state->parent)) {
         $mainUnion = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
         // in relations
         if (isset($setup->config->hierarchyRelations->in)) {
             // default stuff
             if (count($setup->config->hierarchyRelations->in) > 1) {
                 // parse config gile
                 foreach ($setup->config->hierarchyRelations->in as $rel) {
                     // set type
                     $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     // add triplen
                     $ggp->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel), new Erfurt_Sparql_Query2_IriRef($setup->state->parent));
                     // add triplet to union var
                     $mainUnion->addElement($ggp);
                 }
             } else {
                 $rel = $setup->config->hierarchyRelations->in;
                 $queryOptional = new Erfurt_Sparql_Query2_GroupGraphPattern();
                 $queryOptional->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel[0]), new Erfurt_Sparql_Query2_IriRef($setup->state->parent));
                 $mainUnion->addElement($queryOptional);
             }
         }
         // out relations
         if (isset($setup->config->hierarchyRelations->out)) {
             // if there's out relations
             if (count($setup->config->hierarchyRelations->out) > 1) {
                 // parse config gile
                 foreach ($setup->config->hierarchyRelations->out as $rel) {
                     // set type
                     $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     // add triplen
                     $ggp->addTriple(new Erfurt_Sparql_Query2_IriRef($setup->state->parent), new Erfurt_Sparql_Query2_IriRef($rel), $searchVar);
                     // add triplet to union var
                     $mainUnion->addElement($ggp);
                 }
             } else {
                 // get one relation
                 $rel = $setup->config->hierarchyRelations->out;
                 $queryOptional = new Erfurt_Sparql_Query2_GroupGraphPattern();
                 $queryOptional->addTriple(new Erfurt_Sparql_Query2_IriRef($setup->state->parent), new Erfurt_Sparql_Query2_IriRef($rel[0]), $searchVar);
                 $mainUnion->addElement($queryOptional);
             }
         }
         $elements[] = $mainUnion;
     } else {
         // if default request
         if (!$forImplicit) {
             // set hierarchy types
             //$u1 = new Erfurt_Sparql_Query2_GroupGraphPattern();
             // add triplen
             //                $u1->addTriple( $searchVar,
             //                    new Erfurt_Sparql_Query2_IriRef(EF_RDF_TYPE),
             //                    $classVar
             //                );
             $elements[] = new Erfurt_Sparql_Query2_Triple($searchVar, new Erfurt_Sparql_Query2_IriRef(EF_RDF_TYPE), $classVar);
             //$mainUnion = new Erfurt_Sparql_Query2_GroupGraphPattern();//OrUnion
             //$mainUnion->addElement($u1);
             // request sub elements
             // in relations
             $optional = new Erfurt_Sparql_Query2_OptionalGraphPattern();
             $unionSub = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
             if (isset($setup->config->hierarchyRelations->in)) {
                 if (count($setup->config->hierarchyRelations->in) > 1) {
                     // init union var
                     //$unionSub = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
                     // parse config gile
                     foreach ($setup->config->hierarchyRelations->in as $rel) {
                         // sub stuff
                         $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                         // add triplen
                         $ggp->addTriple($subVar, new Erfurt_Sparql_Query2_IriRef($rel), $searchVar);
                         // add triplet to union var
                         $unionSub->addElement($ggp);
                     }
                 } else {
                     $rel = $setup->config->hierarchyRelations->in;
                     // add optional sub relation
                     // create optional graph to load sublacsses of selected class
                     //$queryOptional = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     $optional->addTriple($subVar, new Erfurt_Sparql_Query2_IriRef($rel[0]), $searchVar);
                     //$unionSub->addElement($queryOptional);
                 }
             }
             if (isset($setup->config->hierarchyRelations->out)) {
                 // init union var
                 //$unionSub = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
                 if (count($setup->config->hierarchyRelations->out) > 1) {
                     // parse config gile
                     foreach ($setup->config->hierarchyRelations->out as $rel) {
                         // sub stuff
                         $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                         // add triplen
                         $ggp->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel), $subVar);
                         // add triplet to union var
                         $unionSub->addElement($ggp);
                     }
                 } else {
                     $rel = $setup->config->hierarchyRelations->out;
                     // add optional sub relation
                     // create optional graph to load sublacsses of selected class
                     //$queryOptional = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     $optional->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel[0]), $subVar);
                     //$unionSub->addElement($queryOptional);
                 }
             }
             //$mainUnion->addElement($unionSub);
             if ($unionSub->size() > 0) {
                 $optional->addElement($unionSub);
             }
             $elements[] = $optional;
             // create filter for types
             $filterType = array();
             $filterUris = array();
             foreach ($setup->config->hierarchyTypes as $type) {
                 $uriElem = new Erfurt_Sparql_Query2_IriRef($type);
                 $filterUris[] = $uriElem;
                 $filterType[] = new Erfurt_Sparql_Query2_sameTerm($classVar, $uriElem);
             }
             $owApp = OntoWiki::getInstance();
             $store = $owApp->erfurt->getStore();
             if ($store->isInSyntaxSupported()) {
                 // e.g. Virtuoso
                 $elements[] = new Erfurt_Sparql_Query2_Filter(new Erfurt_Sparql_Query2_InExpression($classVar, $filterUris));
             } else {
                 // sameTerm || sameTerm ... as supported by EfZendDb adapter
                 // add filter
                 $elements[] = new Erfurt_Sparql_Query2_Filter(new Erfurt_Sparql_Query2_ConditionalOrExpression($filterType));
             }
         } else {
             // define subvar
             $subVar = new Erfurt_Sparql_Query2_Var('sub');
             // init union var
             $union = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
             // parse config
             if (isset($setup->config->hierarchyRelations->out)) {
                 if (is_string($setup->config->hierarchyRelations->out)) {
                     $setup->config->hierarchyRelations->out = array($setup->config->hierarchyRelations->out);
                 }
                 foreach ($setup->config->hierarchyRelations->out as $rel) {
                     // create new graph pattern
                     $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     // add triplen
                     $ggp->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel), $subVar);
                     // add triplet to union var
                     $union->addElement($ggp);
                 }
             }
             // parse config
             if (isset($setup->config->hierarchyRelations->in)) {
                 if (is_string($setup->config->hierarchyRelations->in)) {
                     $setup->config->hierarchyRelations->in = array($setup->config->hierarchyRelations->in);
                 }
                 foreach ($setup->config->hierarchyRelations->in as $rel) {
                     // create new graph pattern
                     $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     // add triplen
                     $ggp->addTriple($subVar, new Erfurt_Sparql_Query2_IriRef($rel), $searchVar);
                     // add triplet to union var
                     $union->addElement($ggp);
                 }
             }
             // parse config
             if (isset($setup->config->instanceRelation->out)) {
                 if (is_string($setup->config->instanceRelation->out)) {
                     $setup->config->instanceRelation->out = array($setup->config->instanceRelation->out);
                 }
                 foreach ($setup->config->instanceRelation->out as $rel) {
                     // create new graph pattern
                     $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     // add triplen
                     $ggp->addTriple($subVar, new Erfurt_Sparql_Query2_IriRef($rel), $searchVar);
                     // add triplet to union var
                     $union->addElement($ggp);
                 }
             }
             // parse config
             if (isset($setup->config->instanceRelation->in)) {
                 if (is_string($setup->config->instanceRelation->in)) {
                     $setup->config->instanceRelation->in = array($setup->config->instanceRelation->in);
                 }
                 foreach ($setup->config->instanceRelation->in as $rel) {
                     // create new graph pattern
                     $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     // add triplen
                     $ggp->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel), $subVar);
                     // add triplet to union var
                     $union->addElement($ggp);
                 }
             }
             $elements[] = $union;
         }
     }
     if (isset($setup->config->rootElement)) {
         $union = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
         if (isset($setup->config->hierarchyRelations->in)) {
             foreach ($setup->config->hierarchyRelations->in as $rel) {
                 // create new graph pattern
                 $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                 // add triplen
                 $ggp->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel), new Erfurt_Sparql_Query2_IriRef($setup->config->rootElement));
                 // add triplet to union var
                 $union->addElement($ggp);
             }
             $superUsed = true;
         }
         if (isset($setup->config->hierarchyRelations->out)) {
             foreach ($setup->config->hierarchyRelations->out as $rel) {
                 // create new graph pattern
                 $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                 // add triplen
                 $ggp->addTriple(new Erfurt_Sparql_Query2_IriRef($setup->config->rootElement), new Erfurt_Sparql_Query2_IriRef($rel), $searchVar);
                 // add triplet to union var
                 $union->addElement($ggp);
             }
             $superUsed = true;
         }
         if ($superUsed) {
             $elements[] = $union;
         }
     }
     $elements[] = new Erfurt_Sparql_Query2_Filter(new Erfurt_Sparql_Query2_UnaryExpressionNot(new Erfurt_Sparql_Query2_isBlank(new Erfurt_Sparql_Query2_Var('resourceUri'))));
     // namespaces to be ignored, rdfs/owl-defined objects
     if (!isset($setup->state->showHidden)) {
         if (isset($setup->config->hiddenRelation)) {
             // optional var
             $queryOptional = new Erfurt_Sparql_Query2_OptionalGraphPattern();
             // parse config
             if (is_string($setup->config->hiddenRelation)) {
                 $setup->config->hiddenRelation = array($setup->config->hiddenRelation);
             }
             foreach ($setup->config->hiddenRelation as $ignore) {
                 $queryOptional->addTriple(new Erfurt_Sparql_Query2_Var('resourceUri'), new Erfurt_Sparql_Query2_IriRef($ignore), new Erfurt_Sparql_Query2_Var('reg'));
                 $regUsed = true;
             }
             if ($regUsed) {
                 $elements[] = $queryOptional;
                 $elements[] = new Erfurt_Sparql_Query2_Filter(new Erfurt_Sparql_Query2_UnaryExpressionNot(new Erfurt_Sparql_Query2_bound(new Erfurt_Sparql_Query2_Var('reg'))));
             }
         }
         if (isset($setup->config->hiddenNS)) {
             // parse config
             foreach ($setup->config->hiddenNS as $ignore) {
                 $elements[] = new Erfurt_Sparql_Query2_Filter(new Erfurt_Sparql_Query2_UnaryExpressionNot(new Erfurt_Sparql_Query2_Regex(new Erfurt_Sparql_Query2_Str(new Erfurt_Sparql_Query2_Var('resourceUri')), new Erfurt_Sparql_Query2_RDFLiteral('^' . $ignore))));
             }
         }
     }
     // dont't show rdfs/owl entities and subtypes in the first level
     if (!isset($setup->state->parent) && !isset($setup->config->rootElement)) {
         OntoWiki::getInstance()->logger->info("BACKEND: " . $backend);
         // optional var
         if ($backend == "zenddb") {
             $queryUnion = new Erfurt_Sparql_Query2_OptionalGraphPattern();
         } else {
             $queryUnion = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
         }
         if (isset($setup->config->hierarchyRelations->in)) {
             if (count($setup->config->hierarchyRelations->in) > 1) {
                 foreach ($setup->config->hierarchyRelations->in as $rel) {
                     $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     $ggp->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel), new Erfurt_Sparql_Query2_Var('super'));
                     $queryUnion->addElement($ggp);
                 }
             } else {
                 $rel = $setup->config->hierarchyRelations->in;
                 // add optional sub relation
                 if ($backend == "zenddb") {
                     $queryUnion->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel[0]), new Erfurt_Sparql_Query2_Var('super'));
                 } else {
                     $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     $ggp->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel[0]), new Erfurt_Sparql_Query2_Var('super'));
                     $queryUnion->addElement($ggp);
                 }
             }
             //$mainUnion->addElement($u1);
             $superUsed = true;
         }
         if (isset($setup->config->hierarchyRelations->out)) {
             if (count($setup->config->hierarchyRelations->out) > 1) {
                 foreach ($setup->config->hierarchyRelations->out as $rel) {
                     $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     $ggp->addTriple(new Erfurt_Sparql_Query2_Var('super'), new Erfurt_Sparql_Query2_IriRef($rel), $searchVar);
                     $queryUnion->addElement($ggp);
                 }
             } else {
                 $rel = $setup->config->hierarchyRelations->out;
                 // add optional sub relation
                 if ($backend == "zenddb") {
                     $queryUnion->addTriple(new Erfurt_Sparql_Query2_Var('super'), new Erfurt_Sparql_Query2_IriRef($rel[0]), $searchVar);
                 } else {
                     $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
                     $ggp->addTriple(new Erfurt_Sparql_Query2_Var('super'), new Erfurt_Sparql_Query2_IriRef($rel[0]), $searchVar);
                     $queryUnion->addElement($ggp);
                 }
             }
             //$mainUnion->addElement($u1);
             $superUsed = true;
         }
         if ($superUsed) {
             if ($backend == "zenddb") {
                 $elements[] = $queryUnion;
             } else {
                 $queryOptional = new Erfurt_Sparql_Query2_OptionalGraphPattern();
                 $queryOptional->addElement($queryUnion);
                 $elements[] = $queryOptional;
             }
             $filter[] = new Erfurt_Sparql_Query2_Regex(new Erfurt_Sparql_Query2_Str(new Erfurt_Sparql_Query2_Var('super')), new Erfurt_Sparql_Query2_RDFLiteral('^' . EF_OWL_NS));
             $filter[] = new Erfurt_Sparql_Query2_UnaryExpressionNot(new Erfurt_Sparql_Query2_bound(new Erfurt_Sparql_Query2_Var('super')));
             $elements[] = new Erfurt_Sparql_Query2_Filter(new Erfurt_Sparql_Query2_ConditionalOrExpression($filter));
         }
     }
     if (isset($setup->state->sorting)) {
         $sortRel = new Erfurt_Sparql_Query2_IriRef($setup->state->sorting);
         $sortVar = new Erfurt_Sparql_Query2_Var('sortRes');
         $queryOptional = new Erfurt_Sparql_Query2_OptionalGraphPattern();
         $queryOptional->addTriple(new Erfurt_Sparql_Query2_Var('resourceUri'), $sortRel, $sortVar);
         $elements[] = $queryOptional;
     }
     return $elements;
 }
 protected function _buildSubCheckQuery($uri, $setup)
 {
     $subVar = new Erfurt_Sparql_Query2_Var('subResourceUri');
     $searchVar = new Erfurt_Sparql_Query2_Var('resourceUri');
     //$classVar = new Erfurt_Sparql_Query2_Var('classUri');
     $query = new Erfurt_Sparql_Query2();
     $query->addProjectionVar($subVar);
     $query->setDistinct();
     $this->_owApp->logger->info("data: " . print_r($query, true));
     $elements = array();
     $in = array();
     $out = array();
     if (isset($setup->config->hierarchyRelations->in)) {
         if (count($setup->config->hierarchyRelations->in) > 1) {
             // init union var
             $unionSub = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
             // parse config gile
             foreach ($setup->config->hierarchyRelations->in as $rel) {
                 // sub stuff
                 $groupPattern = new Erfurt_Sparql_Query2_GroupGraphPattern();
                 // add triplen
                 $groupPattern->addTriple($subVar, new Erfurt_Sparql_Query2_IriRef($rel), $searchVar);
                 // add triplet to union var
                 $unionSub->addElement($groupPattern);
             }
             $in[] = $unionSub;
         } else {
             $rel = $setup->config->hierarchyRelations->in;
             // add optional sub relation
             // create optional graph to load sublacsses of selected class
             $queryOptional = new Erfurt_Sparql_Query2_GroupGraphPattern();
             $queryOptional->addTriple($subVar, new Erfurt_Sparql_Query2_IriRef($rel[0]), $searchVar);
             $in[] = $queryOptional;
         }
     }
     if (isset($setup->config->hierarchyRelations->out)) {
         if (count($setup->config->hierarchyRelations->out) > 1) {
             // init union var
             $unionSub = new Erfurt_Sparql_Query2_GroupGraphPattern();
             // parse config gile
             foreach ($setup->config->hierarchyRelations->out as $rel) {
                 // sub stuff
                 $optPattern = new Erfurt_Sparql_Query2_OptionalGraphPattern();
                 // add triple
                 $optPattern->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel), $subVar);
                 // add triplet to union var
                 $unionSub->addElement($optPattern);
             }
             $out[] = $unionSub;
         } else {
             $rel = $setup->config->hierarchyRelations->out;
             // add optional sub relation
             // create optional graph to load sublacsses of selected class
             $queryOptional = new Erfurt_Sparql_Query2_GroupGraphPattern();
             $queryOptional->addTriple($searchVar, new Erfurt_Sparql_Query2_IriRef($rel[0]), $subVar);
             $out[] = $queryOptional;
         }
     }
     $inout = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
     $inout->addElements($in);
     $inout->addElements($out);
     $elements[] = $inout;
     /*$elements[] = new Erfurt_Sparql_Query2_Triple(
           $searchVar,
           new Erfurt_Sparql_Query2_IriRef(EF_RDF_TYPE),
           $classVar
       );*/
     // add filter
     $elements[] = new Erfurt_Sparql_Query2_Filter(new Erfurt_Sparql_Query2_sameTerm($searchVar, new Erfurt_Sparql_Query2_IriRef($uri)));
     $query->addElements($elements);
     $query->setLimit(1);
     // log results
     $this->_owApp->logger->info('NavigationController CHECK SUB: ' . PHP_EOL . $query->__toString());
     return $query;
 }
 /**
  * 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;
 }
 public function __construct($resourceUri)
 {
     $owApp = OntoWiki::getInstance();
     $store = $owApp->erfurt->getStore();
     $model = $owApp->selectedModel;
     $resource = new Erfurt_Sparql_Query2_IriRef($resourceUri);
     $ontology = new Erfurt_Sparql_Query2_IriRef(EF_OWL_ONTOLOGY);
     $fetchFrom = new Erfurt_Sparql_Query2_IriRef(static::SITE_FETCH_OPTIONS_FROM);
     // fetch options from this resource
     $query = new Erfurt_Sparql_Query2();
     list($key, $value, $class, $dataset) = $this->_queryAddVars($query, array('key', 'value', 'class', 'dataset'));
     $union = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
     // resource options
     $group = new Erfurt_Sparql_Query2_GroupGraphPattern();
     $group->addTriple($resource, $key, $value);
     $union->addElement($group);
     // class options
     $group = new Erfurt_Sparql_Query2_GroupGraphPattern();
     $group->addTriple($resource, EF_RDF_TYPE, $class);
     $group->addTriple($class, $key, $value);
     $union->addElement($group);
     // dataset options
     $group = new Erfurt_Sparql_Query2_GroupGraphPattern();
     $group->addTriple($dataset, EF_RDF_TYPE, new Erfurt_Sparql_Query2_IriRef(EF_OWL_ONTOLOGY));
     $group->addTriple($dataset, $key, $value);
     $union->addElement($group);
     $query->addElement($union);
     $query->addTriple($key, EF_RDF_TYPE, new Erfurt_Sparql_Query2_IriRef(static::SITE_TEMPLATE_OPTION));
     $results = $model->sparqlQuery($query);
     foreach ($results as $result) {
         $arrayKey = $result[$key->getName()];
         $this->_options[$arrayKey][$this->_getPriority($result)][] = $result[$value->getName()];
         $templateOption = new Erfurt_Rdf_Resource($arrayKey, $model);
         $arrayKeyLocalName = $templateOption->getLocalName();
         $this->_optionLocalNames[$arrayKeyLocalName][] = $arrayKey;
     }
     // fetch options from linked resources
     $query = new Erfurt_Sparql_Query2();
     list($other, $class, $dataset) = $this->_queryAddVars($query, array('other', 'class', 'dataset'));
     $union = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
     // resource links
     $group = new Erfurt_Sparql_Query2_GroupGraphPattern();
     $group->addTriple($resource, $fetchFrom, $other);
     $union->addElement($group);
     // class links
     $group = new Erfurt_Sparql_Query2_GroupGraphPattern();
     $group->addTriple($resource, EF_RDF_TYPE, $class);
     $group->addTriple($class, $fetchFrom, $other);
     $union->addElement($group);
     // dataset links
     $group = new Erfurt_Sparql_Query2_GroupGraphPattern();
     $group->addTriple($dataset, EF_RDF_TYPE, $ontology);
     $group->addTriple($dataset, $fetchFrom, $other);
     $union->addElement($group);
     $query->addElement($union);
     $results = $model->sparqlQuery($query);
     foreach ($results as $result) {
         $options = new TemplateOptionsClass($result[$other->getName()]);
         foreach ($options->_options as $arrayKey => $priorities) {
             foreach ($priorities as $priority => $values) {
                 $floor = floor($priority);
                 $this->_options[$arrayKey][(string) ($floor + 0.1 * $this->_getPriority($result) + 0.1 * ($priority - $floor))] = $values;
             }
         }
         foreach ($options->_optionLocalNames as $arrayKeyLocalName => $keys) {
             foreach ($keys as $key) {
                 if (!isset($this->_optionLocalNames[$arrayKeyLocalName]) || !in_array($key, $this->_optionLocalNames[$arrayKeyLocalName])) {
                     $this->_optionLocalNames[$arrayKeyLocalName][] = $key;
                 }
             }
         }
     }
     foreach (array_keys($this->_options) as $key) {
         ksort($this->_options[$key]);
     }
 }
 private function checkConfig($config)
 {
     $resVar = new Erfurt_Sparql_Query2_Var('resourceUri');
     $typeVar = new Erfurt_Sparql_Query2_IriRef(EF_RDF_TYPE);
     $query = new Erfurt_Sparql_Query2();
     $query->addProjectionVar($resVar)->setDistinct(true);
     $union = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
     if (is_string($config->hierarchyTypes)) {
         $config->hierarchyTypes = array($config->hierarchyTypes);
     }
     foreach ($config->hierarchyTypes->toArray() as $type) {
         $ggp = new Erfurt_Sparql_Query2_GroupGraphPattern();
         $ggp->addTriple($resVar, $typeVar, new Erfurt_Sparql_Query2_IriRef($type));
         $union->addElement($ggp);
     }
     $query->addElement($union);
     $query->setLimit(1);
     $allResults = $this->_owApp->selectedModel->sparqlQuery($query);
     /*$this->_owApp->logger->info(
           'Navigation Query: ' .PHP_EOL . $query->__toString()
       );
       $this->_owApp->logger->info(
           'Navigation Query Results: ' .PHP_EOL . print_r($all_results)
       );*/
     return count($allResults);
 }
示例#8
0
 /**
  * Moves resource to new URI
  * renaming all occurences of the resource.
  *
  * @param string $oldUri The URI that identifies the resource.
  * @param string $newUri The URI to move resource to.
  *
  * @return void
  */
 public function renameResource($oldUri, $newUri)
 {
     $query = new Erfurt_Sparql_Query2();
     $query->setDistinct(true);
     $vars = array();
     foreach (array('s', 'p', 'o') as $varName) {
         $vars[$varName] = new Erfurt_Sparql_Query2_Var($varName);
         $query->addProjectionVar($vars[$varName]);
     }
     $oldUriRef = new Erfurt_Sparql_Query2_IriRef($oldUri);
     $union = new Erfurt_Sparql_Query2_GroupOrUnionGraphPattern();
     foreach ($vars as $var) {
         $group = new Erfurt_Sparql_Query2_GroupGraphPattern();
         $group->addTriple($vars['s'], $vars['p'], $vars['o']);
         $group->addFilter(new Erfurt_Sparql_Query2_sameTerm($var, $oldUriRef));
         $union->addElement($group);
     }
     $query->addElement($union);
     $result = $this->sparqlQuery($query, array('result_format' => 'extended'));
     $removed = array();
     $added = array();
     foreach ($result['results']['bindings'] as $s) {
         // result format from sparqlQuery
         // isn't the same as format for delete/addMultipleStatements
         if (array_key_exists('xml:lang', $s['o'])) {
             $s['o']['lang'] = $s['o']['xml:lang'];
             unset($s['o']['xml:lang']);
         }
         $removed[$s['s']['value']][$s['p']['value']][] = $s['o'];
         foreach (array('s', 'p', 'o') as $varName) {
             if ($s[$varName]['type'] === 'uri' && $s[$varName]['value'] === $oldUri) {
                 $s[$varName]['value'] = $newUri;
             }
         }
         $added[$s['s']['value']][$s['p']['value']][] = $s['o'];
     }
     $this->deleteMultipleStatements($removed);
     $this->addMultipleStatements($added);
 }