/** * 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()); }
/** * emit the code for the head clause */ void emitHead(TriplePattern head) { if (permanentVars.size() > 0) { code[p++] = ALLOCATE; code[p++] = (byte)permanentVars.size(); } emitHeadGet(head.getSubject(), 0); emitHeadGet(head.getPredicate(), 1); emitHeadGet(head.getObject(), 2); }
/** * 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()); }
/** * emit the code for the head clause */ void emitHead(TriplePattern head) { if (permanentVars.size() > 0) { code[p++] = ALLOCATE; code[p++] = (byte)permanentVars.size(); } emitHeadGet(head.getSubject(), 0); emitHeadGet(head.getPredicate(), 1); emitHeadGet(head.getObject(), 2); }
/** * 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; } }
/** * 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()) + ")"; }
/** * 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()) + ")"; }
/** * Return a dereferenced copy of a triple. */ public static Triple deref(TriplePattern t) { if (t == null) return null; return new Triple(deref(t.getSubject()), deref(t.getPredicate()), deref(t.getObject())); }
/** * 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 bindings */ public TriplePattern partInstantiate(TriplePattern goal) { return new TriplePattern( getGroundVersion(goal.getSubject()), getGroundVersion(goal.getPredicate()), getGroundVersion(goal.getObject()) ); }
/** * Return a dereferenced copy of a triple. */ public static Triple deref(TriplePattern t) { if (t == null) return null; return new Triple(deref(t.getSubject()), deref(t.getPredicate()), deref(t.getObject())); }
/** * 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 bindings */ public TriplePattern partInstantiate(TriplePattern goal) { return new TriplePattern( getGroundVersion(goal.getSubject()), getGroundVersion(goal.getPredicate()), getGroundVersion(goal.getObject()) ); }
/** * 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); } }
/** * 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); } }
/** * Find all the variables in a TriplePattern. */ private int findVars(TriplePattern t, int maxIn) { int max = maxIn; max = maxVarIndex(t.getSubject(), max); max = maxVarIndex(t.getPredicate(), max); Node obj = t.getObject(); if (obj instanceof Node_RuleVariable) { max = maxVarIndex(obj, max); } else if (Functor.isFunctor(obj)) { max = findVars((Functor)obj.getLiteralValue(), max); } return max; }
/** * Find all the variables in a TriplePattern. */ private int findVars(TriplePattern t, int maxIn) { int max = maxIn; max = maxVarIndex(t.getSubject(), max); max = maxVarIndex(t.getPredicate(), max); Node obj = t.getObject(); if (obj instanceof Node_RuleVariable) { max = maxVarIndex(obj, max); } else if (Functor.isFunctor(obj)) { max = findVars((Functor)obj.getLiteralValue(), max); } return max; }
/** * Instantiate a triple pattern against the current environment. * This version handles unbound variables by turning them into bNodes. * @param pattern the triple pattern to match * @return a new, instantiated triple */ @Override public Triple instantiate(TriplePattern pattern) { Node s = getGroundVersion(pattern.getSubject()); if (s.isVariable()) s = NodeFactory.createBlankNode(); Node p = getGroundVersion(pattern.getPredicate()); if (p.isVariable()) p = NodeFactory.createBlankNode(); Node o = getGroundVersion(pattern.getObject()); if (o.isVariable()) o = NodeFactory.createBlankNode(); return new Triple(s, p, o); }
/** * Instantiate a triple pattern against the current environment. * This version handles unbound variables by turning them into bNodes. * @param pattern the triple pattern to match * @return a new, instantiated triple */ @Override public Triple instantiate(TriplePattern pattern) { Node s = getGroundVersion(pattern.getSubject()); if (s.isVariable()) s = NodeFactory.createBlankNode(); Node p = getGroundVersion(pattern.getPredicate()); if (p.isVariable()) p = NodeFactory.createBlankNode(); Node o = getGroundVersion(pattern.getObject()); if (o.isVariable()) o = NodeFactory.createBlankNode(); return new Triple(s, p, o); }
/** * Instantiate a triple pattern against the current environment. * This version handles unbound variables by turning them into bNodes. * @param pattern the triple pattern to match * @return a new, instantiated triple */ @Override public Triple instantiate(TriplePattern pattern) { Node s = getGroundVersion(pattern.getSubject()); if (s.isVariable()) s = NodeFactory.createBlankNode(); Node p = getGroundVersion(pattern.getPredicate()); if (p.isVariable()) p = NodeFactory.createBlankNode(); Node o = getGroundVersion(pattern.getObject()); if (o.isVariable()) o = NodeFactory.createBlankNode(); return new Triple(s, p, o); }
/** * Instantiate a triple pattern against the current environment. * This version handles unbound variables by turning them into bNodes. * @param pattern the triple pattern to match * @return a new, instantiated triple */ @Override public Triple instantiate(TriplePattern pattern) { Node s = getGroundVersion(pattern.getSubject()); if (s.isVariable()) s = NodeFactory.createBlankNode(); Node p = getGroundVersion(pattern.getPredicate()); if (p.isVariable()) p = NodeFactory.createBlankNode(); Node o = getGroundVersion(pattern.getObject()); if (o.isVariable()) o = NodeFactory.createBlankNode(); return new Triple(s, p, o); }
/** * Instantiate a triple pattern against the current environment. * This version handles unbound variables by turning them into bNodes. * @param pattern the triple pattern to match * @return a new, instantiated triple */ @Override public Triple instantiate(TriplePattern pattern) { Node s = getGroundVersion(pattern.getSubject()); if (s.isVariable()) s = NodeFactory.createBlankNode(); Node p = getGroundVersion(pattern.getPredicate()); if (p.isVariable()) p = NodeFactory.createBlankNode(); Node o = getGroundVersion(pattern.getObject()); if (o.isVariable()) o = NodeFactory.createBlankNode(); return new Triple(s, p, o); }