/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.ctakes.temporal.ae;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.ctakes.assertion.medfacts.cleartk.PolarityCleartkAnalysisEngine;
import org.apache.ctakes.clinicalpipeline.ClinicalPipelineFactory;
import org.apache.ctakes.clinicalpipeline.ClinicalPipelineFactory.CopyNPChunksToLookupWindowAnnotations;
import org.apache.ctakes.clinicalpipeline.ClinicalPipelineFactory.RemoveEnclosedLookupWindows;
import org.apache.ctakes.dependency.parser.ae.ClearNLPDependencyParserAE;
import org.apache.ctakes.dictionary.lookup.ae.UmlsDictionaryLookupAnnotator;
import org.apache.ctakes.temporal.ae.BackwardsTimeAnnotator;
import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
import org.apache.ctakes.typesystem.type.textsem.TimeMention;
import org.apache.log4j.Logger;
import org.apache.uima.UIMAException;
import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.jcas.JCas;
import org.apache.uima.resource.ResourceInitializationException;
import org.cleartk.classifier.CleartkAnnotator;
import org.cleartk.classifier.jar.GenericJarClassifierFactory;
import org.junit.Test;
import org.uimafit.factory.AggregateBuilder;
import org.uimafit.factory.AnalysisEngineFactory;
import org.uimafit.factory.JCasFactory;
import org.uimafit.pipeline.SimplePipeline;
import org.uimafit.util.JCasUtil;
public class BackwardsTimeAnnotatorTest {
// LOG4J logger based on class name
private Logger LOGGER = Logger.getLogger(getClass().getName());
@Test
public void testPipeline() throws UIMAException, IOException {
String note = "The patient is a 55-year-old man referred by Dr. Good for recently diagnosed colorectal cancer. "
+ "The patient was well till 6 months ago, when he started having a little blood with stool.";
JCas jcas = JCasFactory.createJCas();
jcas.setDocumentText(note);
// Get the default pipeline with umls dictionary lookup
AggregateBuilder builder = new AggregateBuilder();
builder.add(ClinicalPipelineFactory.getTokenProcessingPipeline());
builder.add(AnalysisEngineFactory
.createPrimitiveDescription(CopyNPChunksToLookupWindowAnnotations.class));
builder.add(AnalysisEngineFactory
.createPrimitiveDescription(RemoveEnclosedLookupWindows.class));
// Commented out the Dictionary lookup for the test
// Uncomment and set -Dctakes.umlsuser and -Dctakes.umlspw env params if
// needed
// builder.add(UmlsDictionaryLookupAnnotator.createAnnotatorDescription());
builder.add(ClearNLPDependencyParserAE.createAnnotatorDescription());
// Add BackwardsTimeAnnotator
builder.add(BackwardsTimeAnnotator
.createAnnotatorDescription("/org/apache/ctakes/temporal/ae/timeannotator/model.jar"));
SimplePipeline.runPipeline(jcas, builder.createAggregateDescription());
Collection<TimeMention> mentions = JCasUtil.select(jcas,
TimeMention.class);
ArrayList<String> temp = new ArrayList<>();
for (TimeMention mention : mentions) {
LOGGER.info("Event: " + mention.getCoveredText());
temp.add(mention.getCoveredText());
}
assertEquals(2, temp.size());
assertTrue(temp.contains("recently"));
assertTrue(temp.contains("6 months ago"));
}
}