Examples of DrugChangeStatusAnnotation


Examples of org.apache.ctakes.drugner.type.DrugChangeStatusAnnotation

        ann = new FractionStrengthAnnotation(jcas, oldAnn.getStartOffset(), oldAnn.getEndOffset());
      else if (DecimalStrengthAnnotation.type == type)
        ann = new DecimalStrengthAnnotation(jcas, oldAnn.getStartOffset(), oldAnn.getEndOffset());
      else if (DrugChangeStatusAnnotation.type == type)
      {
        ann = new DrugChangeStatusAnnotation(jcas, oldAnn.getStartOffset(), oldAnn.getEndOffset());
        ((DrugChangeStatusAnnotation)ann).setChangeStatus(((DrugChangeStatusToken)oldAnn).getDrugChangeStatus());
      }
      else if (RangeStrengthAnnotation.type == type)
        ann = new RangeStrengthAnnotation(jcas, oldAnn.getStartOffset(), oldAnn.getEndOffset());
View Full Code Here

Examples of org.apache.ctakes.drugner.type.DrugChangeStatusAnnotation

          // status changes list (unless Maximum special case)
          boolean isolate = false;
          if (!findSubSection.hasNext())
          {

            DrugChangeStatusAnnotation dsa = (DrugChangeStatusAnnotation) statusChangeItr.next();

            // Maximum case means the drug mention elements should
            // be overridden by this value
            if (((dsa.getChangeStatus().compareTo(
                DrugChangeStatusElement.MAXIMUM_STATUS) != 0)
                && dsa.getEnd() < holdRightEnd)
                && (localSpan[0]<dsa.getBegin() && localSpan[1]> dsa.getEnd()))
            {
              holdStatusChanges.add(dsa);
            } else if (dsa.getChangeStatus().compareTo(
                DrugChangeStatusElement.MAXIMUM_STATUS) == 0
                && dsa.getEnd() < holdRightEnd)
            {
              maxExists = true;
              maxOffsetEnd = dsa.getEnd();
            }

          } else
          {
            statusChangeItr.next();// Added this line to make sure the the next DrugChangeStatusAnnotation in the event that there is no subsection to look at
            boolean noWeirdError = true;
            boolean pullOut = false;
            while (!pullOut && !isolate && findSubSection.hasNext()
                && noWeirdError)
            {
              try
              {
                // each status change is checked against all
                // available sub-spans in that range
                SubSectionAnnotation sub = (SubSectionAnnotation) findSubSection.next();
                Iterator findStartLF = FSUtil.getAnnotationsIteratorInSpan(
                    jcas, NewlineToken.type, holdLeftStart, sub.getBegin() + 1);
                Iterator findEndLF = FSUtil.getAnnotationsIteratorInSpan(jcas,
                    NewlineToken.type, sub.getEnd(), holdRightEnd);

                if (findStartLF.hasNext() && findEndLF.hasNext())
                {

                  while (findStartLF.hasNext())
                  {
                    // int countSymbols = 0;
                    NewlineToken nta = (NewlineToken) findStartLF.next();

                    // Iterator findSymbols =
                    // FSUtil.getAnnotationsInSpanIterator(jcas,
                    // SymbolToken.type,
                    // nta.getEnd(), sub.getBegin());
                    //         
                    // while (findSymbols.hasNext())
                    // {
                    // findSymbols.next();
                    // countSymbols++;
                    // }

                    int countSymbols = FSUtil.countAnnotationsInSpan(jcas,
                        SymbolToken.type, nta.getEnd(), sub.getBegin());

                    if ((nta.getEnd() + countSymbols + 1) >= sub.getBegin())
                    {
                      isolate = true;
                      holdRightEnd = sub.getBegin();
                      end = sub.getBegin();
                    }
                  }

                  if (!isolate)
                  {
                    DrugChangeStatusAnnotation dsa = (DrugChangeStatusAnnotation) statusChangeItr.next();
                    holdStatusChanges.add(dsa);
                    pullOut = true;
                    sub.removeFromIndexes();
                  }
                } else if (findEndLF.hasNext())
                {
                  // subsection is on a prior separate line than the rest
                  // of the content
                  holdLeftStart = sub.getEnd();
                  // sub.removeFromIndexes();

                } else if (sub.getBegin() > tokenAnt.getEnd())
                {
                  end = sub.getBegin();
                  holdRightEnd = sub.getBegin();
                  sub.removeFromIndexes();
                } else
                {
                  holdLeftStart = sub.getEnd();
                  holdRightEnd = tokenAnt.getBegin();
                }
              } catch (NoSuchElementException nsee)
              {
                noWeirdError = false;
                iv_logger.info(nsee.getLocalizedMessage());
              }
            }
          }
        }

        // handles cases like "then discontinue" so the two change status mentions are merged and the last
        // value is used for the change status i.e. 'discontinue'

        List modifiedOrderDrugStatusChanges = new ArrayList();
        Iterator sortStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();
        Iterator sortNextStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();
        // increment sortNextStatusChanges
        if (sortNextStatusChanges.hasNext()) sortNextStatusChanges.next();
        boolean skipNext = false;
        int checkSkippedOffsetBegin = 0, checkSkippedOffsetEnd = 0;
        while (sortStatusChanges.hasNext()) {
          DrugChangeStatusAnnotation hos1 = (DrugChangeStatusAnnotation) sortStatusChanges.next();
          if (sortNextStatusChanges.hasNext()) {

            DrugChangeStatusAnnotation hos2 = (DrugChangeStatusAnnotation) sortNextStatusChanges.next();
            if (hos1.getBegin() == hos2.getBegin()) {
              if (hos1.getEnd() >= hos2.getEnd()) {
                skipNext = true;
                checkSkippedOffsetBegin = hos2.getBegin();
                checkSkippedOffsetEnd = hos2.getEnd();
                hos2.removeFromIndexes();
                modifiedOrderDrugStatusChanges.add(hos1);

              } else {
                iv_logger.info("found reverse case . . need to handle");
              }

            } else if (!skipNext) {
              modifiedOrderDrugStatusChanges.add(hos1);
            } else
              skipNext = false;
          }
          else if (checkSkippedOffsetBegin == 0 || (checkSkippedOffsetBegin != hos1.getBegin() && checkSkippedOffsetEnd != hos1.getEnd())){
            modifiedOrderDrugStatusChanges.add(hos1);
          }
        }       

        Iterator orderedStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();
        Iterator orderedDrugStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();

        if (modifiedOrderDrugStatusChanges.size() > 0 ) {
          int [] newSpan = {begin, end};
          newSpan = statusChangePhraseGenerator ( jcas,  begin,  end,  maxExists,  uniqueNER,
              orderedStatusChanges,  modifiedOrderDrugStatusChanges,  relatedStatus,  drugTokenAnt, 
              globalDrugNER,  countNER );
          begin = newSpan[0];
          end = newSpan[1];
          if ((drugTokenAnt.getDrugChangeStatus() != null && drugTokenAnt.getDrugChangeStatus().equals(DrugChangeStatusToken.NOCHANGE)) ||
              (drugTokenAnt.getDrugChangeStatus() != null && drugTokenAnt.getDrugChangeStatus().equals(DrugChangeStatusToken.OTHER)))  {
            keepNoChangeStatus = true;
            if (drugTokenAnt.getDrugChangeStatus().equals(DrugChangeStatusToken.OTHER))
              drugTokenAnt.setDrugChangeStatus(DrugChangeStatusToken.NOCHANGE);
          }           
          // No change is default state since the change state has been handled
        }
        DrugMention dm = new DrugMention(jcas, begin, end)
        boolean overrideStatus = false;
        boolean statusFound = false;
        if (!keepNoChangeStatus) {
          // All entries may not be appropriate, so some
          // filtering
          // may need to be implemented here
          JFSIndexRepository indexes = jcas.getJFSIndexRepository();
          Iterator subSectionItr = indexes.getAnnotationIndex(
              SubSectionAnnotation.type).iterator();

          String statusKey = null;
          while (subSectionItr.hasNext() && !statusFound)
          {

            SubSectionAnnotation ssid = (SubSectionAnnotation) subSectionItr.next();

            if (ssid.getSubSectionBodyBegin() <= tokenAnt.getBegin()
                && ssid.getSubSectionBodyEnd() >= tokenAnt.getEnd())
            {

              // Look for special case where date comes before the
              // drug mention
              // A better means to locate the beginning of the chunk
              // is lacking here mainly due
              // to the fact that the sentence annotator cannot be
              // trusted to find the beginning
              // accurately.
              boolean overrideDate = false;
              Iterator statusSpecialDateItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DateAnnotation.type, ssid.getEnd(), drugTokenAnt.getBegin());
              while (statusSpecialDateItr.hasNext() && !overrideDate)
              {
                DateAnnotation specialDate = (DateAnnotation) statusSpecialDateItr.next();
                Iterator findLF = FSUtil.getAnnotationsIteratorInSpan(jcas,
                    NewlineToken.type, ssid.getEnd(), specialDate.getBegin());
                if (!findLF.hasNext())
                {
                  // if (specialDate.getEnd() <=
                  // drugTokenAnt.getBegin() ){
                  drugTokenAnt.setStartDate(specialDate.getCoveredText());
                  overrideDate = true;
                }
              }

              DrugChangeStatusAnnotation dsa = null;
              if (orderedDrugStatusChanges.hasNext())
              {
                dsa = (DrugChangeStatusAnnotation) orderedDrugStatusChanges.next();
              }
              if (dsa != null
                  && (dsa.getChangeStatus().compareTo(DrugChangeStatusElement.START_STATUS) == 0 ||
                      dsa.getChangeStatus().compareTo(DrugChangeStatusElement.STOP_STATUS) == 0))
              {
                // Should we override here? Let's get only the first
                // one as an override

                drugTokenAnt.setDrugChangeStatus(dsa.getChangeStatus());
              } else
              {
                statusKey = dm.convertToChangeStatus(ssid.getCoveredText());
                if (ssid.getStatus() == 1)
                {

                  // drugTokenAnt.setCertainty(-1);
                  statusKey = DrugChangeStatusToken.STOP;
                }
                if (statusKey.compareTo(DrugChangeStatusToken.NOCHANGE) == 0)
                {
                  Iterator oneDrugChangeStatus = FSUtil.getAnnotationsIteratorInSpan(jcas,
                      DrugChangeStatusAnnotation.type, ssid.getBegin(), ssid.getEnd() + 1);
                  if (oneDrugChangeStatus.hasNext())
                  {
                    dsa = (DrugChangeStatusAnnotation) oneDrugChangeStatus.next();
                    drugTokenAnt.setDrugChangeStatus(dsa.getChangeStatus());
                    statusKey = dsa.getChangeStatus();
                  }
                }
                drugTokenAnt.setStatus(ssid.getStatus());
                dm.setDrugChangeStatusElement(statusKey, begin, end);

                statusFound = true;
              }
            }
          }

          // Look for special case where status comes before the drug
          // mention
          // A better means to locate the beginning of the chunk is
          // lacking here mainly due
          // to the fact that the sentence annotator cannot be trusted to
          // find the beginning
          // accurately.

          Iterator statusSpecialChangeItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DrugChangeStatusAnnotation.type, begin - 20, drugTokenAnt.getBegin() + 1);
          while (statusSpecialChangeItr.hasNext())
          {
            DrugChangeStatusAnnotation specialDsa = (DrugChangeStatusAnnotation) statusSpecialChangeItr.next();
            if (specialDsa.getEnd() + 1 == drugTokenAnt.getBegin()
                && relatedStatus == null)
            {
              drugTokenAnt.setDrugChangeStatus(specialDsa.getChangeStatus());
              drugTokenAnt.setChangeStatusBegin(specialDsa.getBegin());
              drugTokenAnt.setChangeStatusEnd(specialDsa.getEnd());
              overrideStatus = true;
            }
          }
        }
        // If a strength token is discovered before the next
