Package net.openai.util.fsm

Examples of net.openai.util.fsm.Machine


    for (int i = 0; i < tokens.size(); i++) {
      BaseToken token = (BaseToken) tokens.get(i);

      Iterator machineItr = iv_machineSet.iterator();
      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.
            tokenStartIndex = 0;
          } else {
            tokenStartIndex = ((Integer) o).intValue();
            // skip ahead over single token we don't want
            tokenStartIndex++;
          }
          BaseToken startToken = null;
          if (currentState instanceof IndentStartState) {
            startToken = (BaseToken) tokens
                .get(tokenStartIndex + 1);

          } else {
            startToken = (BaseToken) tokens.get(tokenStartIndex);

          }
          BaseToken endToken = null;
          if (currentState instanceof NonTerminalEndState) {
            endToken = (BaseToken) tokens.get(i - 1);
          } else {
            endToken = token;
          }
          FrequencyToken fractionToken = new FrequencyToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset());
          fractionSet.add(fractionToken);
          fsm.reset();
        }
      }
    }

    // cleanup
    tokenStartMap.clear();

    // reset machines
    Iterator itr = iv_machineSet.iterator();
    while (itr.hasNext()) {
      Machine fsm = (Machine) itr.next();
      fsm.reset();
    }

    return fractionSet;
  }
View Full Code Here


        }
      }

      Iterator machineItr = iv_machineSet.iterator();
      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 = null;
          if (currentState instanceof IndentStartState) {
            startToken = (BaseToken) tokens
                .get(tokenStartIndex + 1);

          } else {
            startToken = (BaseToken) tokens.get(tokenStartIndex);

          }
          BaseToken endToken = null;
          if (currentState instanceof NonTerminalEndState) {
            endToken = (BaseToken) tokens.get(i - 1);
          } else {
            endToken = token;
          }
          FrequencyToken measurementToken = new FrequencyToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset());
          measurementSet.add(measurementToken);
          fsm.reset();
        }
      }
    }

    // cleanup
    tokenStartMap.clear();

    // reset machines
    Iterator itr = iv_machineSet.iterator();
    while (itr.hasNext()) {
      Machine fsm = (Machine) itr.next();
      fsm.reset();
    }

    return measurementSet;
  }
View Full Code Here

    State ntEndState = new NonTerminalEndState("NON TERMINAL END");
    endState.setEndStateFlag(true);
    ntEndState.setEndStateFlag(true);

    Machine m = new Machine(startState);

    Condition subFirstBegin = new TextSetCondition(iv_historySubBeginSet,
        false);
    Condition subFirstMid = new TextSetCondition(iv_historySubMidSet,
        false);
View Full Code Here

    for (int i = 0; i < tokens.size(); i++) {
      BaseToken token = (BaseToken) tokens.get(i);

      Iterator machineItr = iv_machineSet.iterator();
      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.
            tokenStartIndex = 0;
          } else {
            tokenStartIndex = ((Integer) o).intValue();
            // skip ahead over single token we don't want
            tokenStartIndex++;
          }
          BaseToken endToken = null;
          if (currentState instanceof NonTerminalEndState) {
            endToken = (BaseToken) tokens.get(i - 1);
          } else {
            endToken = token;
          }

          BaseToken startToken = (BaseToken) tokens
              .get(tokenStartIndex);
          SubSectionIndicator subs = null;
          if (fsm.equals(iv_subSectionIDProbableMachine)) {
            subs = new SubSectionIndicator(startToken
                .getStartOffset(), endToken.getEndOffset(),
                SubSectionIndicator.PROBABLE_STATUS);
          } else if (fsm.equals(iv_subSectionIDHistoryMachine)) {
            subs = new SubSectionIndicator(startToken
                .getStartOffset(), endToken.getEndOffset(),
                SubSectionIndicator.HISTORY_STATUS);
          } else if (fsm.equals(iv_subSectionIDConfirmMachine)) {
            subs = new SubSectionIndicator(startToken
                .getStartOffset(), endToken.getEndOffset(),
                SubSectionIndicator.CONFIRMED_STATUS);
          } else
            subs = new SubSectionIndicator(startToken
                .getStartOffset(), endToken.getEndOffset(),
                SubSectionIndicator.FAMILY_HISTORY_STATUS);
          outSet.add(subs);

          fsm.reset();
        }
      }
    }

    // cleanup
    tokenStartMap.clear();

    // reset machines
    Iterator itr = iv_machineSet.iterator();
    while (itr.hasNext()) {
      Machine fsm = (Machine) itr.next();
      fsm.reset();
    }
 
    return outSet;
  }
