Package org.apache.ctakes.core.fsm.token

Examples of org.apache.ctakes.core.fsm.token.BaseToken


    // maps a fsm to a token start index
    // key = fsm , value = token start index
    Map tokenStartMap = new HashMap();

    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();
        BaseToken startToken = null;

        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++;
          }
         
                 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;
                    }
          FrequencyUnitToken fractionToken = null;
           if (fsm.equals(iv_EveryOtherHourMachine))
              fractionToken = new FrequencyUnitToken(
                startToken.getStartOffset(), endToken
                    .getEndOffset(), FrequencyUnitToken.QUANTITY_24/2);
           else if (fsm.equals(iv_SixTimesADayMachine))
              fractionToken = new FrequencyUnitToken(
                startToken.getStartOffset(), endToken
                    .getEndOffset(), FrequencyUnitToken.QUANTITY_SIX);
           else if (fsm.equals(iv_FiveTimesADayMachine))
              fractionToken = new FrequencyUnitToken(
                startToken.getStartOffset(), endToken
                    .getEndOffset(), FrequencyUnitToken.QUANTITY_FIVE);
           else if (fsm.equals(iv_FourTimesADayMachine))
              fractionToken = new FrequencyUnitToken(
                startToken.getStartOffset(), endToken
                    .getEndOffset(), FrequencyUnitToken.QUANTITY_FOUR);
           else if (fsm.equals(iv_ThreeTimesADayMachine))
              fractionToken = new FrequencyUnitToken(
                startToken.getStartOffset(), endToken
                    .getEndOffset(), FrequencyUnitToken.QUANTITY_THREE);
          else if (fsm.equals(iv_HourlyMachine) || fsm.equals(iv_HourlySuffixMachine))
              fractionToken = new FrequencyUnitToken(
                startToken.getStartOffset(), endToken
                    .getEndOffset(), FrequencyUnitToken.QUANTITY_24);
          else if (fsm.equals(iv_TwiceADayMachine))
            fractionToken = new FrequencyUnitToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset(), FrequencyUnitToken.QUANTITY_TWO);
          else if (fsm.equals(iv_DailyMachine) || fsm.equals(iv_DailySuffixMachine))
            fractionToken = new FrequencyUnitToken(
                startToken.getStartOffset(), endToken
                    .getEndOffset(), FrequencyUnitToken.QUANTITY_ONE);
          else if (fsm.equals(iv_EveryOtherDayMachine))
            fractionToken = new FrequencyUnitToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset(), FrequencyUnitToken.QUANTITY_EVERY_OTHER_DAY);
          else if (fsm.equals(iv_WeeklyMachine)|| fsm.equals(iv_WeeklySuffixMachine))
            fractionToken = new FrequencyUnitToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset(), FrequencyUnitToken.QUANTITY_WEEKLY);
          else if (fsm.equals(iv_MonthlySuffixMachine))
            fractionToken = new FrequencyUnitToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset(), FrequencyUnitToken.QUANTITY_MONTHLY);
          else if (fsm.equals(iv_YearlySuffixMachine))
            fractionToken = new FrequencyUnitToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset(), FrequencyUnitToken.QUANTITY_YEARLY);
          else
            fractionToken = new FrequencyUnitToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset(), FrequencyUnitToken.QUANTITY_PRN);
       
          fractionSet.add(fractionToken);
          fsm.reset();
        }
View Full Code Here


    Iterator overrideTokenItr = overrideSet.iterator();
    // key = start offset, value = override BaseToken object
    Map overrideTokenMap = new HashMap();
    while (overrideTokenItr.hasNext()) {
      BaseToken t = (BaseToken) overrideTokenItr.next();
      Integer key = new Integer(t.getStartOffset());
      overrideTokenMap.put(key, t);
    }

    boolean overrideOn = false;
    int overrideEndOffset = -1;
    for (int i = 0; i < tokens.size(); i++) {
      BaseToken token = (BaseToken) tokens.get(i);

      Integer key = new Integer(token.getStartOffset());

      if (overrideOn) {
        if (token.getStartOffset() >= overrideEndOffset) {
          overrideOn = false;
          overrideEndOffset = -1;
        } else {
          // step to next iteration of for loop
          continue;
        }
      } else {
        if (overrideTokenMap.containsKey(key)) {
          // override one or more tokens until the override
          // token is complete
          token = (BaseToken) overrideTokenMap.get(key);
          overrideOn = true;
          overrideEndOffset = token.getEndOffset();
        }
      }

      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 = (BaseToken) tokens
              .get(tokenStartIndex);
          BaseToken endToken = token;
          SuffixFrequencyToken segmentToken = new SuffixFrequencyToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset());
          rangeSet.add(segmentToken);
          fsm.reset();
        }
      }