View Full Code Here

Examples of org.apache.ctakes.drugner.type.DrugChangeStatusAnnotation

      // sortStatusMentionsItr(holdStatusChanges.toArray()).iterator();
      Iterator nextStatusChanges = sortAnnotations(
          holdStatusChanges.toArray()).iterator();

      // prime for next status change in chunk
      DrugChangeStatusAnnotation nextDrugStatus = null;
      if (nextStatusChanges.hasNext())
      {
        nextDrugStatus = (DrugChangeStatusAnnotation) nextStatusChanges.next();
      }
      DrugChangeStatusAnnotation drugStatus = (DrugChangeStatusAnnotation) orderedStatusChanges.next();

      if (nextStatusChanges.hasNext()
          && drugStatus.getChangeStatus().compareTo(
              DrugChangeStatusToken.STOP) != 0)
      {
        nextDrugStatus = (DrugChangeStatusAnnotation) nextStatusChanges.next();
        if (drugStatus.getBegin() == nextDrugStatus.getBegin())
        {
          if (drugStatus.getEnd() < nextDrugStatus.getEnd())
            drugStatus = nextDrugStatus;
          else
            nextDrugStatus = drugStatus;
        }
        if (!uniqueNER.hasNext())
        {
          if ((nextDrugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.INCREASE) == 0
              || nextDrugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.DECREASE) == 0
              || nextDrugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.OTHER) == 0)
                  && (drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.START) == 0
              || (drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.STOP) == 0))
              || (drugTokenAnt.getEnd() + 1 == drugStatus.getBegin()))
          {
            drugStatus = nextDrugStatus;
            deferRight = true;
          }

        }
        // +2 takes the cases of adjacent drug mentions with or
        // without a punctuation token
        else if (nextDrugStatus.getBegin() <= drugStatus.getEnd() + 2)
        {
          if (orderedStatusChanges.hasNext()
              && nextDrugStatus.getBegin() != drugStatus.getBegin())
          {
            orderedStatusChanges.next();
          }
          // Decrease or Increase should trump stop, start and change
          else
          {
            if ((nextDrugStatus.getChangeStatus().compareTo(
                DrugChangeStatusToken.INCREASE) == 0
                || nextDrugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.DECREASE) == 0
                || nextDrugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.OTHER) == 0)
                    && (drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.START) == 0
                || (drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.STOP) == 0)))
              drugStatus = nextDrugStatus;
          }
        }
        if (relatedStatus != null)
          end = nextDrugStatus.getBegin();
      }
      if (drugStatus.getEnd() < end
          && !maxExists
          && (drugStatus.getEnd() != nextDrugStatus.getEnd()
              || drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.DECREASE) == 0
              || drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.DECREASEFROM) == 0
              || drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.INCREASE) == 0
              || drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.INCREASEFROM) == 0)
              || drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.OTHER) == 0)
      {

        checkSpan = generateAdditionalNER(jcas, drugTokenAnt, drugStatus, begin, end,
            countNER, globalDrugNER);
View Full Code Here

Examples of org.apache.ctakes.drugner.type.DrugChangeStatusAnnotation

      }

    }
    else if (elementType == DrugChangeStatusAnnotation.type) {
      while (neItr.hasNext()) {
        DrugChangeStatusAnnotation nea = (DrugChangeStatusAnnotation) neItr.next();
        lastLocation[0] = nea.getBegin();
        lastLocation[1] = nea.getEnd();
        if (nea.getBegin()>=begin && nea.getEnd() <= end && (counter == || (counter> 0 && lastLocation[0] !=  location[counter - 1][0]))) {
          location[counter][0]= lastLocation[0];
          location[counter][1]= lastLocation[1];
          counter++;
        }
      }

    } else if (elementType == MedicationMention.type) {
      while (neItr.hasNext()) {
        MedicationMention nea = (MedicationMention) neItr.next();
        if(nea.getTypeID()==1 || nea.getTypeID()==0) {
          lastLocation[0]= nea.getBegin();
          lastLocation[1] = nea.getEnd();
          if ((counter == 0 || lastLocation[0] != location[counter-1][0]) && (nea.getBegin()>=begin && nea.getEnd() <= end)) {
            location[counter][0]= lastLocation[0];
            location[counter][1]= lastLocation[1];
            counter++;
          }

        }
      }
    } else if (elementType == PunctuationToken.type) {
      while (neItr.hasNext()) {
        boolean foundPair = false;
        PunctuationToken nea = (PunctuationToken) neItr.next();
        if (nea.getCoveredText().compareTo("(")==0)
          lastLocation[0] = nea.getBegin();
        else if (nea.getCoveredText().compareTo(")")==0) {
          lastLocation[1] = nea.getEnd();
          foundPair = true;
        }
        if (nea.getBegin()>=begin && nea.getEnd() <= end && foundPair && (counter == || (counter> 0 && lastLocation[0] !=  location[counter - 1][0]))) {
          location[counter][0]= lastLocation[0];
          location[counter][1]= lastLocation[1];
          counter++;
        }
      }
View Full Code Here

Examples of org.apache.ctakes.drugner.type.DrugChangeStatusAnnotation

      numElements++;
    }
    neItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
        DrugChangeStatusAnnotation.type, begin, end);
    while (neItr.hasNext()) {
      DrugChangeStatusAnnotation nea = (DrugChangeStatusAnnotation) neItr.next();

      numElements++;
    }

    if (numElements > 1)
