Ejemplo n.º 1
0
 /**
  * Removes all statements from a (default-) graph which match with given statement.
  *
  * @param  Statement $statement          It can be either a concrete or pattern-statement.
  * @param  Node      $graph     optional Overrides target graph. If set, all statements will be delete in
  *                                       that graph.
  * @param  array     $options   optional It contains key-value pairs and should provide additional
  *                                       introductions for the store and/or its adapter(s).
  * @return boolean Returns true, if function performed without errors. In case an error occur, an exception
  *                 will be thrown.
  */
 public function deleteMatchingStatements(Statement $statement, Node $graph = null, array $options = array())
 {
     // TODO migrate code to new interface
     $graphUri = null;
     if ($graph !== null) {
         $graphUri = $graph->getUri();
     }
     // log it
     $this->addToLog(array('method' => 'deleteMatchingStatements', 'parameter' => array('statement' => $statement, 'graphUri' => $graphUri, 'options' => $options)));
     // if successor is set, ask it first before run the command yourself.
     if ($this->successor instanceof Store) {
         $this->invalidateByTriplePattern($this->statementIteratorFactory->createIteratorFromArray(array($statement)), $graphUri);
         return $this->successor->deleteMatchingStatements($statement, $graph, $options);
         // dont run command by myself
     } else {
         throw new \Exception('QueryCache does not support delete matching statements, only by successor.');
     }
 }
Ejemplo n.º 2
0
 /**
  * Returns true or false depending on whether or not the statements pattern
  * has any matches in the given graph.
  *
  * @param  Statement $Statement          It can be either a concrete or pattern-statement.
  * @param  Node      $graph     optional Overrides target graph.
  * @param  array     $options   optional It contains key-value pairs and should provide additional
  *                                       introductions for the store and/or its adapter(s).
  * @return boolean Returns true if at least one match was found, false otherwise.
  */
 public function hasMatchingStatement(Statement $statement, Node $graph = null, array $options = array())
 {
     // if $graph was given, but its not a named node, set it to null.
     if (null !== $graph && false === $graph->isNamed()) {
         $graph = null;
     }
     // otherwise check, if graph was set in the statement and it is a named node and use it, if so.
     if (null === $graph && null !== $statement->getGraph() && true === $statement->getGraph()->isNamed()) {
         $graph = $statement->getGraph();
     }
     $statementIterator = $this->statementIteratorFactory->createIteratorFromArray(array($statement));
     $result = $this->query('ASK { ' . $this->sparqlFormat($statementIterator, $graph) . '}', $options);
     if (true === is_object($result)) {
         return $result->getValue();
     } else {
         return $result;
     }
 }
Ejemplo n.º 3
0
 /**
  * Removes all statements from a (default-) graph which match with given statement.
  *
  * @param  Statement $statement          It can be either a concrete or pattern-statement.
  * @param  Node      $graph     optional Overrides target graph. If set, all statements will
  *                                       be delete in that graph.
  * @param  array     $options   optional Key-value pairs which provide additional introductions
  *                                       for the store and/or its adapter(s).
  */
 public function deleteMatchingStatements(Statement $statement, Node $graph = null, array $options = array())
 {
     // given $graph forces usage of it and not the graph from the statement instance
     if (null !== $graph) {
         // use given $graph
         // use graphUri from statement
     } elseif (null === $graph && null !== $statement->getGraph()) {
         $graph = $statement->getGraph();
     }
     // create triple statement, because we have to handle the graph extra
     $tripleStatement = $this->statementFactory->createStatement($statement->getSubject(), $statement->getPredicate(), $statement->getObject());
     $statementIterator = $this->statementIteratorFactory->createIteratorFromArray(array($tripleStatement));
     $triple = $this->sparqlFormat($statementIterator);
     $query = 'DELETE ';
     if (null !== $graph) {
         $query .= 'FROM <' . $graph->getUri() . '> ';
     }
     $query .= '{' . $triple . '} WHERE {' . $triple . '}';
     $this->query($query);
 }
Ejemplo n.º 4
0
 /**
  * Create statements from query.
  *
  * @param  Query             $queryObject Query object which represents a SPARQL query.
  * @return StatementIterator StatementIterator object
  */
 protected function getStatements(Query $queryObject)
 {
     $queryParts = $queryObject->getQueryParts();
     $statementArray = array();
     // if only triples, but no quads
     if (true === isset($queryParts['triple_pattern']) && false === isset($queryParts['quad_pattern'])) {
         foreach ($queryParts['triple_pattern'] as $pattern) {
             /**
              * Create Node instances for S, P and O to build a Statement instance later on
              */
             $s = $this->createNodeByValueAndType($pattern['s'], $pattern['s_type']);
             $p = $this->createNodeByValueAndType($pattern['p'], $pattern['p_type']);
             $o = $this->createNodeByValueAndType($pattern['o'], $pattern['o_type']);
             $g = null;
             $statementArray[] = $this->statementFactory->createStatement($s, $p, $o, $g);
         }
         // if only quads, but not triples
     } elseif (false === isset($queryParts['triple_pattern']) && true === isset($queryParts['quad_pattern'])) {
         foreach ($queryParts['quad_pattern'] as $pattern) {
             /**
              * Create Node instances for S, P and O to build a Statement instance later on
              */
             $s = $this->createNodeByValueAndType($pattern['s'], $pattern['s_type']);
             $p = $this->createNodeByValueAndType($pattern['p'], $pattern['p_type']);
             $o = $this->createNodeByValueAndType($pattern['o'], $pattern['o_type']);
             $g = $this->createNodeByValueAndType($pattern['g'], $pattern['g_type']);
             $statementArray[] = $this->statementFactory->createStatement($s, $p, $o, $g);
         }
         // found quads and triples
     } elseif (true === isset($queryParts['triple_pattern']) && true === isset($queryParts['quad_pattern'])) {
         throw new \Exception('Query contains quads and triples. That is not supported yet.');
         // neither quads nor triples
     } else {
         throw new \Exception('Query contains neither quads nor triples.');
     }
     return $this->statementIteratorFactory->createIteratorFromArray($statementArray);
 }