我尝试将UIMA Ruta脚本(Main.ruta
)集成在uimaFIT管道(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"
文件夹附加到项目路径。但是它却为它做准备。
有人可以帮我吗?
编辑
我发现this链接到文档,其中解释了参数mainScript
和scriptPaths
的用法。路径必须用“。”书写。而不是“ /”。
我更改了代码,如下所示:
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。
答案 0 :(得分: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(另请参见this question)。
UIMA Ruta 3最近发布了。我想这个版本可以与UIMA v3更好地协同工作。