如何以编程方式重新配置uima ruta分析引擎(更改参数值)? [英] How to reconfigure uima ruta analysis engine (change the parameter values) programmatically?

查看:99
本文介绍了如何以编程方式重新配置uima ruta分析引擎(更改参数值)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题的延续:请指导我以编程方式重新配置分析引擎(通过更改参数值).

Please guide me to reconfigure analysis engine (by changing the parameter values) programmatically.

推荐答案

情况:您具有UIMA Ruta分析引擎的正确xml描述符,并且想要重新配置,以便路径指向描述符的文件夹.javaurl提交

Situation: you have a correct xml descriptor of a UIMA Ruta analysis engine and you want to reconfigure so that the paths point to the folder of the descriptor.java url to file

以下代码通过在不同阶段更改参数值来说明这一点.只需要一个阶段.哪种是您的正确选择取决于您的代码.

The following code illustrates that by changing the parameter values in different stages. Only one stage is required. Which is the correct one for you depends on your code.

package example;

import java.io.File;
import java.net.URL;

import org.apache.uima.analysis_engine.AnalysisEngine;
import org.apache.uima.analysis_engine.AnalysisEngineDescription;
import org.apache.uima.fit.factory.AnalysisEngineFactory;
import org.apache.uima.resource.metadata.ConfigurationParameterSettings;
import org.apache.uima.ruta.engine.RutaEngine;

public class ReconfigureExample {

  public static void main(String[] args) throws Exception {

    File file = new File("path to descriptor");
    String path = new File(file.toURI()).getParentFile().getAbsolutePath();
    String[] pathsArray = new String[] { path };

    // override the values in the descriptor when creating the description
    AnalysisEngineDescription desc = AnalysisEngineFactory.createEngineDescriptionFromPath(
            file.getAbsolutePath(), RutaEngine.PARAM_SCRIPT_PATHS, pathsArray,
            RutaEngine.PARAM_DESCRIPTOR_PATHS, pathsArray, RutaEngine.PARAM_RESOURCE_PATHS,
            pathsArray);

    // in case the location of the descriptor is not known...
    URL sourceUrl = desc.getSourceUrl();
    path = new File(sourceUrl.toURI()).getParentFile().getAbsolutePath();
    pathsArray = new String[] { path };

    // set the values in the description
    ConfigurationParameterSettings settings = desc.getAnalysisEngineMetaData()
            .getConfigurationParameterSettings();
    settings.setParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, pathsArray);
    settings.setParameterValue(RutaEngine.PARAM_DESCRIPTOR_PATHS, pathsArray);
    settings.setParameterValue(RutaEngine.PARAM_RESOURCE_PATHS, pathsArray);

    // override the values in the descriptor when creating the analysis engine
    AnalysisEngine ae = AnalysisEngineFactory.createEngine(desc, RutaEngine.PARAM_SCRIPT_PATHS, pathsArray,
            RutaEngine.PARAM_DESCRIPTOR_PATHS, pathsArray, RutaEngine.PARAM_RESOURCE_PATHS,
            pathsArray);

    // set the values in the analysis engine and reconfigure it
    ae.setConfigParameterValue(RutaEngine.PARAM_SCRIPT_PATHS, pathsArray);
    ae.setConfigParameterValue(RutaEngine.PARAM_DESCRIPTOR_PATHS, pathsArray);
    ae.setConfigParameterValue(RutaEngine.PARAM_RESOURCE_PATHS, pathsArray);
    ae.reconfigure();

  }

}

免责声明:我是UIMA Ruta的开发人员

这篇关于如何以编程方式重新配置uima ruta分析引擎(更改参数值)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