View Full Code Here

    // maps a fsm to a token start index
    // key = fsm , value = token start index
    Map tokenStartMap = new HashMap();

    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 = (BaseToken) tokens
              .get(tokenStartIndex);
          BaseToken endToken = token;
          SuffixFrequencyToken fractionToken = new SuffixFrequencyToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset());
          fractionSet.add(fractionToken);
          fsm.reset();
        }
      }
View Full Code Here

    Iterator overrideTokenItr = overrideSet.iterator();
    // key = start offset, value = override BaseToken object
    Map overrideTokenMap = new HashMap();
    while (overrideTokenItr.hasNext()) {
      BaseToken t = (BaseToken) overrideTokenItr.next();
      Integer key = new Integer(t.getStartOffset());
      overrideTokenMap.put(key, t);
    }

    boolean overrideOn = false;
    int overrideEndOffset = -1;
    for (int i = 0; i < tokens.size(); i++) {
      BaseToken token = (BaseToken) tokens.get(i);

      Integer key = new Integer(token.getStartOffset());

      if (overrideOn) {
        if (token.getStartOffset() >= overrideEndOffset) {
          overrideOn = false;
          overrideEndOffset = -1;
        } else {
          // step to next iteration of for loop
          continue;
        }
      } else {
        if (overrideTokenMap.containsKey(key)) {
          // override one or more tokens until the override
          // token is complete
          token = (BaseToken) overrideTokenMap.get(key);
          overrideOn = true;
          overrideEndOffset = token.getEndOffset();
        }
      }

      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 segmentToken = new FrequencyToken(startToken
              .getStartOffset(), endToken.getEndOffset());
          rangeSet.add(segmentToken);
          fsm.reset();
        }
      }
    }
View Full Code Here

    // maps a fsm to a token start index
    // key = fsm , value = token start index
    Map tokenStartMap = new HashMap();

    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();
        }
      }
View Full Code Here

    Map overrideTokenMap1 = new HashMap();
    Map overrideTokenMap2 = new HashMap();
    Map overrideBeginTokenMap1 = new HashMap();
    Map overrideBeginTokenMap2 = new HashMap();
    while (overrideTokenItr1.hasNext()) {
      BaseToken t = (BaseToken) overrideTokenItr1.next();
      Integer key = new Integer(t.getStartOffset());
      overrideTokenMap1.put(key, t);
    }

    while (overrideTokenItr2.hasNext()) {
      BaseToken t = (BaseToken) overrideTokenItr2.next();
      Integer key = new Integer(t.getStartOffset());
      overrideTokenMap2.put(key, t);
    }

    boolean overrideOn1 = false;
    boolean overrideOn2 = false;
    int overrideEndOffset1 = -1;
    int overrideEndOffset2 = -1;
    int tokenOffset1 = 0;
    int tokenOffset2 = 0;
    int anchorKey1 = 0;
    int anchorKey2 = 0;

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

      Integer key = new Integer(token.getStartOffset());
      if (overrideOn1 && overrideOn2) {
        if (overrideEndOffset1 >= overrideEndOffset2)
          overrideOn1 = false;
        else
          overrideOn2 = false;
      }
      if (overrideOn1) {
        if (token.getStartOffset() >= overrideEndOffset1) {
          if (tokenOffset1 > 0)
            overrideBeginTokenMap1.put(new Integer(anchorKey1), new Integer(tokenOffset1));
          overrideOn1 = false;
          overrideEndOffset1 = -1;
        } else {
          tokenOffset1++;
          // step to next iteration of for loop
          continue;
        }
      } else if (overrideOn2) {
        if (token.getStartOffset() >= overrideEndOffset2) {
          if (tokenOffset2 > 0)
            overrideBeginTokenMap2.put(new Integer(anchorKey2), new Integer(tokenOffset2));
          overrideOn2 = false;
          overrideEndOffset2 = -1;
        } else {
          tokenOffset2++;
          // step to next iteration of for loop
          continue;
        }
      } else {
        if (overrideTokenMap1.containsKey(key)) {
          // override one or more tokens until the override
          // token is complete
          anchorKey1 = key.intValue();
          token = (BaseToken) overrideTokenMap1.get(key);
          overrideOn1 = true;
          overrideEndOffset1 = token.getEndOffset();
          tokenOffset1 = 0;
        }
        if (overrideTokenMap2.containsKey(key)) {
          // override one or more tokens until the override
          // token is complete
          anchorKey2 = key.intValue();
          token = (BaseToken) overrideTokenMap2.get(key);
          overrideOn2 = true;
          overrideEndOffset2 = token.getEndOffset();
          tokenOffset2 = 0;
        }
      }

      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();
        }
      }
View Full Code Here

    // maps a fsm to a token start index
    // key = fsm , value = token start index
    Map tokenStartMap = new HashMap();

    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();
