/** * Get the value at the index. * @param index The index. */ public Object getObject(int index) { Tuple target = this; for(int i=size-1; i>index; i--) target = target.getLastTuple(); return target.getObject(); }
/** * Evaluate the constraints given the right object, left tuple * (null for alpha nodes) and the state. * @param right The right input object. * @param left The left input tuple. * @param state The working memory. */ public boolean evaluate(Object right, Tuple left, IOAVState state) { // System.out.println("Not match: "+left+", "+right); Tuple tright = (Tuple)right; int diff = tright.size() - left.size(); for(int i=0; i<diff; i++) tright = tright.getLastTuple(); return left.equals(tright); }
/** * Create a pattern matcher instance for a given state. */ public IPatternMatcherState createMatcherState(IOAVState state, AbstractAgenda agenda) { return new RetePatternMatcherState(node, state, new ReteMemory(state), agenda); }
/** * Create a new tuple. */ public Tuple(IOAVState state, Tuple last, Object object) { this.state = state; this.object = object; this.last = last; this.size = last==null? 1: last.size()+1; int hash = 31 + ((last == null) ? 0 : last.hashCode()); hash = 31 * hash + ((object == null) ? 0 : object.hashCode()); this.hashcode = hash; }
/** * Initialize the pattern matcher. * Called before the agenda is accessed * to perform any initialization, if necessary. */ public void init(IOAVState state, ReteMemory mem, AbstractAgenda agenda) { this.initial_fact_tuple = new Tuple(state, null, INITIAL_FACT); this.initial_fact_mem = Collections.singletonList(initial_fact_tuple); ITupleConsumerNode[] tcon = tconsumers; for(int i=0; tcon!=null && i<tcon.length; i++) tcon[i].addTuple(initial_fact_tuple, state, mem, agenda); }
/** * Get the value of an attribute from an object or tuple. * @param left The left input tuple. * @param right The right input object. * @param prefix The prefix input object (last value from previous extractor in a chain). * @param state The working memory. */ public Object getValue(Tuple left, Object right, Object prefix, IOAVState state) { // Fetch the virtual fact Object object = tupleindex==-1? right: left.getObject(tupleindex); if(!(object instanceof VirtualFact)) { throw new RuntimeException("Multiextractor can only work with virtual fact: "+object); } VirtualFact vf = (VirtualFact)object; return vf.getSubAttributeValue(attr, subindex); }
/** * Create an index tuple from a tuple. * The index tuple excludes the index position at * which the compression happens (and all elements * thereafter -> why, could be the last node?). * @param tuple The tuple. * @return The index tuple. */ protected Tuple createIndexTuple(IOAVState state, Tuple tuple, ReteMemory mem) { List obs = tuple.getObjects(); Tuple t = null; for(int i=0; i<obs.size(); i++) { if(i<tupleindex) t = mem.getTuple(state, t, obs.get(i)); // Create tuple from tuples } return t; }
/** * Get the string representation. * @return The string representation. */ public String toString() { return SReflect.getInnerClassName(this.getClass())+"(values="+getObjects()+")"; } }
/** * Get a tuple. * Returns an existing tuple from the cache, if present. * Otherwise a new one is created. */ public Tuple getTuple(IOAVState state, Tuple left, Object right) { return new Tuple(state, left, right); // Tuple ret; // Map lefties = (Map)tuplememory.get(left); // if(lefties==null) // { // lefties = new WeakHashMap(); // tuplememory.put(left, lefties); // ret = new Tuple(left, right); // lefties.put(right, ret); // } // else // { // ret = (Tuple)lefties.get(right); // if(ret==null) // { // ret = new Tuple(left, right); // lefties.put(right, ret); // } // } // return ret; }
/** * Evaluate the constraints given the right object, left tuple * (null for alpha nodes) and the state. * @param right The right input object. * @param left The left input tuple. * @param state The working memory. */ public boolean evaluate(Object right, Tuple left, IOAVState state) { // System.out.println("Not match: "+left+", "+right); Tuple tright = (Tuple)right; int diff = tright.size() - left.size(); for(int i=0; i<diff; i++) tright = tright.getLastTuple(); return left.equals(tright); }
/** * Get the value at the index. * @param index The index. */ public Object getObject(int index) { Tuple target = this; for(int i=size-1; i>index; i--) target = target.getLastTuple(); return target.getObject(); }
/** * Create a pattern matcher instance for a given state. */ public IPatternMatcherState createMatcherState(IOAVState state, AbstractAgenda agenda) { return new RetePatternMatcherState(node, state, new ReteMemory(state), agenda); }
/** * Create a new tuple. */ public Tuple(IOAVState state, Tuple last, Object object) { this.state = state; this.object = object; this.last = last; this.size = last==null? 1: last.size()+1; int hash = 31 + ((last == null) ? 0 : last.hashCode()); hash = 31 * hash + ((object == null) ? 0 : object.hashCode()); this.hashcode = hash; }
/** * Initialize the pattern matcher. * Called before the agenda is accessed * to perform any initialization, if necessary. */ public void init(IOAVState state, ReteMemory mem, AbstractAgenda agenda) { this.initial_fact_tuple = new Tuple(state, null, INITIAL_FACT); this.initial_fact_mem = Collections.singletonList(initial_fact_tuple); ITupleConsumerNode[] tcon = tconsumers; for(int i=0; tcon!=null && i<tcon.length; i++) tcon[i].addTuple(initial_fact_tuple, state, mem, agenda); }
/** * Get the value of an attribute from an object or tuple. * @param left The left input tuple. * @param right The right input object. * @param prefix The prefix input object (last value from previous extractor in a chain). * @param state The working memory. */ public Object getValue(Tuple left, Object right, Object prefix, IOAVState state) { // Fetch the virtual fact Object object = tupleindex==-1? right: left.getObject(tupleindex); if(!(object instanceof VirtualFact)) { throw new RuntimeException("Multiextractor can only work with virtual fact: "+object); } VirtualFact vf = (VirtualFact)object; return vf.getSubAttributeValue(attr, subindex); }
/** * Create an index tuple from a tuple. * The index tuple excludes the index position at * which the compression happens (and all elements * thereafter -> why, could be the last node?). * @param tuple The tuple. * @return The index tuple. */ protected Tuple createIndexTuple(IOAVState state, Tuple tuple, ReteMemory mem) { List obs = tuple.getObjects(); Tuple t = null; for(int i=0; i<obs.size(); i++) { if(i<tupleindex) t = mem.getTuple(state, t, obs.get(i)); // Create tuple from tuples } return t; }
/** * Get the string representation. * @return The string representation. */ public String toString() { return SReflect.getInnerClassName(this.getClass())+"(values="+getObjects()+")"; } }
/** * Get a tuple. * Returns an existing tuple from the cache, if present. * Otherwise a new one is created. */ public Tuple getTuple(IOAVState state, Tuple left, Object right) { return new Tuple(state, left, right); // Tuple ret; // Map lefties = (Map)tuplememory.get(left); // if(lefties==null) // { // lefties = new WeakHashMap(); // tuplememory.put(left, lefties); // ret = new Tuple(left, right); // lefties.put(right, ret); // } // else // { // ret = (Tuple)lefties.get(right); // if(ret==null) // { // ret = new Tuple(left, right); // lefties.put(right, ret); // } // } // return ret; }
/** * Get the values. */ public List getObjects() { List ret = new LinkedList(); Tuple current = this; while(current!=null) { ret.add(0, current.getObject()); current = current.getLastTuple(); } return ret; }
/** * Get the values. */ public List getObjects() { List ret = new LinkedList(); Tuple current = this; while(current!=null) { ret.add(0, current.getObject()); current = current.getLastTuple(); } return ret; }