org.jactr.tools.analysis.production.endstates.impl
Class BufferStateUtilities

java.lang.Object
  extended by org.jactr.tools.analysis.production.endstates.impl.BufferStateUtilities

public class BufferStateUtilities
extends java.lang.Object


Nested Class Summary
static class BufferStateUtilities.Consistent
           means that given the values and the conditions the slots have, they COULD be equivalent (but still might not be)
means that given the values and the conditions, the two slots can never be equivalent
means that the given values and conditions are not sufficient to make any judgement.
 
Constructor Summary
BufferStateUtilities()
           
 
Method Summary
static boolean conditionIs(org.antlr.runtime.tree.CommonTree slot, int condition)
          uses IConditionalSlot condition constants, not JACTRBuilder
static boolean contentIsType(org.antlr.runtime.tree.CommonTree slot, int type)
           
static java.util.Collection<org.antlr.runtime.tree.CommonTree> expandVariable(java.lang.String slotName, java.lang.String variableName, BufferEndStates endStates)
          this will search through all the conditions and queries looking for more information about variableName.
static java.util.Collection<org.antlr.runtime.tree.CommonTree> getAssignments(java.util.Map<java.lang.Integer,java.util.Collection<org.antlr.runtime.tree.CommonTree>> mapOfTrees)
          return all slots that are equality conditions (aka assignments), even variables
static java.lang.String getContent(org.antlr.runtime.tree.CommonTree slot)
           
static java.util.Collection<org.antlr.runtime.tree.CommonTree> getNonVariables(java.util.Map<java.lang.Integer,java.util.Collection<org.antlr.runtime.tree.CommonTree>> mapOfSlots)
          return all slots that arent variables
static java.util.Map<java.lang.Integer,java.util.Collection<org.antlr.runtime.tree.CommonTree>> getSlots(org.antlr.runtime.tree.CommonTree conditionOrAction)
          return a map of collections of slot ASTs contained by the condition or action.
static BufferStateUtilities.Consistent isConsistentWith(org.antlr.runtime.tree.CommonTree endStateSlot, org.antlr.runtime.tree.CommonTree conditionalSlot)
          return true if the endstate slot is consistent with the conditional slot.
static boolean slotIsApplicable(org.antlr.runtime.tree.CommonTree endStateSlot, org.antlr.runtime.tree.CommonTree conditionalSlot)
          compare two slots to see if they are applicable, this is just a name check
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferStateUtilities

public BufferStateUtilities()
Method Detail

expandVariable

public static java.util.Collection<org.antlr.runtime.tree.CommonTree> expandVariable(java.lang.String slotName,
                                                                                     java.lang.String variableName,
                                                                                     BufferEndStates endStates)
this will search through all the conditions and queries looking for more information about variableName. When it finds another slot that matches to that variable name, all other non-variable conditions for that slot are saved and remapped to the provided slotName. ex:
(p =goal> isa fact - arg1 Z arg1 =value ==> +retrieval> isa other-fact argA =value )
We know that other-fact.argA cannot be null OR Z.
Ideally this method should be recursively because some mean modeler might use a whole slew of variable indirections within a single production.. but that will be for version 2.

Parameters:
slotName -
variableName -
endStates -
Returns:

getSlots

public static java.util.Map<java.lang.Integer,java.util.Collection<org.antlr.runtime.tree.CommonTree>> getSlots(org.antlr.runtime.tree.CommonTree conditionOrAction)
return a map of collections of slot ASTs contained by the condition or action. the map is keyed on the type of content in the slot, typically JACTRBuilder.IDENTIFIER, JACTRBuilder.VARIABLE, or JACTRBuilder.NUMBER

Parameters:
conditionOrAction -
Returns:

getNonVariables

public static java.util.Collection<org.antlr.runtime.tree.CommonTree> getNonVariables(java.util.Map<java.lang.Integer,java.util.Collection<org.antlr.runtime.tree.CommonTree>> mapOfSlots)
return all slots that arent variables

Parameters:
mapOfSlots -
Returns:

getAssignments

public static java.util.Collection<org.antlr.runtime.tree.CommonTree> getAssignments(java.util.Map<java.lang.Integer,java.util.Collection<org.antlr.runtime.tree.CommonTree>> mapOfTrees)
return all slots that are equality conditions (aka assignments), even variables

Parameters:
mapOfTrees -
Returns:

contentIsType

public static boolean contentIsType(org.antlr.runtime.tree.CommonTree slot,
                                    int type)

getContent

public static java.lang.String getContent(org.antlr.runtime.tree.CommonTree slot)

conditionIs

public static boolean conditionIs(org.antlr.runtime.tree.CommonTree slot,
                                  int condition)
uses IConditionalSlot condition constants, not JACTRBuilder

Parameters:
slot -
condition -
Returns:

slotIsApplicable

public static boolean slotIsApplicable(org.antlr.runtime.tree.CommonTree endStateSlot,
                                       org.antlr.runtime.tree.CommonTree conditionalSlot)
compare two slots to see if they are applicable, this is just a name check

Parameters:
endStateSlot -
conditionalSlot -
Returns:

isConsistentWith

public static BufferStateUtilities.Consistent isConsistentWith(org.antlr.runtime.tree.CommonTree endStateSlot,
                                                               org.antlr.runtime.tree.CommonTree conditionalSlot)
return true if the endstate slot is consistent with the conditional slot. this will check the conditions on both the slots and compare their values accordingly. The values should NEVER be variables in either slot. similarly, before calling this, slotIsApplicable(CommonTree, CommonTree) should have returned true.

Currently this will return ambiguous if either slot condition is anything but equals or not

Parameters:
endStateSlot -
conditionalSlot -
Returns:
BufferStateUtilities.Consistent
Throws:
java.lang.IllegalStateException - if either is a variable or the condition type is not recognized