Examples of SubSectionAnnotation


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

      SubSectionIndicator ssi = (SubSectionIndicator) sortedSubSecInds.get(i);
      Segment segment = getSegmentContainingOffsets(jcas, ssi.getStartOffset(),
          ssi.getEndOffset());
      endBodyOffset = segment.getEnd(); // backup

      SubSectionAnnotation ssa = new SubSectionAnnotation(jcas);

      ssa.setBegin(ssi.getStartOffset());
      // header is marked by the indicator
      ssa.setSubSectionHeaderBegin(ssi.getStartOffset());
      ssa.setSubSectionHeaderEnd(ssi.getEndOffset());

      // body begins where SubSectionIndicator ends
      ssa.setSubSectionBodyBegin(ssi.getEndOffset() + 1);

      if (i + 1 < sortedSubSecInds.size()) // i is not the last element
      {
        SubSectionIndicator nextSsi = (SubSectionIndicator) sortedSubSecInds.get(i + 1);
        endBodyOffset = getSubSectionAnnotationBodyEnd(segment, nextSsi);

      } else
        // this was the last SubSectionIndicator
      {
        endBodyOffset = getSubSectionAnnotationBodyEnd(segment, null);
      }
      ssa.setSubSectionBodyEnd(endBodyOffset);
      ssa.setEnd(endBodyOffset);
      ssa.addToIndexes();
    }
      }
View Full Code Here

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

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

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

      SubSectionIndicator ssi = (SubSectionIndicator) sortedSubSecInds.get(i);
      Segment segment = getSegmentContainingOffsets(jcas, ssi.getStartOffset(),
          ssi.getEndOffset());
      endBodyOffset = segment.getEnd(); // backup

      SubSectionAnnotation ssa = new SubSectionAnnotation(jcas);

      ssa.setBegin(ssi.getStartOffset());
      // header is marked by the indicator
      ssa.setSubSectionHeaderBegin(ssi.getStartOffset());
      ssa.setSubSectionHeaderEnd(ssi.getEndOffset());

      // body begins where SubSectionIndicator ends
      ssa.setSubSectionBodyBegin(ssi.getEndOffset() + 1);

      if (i + 1 < sortedSubSecInds.size()) // i is not the last element
      {
        SubSectionIndicator nextSsi = (SubSectionIndicator) sortedSubSecInds.get(i + 1);
        endBodyOffset = getSubSectionAnnotationBodyEnd(segment, nextSsi);

      } else
        // this was the last SubSectionIndicator
      {
        endBodyOffset = getSubSectionAnnotationBodyEnd(segment, null);
      }
      ssa.setSubSectionBodyEnd(endBodyOffset);
      ssa.setEnd(endBodyOffset);
      ssa.addToIndexes();
    }
      }
View Full Code Here

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

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

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

                String containedInSubSection = segmentID;
                Iterator subSectionItr = indexes.getAnnotationIndex(
                    SubSectionAnnotation.type).iterator();
                while (subSectionItr.hasNext())
                {
                    SubSectionAnnotation ssAnnot = (SubSectionAnnotation) subSectionItr.next();
                    if (ssAnnot.getSubSectionBodyBegin() <= neAnnot.getBegin() && ssAnnot.getSubSectionBodyEnd() >= neAnnot.getEnd())
                    {
                  Iterator textSpanInSs = FSUtil.getAnnotationsIteratorInSpan(jcas, WordToken.type, ssAnnot.getSubSectionHeaderBegin(), ssAnnot.getSubSectionHeaderEnd());
                  String subSectionHeaderName = "";
                   
                  while (textSpanInSs.hasNext())
                  {
                      WordToken wta = (WordToken) textSpanInSs.next();
                      subSectionHeaderName = subSectionHeaderName + " " + wta.getCoveredText();
                  }
                  containedInSubSection = containedInSubSection+"|"+subSectionHeaderName+"|"+ssAnnot.getStatus();
                    }
                }
                gotMeds = true;
                trackMedOccur++;
