2

我尝试将 UIMA Ruta 脚本 ( Main.ruta) 集成到 uimaFIT 管道 (in Main.java) 中,但找不到该脚本。这是我的项目结构:

uima-ruta-maven-test-project/src/main/Main.java
uima-ruta-maven-test-project/script/ruta/Main.ruta
uima-ruta-maven-test-project/descriptor/ruta/MainEngine.xml

这是我创建的代码AnalysisEngineDescription

File file = new File("descriptor/ruta/MainEngine.xml");

AnalysisEngineDescription rutaScript = AnalysisEngineFactory.createEngineDescriptionFromPath(
                    file.getPath(),
                    RutaEngine.PARAM_SCRIPT_PATHS, "script",
                    RutaEngine.PARAM_MAIN_SCRIPT, "Main.ruta");

这是我的控制台输出:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
SLF4J: Failed to load class "org.slf4j.impl.StaticMDCBinder".
SLF4J: Defaulting to no-operation MDCAdapter implementation.
SLF4J: See http://www.slf4j.org/codes.html#no_static_mdc_binder for further details.
org.apache.uima.resource.ResourceInitializationException: Initialization of annotator class "org.apache.uima.ruta.engine.RutaEngine" failed.  (Descriptor: file:/D:/Programming/MA/uima-ruta-maven-test-project/descriptor/ruta/MainEngine.xml)
    at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initializeAnalysisComponent(PrimitiveAnalysisEngine_impl.java:260)
    at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initialize(PrimitiveAnalysisEngine_impl.java:173)
    at org.apache.uima.impl.AnalysisEngineFactory_impl.produceResource(AnalysisEngineFactory_impl.java:94)
    at org.apache.uima.impl.CompositeResourceFactory_impl.produceResource(CompositeResourceFactory_impl.java:62)
    at org.apache.uima.UIMAFramework.produceResource(UIMAFramework.java:289)
    at org.apache.uima.UIMAFramework.produceAnalysisEngine(UIMAFramework.java:417)
    at org.apache.uima.analysis_engine.asb.impl.ASB_impl.setup(ASB_impl.java:256)
    at org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.initASB(AggregateAnalysisEngine_impl.java:435)
    at org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.initializeAggregateAnalysisEngine(AggregateAnalysisEngine_impl.java:379)
    at org.apache.uima.analysis_engine.impl.AggregateAnalysisEngine_impl.initialize(AggregateAnalysisEngine_impl.java:192)
    at org.apache.uima.impl.AnalysisEngineFactory_impl.produceResource(AnalysisEngineFactory_impl.java:94)
    at org.apache.uima.impl.CompositeResourceFactory_impl.produceResource(CompositeResourceFactory_impl.java:62)
    at org.apache.uima.UIMAFramework.produceResource(UIMAFramework.java:289)
    at org.apache.uima.UIMAFramework.produceResource(UIMAFramework.java:341)
    at org.apache.uima.UIMAFramework.produceAnalysisEngine(UIMAFramework.java:458)
    at org.apache.uima.fit.pipeline.SimplePipeline.runPipeline(SimplePipeline.java:178)
    at Main.main(Main.java:52)
Caused by: org.apache.uima.resource.ResourceInitializationException
    at org.apache.uima.ruta.engine.RutaEngine.initialize(RutaEngine.java:579)
    at org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase.lambda$callInitializeMethod$2(AnalysisEngineImplBase.java:612)
    at org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase.withContexts(AnalysisEngineImplBase.java:653)
    at org.apache.uima.analysis_engine.impl.AnalysisEngineImplBase.callInitializeMethod(AnalysisEngineImplBase.java:612)
    at org.apache.uima.analysis_engine.impl.PrimitiveAnalysisEngine_impl.initializeAnalysisComponent(PrimitiveAnalysisEngine_impl.java:252)
    ... 16 more
Caused by: org.apache.uima.analysis_engine.AnalysisEngineProcessException
    at org.apache.uima.ruta.engine.RutaEngine.initializeScript(RutaEngine.java:857)
    at org.apache.uima.ruta.engine.RutaEngine.initialize(RutaEngine.java:576)
    ... 20 more
