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

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


        // adapt JCas objects into objects expected by the Finite state
        // machines
        List<BaseToken> baseTokenList = new ArrayList<>();
        for(org.apache.ctakes.typesystem.type.syntax.BaseToken bta : tokens){
          // ignore newlines, avoid null tokens
          BaseToken bt = adaptToBaseToken(bta);
          if(bt != null && !(bt instanceof EolToken))
            baseTokenList.add(bt);
        }

        // execute FSM logic
View Full Code Here


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

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

      Iterator<Machine> machineItr = iv_machineSet.iterator();
      while (machineItr.hasNext()) {
        Machine fsm = 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 = tokens.get(i - 1);
          } else {
            endToken = token;
          }

          BaseToken startToken = tokens
              .get(tokenStartIndex);
          DateToken dateToken = new DateToken(startToken
              .getStartOffset(), endToken.getEndOffset());
          dateSet.add(dateToken);
          fsm.reset();
        }
      }
View Full Code Here

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

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

      Iterator<Machine> 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_subSectionIDConfirmMachine)) {
            subs = new SubSectionIndicator(startToken
                .getStartOffset(), endToken.getEndOffset(),
                SubSectionIndicator.CONFIRMED_STATUS);
          } else if (fsm.equals(iv_subSectionIDNegateMachine)) {
            subs = new SubSectionIndicator(startToken
                .getStartOffset(), endToken.getEndOffset(),
                SubSectionIndicator.NEGATED_STATUS);
          } else if (fsm.equals(iv_subSectionIDProbableMachine)) {
            subs = new SubSectionIndicator(startToken
                .getStartOffset(), endToken.getEndOffset(),
                SubSectionIndicator.PROBABLE_STATUS);
          }
          outSet.add(subs);
View Full Code Here

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

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

      Iterator<Machine> machineItr = iv_machineSet.iterator();
      while (machineItr.hasNext()) {
        Machine fsm = 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 = new NegationIndicator(startToken
              .getStartOffset(), endToken.getEndOffset());
          outSet.add(neg);
          fsm.reset();
        }
      }
View Full Code Here

        // key = Machine , value = token start index
        Map <Machine, Integer>tokenStartMap = new HashMap<Machine, Integer>();

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

            Iterator<Machine>machineItr = iv_machineSet.iterator();
            while (machineItr.hasNext())
            {
                Machine m = (Machine) machineItr.next();

                m.input(token);

                State currentState = m.getCurrentState();
                if (currentState.getStartStateFlag())
                {
                    tokenStartMap.put(m, new Integer(i));
                }
                if (currentState.getEndStateFlag())
                {
                    Object o = tokenStartMap.get(m);
                    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);
                    IllnessDxIndicator si = null;
                    if (m.equals(iv_brainDxMachine))
                    {
                        si = new IllnessDxIndicator(
                                startToken.getStartOffset(),
                                endToken.getEndOffset(),
                                IllnessDxIndicator.BRAIN_STATUS);
                    }
                    else if (m.equals(iv_breastDxMachine))
                    {
                        si = new IllnessDxIndicator(
                                startToken.getStartOffset(),
                                endToken.getEndOffset(),
                                IllnessDxIndicator.BREAST_STATUS);
                    }
                    else if (m.equals(iv_colonDxMachine))
                    {
                        si = new IllnessDxIndicator(
                                startToken.getStartOffset(),
                                endToken.getEndOffset(),
                                IllnessDxIndicator.COLON_STATUS);
                    }
                    else if (m.equals(iv_padDxMachine))
                    {
                        si = new IllnessDxIndicator(
                                startToken.getStartOffset(),
                                endToken.getEndOffset(),
                                IllnessDxIndicator.PAD_STATUS);
                    }
                    outSet.add(si);
                    m.reset();
View Full Code Here

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

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

            Iterator<Machine> 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

        // 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, Integer.valueOf(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;
                    DecimalStrengthToken fractionToken =
                        new DecimalStrengthToken(
                            startToken.getStartOffset(),
                            endToken.getEndOffset());
                    fractionSet.add(fractionToken);
                    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, Integer.valueOf(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;
          DrugChangeStatusToken fractionToken = null;
          if (fsm.equals(iv_startStatusMachine)) {
            fractionToken = new DrugChangeStatusToken(startToken
                .getStartOffset(), endToken.getEndOffset(),DrugChangeStatusToken.START);
          } else if (fsm.equals(iv_stopStatusMachine)) {
            fractionToken = new DrugChangeStatusToken(startToken
                .getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.STOP);
          } else if (fsm.equals(iv_increaseFromStatusMachine)) {
            fractionToken = new DrugChangeStatusToken(startToken
                .getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.INCREASEFROM);
          } else if (fsm.equals(iv_decreaseFromStatusMachine)) {
            fractionToken = new DrugChangeStatusToken(startToken
                .getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.DECREASEFROM);
          else if (fsm.equals(iv_increaseStatusMachine)) {
            fractionToken = new DrugChangeStatusToken(startToken
                .getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.INCREASE);
          } else if (fsm.equals(iv_decreaseStatusMachine)) {
            fractionToken = new DrugChangeStatusToken(startToken
                .getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.DECREASE);
          } else if (fsm.equals(iv_noChangeStatusMachine)) {
            fractionToken = new DrugChangeStatusToken(startToken
                .getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.NOCHANGE);
           
          } else if (fsm.equals(iv_changeStatusMachine)) {
            fractionToken = new DrugChangeStatusToken(startToken
                .getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.OTHER);
          } else if (fsm.equals(iv_sumStatusMachine)) {
            fractionToken = new DrugChangeStatusToken(startToken
                .getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.SUM);
           
          } else if (fsm.equals(iv_maxStatusMachine)) {
            fractionToken = new DrugChangeStatusToken(startToken
                .getStartOffset(), endToken.getEndOffset(), DrugChangeStatusToken.MAX);
           
          }

          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;
          SuffixStrengthToken segmentToken = new SuffixStrengthToken(
              startToken.getStartOffset(), endToken
                  .getEndOffset());
          rangeSet.add(segmentToken);
          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);
        BaseToken startToken = null;
       
        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++;
          }
         
                   
          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);
         
          rangeSet.add(fractionToken);
          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.