Examples of DrugChangeStatusAnnotation


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

  private static final Pattern lookForPercent = Pattern.compile("[%]");

  public DrugMention(JCas jcas, int beginPos, int endPos) {
    Iterator drugStatusTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DrugChangeStatusAnnotation.type, beginPos, endPos);
    while (drugStatusTokenItr.hasNext()){
      DrugChangeStatusAnnotation focusToken = (DrugChangeStatusAnnotation) drugStatusTokenItr.next();
      String localStatus = null;
      if ((localStatus = findDrugChangeStatusElement(jcas, focusToken
          .getBegin(), focusToken.getEnd())) == null) {
        changeStatus = new DrugChangeStatusElement(focusToken
            .getCoveredText(), focusToken.getBegin(),
            focusToken.getEnd());
      } else {
        setDrugChangeStatusElement(localStatus, focusToken
            .getBegin(), focusToken.getEnd());
      }
    }
   
    if (changeStatus != null
        && (changeStatus.getDrugChangeStatus().equals(DrugChangeStatusToken.INCREASEFROM)
            || changeStatus.getDrugChangeStatus().equals(DrugChangeStatusToken.DECREASE))) {
      findMaxValue = false;
     
    }
     
    Iterator dateTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
        DateAnnotation.type, beginPos, endPos);
    while (dateTokenItr.hasNext()){
      DateAnnotation focusToken = (DateAnnotation) dateTokenItr.next();
      String localDate = null;
      if ((localDate = findStartDateElement(jcas, focusToken.getBegin(),
          focusToken.getEnd())) == null) {

        startDate = new StartDateElement(focusToken.getCoveredText(),
            focusToken.getBegin(), focusToken.getEnd());
      } else {
        setStartDateElement(localDate, focusToken.getBegin(),
            focusToken.getEnd());
      }
    }
     
    Iterator doseTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
        DosagesAnnotation.type, beginPos, endPos);
    while (doseTokenItr.hasNext()){
      DosagesAnnotation focusToken = (DosagesAnnotation) doseTokenItr.next();
      String localDose = null;
      if ((localDose = findDosageElement(jcas, focusToken.getBegin(),
          focusToken.getEnd())) == null) {

        dosage = new DosageElement(focusToken.getCoveredText(),
            focusToken.getBegin(), focusToken.getEnd());
      } else {
        setDosageElement(localDose, focusToken.getBegin(),
            focusToken.getEnd());
       
      }
    }
    Iterator frequencyTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
        FrequencyAnnotation.type, beginPos, endPos);
    while (frequencyTokenItr.hasNext()){
      FrequencyAnnotation focusToken = (FrequencyAnnotation) frequencyTokenItr.next();
      String localFreq = null;
      if ((localFreq = findFrequencyElement(jcas, focusToken
          .getBegin(), focusToken.getEnd())) == null) {

        frequency = new FrequencyElement(focusToken
            .getCoveredText(), focusToken.getBegin(),
            focusToken.getEnd());
      } else if ((frequency != null && localFreq != null)
          && (frequency.getFrequencyMention().compareTo("") != 0)
          && (localFreq.compareTo("") != 0)
          && (parseIntValue(localFreq) > parseIntValue(frequency
              .getFrequencyMention()) && findMaxValue == true)) {
        // Need a way to find the largest frequency and/or convert
        // it to factor daily dosage

        setFrequencyElement(localFreq, focusToken.getBegin(),
            focusToken.getEnd());
    } else {
      setFrequencyElement(localFreq, focusToken.getBegin(),
          focusToken.getEnd());
    }
    } 
      Iterator frequencyUnitTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas,
          FrequencyUnitAnnotation.type, beginPos, endPos);
      while (frequencyUnitTokenItr.hasNext()){
        FrequencyUnitAnnotation focusToken = (FrequencyUnitAnnotation) frequencyUnitTokenItr.next();
        String localFreq = null;
        if ((localFreq = findFrequencyUnitElement(jcas,
                focusToken.getBegin(), focusToken.getEnd())) == null) {
          frequencyUnit = new FrequencyUnitElement(focusToken
              .getCoveredText(), focusToken.getBegin(),
              focusToken.getEnd());
        } else if (frequencyUnit == null
            && findMaxValue == true) {
          // Need a way to find the largest frequency and/or convert
          // it to factor daily dosage
          setFrequencyUnitElement(localFreq, focusToken.getBegin(),
              focusToken.getEnd());
        }
      }
      Iterator strengthUnitTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, StrengthUnitAnnotation.type, beginPos, endPos);
      while (strengthUnitTokenItr.hasNext()){
        StrengthUnitAnnotation focusToken = (StrengthUnitAnnotation) strengthUnitTokenItr.next();
        setStrengthUnitElement(focusToken.getCoveredText(),
            focusToken.getBegin(), focusToken.getEnd());
      }
      Iterator strengthTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, StrengthAnnotation.type, beginPos, endPos);
      while (strengthTokenItr.hasNext()){
        StrengthAnnotation focusToken = (StrengthAnnotation) strengthTokenItr.next();
        

            String localStrength = null;
            if ((localStrength = findStrengthElement(jcas, focusToken
                .getBegin(), focusToken.getEnd())) == null) {
              strength = new StrengthElement(focusToken.getCoveredText(),
                  focusToken.getBegin(), focusToken.getEnd());
            } else {
              if (strength != null) {
                // check for range and compare
                int spacePosition = strength.getStrengthMention()
                    .indexOf(" ");
                int spacePos = localStrength
                .indexOf(" ");
                if (spacePosition > 0 && spacePos > 0
                    && parseDoubleValue(strength
                        .getStrengthMention().substring(0,
                            spacePosition)) < parseDoubleValue(localStrength
                        .substring(0, localStrength
                            .indexOf(" ")))&& findMaxValue == true) {
                  setStrengthElement(localStrength, focusToken
                      .getBegin(), focusToken.getEnd());
                } else {
                  String stringRange = strength.getStrengthMention();
                  int hyphPosition = 0;
                  if ((stringRange.length() > 0)
                      && (stringRange.indexOf('-') > 0)) {
                    hyphPosition = stringRange.indexOf('-');
                    Double firstValue = new Double(
                        parseDoubleValue(stringRange
                            .subSequence(0, hyphPosition)));
                    Double secondValue = new Double(
                        parseDoubleValue(stringRange
                            .substring(hyphPosition + 2)));
                    if (firstValue.doubleValue() >= secondValue
                        .doubleValue() && findMaxValue == true) {
                      setStrengthElement(firstValue.toString(),
                          focusToken.getBegin(), focusToken
                              .getEnd());
                    } else {
                      setStrengthElement(firstValue.toString(),
                          focusToken.getBegin(), focusToken
                              .getEnd());
                    }
                  }
                }
              } else if ((localStrength.length() > 0)
                  && (localStrength.indexOf('-') > 0)) {

                int hyphPosition = 0;

                hyphPosition = localStrength.indexOf('-');
                Double firstValue = new Double(
                    parseDoubleValue(localStrength.subSequence(0,
                        hyphPosition)));
                Double secondValue = new Double(
                    parseDoubleValue(localStrength
                        .substring(hyphPosition + 2)));
                if (firstValue.doubleValue() >= secondValue
                    .doubleValue() && findMaxValue == true) {
                  setStrengthElement(firstValue.toString(),
                      focusToken.getBegin(), focusToken.getEnd());
                } else {
                  setStrengthElement(firstValue.toString(),
                      focusToken.getBegin(), focusToken.getEnd());
                }

                setStrengthElement(localStrength,
                    focusToken.getBegin(), focusToken.getEnd());
              } else {
                setStrengthElement(localStrength,
                    focusToken.getBegin(), focusToken.getEnd());
              }
            }
      }
      Iterator formTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, FormAnnotation.type, beginPos, endPos);
      while (formTokenItr.hasNext()){
        FormAnnotation focusToken = (FormAnnotation) formTokenItr.next();
        String localForm = null;
        if ((localForm = findFormElement(jcas, focusToken.getBegin(),
            focusToken.getEnd())) == null) {
          form = new FormElement(focusToken.getCoveredText(),
              focusToken.getBegin(), focusToken.getEnd());
        } else {
          setFormElement(localForm, focusToken.getBegin(), focusToken
              .getEnd());
        }
      }
      Iterator routeTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, RouteAnnotation.type, beginPos, endPos);
      while (routeTokenItr.hasNext()){
        RouteAnnotation focusToken = (RouteAnnotation) routeTokenItr.next();
        String localRoute = null;
        if ((localRoute = findRouteElement(jcas, focusToken.getBegin(),
            focusToken.getEnd())) == null) {
          route = new RouteElement(focusToken.getCoveredText(),
              focusToken.getBegin(), focusToken.getEnd());
        } else {
          setRouteElement(localRoute, focusToken.getBegin(),
              focusToken.getEnd());
        }
      }
      Iterator durationTokenItr = FSUtil.getAnnotationsIteratorInSpan(jcas, DurationAnnotation.type, beginPos, endPos);
      while (durationTokenItr.hasNext()){
        DurationAnnotation focusToken = (DurationAnnotation) durationTokenItr.next();
        String localDuration = null;
        if ((localDuration = findDurationElement(jcas, focusToken
            .getBegin(), focusToken.getEnd())) == null) {
          duration = new DurationElement(focusToken.getCoveredText(),
              focusToken.getBegin(), focusToken.getEnd());
        } else {
          setDurationElement(localDuration, focusToken.getBegin(),
              focusToken.getEnd());
        }
      }

     
 
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

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

        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
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.