/** * Match a pattern just against the stored data (raw data, schema, * axioms) but no derivation. */ @Override public ExtendedIterator<Triple> findDataMatches(TriplePattern pattern) { return dataFind.find(pattern); }
/** * 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 (second == null) { return first.find(pattern); } else if (first == null) { return second.find(pattern); } else { return first.findWithContinuation(pattern, second); } }
/** * Search the combination of data and deductions graphs for the given triple pattern. * This may different from the normal find operation in the base of hybrid reasoners * where we are side-stepping the backward deduction step. */ @Override public ExtendedIterator<Triple> findDataMatches(TriplePattern pattern) { return dataFind.find(pattern); }
/** * Search the combination of data and deductions graphs for the given triple pattern. * This may different from the normal find operation in the base of hybrid reasoners * where we are side-stepping the backward deduction step. */ @Override public ExtendedIterator<Triple> findDataMatches(Node subject, Node predicate, Node object) { return dataFind.find(new TriplePattern(subject, predicate, object)); }
/** * 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) { return (FinderUtil.cascade(first, second, continuation)).find(pattern); }
/** * Helper - returns the (singleton) value for the given property on the given * root node in the data graph. */ public static Node getPropValue(Node root, Node prop, Finder context) { return doGetPropValue(context.find(new TriplePattern(root, prop, null))); }
/** * Process all available data. This version expects that all the axioms * have already be preprocessed and the clause index already exists. * @param inserts the set of triples to be processed, normally this is the * raw data graph but may include additional deductions made by preprocessing hooks */ @Override public void fastInit(Finder inserts) { findAndProcessActions(); // Create the reasoning context BFRuleContext context = new BFRuleContext(infGraph); // Insert the data if (wildcardRule) { for (Iterator<Triple> i = inserts.find(new TriplePattern(null, null, null)); i.hasNext(); ) { context.addTriple(i.next()); } } else { for (Iterator<Node> p = predicatesUsed.iterator(); p.hasNext(); ) { Node predicate = p.next(); for (Iterator<Triple> i = inserts.find(new TriplePattern(null, predicate, null)); i.hasNext(); ) { context.addTriple(i.next()); } } } // Run the engine addSet(context); }
for (Iterator<Triple> i = inserts.find(new TriplePattern(null, null, null)); i.hasNext(); ) { addTriple( i.next(), false ); for (Map.Entry<Node, Node> ent : predicatePatterns.entrySet()) { for (Iterator<Triple> i = inserts.find(new TriplePattern(null, ent.getKey(), ent.getValue())); i.hasNext(); ) { Triple t = i.next(); addTriple(t, false);
/** * Extended find interface used in situations where the implementator * may or may not be able to answer the complete query. * <p> * In this case any query on the direct or closed predicates will * be assumed complete, any other query will pass on to the continuation.</p> * @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) { Node p = pattern.getPredicate(); if (p.isVariable()) { // wildcard predicate so return merge of cache and continuation return find(pattern).andThen(continuation.find(pattern)); } else if (p.equals(directPredicate) || p.equals(closedPredicate)) { // Satisfy entire query from the cache return find(pattern); } else { // No matching triples in this cache so just search the continuation return continuation.find(pattern); } }
/** * Cache all instances of the given predicate which are * present in the given Graph. * @param graph the searchable set of triples to cache * @param predicate the predicate to cache, need not be the registered * predicate due to subProperty declarations * @return returns true if new information has been cached */ public boolean cacheAll(Finder graph, Node predicate) { ExtendedIterator<Triple> it = graph.find(new TriplePattern(null, predicate, null)); boolean foundsome = it.hasNext(); while (it.hasNext()) { addRelation(it.next()); } it.close(); return foundsome; }
/** * 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) { checkOpen(); this.requirePrepared(); Finder cascade = transitiveEngine.getFinder(pattern, FinderUtil.cascade(tbox, continuation)); return cascade.find(pattern).filterKeep( new UniqueFilter<Triple>()); }
Iterator<Triple> it = dataFind.find(new TriplePattern(null, OWL.intersectionOf.asNode(), null)); while (it.hasNext()) { Triple decl = it.next();
Iterator<Triple> it = dataFind.find(new TriplePattern(null, OWL.intersectionOf.asNode(), null)); while (it.hasNext()) { Triple decl = it.next();
/** * 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)); } }
/** * Invoke the preprocessing hook. This will be called during the * preparation time of the hybrid reasoner. * @param infGraph the inference graph which is being prepared, * the hook code can use this to addDeductions or add additional * rules (using addRuleDuringPrepare). * @param dataFind the finder which packages up the raw data (both * schema and data bind) and any cached transitive closures. * @param inserts a temporary graph into which the hook should insert * all new deductions that should be seen by the rules. */ @Override public void run(FBRuleInfGraph infGraph, Finder dataFind, Graph inserts) { ExtendedIterator<Triple> it = dataFind.find(new TriplePattern(null, null, null)); HashSet<Node> properties = new HashSet<Node>(); while (it.hasNext()) { Triple triple = it.next(); Node prop = triple.getPredicate(); if (prop.equals(RDF.Nodes.type) && triple.getObject().equals(RDF.Nodes.Property) ) { prop = triple.getSubject(); } if (properties.add(prop)) { if (prop.getURI().startsWith(memberPrefix)) { // A container property inserts.add(new Triple(prop, RDF.Nodes.type, RDFS.Nodes.ContainerMembershipProperty)); } } } }
/** * 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 synchronized ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder continuation) { checkOpen(); this.requirePrepared(); ExtendedIterator<Triple> result = engine.find(pattern).filterKeep( new UniqueFilter<Triple>()); if (continuation != null) { result = result.andThen(continuation.find(pattern)); } return result.filterDrop(Functor.acceptFilter); }
@Override public ExtendedIterator<Triple> findWithContinuation(TriplePattern pattern, Finder finder) { prepare(); Node subject = pattern.getSubject(); Node predicate = pattern.getPredicate(); Node object = pattern.getObject(); ExtendedIterator<Triple> i = GraphQueryHandler.findTriple( kb, this, subject, predicate, object ); // always look at asserted triples at the end if( finder != null ) { TriplePattern tp = new TriplePattern( subject, predicate, object ); i = i.andThen( finder.find( tp ) ); } // make sure we don't have duplicates return UniqueExtendedIterator.create( i ); }
/** * 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) { checkOpen(); this.requirePrepared(); ExtendedIterator<Triple> result =bEngine.find(pattern).filterKeep( new UniqueFilter<Triple>()); if (continuation != null) { result = result.andThen(continuation.find(pattern)); } if (filterFunctors) { // return result.filterDrop(Functor.acceptFilter); return result.filterDrop( new Filter<Triple>() { @Override public boolean accept( Triple o ) { return FBRuleInfGraph.this.accept( o ); }} ); } else { return result; } }