View Full Code Here

Examples of org.apache.ctakes.drugner.type.DrugChangeStatusAnnotation

      int endOffset) {

    Iterator firItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
        DrugChangeStatusAnnotation.type, beginOffset, endOffset + 1);
    while (firItr.hasNext()) {
      DrugChangeStatusAnnotation dcsa = (DrugChangeStatusAnnotation) firItr
          .next();
      if (dcsa.getBegin() == beginOffset) {
        int posSpace = dcsa.getCoveredText().indexOf(' ');
        int posHyph = dcsa.getCoveredText().indexOf('-');
        String firstTerm = dcsa.getCoveredText();
        if (posSpace > 0)
          firstTerm = dcsa.getCoveredText().substring(0, posSpace);
        if (posHyph > 0)
          firstTerm = firstTerm.substring(0, posHyph);

        return dcsa.getChangeStatus();//convertToChangeStatus(firstTerm);

      }
    }
    return null;
  }
View Full Code Here

Examples of org.apache.ctakes.drugner.type.DrugChangeStatusAnnotation

        ann = new FractionStrengthAnnotation(jcas, oldAnn.getStartOffset(), oldAnn.getEndOffset());
      else if (DecimalStrengthAnnotation.type == type)
        ann = new DecimalStrengthAnnotation(jcas, oldAnn.getStartOffset(), oldAnn.getEndOffset());
      else if (DrugChangeStatusAnnotation.type == type)
      {
        ann = new DrugChangeStatusAnnotation(jcas, oldAnn.getStartOffset(), oldAnn.getEndOffset());
        ((DrugChangeStatusAnnotation)ann).setChangeStatus(((DrugChangeStatusToken)oldAnn).getDrugChangeStatus());
      }
      else if (RangeStrengthAnnotation.type == type)
        ann = new RangeStrengthAnnotation(jcas, oldAnn.getStartOffset(), oldAnn.getEndOffset());
