/** * Translate a program counter offset to the index of the corresponding * body term (or -1 if a head term or a dummy rule). */ public int termIndex(int pc) { if (rule == null) return -1; int term = 0; // Trivial linear search because this is only used for logging which is // horribly expensive anyway. while (term < rule.bodyLength()) { if (pc <= termStart[term]) { return term - 1; } term++; } return term - 1; }
/** * Translate a program counter offset to the index of the corresponding * body term (or -1 if a head term or a dummy rule). */ public int termIndex(int pc) { if (rule == null) return -1; int term = 0; // Trivial linear search because this is only used for logging which is // horribly expensive anyway. while (term < rule.bodyLength()) { if (pc <= termStart[term]) { return term - 1; } term++; } return term - 1; }
/** * Constructor. */ CompileState(Rule rule) { classifyVariables(rule); this.rule = rule; // Create a scratch area for assembling the code, use a worst-case size estimate code = new byte[10 + totalOccurrences + rule.bodyLength()*10]; args = new ArrayList<>(); }
/** * Constructor. */ CompileState(Rule rule) { classifyVariables(rule); this.rule = rule; // Create a scratch area for assembling the code, use a worst-case size estimate code = new byte[10 + totalOccurrences + rule.bodyLength()*10]; args = new ArrayList<>(); }
/** * Scan the initial rule set and pick out all the backward-only rules with non-null bodies, * and transfer these rules to the backward engine. */ private static List<Rule> extractPureBackwardRules(List<Rule> rules) { List<Rule> bRules = new ArrayList<>(); for ( Rule r : rules ) { if ( r.isBackward() && r.bodyLength() > 0 ) { bRules.add( r ); } } return bRules; }
/** * Scan the initial rule set and pick out all the backward-only rules with non-null bodies, * and transfer these rules to the backward engine. */ private static List<Rule> extractPureBackwardRules(List<Rule> rules) { List<Rule> bRules = new ArrayList<>(); for ( Rule r : rules ) { if ( r.isBackward() && r.bodyLength() > 0 ) { bRules.add( r ); } } return bRules; }
/** * Constructor * @param clause the compiled code being interpreted by this env frame */ public EnvironmentFrameWithDerivation(RuleClauseCode clause) { super(clause); if (clause.getRule() != null) { matches = new TriplePattern[clause.getRule().bodyLength()]; } }
/** * Constructor * @param clause the compiled code being interpreted by this env frame */ public EnvironmentFrameWithDerivation(RuleClauseCode clause) { super(clause); if (clause.getRule() != null) { matches = new TriplePattern[clause.getRule().bodyLength()]; } }
/** * Check whether the rule should fire in this context. */ public boolean shouldFire(boolean allowUnsafe) { // Check any non-pattern clauses for (int i = 0; i < rule.bodyLength(); i++) { Object clause = rule.getBodyElement(i); if (clause instanceof Functor) { // Fire a built in if (allowUnsafe) { if (!((Functor)clause).evalAsBodyClause(this)) { // Failed guard so just discard and return return false; } } else { // Don't re-run side-effectful clause on a re-run if (!((Functor)clause).safeEvalAsBodyClause(this)) { // Failed guard so just discard and return return false; } } } } return true; }
/** * Check whether the rule should fire in this context. */ public boolean shouldFire(boolean allowUnsafe) { // Check any non-pattern clauses for (int i = 0; i < rule.bodyLength(); i++) { Object clause = rule.getBodyElement(i); if (clause instanceof Functor) { // Fire a built in if (allowUnsafe) { if (!((Functor)clause).evalAsBodyClause(this)) { // Failed guard so just discard and return return false; } } else { // Don't re-run side-effectful clause on a re-run if (!((Functor)clause).safeEvalAsBodyClause(this)) { // Failed guard so just discard and return return false; } } } } return true; }
/** * Check if a rule from the conflict set is still OK to fire. * Just checks the non-monotonic guards such as noValue. */ public boolean shouldStillFire() { // Check any non-pattern clauses for (int i = 0; i < rule.bodyLength(); i++) { Object clause = rule.getBodyElement(i); if (clause instanceof Functor) { Builtin builtin = ((Functor)clause).getImplementor(); if (builtin != null && !builtin.isMonotonic()) { if (!((Functor)clause).evalAsBodyClause(this)) { return false; } } } } return true; }
/** * Check if a rule from the conflict set is still OK to fire. * Just checks the non-monotonic guards such as noValue. */ public boolean shouldStillFire() { // Check any non-pattern clauses for (int i = 0; i < rule.bodyLength(); i++) { Object clause = rule.getBodyElement(i); if (clause instanceof Functor) { Builtin builtin = ((Functor)clause).getImplementor(); if (builtin != null && !builtin.isMonotonic()) { if (!((Functor)clause).evalAsBodyClause(this)) { return false; } } } } return true; }
while (i < rule.bodyLength()) { ClauseEntry term = rule.getBodyElement(i); if (term instanceof Functor) {
termStart = new int[rule.bodyLength()]; for (int i = skip; i < rule.bodyLength(); i++) { termStart[i] = state.p; ClauseEntry entry = rule.getBodyElement(i);
termStart = new int[rule.bodyLength()]; for (int i = skip; i < rule.bodyLength(); i++) { termStart[i] = state.p; ClauseEntry entry = rule.getBodyElement(i);
/** * Scan the rules for any axioms and insert those */ protected void findAndProcessAxioms() { BFRuleContext context = new BFRuleContext(infGraph); for ( Rule r : rules ) { if ( r.bodyLength() == 0 ) { // An axiom for ( int j = 0; j < r.headLength(); j++ ) { Object head = r.getHeadElement( j ); if ( head instanceof TriplePattern ) { TriplePattern h = (TriplePattern) head; Triple t = new Triple( h.getSubject(), h.getPredicate(), h.getObject() ); context.addTriple( t ); infGraph.getDeductionsGraph().add( t ); } } } } addSet(context); processedAxioms = true; }
/** * Scan the rules for any axioms and insert those */ protected void findAndProcessAxioms() { BFRuleContext context = new BFRuleContext(infGraph); for ( Rule r : rules ) { if ( r.bodyLength() == 0 ) { // An axiom for ( int j = 0; j < r.headLength(); j++ ) { Object head = r.getHeadElement( j ); if ( head instanceof TriplePattern ) { TriplePattern h = (TriplePattern) head; Triple t = new Triple( h.getSubject(), h.getPredicate(), h.getObject() ); context.addTriple( t ); infGraph.getDeductionsGraph().add( t ); } } } } addSet(context); processedAxioms = true; }
for ( Rule r : rules ) if ( r.bodyLength() == 0 )
for ( Rule r : rules ) if ( r.bodyLength() == 0 )
for ( Rule r : rules ) if ( r.bodyLength() == 0 )