/** * 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 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; }
/** * 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); }
if(next.getLastTuple().equals(left)) System.out.println("error: "+this+" "+next); assert !next.getLastTuple().equals(left) : "Tuple not removed: "+left+", "+this;
List obs = left.getObjects(); for(int i=0; i<obs.size(); i++) Object newob = left.getObject(tupleindex); Set vals = (Set)resulttuple.getObject(tupleindex); if(vals.contains(newob)) throw new UnsupportedOperationException("Multiple matches to same object not supported: "+newob);
/** * Get the string representation. * @return The string representation. */ public String toString() { return SReflect.getInnerClassName(this.getClass())+"(values="+getObjects()+")"; } }
/** * Propagate an object change to this node. * @param right The new object. */ public void modifyObject(Object right, OAVAttributeType type, Object oldvalue, Object newvalue, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { if(!getRelevantAttributes().contains(type)) return; super.modifyObject(right, type, oldvalue, newvalue, state, mem, agenda); if(!isAffected(type)) { Collection tmem = fetchTupleMemory(state, right, mem); if(tmem!=null) { for(Iterator it=tmem.iterator(); it.hasNext(); ) { Tuple left = (Tuple)it.next(); boolean contains = isMatchContained(state, left, right, mem); // Tuple changed in memory -> propagate modification if(contains) propagateModification(left, right, left.size(), type, oldvalue, newvalue, 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 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; }
if(next.getLastTuple().equals(left)) System.out.println("error: "+this+" "+next); assert !next.getLastTuple().equals(left) : "Tuple not removed: "+left+", "+this;
List obs = left.getObjects(); for(int i=0; i<obs.size(); i++) Object newob = left.getObject(tupleindex); Set vals = (Set)resulttuple.getObject(tupleindex); if(vals.contains(newob)) throw new UnsupportedOperationException("Multiple matches to same object not supported: "+newob);
/** * Get the string representation. * @return The string representation. */ public String toString() { return SReflect.getInnerClassName(this.getClass())+"(values="+getObjects()+")"; } }
/** * Propagate an object change to this node. * @param right The new object. */ public void modifyObject(Object right, OAVAttributeType type, Object oldvalue, Object newvalue, IOAVState state, ReteMemory mem, AbstractAgenda agenda) { if(!getRelevantAttributes().contains(type)) return; super.modifyObject(right, type, oldvalue, newvalue, state, mem, agenda); if(!isAffected(type)) { Collection tmem = fetchTupleMemory(state, right, mem); if(tmem!=null) { for(Iterator it=tmem.iterator(); it.hasNext(); ) { Tuple left = (Tuple)it.next(); boolean contains = isMatchContained(state, left, right, mem); // Tuple changed in memory -> propagate modification if(contains) propagateModification(left, right, left.size(), type, oldvalue, newvalue, state, mem, agenda); } } } }
/** * 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(); }
/** * Check the consistency of the node. */ public boolean checkNodeConsistency(ReteMemory mem) { boolean consistent = true; Collection tuples = getNodeMemory(mem); Collection objects = getObjectSource().getNodeMemory(mem); if(tuples!=null) { for(Iterator it=tuples.iterator(); consistent && it.hasNext(); ) { Tuple tuple = (Tuple)it.next(); consistent = objects.contains(tuple.getObject()); } } Object node = this; while(node instanceof IObjectConsumerNode) node = ((IObjectConsumerNode)node).getObjectSource(); ((ReteNode)node).checked.add(this); return consistent; } }
/** * 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 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; }