java - 我们如何处理大型 GATE 文档

标签 java annotations gate

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

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

我的JAVA代码是这样的:

TestGate 类:

    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();
}

主类包含:

            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 文档中的大块数据。

最佳答案

你需要打电话

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

在每个文档之后,否则如果你运行它的次数足够多,你最终会在任何大小的文档上得到 OutOfMemory(尽管你在方法中初始化 gate 的方式看起来你真的只需要处理一个文档一次) .

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

关于java - 我们如何处理大型 GATE 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32609049/

相关文章:

java - 当仅编码一个参数时,Jython java 调用会抛出异常,要求提供 2 个参数

java - try block 内声明的变量无法解析

java - 如何使用接口(interface)声明 DAO 变量,但在 Spring 框架中放入具体实现?

java - 如何使用 javax 验证注释将 json 数组转换为字符串列表?

java - 约束注释中的变量字段

nlp - UIMA 只提供一个包装器还是像 StandfordCore NLP 和 GATE 一样?

java - 缓冲字节数组(来自 DatagramPacket)

java - 使用 JAXB 将多个 XML 元素的内容提取为文本

java - 解析 GATE 中的字体样式或段落 block