View Full Code Here

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

          Segment sa = (Segment) saIter.next();
          if(sa.getBegin()<pse.ne.getBegin() && sa.getEnd()>pse.ne.getEnd()) {
            Iterator ssIter = FSUtil.getAnnotationsInSpanIterator(
                jcas, SubSectionAnnotation.type, sa.getBegin(), sa.getEnd());
            while(ssIter.hasNext()) {
              SubSectionAnnotation ss = (SubSectionAnnotation) ssIter.next();
              //if(ss.getCoveredText().replaceAll(":","").trim().equalsIgnoreCase("medication"))
                if(ss.getCoveredText().toLowerCase().trim().startsWith("medication"))
                if(ss.getSubSectionHeaderBegin()<pse.ne.getBegin() &&
                    ss.getSubSectionBodyEnd()>pse.ne.getEnd()) {
                  inMedication = true;
                  break;
                }
            }
          }
View Full Code Here

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

      SubSectionIndicator ssi = (SubSectionIndicator) sortedSubSecInds.get(i);
      Segment segment = getSegmentContainingOffsets(jcas, ssi.getStartOffset(),
          ssi.getEndOffset());
      endBodyOffset = segment.getEnd(); // backup

      SubSectionAnnotation ssa = new SubSectionAnnotation(jcas);

      ssa.setBegin(ssi.getStartOffset());
      // header is marked by the indicator
      ssa.setSubSectionHeaderBegin(ssi.getStartOffset());
      ssa.setSubSectionHeaderEnd(ssi.getEndOffset());

      // body begins where SubSectionIndicator ends
      ssa.setSubSectionBodyBegin(ssi.getEndOffset() + 1);

      if (i + 1 < sortedSubSecInds.size()) // i is not the last element
      {
        SubSectionIndicator nextSsi = (SubSectionIndicator) sortedSubSecInds.get(i + 1);
        endBodyOffset = getSubSectionAnnotationBodyEnd(segment, nextSsi);

      } else
        // this was the last SubSectionIndicator
      {
        endBodyOffset = getSubSectionAnnotationBodyEnd(segment, null);
      }
      ssa.setSubSectionBodyEnd(endBodyOffset);
      ssa.setEnd(endBodyOffset);
      ssa.addToIndexes();
    }
      }
View Full Code Here

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

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

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

                String containedInSubSection = segmentID;
                Iterator subSectionItr = indexes.getAnnotationIndex(
                    SubSectionAnnotation.type).iterator();
                while (subSectionItr.hasNext())
                {
                    SubSectionAnnotation ssAnnot = (SubSectionAnnotation) subSectionItr.next();
                    if (ssAnnot.getSubSectionBodyBegin() <= neAnnot.getBegin() && ssAnnot.getSubSectionBodyEnd() >= neAnnot.getEnd())
                    {
                  Iterator textSpanInSs = FSUtil.getAnnotationsIteratorInSpan(jcas, WordToken.type, ssAnnot.getSubSectionHeaderBegin(), ssAnnot.getSubSectionHeaderEnd());
                  String subSectionHeaderName = "";
                   
                  while (textSpanInSs.hasNext())
                  {
                      WordToken wta = (WordToken) textSpanInSs.next();
                      subSectionHeaderName = subSectionHeaderName + " " + wta.getCoveredText();
                  }
                  containedInSubSection = containedInSubSection+"|"+subSectionHeaderName+"|"+ssAnnot.getStatus();
                    }
                }
                gotMeds = true;
                trackMedOccur++;
View Full Code Here

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

      SubSectionIndicator ssi = (SubSectionIndicator) sortedSubSecInds.get(i);
      Segment segment = getSegmentContainingOffsets(jcas, ssi.getStartOffset(),
          ssi.getEndOffset());
      endBodyOffset = segment.getEnd(); // backup

      SubSectionAnnotation ssa = new SubSectionAnnotation(jcas);

      ssa.setBegin(ssi.getStartOffset());
      // header is marked by the indicator
      ssa.setSubSectionHeaderBegin(ssi.getStartOffset());
      ssa.setSubSectionHeaderEnd(ssi.getEndOffset());

      // body begins where SubSectionIndicator ends
      ssa.setSubSectionBodyBegin(ssi.getEndOffset() + 1);

      if (i + 1 < sortedSubSecInds.size()) // i is not the last element
      {
        SubSectionIndicator nextSsi = (SubSectionIndicator) sortedSubSecInds.get(i + 1);
        endBodyOffset = getSubSectionAnnotationBodyEnd(segment, nextSsi);

      } else
        // this was the last SubSectionIndicator
      {
        endBodyOffset = getSubSectionAnnotationBodyEnd(segment, null);
      }
      ssa.setSubSectionBodyEnd(endBodyOffset);
      ssa.setEnd(endBodyOffset);
      ssa.addToIndexes();
    }
      }
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.