Beispiel #1
0
 /**
  * setValue
  * @param string $val
  * @return Erfurt_Sparql_Query2_NumricLiteral $this
  */
 public function setValue($val)
 {
     if (is_numeric($val)) {
         $this->value = $val;
     } else {
         throw new RuntimeException('Argument 1 passed to Erfurt_Sparql_Query2_NumericLiteral::setValue must be numeric, instance of ' . typeHelper($val) . ' given');
     }
     return $this;
 }
Beispiel #2
0
 /**
  * add
  * add an expression to this order clause - expresssion will mostly be a Var... but by the grammar this can be almost anything
  * @param Erfurt_Sparql_Query2_Expression $exp
  * @return int index of added element
  */
 public function add(Erfurt_Sparql_Query2_Expression $exp, $order = self::ASC)
 {
     if ($order != self::ASC && $order != self::DESC) {
         throw new RuntimeException('Argument 2 passed to Erfurt_Sparql_Query2_OrderClause::add must be \'ASC\' or \'DESC\', ' . $order . ' (instance of ' . typeHelper($order) . ') given');
     }
     $this->exps[] = array('exp' => $exp, 'dir' => $order);
     return count($this->exps) - 1;
     //last index = index of added element
 }
 /**
  * setElement
  * @param int $i
  * @param Erfurt_Sparql_Query2_GroupGraphPattern $element
  * @return Erfurt_Sparql_Query2_GroupOrUnionGraphPattern $this
  */
 public function setElement($i, $element)
 {
     if (!$element instanceof Erfurt_Sparql_Query2_GroupGraphPattern) {
         throw new RuntimeException('Argument 2 passed to Erfurt_Sparql_Query2_GroupOrUnionGraphPattern::setElement must be an instance of Erfurt_Sparql_Query2_GroupGraphPattern, instance of ' . typeHelper($element) . ' given');
     }
     $this->elements[$i] = $element;
     $element->addParent($this);
     return $this;
     //for chaining
 }
Beispiel #4
0
 /**
  * @param string $nname
  */
 public function __construct($nname)
 {
     if (is_string($nname) && $nname != '') {
         $this->name = preg_replace('/[^\\w]/', '', $nname);
     } else {
         if ($nname instanceof Erfurt_Sparql_Query2_IriRef) {
             $this->name = self::extractName($nname->getIri());
         } else {
             throw new RuntimeException('Argument 1 passed to Erfurt_Sparql_Query2_Var : string (not empty) or Erfurt_Sparql_Query2_IriRef expected. ' . typeHelper($nname) . ' found.');
         }
     }
     parent::__construct();
 }
 /**
  * setElement
  * @param int $i
  * @param Erfurt_Sparql_Query2_IF_TriplesSameSubject $element
  * @return Erfurt_Sparql_Query2_ConstructTemplate $this
  */
 public function setElement($i, $element)
 {
     if (!is_int($i)) {
         throw new RuntimeException('Argument 1 passed to Erfurt_Sparql_Query2_GroupOrUnionGraphPattern::setElement must be an instance of integer, instance of ' . typeHelper($i) . ' given');
     }
     if (!$element instanceof Erfurt_Sparql_Query2_IF_TriplesSameSubject) {
         throw new RuntimeException('Argument 1 passed to Erfurt_Sparql_Query2_GroupOrUnionGraphPattern::addElement must be an instance of Erfurt_Sparql_Query2_IF_TriplesSameSubject');
     }
     $this->elements[$i] = $element;
     $element->addParent($this);
     return $this;
     //for chaining
 }
Beispiel #6
0
 public function setElements($elements)
 {
     if (!is_array($elements)) {
         throw new RuntimeException('Argument 1 passed to Erfurt_Sparql_Query2_ObjectList::setElements must be an array of Erfurt_Sparql_Query2_GraphNode\'s, instance of ' . typeHelper($elements) . ' given');
     } else {
         foreach ($elements as $object) {
             if (!$object instanceof Erfurt_Sparql_Query2_GraphNode) {
                 throw new RuntimeException('Argument 1 passed to Erfurt_Sparql_Query2_ObjectList::setElements must be an array of Erfurt_Sparql_Query2_GraphNode\'s, instance of ' . typeHelper($object) . ' given');
             } else {
                 $this->addElement($object);
             }
         }
     }
 }
Beispiel #7
0
 /**
  * @param string $nresource
  * @param Erfurt_Sparql_Query2_Prefix $prefix
  * @param string $unexpandablePrefix
  */
 public function __construct($nresource, Erfurt_Sparql_Query2_Prefix $prefix = null, $unexpandablePrefix = null)
 {
     if (!is_string($nresource)) {
         throw new RuntimeException('wrong argument 1 passed to Erfurt_Sparql_Query2_IriRef::__construct. string expected. ' . typeHelper($nresource) . ' found.');
     }
     $this->iri = $nresource;
     if ($prefix != null) {
         $this->prefix = $prefix;
     }
     if ($unexpandablePrefix !== null && is_string($unexpandablePrefix)) {
         $this->unexpandablePrefix = $unexpandablePrefix;
     }
     parent::__construct();
 }