View Full Code Here

Examples of org.apache.ctakes.drugner.type.DrugChangeStatusAnnotation

          // status changes list (unless Maximum special case)
          boolean isolate = false;
          if (!findSubSection.hasNext())
          {

            DrugChangeStatusAnnotation dsa = (DrugChangeStatusAnnotation) statusChangeItr.next();

            // Maximum case means the drug mention elements should
            // be overridden by this value
            if (((dsa.getChangeStatus().compareTo(
                DrugChangeStatusElement.MAXIMUM_STATUS) != 0)
                && dsa.getEnd() < holdRightEnd)
                && (localSpan[0]<dsa.getBegin() && localSpan[1]> dsa.getEnd()))
            {
              holdStatusChanges.add(dsa);
            } else if (dsa.getChangeStatus().compareTo(
                DrugChangeStatusElement.MAXIMUM_STATUS) == 0
                && dsa.getEnd() < holdRightEnd)
            {
              maxExists = true;
              maxOffsetEnd = dsa.getEnd();
            }

          } else
          {
            statusChangeItr.next();// Added this line to make sure the the next DrugChangeStatusAnnotation in the event that there is no subsection to look at
            boolean noWeirdError = true;
            boolean pullOut = false;
            while (!pullOut && !isolate && findSubSection.hasNext()
                && noWeirdError)
            {
              try
              {
                // each status change is checked against all
                // available sub-spans in that range
                SubSectionAnnotation sub = (SubSectionAnnotation) findSubSection.next();
                Iterator findStartLF = FSUtil.getAnnotationsIteratorInSpan(
                    jcas, NewlineToken.type, holdLeftStart, sub.getBegin() + 1);
                Iterator findEndLF = FSUtil.getAnnotationsIteratorInSpan(jcas,
                    NewlineToken.type, sub.getEnd(), holdRightEnd);

                if (findStartLF.hasNext() && findEndLF.hasNext())
                {

                  while (findStartLF.hasNext())
                  {
                    // int countSymbols = 0;
                    NewlineToken nta = (NewlineToken) findStartLF.next();

                    // Iterator findSymbols =
                    // FSUtil.getAnnotationsInSpanIterator(jcas,
                    // SymbolToken.type,
                    // nta.getEnd(), sub.getBegin());
                    //         
                    // while (findSymbols.hasNext())
                    // {
                    // findSymbols.next();
                    // countSymbols++;
                    // }

                    int countSymbols = FSUtil.countAnnotationsInSpan(jcas,
                        SymbolToken.type, nta.getEnd(), sub.getBegin());

                    if ((nta.getEnd() + countSymbols + 1) >= sub.getBegin())
                    {
                      isolate = true;
                      holdRightEnd = sub.getBegin();
                      end = sub.getBegin();
                    }
                  }

                  if (!isolate)
                  {
                    DrugChangeStatusAnnotation dsa = (DrugChangeStatusAnnotation) statusChangeItr.next();
                    holdStatusChanges.add(dsa);
                    pullOut = true;
                    sub.removeFromIndexes();
                  }
                } else if (findEndLF.hasNext())
                {
                  // subsection is on a prior separate line than the rest
                  // of the content
                  holdLeftStart = sub.getEnd();
                  // sub.removeFromIndexes();

                } else if (sub.getBegin() > tokenAnt.getEnd())
                {
                  end = sub.getBegin();
                  holdRightEnd = sub.getBegin();
                  sub.removeFromIndexes();
                } else
                {
                  holdLeftStart = sub.getEnd();
                  holdRightEnd = tokenAnt.getBegin();
                }
              } catch (NoSuchElementException nsee)
              {
                noWeirdError = false;
                iv_logger.info(nsee.getLocalizedMessage());
              }
            }
          }
        }

        // handles cases like "then discontinue" so the two change status mentions are merged and the last
        // value is used for the change status i.e. 'discontinue'

        List modifiedOrderDrugStatusChanges = new ArrayList();
        Iterator sortStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();
        Iterator sortNextStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();
        // increment sortNextStatusChanges
        if (sortNextStatusChanges.hasNext()) sortNextStatusChanges.next();
        boolean skipNext = false;
        int checkSkippedOffsetBegin = 0, checkSkippedOffsetEnd = 0;
        while (sortStatusChanges.hasNext()) {
          DrugChangeStatusAnnotation hos1 = (DrugChangeStatusAnnotation) sortStatusChanges.next();
          if (sortNextStatusChanges.hasNext()) {

            DrugChangeStatusAnnotation hos2 = (DrugChangeStatusAnnotation) sortNextStatusChanges.next();
            if (hos1.getBegin() == hos2.getBegin()) {
              if (hos1.getEnd() >= hos2.getEnd()) {
                skipNext = true;
                checkSkippedOffsetBegin = hos2.getBegin();
                checkSkippedOffsetEnd = hos2.getEnd();
                hos2.removeFromIndexes();
                modifiedOrderDrugStatusChanges.add(hos1);

              } else {
                iv_logger.info("found reverse case . . need to handle");
              }

            } else if (!skipNext) {
              modifiedOrderDrugStatusChanges.add(hos1);
            } else
              skipNext = false;
          }
          else if (checkSkippedOffsetBegin == 0 || (checkSkippedOffsetBegin != hos1.getBegin() && checkSkippedOffsetEnd != hos1.getEnd())){
            modifiedOrderDrugStatusChanges.add(hos1);
          }
        }       

        Iterator orderedStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();
        Iterator orderedDrugStatusChanges = sortAnnotations(holdStatusChanges.toArray()).iterator();

        if (modifiedOrderDrugStatusChanges.size() > 0 ) {
          int [] newSpan = {begin, end};
          newSpan = statusChangePhraseGenerator ( jcas,  begin,  end,  maxExists,  uniqueNER,
              orderedStatusChanges,  modifiedOrderDrugStatusChanges,  relatedStatus,  drugTokenAnt, 
              globalDrugNER,  countNER );
          begin = newSpan[0];
          end = newSpan[1];
          if ((drugTokenAnt.getDrugChangeStatus() != null && drugTokenAnt.getDrugChangeStatus().equals(DrugChangeStatusToken.NOCHANGE)) ||
              (drugTokenAnt.getDrugChangeStatus() != null && drugTokenAnt.getDrugChangeStatus().equals(DrugChangeStatusToken.OTHER)))  {
            keepNoChangeStatus = true;
            if (drugTokenAnt.getDrugChangeStatus().equals(DrugChangeStatusToken.OTHER))
              drugTokenAnt.setDrugChangeStatus(DrugChangeStatusToken.NOCHANGE);
          }           
          // No change is default state since the change state has been handled
        }
        DrugMention dm = new DrugMention(jcas, begin, end)
        boolean overrideStatus = false;
        boolean statusFound = false;
        if (!keepNoChangeStatus) {
          // All entries may not be appropriate, so some
          // filtering
          // may need to be implemented here
          JFSIndexRepository indexes = jcas.getJFSIndexRepository();
          Iterator subSectionItr = indexes.getAnnotationIndex(
              SubSectionAnnotation.type).iterator();

          String statusKey = null;
          while (subSectionItr.hasNext() && !statusFound)
          {

            SubSectionAnnotation ssid = (SubSectionAnnotation) subSectionItr.next();

            if (ssid.getSubSectionBodyBegin() <= tokenAnt.getBegin()
                && ssid.getSubSectionBodyEnd() >= tokenAnt.getEnd())
            {

              // Look for special case where date comes before the
              // drug mention
              // A better means to locate the beginning of the chunk
              // is lacking here mainly due
              // to the fact that the sentence annotator cannot be
              // trusted to find the beginning
              // accurately.
              boolean overrideDate = false;
              Iterator statusSpecialDateItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DateAnnotation.type, ssid.getEnd(), drugTokenAnt.getBegin());
              while (statusSpecialDateItr.hasNext() && !overrideDate)
              {
                DateAnnotation specialDate = (DateAnnotation) statusSpecialDateItr.next();
                Iterator findLF = FSUtil.getAnnotationsIteratorInSpan(jcas,
                    NewlineToken.type, ssid.getEnd(), specialDate.getBegin());
                if (!findLF.hasNext())
                {
                  // if (specialDate.getEnd() <=
                  // drugTokenAnt.getBegin() ){
                  drugTokenAnt.setStartDate(specialDate.getCoveredText());
                  overrideDate = true;
                }
              }

              DrugChangeStatusAnnotation dsa = null;
              if (orderedDrugStatusChanges.hasNext())
              {
                dsa = (DrugChangeStatusAnnotation) orderedDrugStatusChanges.next();
              }
              if (dsa != null
                  && (dsa.getChangeStatus().compareTo(DrugChangeStatusElement.START_STATUS) == 0 ||
                      dsa.getChangeStatus().compareTo(DrugChangeStatusElement.STOP_STATUS) == 0))
              {
                // Should we override here? Let's get only the first
                // one as an override

                drugTokenAnt.setDrugChangeStatus(dsa.getChangeStatus());
              } else
              {
                statusKey = dm.convertToChangeStatus(ssid.getCoveredText());
                if (ssid.getStatus() == 1)
                {

                  // drugTokenAnt.setCertainty(-1);
                  statusKey = DrugChangeStatusToken.STOP;
                }
                if (statusKey.compareTo(DrugChangeStatusToken.NOCHANGE) == 0)
                {
                  Iterator oneDrugChangeStatus = FSUtil.getAnnotationsIteratorInSpan(jcas,
                      DrugChangeStatusAnnotation.type, ssid.getBegin(), ssid.getEnd() + 1);
                  if (oneDrugChangeStatus.hasNext())
                  {
                    dsa = (DrugChangeStatusAnnotation) oneDrugChangeStatus.next();
                    drugTokenAnt.setDrugChangeStatus(dsa.getChangeStatus());
                    statusKey = dsa.getChangeStatus();
                  }
                }
                drugTokenAnt.setStatus(ssid.getStatus());
                dm.setDrugChangeStatusElement(statusKey, begin, end);

                statusFound = true;
              }
            }
          }

          // Look for special case where status comes before the drug
          // mention
          // A better means to locate the beginning of the chunk is
          // lacking here mainly due
          // to the fact that the sentence annotator cannot be trusted to
          // find the beginning
          // accurately.

          Iterator statusSpecialChangeItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DrugChangeStatusAnnotation.type, begin - 20, drugTokenAnt.getBegin() + 1);
          while (statusSpecialChangeItr.hasNext())
          {
            DrugChangeStatusAnnotation specialDsa = (DrugChangeStatusAnnotation) statusSpecialChangeItr.next();
            if (specialDsa.getEnd() + 1 == drugTokenAnt.getBegin()
                && relatedStatus == null)
            {
              drugTokenAnt.setDrugChangeStatus(specialDsa.getChangeStatus());
              drugTokenAnt.setChangeStatusBegin(specialDsa.getBegin());
              drugTokenAnt.setChangeStatusEnd(specialDsa.getEnd());
              overrideStatus = true;
            }
          }
        }
        // If a strength token is discovered before the next
