Package net.openai.util.fsm

Examples of net.openai.util.fsm.State


      while (machineItr.hasNext()) {
        Machine fsm = (Machine) machineItr.next();

        fsm.input(token);

        State currentState = fsm.getCurrentState();
        if (currentState.getStartStateFlag()) {
          tokenStartMap.put(fsm, new Integer(i));
        }
        if (currentState.getEndStateFlag()) {
          Object o = tokenStartMap.get(fsm);
          int tokenStartIndex;
          if (o == null) {
            // By default, all machines start with
            // token zero.
View Full Code Here


   * </ol>
   *
   * @return
   */
  private Machine getDosageQuantityMachine() {
    State startState = new NamedState("START");
    State endState = new NamedState("END");
    State ofState = new NamedState("OF");
    State aState = new NamedState("A");
    State numState = new NamedState("NUMVALUE");
    State formState = new NamedState("FORM");
    State leftParenState = new NamedState("LEFTPAREN");
    State ntFalseTermState = new IndentStartState("NON TERMINAL START");
    State ntEndState = new NonTerminalEndState("NON TERMINAL END");
    ntFalseTermState.setEndStateFlag(true);
    endState.setEndStateFlag(true);
    ntEndState.setEndStateFlag(true);

    Machine m = new Machine(startState);
    State hyphState = new NamedState("HYPHTERM");
    State dosageState = new NamedState("DOSAGE");

    Condition decimalCondition = new DecimalCondition();
    Condition numberCondition = new NumberCondition();
    Condition strengthFormCondition = new DisjoinCondition(
        new RouteCondition(), new FormCondition());
    Condition numberTextCondition = new WordSetCondition(iv_textNumberSet,
        false);
    Condition rangeCondition = new RangeStrengthCondition();
    Condition fractionRangeCondition = new FractionStrengthCondition();
    Condition decimalStart = new DisjoinCondition(
        new IntegerValueCondition(0), new NumberCondition());

    startState.addTransition(new WordSetCondition(iv_soloTextSet, true),
        endState);
    startState.addTransition(numberCondition, dosageState);
    startState.addTransition(decimalCondition, dosageState);
    startState.addTransition(rangeCondition, dosageState);
    startState.addTransition(fractionRangeCondition, dosageState);
    startState.addTransition(numberTextCondition, dosageState);
    startState.addTransition(decimalStart, dosageState);
    /*startState.addTransition(new DisjoinCondition(new StrengthCondition(),
        new FormCondition()), formState);*/

    startState.addTransition(new AnyCondition(), startState);

    formState.addTransition(new WordSetCondition(iv_textNumberSet, true),
        ntFalseTermState);
    formState.addTransition(new AnyCondition(), startState);

    dosageState.addTransition(strengthFormCondition, ntEndState);
    dosageState
        .addTransition(new PunctuationValueCondition('-'), hyphState);

    dosageState.addTransition(new PunctuationValueCondition('('),
        leftParenState);
    dosageState.addTransition(new TextValueCondition("of", false), ofState);
    dosageState.addTransition(new AnyCondition(), startState);

    ofState.addTransition(new TextValueCondition("a", false), aState);
    ofState.addTransition(new AnyCondition(), startState);

    aState.addTransition(new DisjoinCondition(new RouteCondition(),
View Full Code Here

      while (machineItr.hasNext()) {
        Machine fsm = (Machine) machineItr.next();

        fsm.input(token);

        State currentState = fsm.getCurrentState();
        if (currentState.getStartStateFlag()) {
          tokenStartMap.put(fsm, new Integer(i));
          tokenOffset1 = 0;
          tokenOffset2 = 0;
        }
        if (currentState.getEndStateFlag()) {
          Object o = tokenStartMap.get(fsm);
          int globalOffset = 0;
          int tokenStartIndex;
          if (o == null) {
            // By default, all machines start with
View Full Code Here

      while (machineItr.hasNext()) {
        Machine fsm = (Machine) machineItr.next();

        fsm.input(token);

        State currentState = fsm.getCurrentState();
        if (currentState.getStartStateFlag()) {
          tokenStartMap.put(fsm, Integer.valueOf(i));
        }
        if (currentState.getEndStateFlag()) {
          Object o = tokenStartMap.get(fsm);
          int tokenStartIndex;
          if (o == null) {
            // By default, all machines start with
            // token zero.
View Full Code Here

   *     <li>25.7-30.2 mg</li>
   *     <li>two-3.5mg</li>
   *  </ol>
   */
  private Machine getStrengthMachine(){
    State startState = new NamedState("START");
    State endState = new NamedState("END");
    State connectState = new NamedState("CONNECT");
    State unitState = new NamedState("UNIT");
    State decimalState = new NamedState("DOT");
    State complexState = new NamedState("COMPLEX");
    State hyphenState = new NamedState("HYPHEN");
    State dateState = new NamedState("DATE");
    State ntEndState = new NonTerminalEndState("NON TERMINAL END");
    State ntEndHyphState = new NonTerminalEndState("NON TERMINAL HYPH END");
    endState.setEndStateFlag(true);
    ntEndState.setEndStateFlag(true);
    ntEndHyphState.setEndStateFlag(true);

    startState.addTransition(new RangeStrengthCondition(), endState);
    startState.addTransition(new FractionStrengthCondition(), dateState);
    startState.addTransition(new NumberCondition(), connectState);
    startState.addTransition(new IntegerCondition(), connectState);
    startState.addTransition(new DecimalCondition(), connectState);
    startState.addTransition(new WordSetCondition(iv_numberTextSet, false), connectState);
    //Mayo SPM 2/20/2012 Changed due to separation of strength tokens
//    startState.addTransition(new StrengthUnitCondition(), ntEndState);
    startState.addTransition(new StrengthUnitCombinedCondition(), endState);
    startState.addTransition(new AnyCondition(), startState);
   
    dateState.addTransition(new NegateCondition( new PunctuationValueCondition('/')), connectState);
    dateState.addTransition(new AnyCondition(), startState);
   
    //Mayo SPM 2/20/2012 Changed due to separation of strength tokens
    connectState.addTransition(new StrengthUnitCondition(), ntEndState);
    connectState.addTransition(new StrengthUnitCombinedCondition(), endState);
    connectState.addTransition(new PunctuationValueCondition('-'), unitState);
    connectState.addTransition(new PunctuationValueCondition('.'), decimalState);
    connectState.addTransition(new AnyCondition(), startState);
   
    //Mayo SPM 2/20/2012 Changed due to separation of strength tokens
    decimalState.addTransition(new StrengthUnitCondition(), ntEndState);
    decimalState.addTransition(new StrengthUnitCombinedCondition(), endState);
    decimalState.addTransition(new PunctuationValueCondition('-'), unitState);
    decimalState.addTransition(new NumberCondition(), complexState);
    decimalState.addTransition(new AnyCondition(), startState);
   
    //Mayo SPM 2/20/2012 Changed due to separation of strength tokens
    unitState.addTransition(new StrengthUnitCondition(), ntEndHyphState);
    unitState.addTransition(new StrengthUnitCombinedCondition(), endState);
    unitState.addTransition(new AnyCondition(), startState);
   
    complexState.addTransition(new PunctuationValueCondition('-'), hyphenState);
    complexState.addTransition(new AnyCondition(), startState);
   
    //Mayo SPM 2/20/2012 Changed due to separation of strength tokens
    hyphenState.addTransition(new StrengthUnitCondition(), ntEndHyphState);
    hyphenState.addTransition(new AnyCondition() , startState);
   
    ntEndHyphState.addTransition(new AnyCondition(), startState);
    ntEndState.addTransition(new AnyCondition(), startState);
    endState.addTransition(new AnyCondition(), startState);
    Machine m = new Machine(startState);
    return m;
  }
View Full Code Here

      while (machineItr.hasNext()) {
        Machine fsm = (Machine) machineItr.next();

        fsm.input(token);

        State currentState = fsm.getCurrentState();
        if (currentState.getStartStateFlag()) {
          tokenStartMap.put(fsm, new Integer(i));
          tokenOffset1 = 0;
          tokenOffset2 = 0;
        }
        if (currentState.getEndStateFlag()) {
          Object o = tokenStartMap.get(fsm);
          int tokenStartIndex;
          int globalOffset = 0;
          if (o == null) {
            // By default, all machines start with
            // token zero.
            tokenStartIndex = 0;
          } else {
            Integer tokenMap1 = new Integer(0);
            Integer tokenMap2 = new Integer(0);
         
            BaseToken lookUpOffset = (BaseToken) tokens.get(((Integer) o).intValue());
             
            if (overrideBeginTokenMap1.get(new Integer(lookUpOffset.getStartOffset())) != null){
              Integer offSet = (Integer) (overrideBeginTokenMap1.get(new Integer(lookUpOffset.getStartOffset())));
              tokenMap1 = new Integer(offSet.intValue()  + tokenMap1.intValue());
            }
            if (overrideBeginTokenMap2.get(new Integer(lookUpOffset.getStartOffset())) != null){
              Integer offSet = (Integer) (overrideBeginTokenMap2.get(new Integer(lookUpOffset.getStartOffset())));
              tokenMap2 = new Integer(offSet.intValue() + tokenMap2.intValue());
              }
           

            globalOffset = tokenMap1.intValue() + tokenMap2.intValue();
            tokenStartIndex = ((Integer) o).intValue() + globalOffset;
            // skip ahead over single token we don't want
            tokenStartIndex++;
          }
         
          BaseToken startToken = (BaseToken) tokens.get(tokenStartIndex);
          BaseToken endToken = null;
          if (currentState instanceof NonTerminalEndState && i > 0) {
            if (!currentState.getName().contentEquals("NON TERMINAL HYPH END"))
              endToken = (BaseToken) tokens.get(i - 1);
            else if (i > 1)
              endToken = (BaseToken) tokens.get(i - 2);
          } else {
            endToken = token;
View Full Code Here

      while (machineItr.hasNext()) {
        Machine fsm = (Machine) machineItr.next();

        fsm.input(token);

        State currentState = fsm.getCurrentState();
        if (currentState.getStartStateFlag()) {
          tokenStartMap.put(fsm, new Integer(i));
          tokenOffset = 0;
        }
        if (currentState.getEndStateFlag()) {
          Object o = tokenStartMap.get(fsm);
          int tokenStartIndex;
          if (o == null) {
            // By default, all machines start with
            // token zero.
            tokenStartIndex = 0;
          } else {
            Integer tokenMap = new Integer(0);
                     
            BaseToken lookUpOffset = (BaseToken) tokens.get(((Integer) o).intValue());
             
            if (overrideBeginTokenMap.get(new Integer(lookUpOffset.getStartOffset())) != null){
              Integer offSet = (Integer) (overrideBeginTokenMap.get(new Integer(lookUpOffset.getStartOffset())));
              tokenMap = new Integer(offSet.intValue()  + tokenMap.intValue());
            }
           
           
            tokenStartIndex = ((Integer) o).intValue() + tokenMap.intValue();
            // skip ahead over single token we don't want
            tokenStartIndex++;
          }
          BaseToken startToken = (BaseToken) tokens
              .get(tokenStartIndex);
          BaseToken endToken = null;
          if (currentState instanceof NonTerminalEndState && i > 0) {
            if (!currentState.getName().contentEquals("NON TERMINAL HYPH END"))
              endToken = (BaseToken) tokens.get(i - 1);
            else if (i > 0)
              endToken = (BaseToken) tokens.get(i - 2);
          } else {
            endToken = token;
View Full Code Here

      while (machineItr.hasNext()) {
        Machine fsm = (Machine) machineItr.next();

        fsm.input(token);

        State currentState = fsm.getCurrentState();
        if (currentState.getStartStateFlag()) {
          tokenStartMap.put(fsm, new Integer(i));
          tokenOffset = 0;
        }
        if (currentState.getEndStateFlag()) {
          Object o = tokenStartMap.get(fsm);
          int tokenStartIndex;
          if (o == null) {
            // By default, all machines start with
            // token zero.
            tokenStartIndex = 0;
          } else {
            Integer tokenMap = new Integer(0);
                     
            BaseToken lookUpOffset = (BaseToken) tokens.get(((Integer) o).intValue());
             
           
            tokenStartIndex = ((Integer) o).intValue() + tokenMap.intValue();
            // skip ahead over single token we don't want
            tokenStartIndex++;
          }
          BaseToken startToken = (BaseToken) tokens
              .get(tokenStartIndex);
          BaseToken endToken = null;
          if (currentState instanceof NonTerminalEndState && i > 0) {
            if (!currentState.getName().contentEquals("NON TERMINAL HYPH END"))
              endToken = (BaseToken) tokens.get(i - 1);
            else if (i > 0)
              endToken = (BaseToken) tokens.get(i - 2);
          } else {
            endToken = token;
View Full Code Here

     * </ol>
     *
     * @return
     */
    private Machine getWeeklyMachine() {
      State startState = new NamedState("START");
      State endState = new NamedState("END");
      State ntEndState = new NonTerminalEndState("NON TERMINAL END");
      ntEndState.setEndStateFlag(true);
      endState.setEndStateFlag(true);
      State leftAbbreviateState = new NamedState("LEFT_FREQ");
     
      Machine m = new Machine(startState);
 
      State leftAbbreviateQState = new NamedState("LEFT_Q");

      State middleAbbreviateQtoWState = new NamedState("MID_Q2W");
 
 
      State rightAbbreviateQWKState = new NamedState("RIGHT_QWK");
 
   
      State firstDotQState = new NamedState("FIRSTDOTQ");

 
      State secondDotQtoWState = new NamedState("SECONDDOTQ2W");
 
 
      Condition firstDotConditionQ = new PunctuationValueCondition('.');
      Condition secondDotConditionQW = new PunctuationValueCondition('.');
      Condition thirdDotConditionQWK = new PunctuationValueCondition('.');

      Condition soloCondition = new TextSetCondition(iv_perWeekWordSet, false);
 
 
      startState.addTransition(new TextValueCondition("q", false),
          leftAbbreviateQState);
      startState.addTransition(new TextValueCondition("a", false),
          leftAbbreviateState);
      startState.addTransition(new TextValueCondition("at", false),
          leftAbbreviateState);
      startState.addTransition(new TextValueCondition("per", false),
          leftAbbreviateState);
 
      startState.addTransition(soloCondition, endState);
      startState.addTransition(new AnyCondition(), startState);
 
      leftAbbreviateQState.addTransition(firstDotConditionQ, firstDotQState);
      leftAbbreviateQState.addTransition(new AnyCondition(), startState);
 
     
      leftAbbreviateState.addTransition(new ContainsSetTextValueCondition(
          iv_perWeekWordSet, false), endState);
      leftAbbreviateState.addTransition(new AnyCondition(), startState);
 
      firstDotQState.addTransition(new TextValueCondition("w", false),
          middleAbbreviateQtoWState);

      firstDotQState.addTransition(new AnyCondition(), startState);
 
 
 
      middleAbbreviateQtoWState.addTransition(secondDotConditionQW,
          secondDotQtoWState);
      middleAbbreviateQtoWState.addTransition(new AnyCondition(), startState);
 
   
      secondDotQtoWState.addTransition(new TextValueCondition("k", false),
          rightAbbreviateQWKState);
      secondDotQtoWState.addTransition(new AnyCondition(), startState);
 
   
      rightAbbreviateQWKState.addTransition(thirdDotConditionQWK, endState);
        rightAbbreviateQWKState.addTransition(new AnyCondition(), startState);
    //  rightAbbreviateQWKState.addTransition(new AnyCondition(), startState);
View Full Code Here

   * </ol>
   *
   * @return
   */
  private Machine getThreeTimesADayMachine() {
    State startState = new NamedState("START");
    State endState = new NamedState("END");
    State ntEndState = new NonTerminalEndState("NON TERMINAL END");
    ntEndState.setEndStateFlag(true);
    endState.setEndStateFlag(true);

    Machine m = new Machine(startState);
    State hyphState = new NamedState("HYPHSTATE");
    State rangeState = new NamedState("RANGESTAGE");
    State handleRangeState = new NamedState("HANDLERANGE");
    State leftAbbreviateTState = new NamedState("LEFT_T");
    State middleAbbreviateTtoIState = new NamedState("MID_T2I");
    State rightAbbreviateTIDState = new NamedState("RIGHT_TID");
    State firstDotTState = new NamedState("FIRSTDOTT");
    State secondDotTtoIState = new NamedState("SECONDDOTT2I");
    State eightHourState = new NamedState("EIGHTHOUR");

    Condition firstDotConditionT = new PunctuationValueCondition('.');
    Condition secondDotConditionTI = new PunctuationValueCondition('.');
    Condition thirdDotConditionTID = new PunctuationValueCondition('.');
   
    Condition TTDCondition = new TextSetCondition(iv_threeTimesADayWordSet, false);
 
    startState.addTransition(new TextValueCondition("t", false),
        leftAbbreviateTState);
    startState.addTransition(new TextValueCondition("q", false),
        eightHourState);
    startState.addTransition(new IntegerValueCondition(8), eightHourState);
    startState.addTransition(TTDCondition, endState);
    startState.addTransition(new DisjoinCondition(new CombineCondition(new NegateCondition(new IntegerRangeCondition(1,7)), new IntegerCondition()), new IntegerValueCondition(8)), handleRangeState);
    startState.addTransition(new DisjoinCondition(new TextSetCondition(iv_postEightWordSet, false), new TextValueCondition("eight", false)), eightHourState);
 
    startState.addTransition(new AnyCondition(), startState);

    handleRangeState.addTransition(new PunctuationValueCondition('-'), hyphState);
    handleRangeState.addTransition(new AnyCondition(), startState);
   
    eightHourState.addTransition(new PunctuationValueCondition('-'), hyphState);
    eightHourState.addTransition(new TextValueCondition("to", false), hyphState);
    eightHourState.addTransition(new TextSetCondition(iv_hourlySuffixSet, false), endState);
    eightHourState.addTransition(new AnyCondition(), startState);

    leftAbbreviateTState.addTransition(firstDotConditionT, firstDotTState);
    leftAbbreviateTState.addTransition(new AnyCondition(), startState);

    hyphState.addTransition(new IntegerRangeCondition(9,10), rangeState);
View Full Code Here

TOP

Related Classes of net.openai.util.fsm.State

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.