private int lastInPattern()

in ctakes-drug-ner/src/main/java/org/apache/ctakes/drugner/ae/DrugMentionAnnotator.java [3467:3609]


	private int lastInPattern(JCas jcas, int begin, int end, int elementType, int[][] location) {
		JFSIndexRepository indexes = jcas.getJFSIndexRepository();
		Iterator neItr = indexes.getAnnotationIndex(elementType).iterator();
		int [] lastLocation =  {-1,-1};
		int counter = 0;
		if (elementType == StrengthAnnotation.type) {
			int holdBeginElement = 0, holdEndElement = 0;
			while (neItr.hasNext()) {
				StrengthAnnotation nea = (StrengthAnnotation) neItr.next();
				lastLocation[0] = nea.getBegin();
				lastLocation[1] = nea.getEnd();
				if (holdBeginElement < nea.getBegin() && nea.getBegin()>=begin && nea.getEnd() <= end && nea.getEnd() > holdEndElement) {
					holdBeginElement = location[counter][0]= lastLocation[0];
					holdEndElement = location[counter][1]= lastLocation[1];
					counter++;
				}
			}
		} else if (elementType == FrequencyAnnotation.type) {
			int holdBeginElement = 0, holdEndElement = 0;
			while (neItr.hasNext()) {
				FrequencyAnnotation nea = (FrequencyAnnotation) neItr.next();
				lastLocation[0] = nea.getBegin();
				lastLocation[1] = nea.getEnd();
				if (holdBeginElement < nea.getBegin() && nea.getBegin()>=begin && nea.getEnd() <= end && nea.getEnd() > holdEndElement) {
					holdBeginElement = location[counter][0]= lastLocation[0];
					holdEndElement = location[counter][1]= lastLocation[1];
					counter++;
				}			}
		} else if (elementType == FrequencyUnitAnnotation.type) {
			int holdBeginElement = 0, holdEndElement = 0;
			while (neItr.hasNext()) {
				FrequencyUnitAnnotation nea = (FrequencyUnitAnnotation) neItr.next();
				lastLocation[0] = nea.getBegin();
				lastLocation[1] = nea.getEnd();
				if (holdBeginElement < nea.getBegin() && nea.getBegin()>=begin && nea.getEnd() <= end && nea.getEnd() > holdEndElement) {
					holdBeginElement = location[counter][0]= lastLocation[0];
					holdEndElement = location[counter][1]= lastLocation[1];
					counter++;
				}
			}
		}    else if (elementType == DosagesAnnotation.type) {
			int holdBeginElement = 0, holdEndElement = 0;
			while (neItr.hasNext()) {
				DosagesAnnotation nea = (DosagesAnnotation) neItr.next();
				lastLocation[0] = nea.getBegin();
				lastLocation[1] = nea.getEnd();
				if (holdBeginElement < nea.getBegin() && nea.getBegin()>=begin && nea.getEnd() <= end && nea.getEnd() > holdEndElement) {
					holdBeginElement = location[counter][0]= lastLocation[0];
					holdEndElement = location[counter][1]= lastLocation[1];
					counter++;
				}
			}
		}else if (elementType == RouteAnnotation.type) {
			int holdBeginElement = 0, holdEndElement = 0;
			while (neItr.hasNext()) {
				RouteAnnotation nea = (RouteAnnotation) neItr.next();
				lastLocation[0] = nea.getBegin();
				lastLocation[1] = nea.getEnd();
				if (holdBeginElement < nea.getBegin() && nea.getBegin()>=begin && nea.getEnd() <= end && nea.getEnd() > holdEndElement) {
					holdBeginElement = location[counter][0]= lastLocation[0];
					holdEndElement = location[counter][1]= lastLocation[1];
					counter++;
				}
			}
		} else if (elementType == FormAnnotation.type) {
			int holdBeginElement = 0, holdEndElement = 0;
			while (neItr.hasNext()) {
				FormAnnotation nea = (FormAnnotation) neItr.next();
				lastLocation[0] = nea.getBegin();
				lastLocation[1] = nea.getEnd();
				if (holdBeginElement < nea.getBegin() && nea.getBegin()>=begin && nea.getEnd() <= end && nea.getEnd() > holdEndElement) {
					holdBeginElement = location[counter][0]= lastLocation[0];
					holdEndElement = location[counter][1]= lastLocation[1];
					counter++;
				}
			}
		}    
		else if (elementType == DurationAnnotation.type) {
			int holdBeginElement = 0, holdEndElement = 0;
			while (neItr.hasNext()) {
				DurationAnnotation nea = (DurationAnnotation) neItr.next();
				lastLocation[0] = nea.getBegin();
				lastLocation[1] = nea.getEnd();
				if (holdBeginElement < nea.getBegin() && nea.getBegin()>=begin && nea.getEnd() <= end && nea.getEnd() > holdEndElement) {
					holdBeginElement = location[counter][0]= lastLocation[0];
					holdEndElement = location[counter][1]= lastLocation[1];
					counter++;
				}
			}

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

		} else if (elementType == MedicationMention.type) {
			int holdEndElement = 0;
			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];
						holdEndElement = location[counter][1] = lastLocation[1];
						counter++;
					} else if (counter > 0 && holdEndElement > lastLocation[1]) {
						holdEndElement = location[counter-1][1] = lastLocation[1];
					}

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

		}

		return counter;
	}