Beispiel #8
0
 /**
  * @param string $nname
  * @param Erfurt_Sparql_Query2_IriRef $iri
  */
 public function __construct($nname, $iri)
 {
     if (!is_string($nname)) {
         throw new RuntimeException('Argument 1 passed to Erfurt_Sparql_Query2_Prefix::__construct must be an instance of string, instance of ' . typeHelper($iri) . ' given');
     }
     $this->name = $nname;
     if (is_string($iri)) {
         $iri = new Erfurt_Sparql_Query2_IriRef($iri);
     }
     if (!$iri instanceof Erfurt_Sparql_Query2_IriRef) {
         throw new RuntimeException("Argument 2 passed to Erfurt_Sparql_Query2_Prefix::__construct must be instance of Erfurt_Sparql_Query2_IriRef or string", E_USER_ERROR);
     }
     $this->iri = $iri;
     parent::__construct();
 }
Beispiel #9
0
 /**
  * addNode
  * 
  * add a node to the tree of class-nodes
  * 
  * @param Erfurt_Sparql_Query2_Abstraction_ClassNode $sourceNode where in the tree of nodes should the new node be added
  * @param Erfurt_Sparql_Query2_IriRef|string $LinkPredicate over which predicate you want to link 
  * @param Erfurt_Sparql_Query2_IriRef|string|null $targetClass can be used to link to a subset of all possible
  * @param bool $withChilds wether to include subclasses of $class
  * @param string|null $varName the var-name to be used for instances of this class
  * @param string $member_predicate the predicate that stands between the class und its instances (mostly rdf:type) 
  * @return Erfurt_Sparql_Query2_Abstraction_ClassNode the new node
  */
 public function addNode(Erfurt_Sparql_Query2_Abstraction_ClassNode $sourceNode, $LinkPredicate, $targetClass = null, $withChilds = true, $varName = null, $member_predicate = EF_RDF_TYPE)
 {
     // hack for overloaded functioncalls
     if (!$LinkPredicate instanceof Erfurt_Sparql_Query2_IriRef) {
         if (is_string($LinkPredicate)) {
             $LinkPredicate = new Erfurt_Sparql_Query2_IriRef($LinkPredicate);
         } else {
             throw new RuntimeException("Argument 2 passed to Erfurt_Sparql_Query2_Abstraction::addNode must be an instance of Erfurt_Sparql_Query2_IriRef or string, instance of " . typeHelper($LinkPredicate) . " given");
         }
     }
     if ($targetClass == null) {
         //TODO: find type of referenced objects
     }
     //add link from source node to new node
     $newnode = new Erfurt_Sparql_Query2_Abstraction_ClassNode($targetClass, $member_predicate, $this->query, $varName, $withChilds);
     $sourceNode->addLink($LinkPredicate, $newnode);
     return $newnode;
     //for chaining
 }
Beispiel #10
0
 /**
  *
  * @param Erfurt_Sparql_Query2_Expression $element1
  * @param Erfurt_Sparql_Query2_Expression $element2
  * @param <type> $element3
  */
 public function __construct(Erfurt_Sparql_Query2_Expression $element1, Erfurt_Sparql_Query2_Expression $element2, $element3 = null)
 {
     $this->element1 = $element1;
     $this->element2 = $element2;
     if ($element3 != null) {
         if ($element3 instanceof Erfurt_Sparql_Query2_Expression) {
             $this->element3 = $element3;
         } else {
             throw new RuntimeException('Argument 3 passed to Erfurt_Sparql_Query2_Regex::__construct must be an instance of Erfurt_Sparql_Query2_Expression or null, instance of ' . typeHelper($element3) . ' given');
         }
     }
     parent::__construct();
 }
Beispiel #11
0
 public static function addFilterHelper(Erfurt_Sparql_Query2 $query, Erfurt_Sparql_Query2_Var $resVar, $predicate, $type, $value)
 {
     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::addFilterHelper must be an instance of Erfurt_Sparql_Query2_IriRef instance of ' . typeHelper($predicate) . ' given');
     }
     switch ($type) {
         case 'contains':
             $propVar = new Erfurt_Sparql_Query2_Var($predicate);
             $filteringTriple = new Erfurt_Sparql_Query2_Triple($resVar, $predicate, $propVar);
             $filterExp = new Erfurt_Sparql_Query2_Filter(new Erfurt_Sparql_Query2_Regex($propVar, new Erfurt_Sparql_Query2_RDFLiteral($value)));
             $query->getWhere()->addElement($filteringTriple);
             $query->getWhere()->addElement($filterExp);
             return array($filteringTriple, $filterExp);
             break;
         case 'equals':
             $filteringTriple = new Erfurt_Sparql_Query2_Triple($resVar, $predicate, new Erfurt_Sparql_Query2_RDFLiteral($value));
             $query->getWhere()->addElement($filteringTriple);
             return $filteringTriple;
             break;
         default:
             throw new RuntimeException('Argument 4 passed to Erfurt_Sparql_Query2_Abstraction_ClassNode::addFilterHelper must be "equals" or "contains", ' . $type . ' given');
             break;
     }
     return null;
 }
