GATE加载处理资源/代词解析

时间:2017-12-03 21:26:33

标签: java gate

我正在尝试使用ANNIE(在Java中)加载pronomial coreference module但是我遇到了以下代码的一些问题:

FeatureMap params = Factory.newFeatureMap();

params.put("resolveIt", "true");
ProcessingResource coref = (ProcessingResource) Factory.createResource("gate.creole.coref.Coreferencer", params);
Collection<ProcessingResource> processingResources = new ArrayList<ProcessingResource>();
processingResources.add(coref);
pipelineController.setPRs(processingResources);

params.clear();
params.put("sourceUrl", url); # this is the url of a test document
params.put("collectRepositioningInfo", new Boolean(true));
Document doc = (Document) Factory.createResource("gate.corpora.DocumentImpl", params);
corpus.add(doc);

pipelineController.setCorpus(corpus);
pipelineController.execute();

执行pipelineController后,我尝试访问“MatchesAnnots”功能或任何其他功能,但我收到错误 Coref警告:没有找到要处理的注释!。有人能指出我的错误方向吗?我应该不使用pipelineController.setPRs()吗?

1 个答案:

答案 0 :(得分:0)

您的代码几乎是正确的。 文档需要预处理,通常由ANNIE GATE应用程序完成。这就是为什么它抱怨&#34;没有找到处理的注释!&#34;。

在下面的代码中,我首先加载ANNIE,然后将Coreferencer添加为最后一个PR。

import java.io.File;
import gate.*;
import gate.creole.ConditionalSerialAnalyserController;
import gate.util.persistence.PersistenceManager;

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

        //load ANNIE GATE app
        Object gapp = PersistenceManager.loadObjectFromFile(
                new File(Gate.getPluginsHome(), "ANNIE/ANNIE_with_defaults.gapp"));
        ConditionalSerialAnalyserController pipelineController = (ConditionalSerialAnalyserController) gapp;

        //add Coreferencer to the end of ANNIE
        ProcessingResource coref = (ProcessingResource) Factory.createResource(
                "gate.creole.coref.Coreferencer", Utils.featureMap("resolveIt", true));
        pipelineController.add(coref);


        //execute it
        Corpus corpus = Factory.newCorpus("corpus name");
        Document doc = Factory.newDocument("Peter was driving his car.");
        corpus.add(doc);
        pipelineController.setCorpus(corpus);
        pipelineController.execute();

        //see the result
        System.err.println(doc.getFeatures().get("MatchesAnnots"));
    }
}