【问题标题】:Text Segmentation using Gate使用 Gate 进行文本分割
【发布时间】:2015-05-11 20:50:13
【问题描述】:

我正在尝试使用 Java 编写自己的程序,以便将一组文本文件分割成句子。我搜索了可用的 NLP 工具,发现了 GATE,但我不能使用它来仅使用管道进行分段。

  1. 关于如何限制管道功能的任何想法
  2. 任何可以帮助我编写程序的代码

【问题讨论】:

  • 到目前为止,您做了哪些调查?您是否查看过文档?句子分割是 GATE 的一项非常基本的任务。
  • 我使用 StandAloneANNIE 并尝试了一些代码,但它不起作用
  • 你也可以尝试改编BatchProcessApp,使用你自己的文本分割管道...但是对于像“它不起作用”这样的一般性问题没有任何帮助 ...

标签: java gate


【解决方案1】:

改编自different answer

import gate.*;
import gate.creole.SerialAnalyserController;
import java.io.File;
import java.util.*;

public class Segmenter {
    public static void main(String[] args) throws Exception {
        Gate.setGateHome(new File("C:\\Program Files\\GATE_Developer_8.0"));
        Gate.init();
        regiterGatePlugin("ANNIE");

        SerialAnalyserController pipeline = (SerialAnalyserController) Factory.createResource("gate.creole.SerialAnalyserController");
        pipeline.add((ProcessingResource) Factory.createResource("gate.creole.tokeniser.DefaultTokeniser"));
        pipeline.add((ProcessingResource) Factory.createResource("gate.creole.splitter.SentenceSplitter"));

        Corpus corpus = Factory.newCorpus("SegmenterCorpus");
        Document document = Factory.newDocument("Text to be segmented.");
        corpus.add(document); 
        pipeline.setCorpus(corpus); 
        pipeline.execute();

        AnnotationSet defaultAS = document.getAnnotations();
        AnnotationSet sentences = defaultAS.get("Sentence");

        for (Annotation sentence : sentences) {
            System.err.println(Utils.stringFor(document, sentence));
        }

        //Clean up
        Factory.deleteResource(document);
        Factory.deleteResource(corpus);
        for (ProcessingResource pr : pipeline.getPRs()) {
            Factory.deleteResource(pr);
        }
        Factory.deleteResource(pipeline);
    }

    public static void regiterGatePlugin(String name) throws Exception {
        Gate.getCreoleRegister().registerDirectories(new File(Gate.getPluginsHome(), name).toURI().toURL());
    }
}

【讨论】:

  • 非常感谢您的帮助!
  • @Dreamer 有帮助吗? ...您可以对答案进行投票或将其标记为正确。我更新知道什么对你有用...... ;-)
猜你喜欢
  • 2022-07-06
  • 2019-05-02
  • 2018-09-02
  • 1970-01-01
  • 2013-10-20
  • 1970-01-01
  • 2013-12-10
  • 2016-07-23
  • 2012-12-16
相关资源
最近更新 更多