Beispiel #12
0
 /**
  * get the bound values for a predicate
  *
  * @param Erfurt_Sparql_Query2_IriRef|string $property
  * @param boolean                            $distinct
  * @param boolean                            $inverse
  *
  * @return array
  */
 public function getPossibleValues($property, $distinct = true, $inverse = false)
 {
     if (is_string($property)) {
         $property = new Erfurt_Sparql_Query2_IriRef($property);
     }
     if (!$property instanceof Erfurt_Sparql_Query2_IriRef) {
         throw new RuntimeException('Argument 1 passed to OntoWiki_Model_Instances::getObjects ' . 'must be instance of string or Erfurt_Sparql_Query2_IriRef, ' . typeHelper($property) . ' given');
     }
     $query = clone $this->_resourceQuery;
     $query->removeAllProjectionVars()->setDistinct($distinct)->setLimit(0)->setOffset(0);
     $valueVar = new Erfurt_Sparql_Query2_Var('obj');
     if ($inverse) {
         $query->addTriple($valueVar, $property, $this->_resourceVar);
     } else {
         $query->addTriple($this->_resourceVar, $property, $valueVar);
     }
     $query->addFilter(new Erfurt_Sparql_Query2_ConditionalAndExpression(array(new Erfurt_Sparql_Query2_UnaryExpressionNot(new Erfurt_Sparql_Query2_isBlank($valueVar)))));
     $query->addProjectionVar($valueVar);
     $results = $this->_store->sparqlQuery($query, array(Erfurt_Store::RESULTFORMAT => Erfurt_Store::RESULTFORMAT_EXTENDED, Erfurt_Store::USE_CACHE => $this->_useCache));
     $values = array();
     foreach ($results['results']['bindings'] as $row) {
         $values[] = $row['obj'];
     }
     return $values;
 }
Beispiel #13
0
 /**
  * hasFrom
  * @param Erfurt_Sparql_Query2_GraphClause|Erfurt_Sparql_Query2_IriRef|string $from
  * @return bool true if the given from is present in this query
  */
 public function hasFrom($from)
 {
     if (!($from instanceof Erfurt_Sparql_Query2_GraphClause || $from instanceof Erfurt_Sparql_Query2_IriRef || is_string($from))) {
         throw new RuntimeException('Argument 1 passed to ' . 'Erfurt_Sparql_Query2::hasFrom must be an instance of ' . 'Erfurt_Sparql_Query2_GraphClause or Erfurt_Sparql_Query2_IriRef ' . 'or string, instance of ' . typeHelper($setNamed) . ' given');
     }
     if ($from instanceof Erfurt_Sparql_Query2_IriRef) {
         $from = new Erfurt_Sparql_Query2_GraphClause($from);
     }
     if (is_string($from)) {
         $from = new Erfurt_Sparql_Query2_GraphClause(new Erfurt_Sparql_Query2_IriRef($from));
     }
     return in_array($from, $this->froms);
 }
Beispiel #14
0
 /**
  * setElement
  * overwrite a element
  * @param int $i index of element to overwrite
  * @param Erfurt_Sparql_Query2_GroupGraphPattern|Erfurt_Sparql_Query2_IF_TriplesSameSubject|Erfurt_Sparql_Query2_Filter $member what to overwrite with
  * @return Erfurt_Sparql_Query2_GroupGraphPattern $this
  */
 public function setElement($i, $member)
 {
     if (!$member instanceof Erfurt_Sparql_Query2_GroupGraphPattern && !$member instanceof Erfurt_Sparql_Query2_IF_TriplesSameSubject && !$member instanceof Erfurt_Sparql_Query2_Filter) {
         throw new RuntimeException('Argument 2 passed to Erfurt_Sparql_Query2_GroupGraphPattern' . '::setElement must be an instance of ' . 'Erfurt_Sparql_Query2_GroupGraphPattern or ' . 'Erfurt_Sparql_Query2_IF_TriplesSameSubject or ' . 'Erfurt_Sparql_Query2_Filter, instance of ' . typeHelper($member) . ' given');
     }
     if (!is_int($i)) {
         throw new RuntimeException('Argument 1 passed to ' . 'Erfurt_Sparql_Query2_GroupGraphPattern::setElement must be ' . 'an instance of integer, instance of ' . typeHelper($i) . ' given');
     }
     $this->elements[$i] = $member;
     $member->addParent($this);
     return $this;
     //for chaining
 }