【问题标题】:Maltparser doesn't do anythingMaltparser 什么都不做
【发布时间】:2014-10-30 18:55:05
【问题描述】:

我正在使用 maltparser,nltk 处理文本。好吧,我在 maltparser 和 nltk 之间进行了集成,效果很好。但是因为每次我执行程序 nltk 调用 java VE 这需要很多时间......所以我认为创建一个 web 服务,它需要 conll .txt 并返回由 java 应用程序解析的 conll。

当我测试来自 maltparser 来源的示例时,问题就来了。我从初始化模型中选择一个并解析一组令牌。我只是将 de 模型更改为常规的英语模型(engmalt.linear-1.7.mco)。所以像输入一样执行并返回句子。

代码是这样的

public static void main(String[] args) {
    // Loading the Swedish model swemalt-mini
    ConcurrentMaltParserModel model = null;
    try {
        URL swemaltMiniModelURL = new File("inputs/engmalt.linear-1.7.mco").toURI().toURL();
        System.out.println(swemaltMiniModelURL.getFile());
        model = ConcurrentMaltParserService.initializeParserModel(swemaltMiniModelURL);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Creates an array of tokens, which contains the Swedish sentence 'Samtidigt får du högsta sparränta plus en skattefri sparpremie.'
    // in the CoNLL data format.
    String[] tokens = new String[5];
    tokens[0] = "1\tThis\t_\tDT\tDT\t_\t0\ta\t_\t_";
    System.out.println(tokens[0]);
    tokens[1] = "2\tis\t_\tVBZ\tVBZ\t_\t0\ta\t_\t_";
    System.out.println(tokens[1]);
    tokens[2] = "3\ta\t_\tZ\tZ\t_\t0\ta\t_\t_";
    System.out.println(tokens[2]);
    tokens[3] = "4\ttest\t_\tNN\tNN\t_\t0\ta\t_\t_";
    System.out.println(tokens[3]);
    tokens[4] = "5\t.\t_\tFp\tFp\t_\t0\ta\t_\t_";
    System.out.println(tokens[4]);
    try {
        String[] outputTokens = model.parseTokens(tokens);
        ConcurrentUtils.printTokens(outputTokens);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

输出是:

/home/tomas/workspace/PruebaMalt/inputs/engmalt.linear-1.7.mco
1   This    _   DT  DT  _   0   a   _   _
2   is  _   VBZ VBZ _   0   a   _   _
3   a   _   Z   Z   _   0   a   _   _
4   test    _   NN  NN  _   0   a   _   _
5   .   _   Fp  Fp  _   0   a   _   _
1   This    _   DT  DT  _   0   a   _   _
2   is  _   VBZ VBZ _   0   a   _   _
3   a   _   Z   Z   _   0   a   _   _
4   test    _   NN  NN  _   0   a   _   _
5   .   _   Fp  Fp  _   0   a   _   _

我尝试使用其他模型和语言,并且相同...有什么建议吗?太棒了!

【问题讨论】:

    标签: parsing nlp


    【解决方案1】:

    我自己发现的。问题是 nlkt 以这种格式发送给 java:

    1 This _ DT DT _ 0 a _ _

    然后返回:1 This _ DT DT _ 2 SUBJ _ _

    但在 java 中格式有点不同,最后 2 个 _ 必须删除。有了它,它会工作的!

    输入:1 This _ DT DT _

    返回:1 This _ DT DT _ 2 SUBJ _ _

    我希望这对其他人有所帮助。

    【讨论】:

      猜你喜欢
      • 2019-03-08
      • 2016-12-24
      • 2017-04-18
      • 2011-08-03
      • 2014-05-11
      • 2014-09-10
      • 1970-01-01
      • 2023-03-29
      • 2013-09-28
      相关资源
      最近更新 更多