Пример #1
0
 /**
  * Extended find interface used in situations where the implementator may or may not be able to
  * answer the complete query. It will attempt to answer the pattern but if its answers are not
  * known to be complete then it will also pass the request on to the nested Finder to append more
  * results.
  *
  * @param pattern a TriplePattern to be matched against the data
  * @param continuation either a Finder or a normal Graph which will be asked for additional match
  *     results if the implementor may not have completely satisfied the query.
  */
 @Override
 public ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder continuation) {
   if (graph == null) return new NullIterator<Triple>();
   if (continuation == null) {
     return graph.find(pattern.asTripleMatch());
   } else {
     return graph.find(pattern.asTripleMatch()).andThen(continuation.find(pattern));
   }
 }
Пример #2
0
 /**
  * @param mGraph
  * @return
  */
 protected static Graph getHiddenTriples(Model m) {
   Graph mGraph = m.getGraph();
   final Reifier r = mGraph.getReifier();
   return new GraphBase() {
     public ExtendedIterator graphBaseFind(TripleMatch m) {
       return r.findEither(m, true);
     }
   };
 }
 /** Removes the triple t (if possible) from the set belonging to this graph. */
 @Override
 public void performDelete(Triple t) {
   version++;
   if (fdata != null) {
     Graph data = fdata.getGraph();
     if (data != null) {
       data.delete(t);
     }
   }
   if (isPrepared) {
     fdeductions.getGraph().delete(t);
   }
 }
 /**
  * Adds a set of precomputed triples to the deductions store. These do not, themselves, fire any
  * rules but provide additional axioms that might enable future rule firing when real data is
  * added. Used to implement bindSchema processing in the parent Reasoner.
  *
  * @return return true if the rule set has also been loaded
  */
 protected boolean preloadDeductions(Graph preloadIn) {
   Graph d = fdeductions.getGraph();
   BasicForwardRuleInfGraph preload = (BasicForwardRuleInfGraph) preloadIn;
   // If the rule set is the same we can reuse those as well
   if (preload.rules == rules) {
     // Load raw deductions
     for (Iterator<Triple> i = preload.find(null, null, null); i.hasNext(); ) {
       d.add(i.next());
     }
     engine.setRuleStore(preload.engine.getRuleStore());
     return true;
   } else {
     return false;
   }
 }
 private void addStages(ArrayList<Stage> stages, NamedGraphMap arguments, Mapping map) {
   Iterator<Map.Entry<String, Cons>> it2 = triples.entrySetIterator();
   while (it2.hasNext()) {
     Map.Entry<String, Cons> e = it2.next();
     String name = e.getKey();
     Cons nodeTriples = e.getValue();
     Graph g = arguments.get(name);
     int nBlocks = Cons.size(nodeTriples), i = nBlocks;
     Triple[] nodes = new Triple[nBlocks];
     while (nodeTriples != null) {
       nodes[--i] = nodeTriples.head;
       nodeTriples = nodeTriples.tail;
     }
     nodes = sortTriples(nodes);
     Stage next = g.queryHandler().patternStage(map, constraint, nodes);
     stages.add(next);
   }
 }
 /**
  * Create the graph used to hold the deductions. Can be overridden by subclasses that need special
  * purpose graph implementations here. Assumes the graph underlying fdeductions and associated
  * SafeGraph wrapper can be reused if present thus enabling preservation of listeners.
  */
 protected Graph createDeductionsGraph() {
   if (fdeductions != null) {
     Graph dg = fdeductions.getGraph();
     if (dg != null) {
       // Reuse the old graph in order to preserve any listeners
       safeDeductions.getBulkUpdateHandler().removeAll();
       return dg;
     }
   }
   Graph dg = Factory.createGraphMem(style);
   safeDeductions = new SafeGraph(dg);
   return dg;
 }
Пример #7
0
 /** Return true if the given pattern occurs somewhere in the find sequence. */
 @Override
 public boolean contains(TriplePattern pattern) {
   return graph.contains(pattern.getSubject(), pattern.getPredicate(), pattern.getObject());
 }
Пример #8
0
 /**
  * Basic pattern lookup interface.
  *
  * @param pattern a TriplePattern to be matched against the data
  * @return a ClosableIterator over all Triples in the data set that match the pattern
  */
 @Override
 public ExtendedIterator<Triple> find(TriplePattern pattern) {
   if (graph == null) return new NullIterator<Triple>();
   return graph.find(pattern.asTripleMatch());
 }
 /**
  * this is a simple-minded implementation of containsNode that uses find up to three times to
  * locate the node. Almost certainly particular graphs will be able to offer better query-handlers
  * ...
  */
 public boolean containsNode(Node n) {
   return graph.contains(n, Node.ANY, Node.ANY)
       || graph.contains(Node.ANY, n, Node.ANY)
       || graph.contains(Node.ANY, Node.ANY, n);
 }
Пример #10
0
 public static ExtendedIterator predicatesFor(Graph g, Node s, Node o) {
   Set predicates = CollectionFactory.createHashedSet();
   ClosableIterator it = g.find(s, Node.ANY, o);
   while (it.hasNext()) predicates.add(((Triple) it.next()).getPredicate());
   return WrappedIterator.createNoRemove(predicates.iterator());
 }
Пример #11
0
 public static ExtendedIterator subjectsFor(Graph g, Node p, Node o) {
   Set objects = CollectionFactory.createHashedSet();
   ClosableIterator it = g.find(Node.ANY, p, o);
   while (it.hasNext()) objects.add(((Triple) it.next()).getSubject());
   return WrappedIterator.createNoRemove(objects.iterator());
 }