View Full Code Here

    Map overrideTokenMap1 = new HashMap();
    Map overrideTokenMap2 = new HashMap();
    Map overrideBeginTokenMap1 = new HashMap();
    Map overrideBeginTokenMap2 = new HashMap();
    while (overrideTokenItr1.hasNext()) {
      BaseToken t = (BaseToken) overrideTokenItr1.next();
      Integer key = new Integer(t.getStartOffset());
      overrideTokenMap1.put(key, t);
    }

    while (overrideTokenItr2.hasNext()) {
      BaseToken t = (BaseToken) overrideTokenItr2.next();
      Integer key = new Integer(t.getStartOffset());
      overrideTokenMap2.put(key, t);
    }

    boolean overrideOn1 = false;
    boolean overrideOn2 = false;
    int overrideEndOffset1 = -1;
    int overrideEndOffset2 = -1;
    int tokenOffset1 = 0;
    int tokenOffset2 = 0;
    int anchorKey1 = 0;
    int anchorKey2 = 0;
    for (int i = 0; i < tokens.size(); i++) {
      BaseToken token = (BaseToken) tokens.get(i);

      Integer key = new Integer(token.getStartOffset());
      if (overrideOn1 && overrideOn2){
        if (overrideEndOffset1 >= overrideEndOffset2)
          overrideOn1 = false;
        else
          overrideOn2 = false;
      }
      if (overrideOn1) {
        if (token.getStartOffset() >= overrideEndOffset1) {
          overrideBeginTokenMap1.put(new Integer(anchorKey1), new Integer(tokenOffset1));
          overrideOn1 = false;
          overrideEndOffset1 = -1;
        } else {
          tokenOffset1++;
          // step to next iteration of for loop
          continue;
        }
      } else if (overrideOn2) {
        if (token.getStartOffset() >= overrideEndOffset2) {
          overrideBeginTokenMap2.put(new Integer(anchorKey2), new Integer(tokenOffset2));
          overrideOn2 = false;
          overrideEndOffset2 = -1;
        } else {
          tokenOffset2++;
          // step to next iteration of for loop
          continue;
        }
      } else {
        if (overrideTokenMap1.containsKey(key)) {
          // override one or more tokens until the override
          // token is complete
          anchorKey1 = key.intValue();
          token = (BaseToken) overrideTokenMap1.get(key);
          overrideOn1 = true;
          overrideEndOffset1 = token.getEndOffset();
          tokenOffset1 = 0;
        }
        if (overrideTokenMap2.containsKey(key)) {
          // override one or more tokens until the override
          // token is complete
          anchorKey2 = key.intValue();
          token = (BaseToken) overrideTokenMap2.get(key);
          overrideOn2 = true;
          overrideEndOffset2 = token.getEndOffset();
          tokenOffset2 = 0;
        }
      }

      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();
        }
View Full Code Here

    Iterator overrideTokenItr = overrideSet.iterator();
    // key = start offset, value = override BaseToken object
    Map overrideTokenMap = new HashMap();
    Map overrideBeginTokenMap = new HashMap();
    while (overrideTokenItr.hasNext()) {
      BaseToken t = (BaseToken) overrideTokenItr.next();
      Integer key = new Integer(t.getStartOffset());
      overrideTokenMap.put(key, t);
    }

    boolean overrideOn = false;
    int overrideEndOffset = -1;
    int tokenOffset = 0;
    int anchorKey = 0;
   
    for (int i = 0; i < tokens.size(); i++) {
      BaseToken token = (BaseToken) tokens.get(i);

      Integer key = new Integer(token.getStartOffset());

      if (overrideOn) {
        if (token.getStartOffset() >= overrideEndOffset) {
          if (tokenOffset > 0)
            overrideBeginTokenMap.put(new Integer(anchorKey), new Integer(tokenOffset));
          overrideOn = false;
          overrideEndOffset = -1;
        } else {
          tokenOffset++;
          // step to next iteration of for loop
          continue;
        }
      } else {
        if (overrideTokenMap.containsKey(key)) {
          // override one or more tokens until the override
          // token is complete
          anchorKey = key.intValue();
          token = (BaseToken) overrideTokenMap.get(key);
          overrideOn = true;
          overrideEndOffset = token.getEndOffset();
          tokenOffset = 0;
        }
      }

      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();
View Full Code Here

        // key = fsm , value = token start index
        Map tokenStartMap = new HashMap();

        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);
                    NegationIndicator neg = null;
                    if (fsm.equals(iv_negInitialDetermineMachine))
                    {
                        neg =  new NegationIndicator(
                                startToken.getStartOffset(),
                                endToken.getEndOffset());
                    }
                    else neg = new NegationIndicator(
                            startToken.getStartOffset(),
                            endToken.getEndOffset());
                    outSet.add(neg);
                    fsm.reset();
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.ctakes.core.fsm.token.BaseToken

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.