Exemplo n.º 1
0
 public function testRemoveOptionals()
 {
     $x = new Erfurt_Sparql_Query2_Var("x");
     $triple = new Erfurt_Sparql_Query2_Triple($x, $x, $x);
     $optional = new Erfurt_Sparql_Query2_OptionalGraphPattern();
     $optional->addElement($triple);
     $this->pattern->addElement($optional);
     $this->pattern->removeAllOptionals();
     $elements = $this->pattern->getElements();
     $this->assertTrue(empty($elements));
 }
Exemplo n.º 2
0
 public function optionalGraphPattern()
 {
     $value = null;
     $groupGraphPattern15 = null;
     try {
         $this->match($this->input, $this->getToken('OPTIONAL'), self::$FOLLOW_OPTIONAL_in_optionalGraphPattern873);
         $this->pushFollow(self::$FOLLOW_groupGraphPattern_in_optionalGraphPattern875);
         $groupGraphPattern15 = $this->groupGraphPattern();
         $this->state->_fsp--;
         $value = new Erfurt_Sparql_Query2_OptionalGraphPattern();
         $value->addElement($groupGraphPattern15);
     } catch (RecognitionException $re) {
         $this->reportError($re);
         $this->recover($this->input, $re);
     } catch (Exception $e) {
         throw $e;
     }
     return $value;
 }