View Full Code Here

    State ntEndState = new NonTerminalEndState("NON TERMINAL END");
    endState.setEndStateFlag(true);
    ntEndState.setEndStateFlag(true);

    Machine m = new Machine(startState);

    Condition subFirstBegin = new TextSetCondition(iv_probableSubBeginSet,
        false);
    Condition subFirstNext = new TextSetCondition(iv_probableSubNextSet,
        false);
View Full Code Here

 
    State ntEndState = new NonTerminalEndState("NON TERMINAL END");
    endState.setEndStateFlag(true);
    ntEndState.setEndStateFlag(true);
 
    Machine m = new Machine(startState);
 
    Condition subFirstBegin = new TextSetCondition(iv_confirmedSubBeginSet,
        false);
    Condition subFirstNext = new TextSetCondition(iv_confirmedSubNextSet,
        false);
View Full Code Here

    unitState.addTransition(new SymbolValueCondition('%'), endState);
    unitState.addTransition(new AnyCondition(), startState);

    ntFalseTermState.addTransition(new AnyCondition(), startState);
    endState.addTransition(new AnyCondition(), startState);
    Machine m = new Machine(startState);
    return m;
  }
View Full Code Here

    unitState.addTransition(new SymbolValueCondition('%'), endState);
    unitState.addTransition(new AnyCondition(), startState);

    ntFalseTermState.addTransition(new AnyCondition(), startState);
    endState.addTransition(new AnyCondition(), startState);
    Machine m = new Machine(startState);
    return m;
  }
View Full Code Here

        }
      }

      Iterator machineItr = iv_machineSet.iterator();
      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 = null;
          BaseToken endToken = token;
          if (currentState instanceof IndentStartState) {
            startToken = (BaseToken) tokens
                .get(tokenStartIndex + 1);

          } else {
            startToken = (BaseToken) tokens.get(tokenStartIndex);

          }
          StrengthUnitToken measurementToken = null;
          StrengthUnitCombinedToken measurementCombinedToken = null;
          if (fsm.equals(iv_strengthCombinedMachine)) {
            measurementCombinedToken = new StrengthUnitCombinedToken(startToken
                .getStartOffset(), endToken.getEndOffset());
            measurementSet.add(measurementCombinedToken);
           
          }
          else {
            measurementToken = new StrengthUnitToken(startToken
                .getStartOffset(), endToken.getEndOffset());
            measurementSet.add(measurementToken);
           
          }
          fsm.reset();
        }
      }
    }

    // cleanup
    tokenStartMap.clear();

    // reset machines
    Iterator itr = iv_machineSet.iterator();
    while (itr.hasNext()) {
      Machine fsm = (Machine) itr.next();
      fsm.reset();
    }

    return measurementSet;
  }
View Full Code Here

        }
      }

      Iterator machineItr = iv_machineSet.iterator();
      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 = null;
          BaseToken endToken = token;
          if (currentState instanceof IndentStartState) {
            startToken = (BaseToken) tokens
                .get(tokenStartIndex + 1);

          } else {
            startToken = (BaseToken) tokens.get(tokenStartIndex);

          }
          StrengthUnitToken measurementToken = null;
          StrengthUnitCombinedToken measurementCombinedToken = null;
          if (fsm.equals(iv_strengthCombinedMachine)) {
            measurementCombinedToken = new StrengthUnitCombinedToken(startToken
                .getStartOffset(), endToken.getEndOffset());
            measurementSet.add(measurementCombinedToken);
           
          }
          else {
            measurementToken = new StrengthUnitToken(startToken
                .getStartOffset(), endToken.getEndOffset());
            measurementSet.add(measurementToken);
           
          }
         
          fsm.reset();
         
        }
      }
    }

    // cleanup
    tokenStartMap.clear();

    // reset machines
    Iterator itr = iv_machineSet.iterator();
    while (itr.hasNext()) {
      Machine fsm = (Machine) itr.next();
      fsm.reset();
    }

    return measurementSet;
  }
View Full Code Here

TOP

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

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.