Caused by: java.io.FileNotFoundException: Script [Main.ruta] cannot be found at [script;D:\Programming\MA\uima-ruta-maven-test-project] or classpath with extension .ruta
    ... 22 more

我的控制台输出的最后一行似乎显示了错误。在显然不存在Main.ruta的路径中搜索,因为它是无效路径。[script;D:\Programming\MA\uima-ruta-maven-test-project]我在想的是该方法createEngineDescriptionFromPath应该将文件夹附加"script"到项目路径中。但相反,它预先设置了它。

有人可以帮我解决这个问题吗?

编辑

我找到了文档的链接,其中解释了参数的用法mainScriptscriptPaths说明。路径必须用“。”写。代替 ”/”。

我改变了我的代码如下:

AnalysisEngineDescription rutaScript = AnalysisEngineFactory.createEngineDescriptionFromPath(
                    file.getPath(),
                    RutaEngine.PARAM_SCRIPT_PATHS, "script.ruta",
                    RutaEngine.PARAM_MAIN_SCRIPT, "script.ruta.Main");

但现在我得到了这个控制台输出:

Exception in thread "main" org.apache.uima.cas.CASRuntimeException: The JCas cannot be initialized.  The following errors occurred: 
JCas Class "org.apache.uima.ruta.type.AnyLine", loaded from "jar:file:/C:/Users/user/.m2/repository/org/apache/uima/ruta-typesystem/2.7.0/ruta-typesystem-2.7.0.jar!/org/apache/uima/ruta/type/AnyLine.class", is missing required constructor; likely cause is wrong version (UIMA version 3 or later JCas required).
JCas Class "org.apache.uima.ruta.type.EmptyLine", loaded from "jar:file:/C:/Users/user/.m2/repository/org/apache/uima/ruta-typesystem/2.7.0/ruta-typesystem-2.7.0.jar!/org/apache/uima/ruta/type/EmptyLine.class", is missing required constructor; likely cause is wrong version (UIMA version 3 or later JCas required).
JCas Class "org.apache.uima.ruta.type.WSLine", loaded from "jar:file:/C:/Users/user/.m2/repository/org/apache/uima/ruta-typesystem/2.7.0/ruta-typesystem-2.7.0.jar!/org/apache/uima/ruta/type/WSLine.class", is missing required constructor; likely cause is wrong version (UIMA version 3 or later JCas required).
...
at org.apache.uima.cas.impl.FSClassRegistry.reportErrors(FSClassRegistry.java:1284)
at org.apache.uima.cas.impl.FSClassRegistry.loadJCasForTSandClassLoader(FSClassRegistry.java:400)
at org.apache.uima.cas.impl.FSClassRegistry.getGeneratorsForClassLoader(FSClassRegistry.java:1320)
at org.apache.uima.cas.impl.TypeSystemImpl.getGeneratorsForClassLoader(TypeSystemImpl.java:2924)
at org.apache.uima.cas.impl.TypeSystemImpl.commit(TypeSystemImpl.java:1442)
at org.apache.uima.cas.impl.CASImpl.commitTypeSystem(CASImpl.java:1822)
at org.apache.uima.util.CasCreationUtils.doCreateCas(CasCreationUtils.java:620)
at org.apache.uima.util.CasCreationUtils.createCas(CasCreationUtils.java:292)
at org.apache.uima.fit.pipeline.SimplePipeline.runPipeline(SimplePipeline.java:181)
at Main.main(Main.java:52)

似乎无法初始化 Ruta 类型。我的 pom.xml 中有 UIMA Ruta 版本 2.7.0 和 DKPro 2.0.0。

4

1 回答 1

0

似乎 UIMA Ruta 2 与 UIMA v3 和其他依赖它的库(在这种情况下为 uimaFit,DKPro)不能很好地配合。

我让它在我的情况下使用以下版本:DKPro 1.11.0、UIMA 2.10.4、UIMA Ruta 2.7.0 和 uimaFit 2.4.0(另见这个问题)。

UIMA Ruta 3最近发布。我想这个版本会更好地与 UIMA v3 一起工作。

于 2020-01-17T13:39:55.380 回答