Exemplo n.º 3
0
 /**
  * addShownPropertyHelper
  * 
  * adds a triple <classVar> $predicate ?newPropertyVar
  * and adds ?newPropertyVar as projectionvar
  * and keep track of that
  * 
  * @param Erfurt_Sparql_Query2 $query
  * @param Erfurt_Sparql_Query2_Var $resVar
  * @param Erfurt_Sparql_Query2_IriRef|string $predicate
  * @param string|null $name
  * @param bool $inverse
  * @return array array('optional' => $optionalpart, 'var' => $var);
  */
 public static function addShownPropertyHelper(Erfurt_Sparql_Query2 $query, Erfurt_Sparql_Query2_Var $resVar, $predicate, $name = null, $inverse = false)
 {
     if (is_string($predicate)) {
         $predicate = new Erfurt_Sparql_Query2_IriRef($predicate);
     }
     if (!$predicate instanceof Erfurt_Sparql_Query2_IriRef) {
         throw new RuntimeException('Argument 3 passed to Erfurt_Sparql_Query2_Abstraction_ClassNode::addShownPropertyHelper must be an instance of Erfurt_Sparql_Query2_IriRef, instance of ' . typeHelper($predicate) . ' given');
     }
     if (!is_string($name)) {
         throw new RuntimeException('Argument 4 passed to Erfurt_Sparql_Query2_Abstraction_ClassNode::addShownPropertyHelper must be an instance of string, instance of ' . typeHelper($name) . ' given');
     }
     if (!is_bool($inverse)) {
         throw new RuntimeException('Argument 5 passed to Erfurt_Sparql_Query2_Abstraction_ClassNode::addShownPropertyHelper must be an instance of bool, instance of ' . typeHelper($inverse) . ' given (' . $inverse . ')');
     }
     $optionalpart = new Erfurt_Sparql_Query2_OptionalGraphPattern();
     if ($name == null) {
         $var = new Erfurt_Sparql_Query2_Var($predicate);
     } else {
         $var = new Erfurt_Sparql_Query2_Var($name);
     }
     if (!$inverse) {
         $triple = new Erfurt_Sparql_Query2_Triple($resVar, $predicate, $var);
     } else {
         $triple = new Erfurt_Sparql_Query2_Triple($var, $predicate, $resVar);
     }
     $optionalpart->addElement($triple);
     $query->getWhere()->addElement($optionalpart);
     /* filtered now in php
          $filter = new Erfurt_Sparql_Query2_Filter(
            new Erfurt_Sparql_Query2_UnaryExpressionNot(
                new Erfurt_Sparql_Query2_isBlank($var)
            )
        );*/
     //$optionalpart->addElement($filter);
     $query->addProjectionVar($var);
     return array('optional' => $optionalpart, 'var' => $var, 'filter' => null);
 }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
 /**
  * add a filter from the filter box - these filters match some predefined schemes
  * (like "equals", "contains")
  *
  * @param string  $property
  * @param boolean $isInverse     whether the property is a indirect property of the resources
  * @param string  $propertyLabel label affects the created variable
  * @param string  $filter        the type of filter ("equals", "bound", "larger", "smaller", "between", "contains")
  * @param string  $value
  * @param string  $valueSecondary
  * @param string  $valuetype     ("uri" or "literal" or "typed-literal")
  * @param string  $literaltype   (if valuetype is set to "typed-literal", you can pass a URI here)
  * @param boolean $hidden        whether to hide this filter in the filter box GUI
  * @param string  $id            optional predined ID, will be generated normally
  * @param boolean $negate        whether to invert the condition
  * @param boolean $optional
  *
  * @return string id
  * @throws RuntimeException
  */
 public function addFilter($property, $isInverse, $propertyLabel, $filter, $value = null, $valueSecondary = null, $valuetype = 'literal', $literaltype = null, $hidden = false, $id = null, $negate = false, $optional = false)
 {
     if ($id == null) {
         $id = 'box' . count($this->_filter);
     } else {
         if (isset($this->_filter[$id])) {
             $this->removeFilter($id);
         }
     }
     $prop = new Erfurt_Sparql_Query2_IriRef($property);
     if (!empty($value)) {
         switch ($valuetype) {
             case 'uri':
                 $valueObj = new Erfurt_Sparql_Query2_IriRef($value);
                 if (!empty($valueSecondary)) {
                     $valueSecondaryObj = new Erfurt_Sparql_Query2_IriRef($valueSecondary);
                 }
                 break;
             case 'literal':
                 if (!empty($literaltype)) {
                     //with language tags
                     $valueObj = new Erfurt_Sparql_Query2_RDFLiteral($value, $literaltype);
                     if (!empty($valueSecondary)) {
                         $valueSecondaryObj = new Erfurt_Sparql_Query2_RDFLiteral($valueSecondary, $literaltype);
                     }
                 } else {
                     //no language tags
                     if (is_array($value)) {
                         $value = current($value);
                     }
                     $meta = '';
                     if (is_scalar($value) && !is_string($value) && !is_array($value)) {
                         $meta = gettype($value);
                     }
                     $valueObj = new Erfurt_Sparql_Query2_RDFLiteral($value, $meta);
                     if (!empty($valueSecondary)) {
                         $valueSecondaryObj = new Erfurt_Sparql_Query2_RDFLiteral($valueSecondary, $meta);
                     }
                 }
                 break;
             case 'typed-literal':
                 if (in_array($literaltype, Erfurt_Sparql_Query2_RDFLiteral::$knownShortcuts)) {
                     //is something like "bool" or "int" - will be converted from "1"^^xsd:int to 1
                     $valueObj = new Erfurt_Sparql_Query2_RDFLiteral($value, $literaltype);
                     if (!empty($valueSecondary)) {
                         $valueSecondaryObj = new Erfurt_Sparql_Query2_RDFLiteral($valueSecondary, $literaltype);
                     }
                 } else {
                     // is a uri
                     $valueObj = new Erfurt_Sparql_Query2_RDFLiteral($value, new Erfurt_Sparql_Query2_IriRef($literaltype));
                     if (!empty($valueSecondary)) {
                         $valueSecondaryObj = new Erfurt_Sparql_Query2_RDFLiteral($valueSecondary, new Erfurt_Sparql_Query2_IriRef($literaltype));
                     }
                 }
                 break;
             default:
                 throw new RuntimeException('called Ontowiki_Model_Instances::addFilter with ' . 'unknown param-value: valuetype = "' . $valuetype . '"');
         }
     }
     switch ($filter) {
         case 'contains':
             $var = new Erfurt_Sparql_Query2_Var($propertyLabel);
             if (!$isInverse) {
                 $triple = $this->_resourceQuery->addTriple($this->_resourceVar, $prop, $var);
             } else {
                 $triple = $this->_resourceQuery->addTriple($var, $prop, $this->_resourceVar);
             }
             $valueObj->setValue(str_replace("\\", "\\\\", preg_quote($valueObj->getValue())));
             $addFilter = null;
             if (!$negate) {
                 $addFilter = new Erfurt_Sparql_Query2_Regex(new Erfurt_Sparql_Query2_Str($var), $valueObj);
             } else {
                 $addFilter = new Erfurt_Sparql_Query2_UnaryExpressionNot(new Erfurt_Sparql_Query2_Regex(new Erfurt_Sparql_Query2_Str($var), $valueObj));
             }
             $filterObj = $this->_resourceQuery->addFilter($addFilter);
             break;
         case 'equals':
             if ($valuetype == 'literal') {
                 $valueVar = new Erfurt_Sparql_Query2_Var($propertyLabel);
                 if (!$isInverse) {
                     $triple = new Erfurt_Sparql_Query2_Triple($this->_resourceVar, $prop, $valueVar);
                 } else {
                     throw new RuntimeException('literal as value for an inverse property ' . 'is a literal subject which is not allowed');
                 }
                 if ($negate) {
                     $optionalGP = new Erfurt_Sparql_Query2_OptionalGraphPattern();
                     $optionalGP->addElement($triple);
                     if ($optional) {
                         $orExpression = new Erfurt_Sparql_Query2_ConditionalOrExpression();
                         $orExpression->addElement(new Erfurt_Sparql_Query2_UnaryExpressionNot(new Erfurt_Sparql_Query2_bound($valueVar)));
                         $orExpression->addElement(new Erfurt_Sparql_Query2_NotEquals($valueVar, $valueObj));
                         $filterObj = $optionalGP->addFilter($orExpression);
                     } else {
                         $filterObj = $optionalGP->addFilter(new Erfurt_Sparql_Query2_NotEquals($valueVar, $valueObj));
                     }
                     $this->_resourceQuery->addElement($optionalGP);
                     $triple = $optionalGP;
                 } else {
                     $this->_resourceQuery->addElement($triple);
                     $filterObj = $this->_resourceQuery->addFilter(new Erfurt_Sparql_Query2_Regex(new Erfurt_Sparql_Query2_Str($valueVar), new Erfurt_Sparql_Query2_RDFLiteral('^' . str_replace("\\", "\\\\", preg_quote($value)) . '$')));
                 }
             } else {
                 if (!$isInverse) {
                     $triple = $this->_resourceQuery->addTriple($this->_resourceVar, $prop, $valueObj);
                 } else {
                     $triple = $this->_resourceQuery->addTriple($valueObj, $prop, $this->_resourceVar);
                 }
             }
             break;
         case 'larger':
             $var = new Erfurt_Sparql_Query2_Var($propertyLabel);
             if (!$isInverse) {
                 $triple = $this->_resourceQuery->addTriple($this->_resourceVar, $prop, $var);
             } else {
                 $triple = $this->_resourceQuery->addTriple($var, $prop, $this->_resourceVar);
             }
             $filterObj = $this->_resourceQuery->addFilter(new Erfurt_Sparql_Query2_Larger($var, $valueObj));
             break;
         case 'smaller':
             $var = new Erfurt_Sparql_Query2_Var($propertyLabel);
             if (!$isInverse) {
                 $triple = $this->_resourceQuery->addTriple($this->_resourceVar, $prop, $var);
             } else {
                 $triple = $this->_resourceQuery->addTriple($var, $prop, $this->_resourceVar);
             }
             $filterObj = $this->_resourceQuery->addFilter(new Erfurt_Sparql_Query2_Smaller($var, $valueObj));
             break;
         case 'between':
             $var = new Erfurt_Sparql_Query2_Var($propertyLabel);
             if (!$isInverse) {
                 $triple = $this->_resourceQuery->addTriple($this->_resourceVar, $prop, $var);
             } else {
                 $triple = $this->_resourceQuery->addTriple($var, $prop, $this->_resourceVar);
             }
             $filterObj = $this->_resourceQuery->addFilter(new Erfurt_Sparql_Query2_ConditionalAndExpression(array(new Erfurt_Sparql_Query2_Larger($var, $valueObj), new Erfurt_Sparql_Query2_Smaller($var, $valueSecondaryObj))));
             break;
         case 'bound':
             $var = new Erfurt_Sparql_Query2_Var($propertyLabel);
             if (!$isInverse) {
                 $triple = new Erfurt_Sparql_Query2_Triple($this->_resourceVar, $prop, $var);
             } else {
                 $triple = new Erfurt_Sparql_Query2_Triple($var, $prop, $this->_resourceVar);
             }
             if ($negate) {
                 $optionalGP = new Erfurt_Sparql_Query2_OptionalGraphPattern();
                 $optionalGP->addElement($triple);
                 $this->_resourceQuery->addElement($optionalGP);
                 $triple = $optionalGP;
                 // to save this obj (see underneath 20 lines)
             } else {
                 $this->_resourceQuery->addElement($triple);
             }
             if ($negate) {
                 $filterObj = $this->_resourceQuery->addFilter(new Erfurt_Sparql_Query2_UnaryExpressionNot(new Erfurt_Sparql_Query2_bound($var)));
             }
             break;
         default:
             throw new RuntimeException('called Ontowiki_Model_Instances::addFilter with ' . 'unknown param-value: filtertype=' . $filter);
     }
     //these filters bring their own triple
     $this->removeAllTriple();
     //save
     $this->_filter[$id] = array('id' => $id, 'mode' => 'box', 'property' => $property, 'isInverse' => $isInverse, 'propertyLabel' => $propertyLabel, 'filter' => $filter, 'value1' => $value, 'value2' => $valueSecondary, 'valuetype' => $valuetype, 'literaltype' => $literaltype, 'hidden' => $hidden, 'negate' => $negate, 'objects' => array($triple, isset($filterObj) ? $filterObj : null));
     $this->invalidate();
     return $id;
 }
 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;
 }