1 10 package com.hp.hpl.jena.reasoner.rulesys.impl; 11 12 import com.hp.hpl.jena.graph.*; 13 import com.hp.hpl.jena.reasoner.TriplePattern; 14 import com.hp.hpl.jena.reasoner.rulesys.BindingEnvironment; 15 import com.hp.hpl.jena.reasoner.rulesys.Node_RuleVariable; 16 17 24 public class LPBindingEnvironment implements BindingEnvironment { 25 26 27 protected LPInterpreter interpreter; 28 29 32 public LPBindingEnvironment(LPInterpreter interpeter) { 33 this.interpreter = interpeter; 34 } 35 36 41 public Node getGroundVersion(Node node) { 42 return LPInterpreter.deref(node); 43 } 44 45 52 public boolean bind(Node var, Node value) { 53 Node dvar = var; 54 if (dvar instanceof Node_RuleVariable) dvar = ((Node_RuleVariable)dvar).deref(); 55 if (dvar instanceof Node_RuleVariable) { 56 interpreter.bind(dvar, value); 57 return true; 58 } else { 59 return var.sameValueAs(value); 60 } 61 62 } 63 64 65 72 public Triple instantiate(TriplePattern pattern) { 73 Node s = getGroundVersion(pattern.getSubject()); 74 if (s.isVariable()) s = Node.createAnon(); 75 Node p = getGroundVersion(pattern.getPredicate()); 76 if (p.isVariable()) p = Node.createAnon(); 77 Node o = getGroundVersion(pattern.getObject()); 78 if (o.isVariable()) o = Node.createAnon(); 79 return new Triple(s, p, o); 80 } 81 82 83 } 84 85 86 | Popular Tags |