CleartkAnnotator extends JCasAnnotator_ImplBase implements
    Initializable { @Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); if (dataWriterFactoryClassName == null && classifierFactoryClassName == null) { CleartkInitializationException.neitherParameterSet( PARAM_DATA_WRITER_FACTORY_CLASS_NAME, dataWriterFactoryClassName, PARAM_CLASSIFIER_FACTORY_CLASS_NAME, classifierFactoryClassName); } if (this.isTraining != null) { this.primitiveIsTraining = this.isTraining; } else if (!DEFAULT_DATA_WRITER_FACTORY_CLASS_NAME.equals(this.dataWriterFactoryClassName)) { this.primitiveIsTraining = true; } else if (context.getConfigParameterValue(DirectoryDataWriterFactory.PARAM_OUTPUT_DIRECTORY) != null) { this.primitiveIsTraining = true; } else if (!DEFAULT_CLASSIFIER_FACTORY_CLASS_NAME.equals(this.classifierFactoryClassName)) { this.primitiveIsTraining = false; } else if (context.getConfigParameterValue(GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH) != null) { this.primitiveIsTraining = false; } else { String message = "Please specify PARAM_IS_TRAINING - unable to infer it from context"; throw new IllegalArgumentException(message); } if (this.isTraining()) { DataWriterFactory<?> factory = InitializableFactory.create( context, dataWriterFactoryClassName, DataWriterFactory.class); DataWriter<?> untypedDataWriter; try { untypedDataWriter = factory.createDataWriter(); } catch (IOException e) { throw new ResourceInitializationException(e); } InitializableFactory.initialize(untypedDataWriter, context); this.dataWriter = ReflectionUtil.uncheckedCast(untypedDataWriter); } else { ClassifierFactory<?> factory = InitializableFactory.create( context, classifierFactoryClassName, ClassifierFactory.class); Classifier<?> untypedClassifier; try { untypedClassifier = factory.createClassifier(); } catch (IOException e) { throw new ResourceInitializationException(e); } this.classifier = ReflectionUtil.uncheckedCast(untypedClassifier); ReflectionUtil.checkTypeParameterIsAssignable( CleartkAnnotator.class, "OUTCOME_TYPE", this, Classifier.class, "OUTCOME_TYPE", this.classifier); InitializableFactory.initialize(untypedClassifier, context); } }  @Override void initialize(UimaContext context); @Override void collectionProcessComplete(); static final String PARAM_CLASSIFIER_FACTORY_CLASS_NAME; static final String PARAM_DATA_WRITER_FACTORY_CLASS_NAME; static final String PARAM_IS_TRAINING; }
@Test public void testBadFileName() throws Throwable { try { CleartkAnnotator<String> classifierAnnotator = new StringTestAnnotator(); classifierAnnotator.initialize(UimaContextFactory.createUimaContext( GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH, new File(outputDirectoryName, "asdf.jar").getPath())); classifierAnnotator.classifier.classify(InstanceFactory.createInstance("hello", 1, 1).getFeatures()); fail("expected exception for invalid classifier name"); } catch (ResourceInitializationException e) { } }
@Test public void testStringClassifierStringAnnotator() throws Exception { CleartkAnnotator<String> classifierAnnotator = new StringTestAnnotator(); classifierAnnotator.initialize(UimaContextFactory.createUimaContext( CleartkAnnotator.PARAM_CLASSIFIER_FACTORY_CLASS_NAME, StringTestClassifierFactory.class.getName())); classifierAnnotator.classifier.classify(InstanceFactory.createInstance("hello", 1, 1).getFeatures()); }
@Test public void testIntegerClassifierStringAnnotator() throws Exception { try { new StringTestAnnotator().initialize(UimaContextFactory.createUimaContext( CleartkAnnotator.PARAM_CLASSIFIER_FACTORY_CLASS_NAME, IntegerTestClassifierFactory.class.getName())); fail("expected exception for Integer classifier and String annotator"); } catch (ResourceInitializationException e) { } }
@Test public void testChildClassifierParentAnnotator() throws Exception { CleartkAnnotator<Parent> classifierAnnotator = new ParentTestAnnotator(); classifierAnnotator.initialize(UimaContextFactory.createUimaContext( CleartkAnnotator.PARAM_CLASSIFIER_FACTORY_CLASS_NAME, ChildClassifierFactory.class.getName())); }
@Test public void testParentClassifierChildAnnotator() throws Exception { try { new ChildTestAnnotator().initialize(UimaContextFactory.createUimaContext( CleartkAnnotator.PARAM_CLASSIFIER_FACTORY_CLASS_NAME, ParentClassifierFactory.class.getName())); fail("expected exception for Parent classifier and Child annotator"); } catch (ResourceInitializationException e) { } }
@Test public void testGenericClassifierGenericAnnotator() throws Exception { CleartkAnnotator<Object> classifierAnnotator = new TestAnnotator<Object>(); classifierAnnotator.initialize(UimaContextFactory.createUimaContext( CleartkAnnotator.PARAM_CLASSIFIER_FACTORY_CLASS_NAME, TestClassifierFactory.class.getName())); }