我们如何处理大型 GATE 文档

How do we deal with a large GATE Document

如果我使用的 GATE 文档稍大,当我尝试执行 Pipeline 时,我得到 Error java.lang.OutOfMemoryError: GC overhead limit exceeded

如果 GATE 文档很小,代码可以正常工作。

我的 JAVA 代码是这样的:

测试门Class:

    public void gateProcessor(Section section) throws Exception { 
                Gate.init();
                Gate.getCreoleRegister().registerDirectories(....
                SerialAnalyserController pipeline .......
                pipeline.add(All the language analyzers)
                pipeline.add(My Jape File)
                Corpus corpus = Factory.newCorpus("Gate Corpus");
                Document doc = Factory.newDocument(section.getContent());
                corpus.add(doc);

                pipeline.setCorpus(corpus);
                pipeline.execute();
}

主要Class包含:

            StringBuilder body = new StringBuilder();
            int character;
            FileInputStream file = new FileInputStream(
                    new File(
                            "filepath\out.rtf"));  //The Document in question
            while (true)
            {
                character = file.read();
                if (character == -1) break;
                body.append((char) character);
            }


            Section section = new Section(body.toString()); //Creating object of Type Section with content field = body.toString()
            TestGate testgate = new TestGate();
            testgate.gateProcessor(section);

有趣的是,这在 GATE Developer 工具中失败了,如果文档超过特定限制,比如超过 1 页,工具基本上会卡住。

这证明我的代码在逻辑上是正确的,但是我的做法是错误的。我们如何处理GATE Document中的大块数据。

每次它创建管道对象时,这就是它占用大量内存的原因。这就是为什么每次使用 'Annie' 清理。

pipeline.cleanup(); 管道=空;

您需要致电

corpus.clear();
Factory.deleteResource(doc);

在每个文档之后,否则如果你 运行 它足够多次,你最终会在任何大小的文档上得到 OutOfMemory(尽管顺便说一句,你在方法中初始化 gate 似乎你真的需要处理单个文档只有一次)。

除此之外,注释和特征通常会占用大量内存。如果您有注释密集型管道,即您生成大量具有大量特征和值的注释,您可能 运行 内存不足。确保您没有以指数方式生成注释的处理资源 - 例如 jape 或 groovy 生成 n 的 W 次方注释,其中 W 是单词数在你的文档中。或者,如果您的文档中每个可能的单词组合都有一个特征,那将生成 W 字符串的阶乘。