private TriplePattern makeSubOfSomeTriple(Node t1, Node p, Node t2) { return new TriplePattern(t1, p, t2); }
/** * 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()); }
/** * 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()); }
/** * Bind the variables in a goal pattern using the binding environment, to * generate a more specialized goal * @param goal the TriplePattern to be instantiated * @return a TriplePattern obtained from the goal by substituting current bindinds */ public TriplePattern partInstantiate(TriplePattern goal) { return new TriplePattern( getGroundVersion(goal.getSubject()), getGroundVersion(goal.getPredicate()), getGroundVersion(goal.getObject()) ); }
/** * Return an ordered list of RuleClauseCode objects to implement the given * query pattern. This may use indexing to narrow the rule set more that the predicate-only case. * @param goal the triple pattern that makes up the query */ public List<RuleClauseCode> codeFor(TriplePattern goal) { List<RuleClauseCode> allRules = codeFor(goal.getPredicate()); if (allRules == null) { return allRules; } Map<Node, List<RuleClauseCode>> indexedCodeTable = indexPredicateToCodeMap.get(goal.getPredicate()); if (indexedCodeTable != null) { List<RuleClauseCode> indexedCode = indexedCodeTable.get(goal.getObject()); if (indexedCode != null) { return indexedCode; } } return allRules; }
envFrame.pVars[0] = argVars[0] = standardize(goal.getSubject(), mappedVars); envFrame.pVars[1] = argVars[1] = standardize(goal.getPredicate(), mappedVars); envFrame.pVars[2] = argVars[2] = standardize(goal.getObject(), mappedVars); if (engine.getDerivationLogging()) { ((EnvironmentFrameWithDerivation)envFrame).initDerivationRecord(argVars); setupClauseCall(0, 0, clauses, goal.isGround());
/** * Return true if the given goal is tabled, currently this is true if the * predicate is a tabled predicate or the predicate is a wildcard and some * tabled predictes exist. */ public boolean isTabled(TriplePattern goal) { return isTabled(goal.getPredicate()); }
ClauseEntry axiom = rule.getHeadElement(j); if (axiom instanceof TriplePattern) { axioms.add(((TriplePattern)axiom).asTriple()); } else if (axiom instanceof Functor) { if (contextForBuiltins == null) {
/** * Clone a clause, cloning any embedded variables. */ private ClauseEntry cloneClause(ClauseEntry clause, Map<Node_RuleVariable, Node> vmap, BindingEnvironment env) { if (clause instanceof TriplePattern) { TriplePattern tp = (TriplePattern)clause; return new TriplePattern ( cloneNode(tp.getSubject(), vmap, env), cloneNode(tp.getPredicate(), vmap, env), cloneNode(tp.getObject(), vmap, env) ); } else { return cloneFunctor((Functor)clause, vmap, env); } }
RuleClauseCode code = new RuleClauseCode(r); allRuleClauseCodes.add(code); Node predicate = ((TriplePattern)term).getPredicate(); if (predicate.isVariable()) { predicate = Node_RuleVariable.WILD; boolean indexed = false; if (head instanceof TriplePattern) { Node objectPattern = ((TriplePattern)head).getObject(); if (!objectPattern.isVariable() && !Functor.isFunctor(objectPattern)) {
/** * Return a Finder instance appropriate for the given query. */ public Finder getFinder(TriplePattern pattern, Finder continuation) { if (!isPrepared) prepare(); Node predicate = pattern.getPredicate(); if (predicate.isVariable()) { // Want everything in the cache, the tbox and the continuation return FinderUtil.cascade(subPropertyCache, subClassCache, continuation); } else if (subPropertyAliases.contains(predicate)) { return subPropertyCache; } else if (subClassAliases.contains(predicate)) { return subClassCache; } else { return continuation; } }
if (head instanceof TriplePattern) { TriplePattern h = (TriplePattern) head; transitiveEngine.add(h.asTriple());
private TriplePattern makeSubOfSomeTriple(Node t1, Node p, Node t2) { return new TriplePattern(t1, p, t2); }
/** * Return the argument index of the given variable. */ int aIndex(Node n) { TriplePattern tp = (TriplePattern)rule.getHeadElement(0); if (tp.getSubject() == n) { return 0; } else if (tp.getPredicate() == n) { return 1; } else if (tp.getObject() == n) { return 2; } else { return -1; } }
@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 ); }
Node predicate = ((TriplePattern)clause).getPredicate(); Node object = ((TriplePattern)clause).getObject(); if (predicate.isVariable()) { clauseIndex.put(Node.ANY, clauseNode);
/** * Return a list of rules that match the given goal pattern * @param goal the goal being matched */ public List<Rule> rulesFor(TriplePattern goal) { List<Rule> rules = new ArrayList<Rule>(); if (goal.getPredicate().isVariable()) { checkAll(goalMap.values().iterator(), goal, rules); } else { checkAll(goalMap.getAll(goal.getPredicate()), goal, rules); checkAll(goalMap.getAll(Node.ANY), goal, rules); } return rules; }
/** * 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)); } }
private TriplePattern makeSubclassTriple(Node t1, Node t2) { return new TriplePattern(t1, PRED_SUB, t2); }
/** * Return a simplified print string for a TriplePattern */ public static String print(TriplePattern triple) { if (triple == null) return "(null)"; return "(" + print(triple.getSubject()) + " " + print(triple.getPredicate()) + " " + print(triple.getObject()) + ")"; }