コード例 #1
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 (null !== $graph) {
         $graphUri = $graph->getUri();
         // no graph information given, use default graph
     } elseif (null === $graph && null === $statement->getGraph()) {
         $graphUri = 'http://saft/defaultGraph/';
         // no graph given, use graph information from $statement
     } elseif (null === $graph && $statement->getGraph()->isNamed()) {
         $graphUri = $statement->getGraph()->getUri();
         // no graph given, use graph information from $statement
     } elseif (null === $graph && false == $statement->getGraph()->isNamed()) {
         $graphUri = 'http://saft/defaultGraph/';
     }
     // use hash to differenciate between statements (no doublings allowed)
     $statementHash = hash('sha256', json_encode($statement));
     // check it
     return isset($this->statements[$graphUri][$statementHash]);
 }
コード例 #2
0
ファイル: ARC2.php プロジェクト: guitarmarx/Saft
 /**
  * Adds multiple Statements to (default-) graph. It overrides parents addStatements because ARC2 only
  * supports SPARQL+ and not SPARQL Update 1.1, which means an INSERT INTO query has to look like:
  * INSERT INTO <http://graph/> { triple ... }.
  *
  * @param  StatementIterator|array $statements       StatementList instance must contain Statement
  *                                                   instances which are 'concret-' and not
  *                                                   'pattern'-statements.
  * @param  Node                    $graph   optional Overrides target graph. If set, all statements
  *                                                   will be add to that graph, if it is available.
  * @param  array                   $options optional Key-value pairs which provide additional
  *                                                   introductions for the store and/or its
  *                                                   adapter(s).
  */
 public function addStatements($statements, Node $graph = null, array $options = array())
 {
     $graphUriToUse = null;
     foreach ($statements as $statement) {
         if (!$statement->isConcrete()) {
             // non-concrete Statement instances not allowed
             // we have to undo the transaction somehow
             throw new \Exception('At least one Statement is not concrete');
         }
         if (null !== $graph) {
             // given $graph forces usage of it and not the graph from the statement instance
             $graphUriToUse = $graph->getUri();
         } elseif (null !== $statement->getGraph()) {
             // use graphUri from statement
             $graphUriToUse = $statement->getGraph()->getUri();
         }
         // else: non-concrete Statement instances not allowed
         $this->query('INSERT INTO <' . $graphUriToUse . '> {' . SparqlUtils::getNodeInSparqlFormat($statement->getSubject()) . ' ' . SparqlUtils::getNodeInSparqlFormat($statement->getPredicate()) . ' ' . SparqlUtils::getNodeInSparqlFormat($statement->getObject()) . ' . ' . '}', $options);
     }
 }
コード例 #3
0
ファイル: Virtuoso.php プロジェクト: guitarmarx/Saft
 /**
  * Checks if a certain graph is available in the store.
  *
  * @param  Node $graph URI of the graph to check if it is available.
  * @return boolean True if graph is available, false otherwise.
  */
 public function isGraphAvailable(Node $graph)
 {
     $graphs = $this->getGraphs();
     return isset($graphs[$graph->getUri()]);
 }
コード例 #4
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) {
         $graphUriToUse = $graph->getUri();
         // use graphUri from statement
     } elseif (null !== $statement->getGraph()) {
         $graph = $statement->getGraph();
         $graphUriToUse = $graph->getUri();
     }
     $statementIterator = $this->statementIteratorFactory->createIteratorFromArray(array($statement));
     $this->query('DELETE WHERE { ' . $this->sparqlFormat($statementIterator, $graph) . '}', $options);
 }
コード例 #5
0
ファイル: QueryCache.php プロジェクト: guitarmarx/Saft
 /**
  * redirects to the query method.
  * 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.
  * @todo cache ask queries
  */
 public function hasMatchingStatement(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' => 'hasMatchingStatement', 'parameter' => array('statement' => $statement, 'graphUri' => $graphUri, 'options' => $options)));
     /**
      * build matching query and check for cache entry
      */
     // create shortcuts for S, P and O
     $s = $statement->getSubject();
     $p = $statement->getPredicate();
     $o = $statement->getObject();
     $query = '';
     // add filter, if subject is a named node or literal
     if (true === $s->isNamed()) {
         $query .= 'FILTER (str(?s) = "' . $s->getUri() . '") ';
     }
     // add filter, if predicate is a named node or literal
     if (true === $p->isNamed()) {
         $query .= 'FILTER (str(?p) = "' . $p->getUri() . '") ';
     }
     // add filter, if predicate is a named node or literal
     if (true === $o->isNamed()) {
         $query .= 'FILTER (str(?o) = "' . $o->getUri() . '") ';
     }
     if (true == $o->isLiteral()) {
         $query .= 'FILTER (str(?o) = ' . $o->getValue() . ') ';
     }
     $query = 'ASK FROM <' . $graphUri . '> { ?s ?p ?o ' . $query . '}';
     $queryCacheContainer = $this->cache->load($query);
     // check, if there is a cache entry for this statement
     if (null !== $queryCacheContainer) {
         return $queryCacheContainer['result'];
         // if successor is set, ask it first before run the command yourself.
     } elseif ($this->successor instanceof Store) {
         $result = $this->successor->hasMatchingStatement($statement, $graph, $options);
         $this->saveResult($this->queryFactory->createInstanceByQueryString($query), $result);
         return $result;
         // dont run command by myself
     } else {
         throw new \Exception('QueryCache does not support has matching statement calls, only by successor.');
     }
 }
コード例 #6
0
ファイル: NodeFactory.php プロジェクト: guitarmarx/Saft
 public function createRedlandNodeFromNode(Node $node)
 {
     if ($node instanceof NamedNode || $node instanceof Literal || $node instanceof BlankNode) {
         return $node->getRedlandNode();
     } elseif ($node->isNamed()) {
         return $this->createNamedNode($node->getUri())->getRedlandNode();
     } elseif ($node->isLiteral()) {
         return $this->createLiteral($node->getValue(), $node->getDatatype(), $node->getLanguage())->getRedlandNode();
     } elseif ($node->isBlank()) {
         return $this->createBlankNode($node->getBlankId())->getRedlandNode();
     }
     throw new \Exception("This node type (" . get_class($node) . ") is not supported by Redland backend");
 }