当前位置: 首页 > 知识库问答 >
问题:

GATE API和JAPE代码,返回空结果

督德泽
2023-03-14

我使用GATE API和java代码,并试图对文档文本运行一个已知的JAPE规则,但不幸的是,我无法得到适当的结果。我的代码如下:

public void initAnnie() throws GateException, IOException {
    Out.prln("Initialising ANNIE...");

    // load the ANNIE application from the saved state in plugins/ANNIE
    File pluginsHome = Gate.getPluginsHome();
    File anniePlugin = new File(pluginsHome, "ANNIE");
    File annieGapp = new File(anniePlugin, "ANNIE_with_defaults.gapp");
    annieController = (CorpusController) PersistenceManager
            .loadObjectFromFile(annieGapp);

    Out.prln("...ANNIE loaded");
} // initAnnie()

/** Tell ANNIE's controller about the corpus you want to run on */
public void setCorpus(Corpus corpus) {
    annieController.setCorpus(corpus);
} // setCorpus

/** Run ANNIE */
public void execute() throws GateException {
    Out.prln("Running ANNIE...");
    annieController.execute();
    Out.prln("...ANNIE complete");
} // execute()

/**
 * Run from the command-line, with a list of URLs as argument.
 * <P>
 * <B>NOTE:</B><BR>
 * This code will run with all the documents in memory - if you want to
 * unload each from memory after use, add code to store the corpus in a
 * DataStore.
 */
public static void main(String args[]) throws GateException, IOException {
// initialise the GATE library
Out.prln("Initialising GATE...");
Gate.init();
Out.prln("...GATE initialised");
// load ANNIE plugin - you must do this before you can create tokeniser
// or JAPE transducer resources.
Gate.getCreoleRegister().registerDirectories(
new File(Gate.getPluginsHome(), "ANNIE").toURI().toURL());

 // Build the pipeline
  SerialAnalyserController pipeline =
 (SerialAnalyserController)Factory.createResource(
   "gate.creole.SerialAnalyserController");
  LanguageAnalyser tokeniser = (LanguageAnalyser)Factory.createResource(
  "gate.creole.tokeniser.DefaultTokeniser");
LanguageAnalyser jape = (LanguageAnalyser)Factory.createResource(
 "gate.creole.Transducer", gate.Utils.featureMap(
     "grammarURL", new     
 File("C:path/to/univerity_rules.jape").toURI().toURL(),
   "encoding", "UTF-8")); // ensure this matches the file
pipeline.add(tokeniser);
pipeline.add(jape);

// create document and corpus
// create a GATE corpus and add a document for each command-line
// argument
Corpus corpus = Factory.newCorpus("JAPE corpus");

 URL u = new URL("file:/path/to/Document.txt");
 FeatureMap params = Factory.newFeatureMap();
 params.put("sourceUrl", u);
 params.put("preserveOriginalContent", new Boolean(true));
 params.put("collectRepositioningInfo", new Boolean(true));
 Out.prln("Creating doc for " + u);
 Document doc = (Document)
   Factory.createResource("gate.corpora.DocumentImpl", params);
 corpus.add(doc);
 pipeline.setCorpus(corpus);

// run it
pipeline.execute();

// extract results
System.out.println("Found annotations of the following types: " +
  doc.getAnnotations().getAllTypes());


} // main

 }
Phase:firstpass 
Input: Lookup Token 

//note that we are using Lookup and Token both inside our rules. 
Options: control = appelt


Rule: University1 
Priority: 20
(
  {Token.string == "University"} 
  {Token.string == "of"}
  {Lookup.minorType == city} 
):orgName 
-->
:orgName.Organisation = 
  {kind = "university", rule = "University1"}
 Initialising GATE...
 log4j:WARN No appenders could be found for logger (gate.Gate).
 log4j:WARN Please initialize the log4j system properly.
 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
  ...GATE initialised
 Creating doc for file:path/to/Document.txt
 Found annotations of the following types: [SpaceToken, Token]

共有1个答案

顾单弓
2023-03-14

问题是您没有“查找”注释,您试图在您的JAPE程序中使用。

您需要添加2个额外的资源:

    LanguageAnalyser gazetter = (LanguageAnalyser)Factory.createResource(
            "gate.creole.gazetteer.DefaultGazetteer");
    LanguageAnalyser splitter = (LanguageAnalyser)Factory.createResource(
            "gate.creole.splitter.SentenceSplitter");

您的处理资源应按以下顺序运行:

    pipeline.add(tokeniser);
    pipeline.add(gazetter);
    pipeline.add(splitter); 
    pipeline.add(jape);
...GATE initialised
Creating doc for file:/Users/andreyshafirin/tmp/testdoc.txt
Found annotations of the following types: [Lookup, Organisation, Token, Split, SpaceToken, Sentence]

我认为从Java代码中使用GATE有一个更好的方法。您可以在GATE Developer中创建应用程序,对其进行自定义并将其保存到文件中(在这里您将找到方法)。然后,您可以从java代码加载GATE应用程序(请参见此示例,并在此查看更多其他示例以了解如何加载)。这样,您就不必担心与处理资源属性相关的大量细节和特性(您将在GUI中定义和更改它们)。

祝盖茨好运。

 类似资料:
  • 我有两个活动,我在第二个活动上启动一个Intent以使用start ActivityForResult(...)检索结果,然后使用onActivityResult(...)处理结果。 问题是结果从第二个活动返回的代码始终RESULT_CANCELED。因此,不要通过条件的“resultCode == RESULT_OK”,在我的Main Acitivty中更新textView。 主要活动 第二项活

  • 问题内容: 我正在使用JDBC来实现非常简单的数据库连接。 我已经创建了连接/语句并执行了查询。我在调试器中检查语句的查询对象,以确认它正在发送正确的查询。然后,我再次检查了数据库中的查询(直接从调试器复制),以确保其返回数据。但是,返回的结果集在.next()上给出false 这里有我遗漏的常见陷阱吗? 还有myDB类(一个简单的包装程序,使我可以将连接/语句代码放入任何项目中) 编辑:根据建议

  • 方法返回空结果。我正在尝试使用Spring-boot、h2数据库和JPA来实现rest服务。 下面是我的 我的文件包括: 实体: 接口:

  • 在我的代码中,list数组的console.log给了我想要的东西,它是输入的一组子集。但它不会传递给结果。结果返回如下所示:[[],[],[],[],[],[],[],[],[],[],[],[],[]] 下面是我的代码: 任何想法都会很棒!谢谢你!

  • 问题内容: 我有一个看起来像这样的JSON Blob 我有一些代码将其转换回go结构 但是我在运行时看到的只是一个零位结构 我尝试先分配该结构,但那也没有用,我不确定为什么它不产生值,并且不返回错误 问题答案: 您的结构字段不会导出。这是因为它们以小写字母开头。 当我说“未导出”时,是指它们在您的包装之外不可见。您的软件包可以愉快地访问它们,因为它们在本地作用域内。 至于包装-它看不到它们。您需要

  • 我试图通过require($page.“.php”)传递一个页面;但是,它只是从页面返回代码。变量$page连接到products页面。代码如下所示。...索引页... 产品列表 第名称第价格 产品ORDER BY name ASC”;$Query=mysql_query($SQL);而($ROW=mysql_fetch_array($query)或die(mysql_error())){?><?