View Full Code Here

Examples of org.apache.ctakes.drugner.type.DrugChangeStatusAnnotation

      // sortStatusMentionsItr(holdStatusChanges.toArray()).iterator();
      Iterator nextStatusChanges = sortAnnotations(
          holdStatusChanges.toArray()).iterator();

      // prime for next status change in chunk
      DrugChangeStatusAnnotation nextDrugStatus = null;
      if (nextStatusChanges.hasNext())
      {
        nextDrugStatus = (DrugChangeStatusAnnotation) nextStatusChanges.next();
      }
      DrugChangeStatusAnnotation drugStatus = (DrugChangeStatusAnnotation) orderedStatusChanges.next();

      if (nextStatusChanges.hasNext()
          && drugStatus.getChangeStatus().compareTo(
              DrugChangeStatusToken.STOP) != 0)
      {
        nextDrugStatus = (DrugChangeStatusAnnotation) nextStatusChanges.next();
        if (drugStatus.getBegin() == nextDrugStatus.getBegin())
        {
          if (drugStatus.getEnd() < nextDrugStatus.getEnd())
            drugStatus = nextDrugStatus;
          else
            nextDrugStatus = drugStatus;
        }
        if (!uniqueNER.hasNext())
        {
          if ((nextDrugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.INCREASE) == 0
              || nextDrugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.DECREASE) == 0
              || nextDrugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.OTHER) == 0)
                  && (drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.START) == 0
              || (drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.STOP) == 0))
              || (drugTokenAnt.getEnd() + 1 == drugStatus.getBegin()))
          {
            drugStatus = nextDrugStatus;
            deferRight = true;
          }

        }
        // +2 takes the cases of adjacent drug mentions with or
        // without a punctuation token
        else if (nextDrugStatus.getBegin() <= drugStatus.getEnd() + 2)
        {
          if (orderedStatusChanges.hasNext()
              && nextDrugStatus.getBegin() != drugStatus.getBegin())
          {
            orderedStatusChanges.next();
          }
          // Decrease or Increase should trump stop, start and change
          else
          {
            if ((nextDrugStatus.getChangeStatus().compareTo(
                DrugChangeStatusToken.INCREASE) == 0
                || nextDrugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.DECREASE) == 0
                || nextDrugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.OTHER) == 0)
                    && (drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.START) == 0
                || (drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.STOP) == 0)))
              drugStatus = nextDrugStatus;
          }
        }
        if (relatedStatus != null)
          end = nextDrugStatus.getBegin();
      }
      if (drugStatus.getEnd() < end
          && !maxExists
          && (drugStatus.getEnd() != nextDrugStatus.getEnd()
              || drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.DECREASE) == 0
              || drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.DECREASEFROM) == 0
              || drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.INCREASE) == 0
              || drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.INCREASEFROM) == 0)
              || drugStatus.getChangeStatus().compareTo(DrugChangeStatusToken.OTHER) == 0)
      {

        checkSpan = generateAdditionalNER(jcas, drugTokenAnt, drugStatus, begin, end,
            countNER, globalDrugNER);
View Full Code Here

Examples of org.apache.ctakes.drugner.type.DrugChangeStatusAnnotation

      }

    }
    else if (elementType == DrugChangeStatusAnnotation.type) {
      while (neItr.hasNext()) {
        DrugChangeStatusAnnotation nea = (DrugChangeStatusAnnotation) neItr.next();
        lastLocation[0] = nea.getBegin();
        lastLocation[1] = nea.getEnd();
        if (nea.getBegin()>=begin && nea.getEnd() <= end && (counter == || (counter> 0 && lastLocation[0] !=  location[counter - 1][0]))) {
          location[counter][0]= lastLocation[0];
          location[counter][1]= lastLocation[1];
          counter++;
        }
      }

    } else if (elementType == MedicationMention.type) {
      while (neItr.hasNext()) {
        MedicationMention nea = (MedicationMention) neItr.next();
        if(nea.getTypeID()==1 || nea.getTypeID()==0) {
          lastLocation[0]= nea.getBegin();
          lastLocation[1] = nea.getEnd();
          if ((counter == 0 || lastLocation[0] != location[counter-1][0]) && (nea.getBegin()>=begin && nea.getEnd() <= end)) {
            location[counter][0]= lastLocation[0];
            location[counter][1]= lastLocation[1];
            counter++;
          }

        }
      }
    } else if (elementType == PunctuationToken.type) {
      while (neItr.hasNext()) {
        boolean foundPair = false;
        PunctuationToken nea = (PunctuationToken) neItr.next();
        if (nea.getCoveredText().compareTo("(")==0)
          lastLocation[0] = nea.getBegin();
        else if (nea.getCoveredText().compareTo(")")==0) {
          lastLocation[1] = nea.getEnd();
          foundPair = true;
        }
        if (nea.getBegin()>=begin && nea.getEnd() <= end && foundPair && (counter == || (counter> 0 && lastLocation[0] !=  location[counter - 1][0]))) {
          location[counter][0]= lastLocation[0];
          location[counter][1]= lastLocation[1];
          counter++;
        }
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.