String navName = null;
List<NominalAttributeValue> removalList = new ArrayList<NominalAttributeValue>();
while (navItr.hasNext())
{
NominalAttributeValue nav = (NominalAttributeValue) navItr.next();
String nVal = nav.getNominalValue();
if (nVal.equals(Const.CLASS_KNOWN)
|| nVal.equals(Const.CLASS_UNKNOWN))
{
kuClassification = nVal;
navName = nav.getAttributeName();
} else if (nVal.equals(Const.CLASS_CURR_SMOKER)
|| nVal.equals(Const.CLASS_PAST_SMOKER)
|| nVal.equals(Const.CLASS_SMOKER))
{
pcsClassification = nVal;
navName = nav.getAttributeName();
} else
{
throw new AnnotatorProcessException(new Exception(
"Nominal value not part of " + Const.class + ": "
+ nVal));
}
removalList.add(nav);
}
// remove old NominalAttributeValue objects from CAS
Iterator<NominalAttributeValue> removalItr = removalList.iterator();
while (removalItr.hasNext())
{
TOP top = (TOP) removalItr.next();
top.removeFromIndexes();
}
/**
*
* This is to deal with cases like "nonsmoker" and "non-smoker"
* There are two dictionaries: smoker.dictionary and nonsmoker.dictionary
* and two NameEntities: SmokerNamedEntityAnnotation and NonSmokerNamedEntityAnnotation
* Each includes smoker or nonsmoker keywords respectively
* Configuration file and dictionary are set up in Resources in DitionaryLookupAnnotator.xml
*/
//Smoker or Nonsmoker NamedEntityAnnotation are created only if the sentence include
//smoker or nonsmoker keywords
int negCnt = getSmokerNegatedCount(jcas);
int nonsmokerCnt = getNonSmokerNegatedCount(jcas);
int negConCnt = getNegConCount(jcas);
String finalClassification = null;
/**
* 12/04/08
* Originally each roundtrip would have processed just one sentence
* Now, we process the complete doc
*
* 1/22/09 REVERTING TO ORIGINAL CODE as classifier need to just one sentence in the cas
*/
if (kuClassification.equals(Const.CLASS_UNKNOWN))
{
finalClassification = kuClassification;
} else
{
if ( (negCnt>0 && negConCnt==0) || nonsmokerCnt>0 )
{
finalClassification = Const.CLASS_NON_SMOKER;
} else
{
finalClassification = pcsClassification;
}
}
//---check sentence-level classification
if (iv_logger.isInfoEnabled())
if(finalClassification!=Const.CLASS_UNKNOWN) {
Iterator senIter = jcas.getJFSIndexRepository().getAnnotationIndex(Sentence.type).iterator();
while(senIter.hasNext()) {
Sentence sen = (Sentence) senIter.next();
iv_logger.info("|"+sen.getCoveredText() + "|" + finalClassification + "|" + negCnt);
}
}
//---
// add final classification as a new NominalAttributeValue object
NominalAttributeValue finalNav = new NominalAttributeValue(jcas);
finalNav.setAttributeName(navName);
finalNav.setNominalValue(finalClassification);
finalNav.addToIndexes();
}