如何将数据库中的 CAS 定义为 uimaFIT 中注释器的外部资源?
How to define a CAS in database as external resource for an annotator in uimaFIT?
我正在尝试使用 uimaFit 构建我的数据处理管道,如下所示:
[annotatorA]
=> [Consumer to dump annotatorA's annotations from CAS into DB]
[annotatorB (should take on annotatorA's annotations from DB as input)]
=>[Consumer for annotatorB]
driver代码:
/* Step 0: Create a reader */
CollectionReader readerInstance= CollectionReaderFactory.createCollectionReader(
FilePathReader.class, typeSystem,
FilePathReader.PARAM_INPUT_FILE,"/path/to/file/to/be/processed");
/*Step1: Define Annotoator A*/
AnalysisEngineDescription annotatorAInstance=
AnalysisEngineFactory.createPrimitiveDescription(
annotatorADbConsumer.class, typeSystem,
annotatorADbConsumer.PARAM_DB_URL,"localhost",
annotatorADbConsumer.PARAM_DB_NAME,"xyz",
annotatorADbConsumer.PARAM_DB_USER_NAME,"name",
annotatorADbConsumer.PARAM_DB_USER_PWD,"pw");
builder.add(annotatorAInstance);
/* Step2: Define binding for annotatorB to take
what-annotator-a put in DB above as input */
/*Step 3: Define annotator B */
AnalysisEngineDescription annotatorBInstance =
AnalysisEngineFactory.createPrimitiveDescription(
GateDateTimeLengthAnnotator.class,typeSystem)
builder.add(annotatorBInstance);
/*Step 4: Run the pipeline*/
SimplePipeline.runPipeline(readerInstance, builder.createAggregate());
我的问题是:
- 以上做法是否正确?
- 我们如何在步骤 2 中定义 annotatorA 在 annotatorB 中的输出的依赖性?
是 https://code.google.com/p/uimafit/wiki/ExternalResources#Resource_injection 中建议的方法吗
, 实现它的正确方向 ?
您可以像这样用 @TypeCapability
定义依赖关系:
@TypeCapability(inputs = { "com.myproject.types.MyType", ... }, outputs = { ... })
public class MyAnnotator extends JCasAnnotator_ImplBase {
....
}
请注意,它在注释级别而不是引擎级别定义合同(这意味着任何引擎都可以创建 com.myproject.types.MyType
)。
我认为没有办法强制执行它。
我确实创建了一些代码来检查引擎是否在管道的上游提供了正确的必需注释,否则会打印错误日志(请参阅 Pipeline.checkAndAddCapabilities() and Pipeline.addCapabilities())。但是请注意,只有当所有引擎都定义了它们的 TypeCapabilities 时它才会起作用,而当使用外部 Engines/libraries.
时通常情况并非如此
我正在尝试使用 uimaFit 构建我的数据处理管道,如下所示:
[annotatorA]
=> [Consumer to dump annotatorA's annotations from CAS into DB]
[annotatorB (should take on annotatorA's annotations from DB as input)]
=>[Consumer for annotatorB]
driver代码:
/* Step 0: Create a reader */
CollectionReader readerInstance= CollectionReaderFactory.createCollectionReader(
FilePathReader.class, typeSystem,
FilePathReader.PARAM_INPUT_FILE,"/path/to/file/to/be/processed");
/*Step1: Define Annotoator A*/
AnalysisEngineDescription annotatorAInstance=
AnalysisEngineFactory.createPrimitiveDescription(
annotatorADbConsumer.class, typeSystem,
annotatorADbConsumer.PARAM_DB_URL,"localhost",
annotatorADbConsumer.PARAM_DB_NAME,"xyz",
annotatorADbConsumer.PARAM_DB_USER_NAME,"name",
annotatorADbConsumer.PARAM_DB_USER_PWD,"pw");
builder.add(annotatorAInstance);
/* Step2: Define binding for annotatorB to take
what-annotator-a put in DB above as input */
/*Step 3: Define annotator B */
AnalysisEngineDescription annotatorBInstance =
AnalysisEngineFactory.createPrimitiveDescription(
GateDateTimeLengthAnnotator.class,typeSystem)
builder.add(annotatorBInstance);
/*Step 4: Run the pipeline*/
SimplePipeline.runPipeline(readerInstance, builder.createAggregate());
我的问题是:
- 以上做法是否正确?
- 我们如何在步骤 2 中定义 annotatorA 在 annotatorB 中的输出的依赖性?
是 https://code.google.com/p/uimafit/wiki/ExternalResources#Resource_injection 中建议的方法吗 , 实现它的正确方向 ?
您可以像这样用 @TypeCapability
定义依赖关系:
@TypeCapability(inputs = { "com.myproject.types.MyType", ... }, outputs = { ... })
public class MyAnnotator extends JCasAnnotator_ImplBase {
....
}
请注意,它在注释级别而不是引擎级别定义合同(这意味着任何引擎都可以创建 com.myproject.types.MyType
)。
我认为没有办法强制执行它。
我确实创建了一些代码来检查引擎是否在管道的上游提供了正确的必需注释,否则会打印错误日志(请参阅 Pipeline.checkAndAddCapabilities() and Pipeline.addCapabilities())。但是请注意,只有当所有引擎都定义了它们的 TypeCapabilities 时它才会起作用,而当使用外部 Engines/libraries.
时通常情况并非如此