/** * Return the number of distinct variables in the rule. Or more precisely, the * size of a binding environment needed to represent the rule. */ public int getNumVars() { if (numVars == -1) { // only have to do this if the rule was generated programatically // the parser will have prefilled this in for normal rules int max = findVars(body, -1); max = findVars(head, max); numVars = max + 1; } return numVars; }
/** * Return the number of distinct variables in the rule. Or more precisely, the * size of a binding environment needed to represent the rule. */ public int getNumVars() { if (numVars == -1) { // only have to do this if the rule was generated programatically // the parser will have prefilled this in for normal rules int max = findVars(body, -1); max = findVars(head, max); numVars = max + 1; } return numVars; }
/** * 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; }