【问题标题】:Embedding jape rules in java (Gate)在java中嵌入jape规则(门)
【发布时间】:2014-03-10 06:06:58
【问题描述】:

我正在尝试编写自己的规则,在我的 java 代码中注释作者(来自作者,jape)我已经初始化了我的新处理资源。代码运行良好,但没有注释 ma 文本: 输入:谁是xyz的作者 输出:它应该被注释为作者并且 shd 将书名保存在一些临时变量中。 我的java代码:

    Gate.init();
Gate.getCreoleRegister().registerDirectories(
           new File(Gate.getPluginsHome(), "ANNIE").toURI().toURL());
SerialAnalyserController pipeline =
          (SerialAnalyserController)gate.Factory.createResource(
             "gate.creole.SerialAnalyserController");
LanguageAnalyser tokeniser = (LanguageAnalyser)gate.Factory.createResource(
             "gate.creole.tokeniser.DefaultTokeniser");
LanguageAnalyser jape = (LanguageAnalyser)gate.Factory.createResource(
          "gate.creole.Transducer", gate.Utils.featureMap(
              "grammarURL", new File("E:\\GATE_Developer_7.1\\plugins\\ANNIE\\resources\\NE\\Author.jape").toURI().toURL(),
              "encoding", "UTF-8"));
pipeline.add(tokeniser);
pipeline.add(jape);
Corpus corpus = gate.Factory.newCorpus(null);
Document doc = gate.Factory.newDocument("Who is author of Inception");
DocumentContent dc=doc.getContent();        
corpus.add(doc);
pipeline.setCorpus(corpus);
pipeline.execute();
System.out.println("Found annotations of the following types: " +
          doc.getAnnotations().getAllTypes());

在输出中它只给出令牌,空格令牌 谁能帮我解决这个问题。?

【问题讨论】:

  • 在 GUI 中使用相同的 JAPE 语法是否有效?如果是这样,请尝试从那里保存已知工作的应用程序状态并使用 PersistenceManager 将其加载到您的嵌入式代码中,这可能比尝试在代码中手动构建管道更容易。
  • 感谢您的回复先生。!我没有使用这个,而是使用了 annieTransducer。我使用以下方法进行初始化,它起作用了: if("gate.creole.ANNIETransducer".equals(ANNIEConstants.PR_NAMES[i])) { File temp_value= new File("E:\\GATE_Developer_7.1\\plugins\\安妮\\资源\\NE"); URL temp_url =temp_value.toURL(); params1.put("grammarURL",temp_url); params1.put("编码", "UTF-8"); pr = ( ProcessingResource) gate.Factory 。 createResource (ANNIEConstants . PR_NAMES [i],params ); }

标签: java nlp information-extraction gate


【解决方案1】:

问题在于您的 JAPE 语法,而不是 Java 代码。您的 Java 代码适用于以下 JAPE 语法:

Phase: Test1 Input: Token Options: control = appelt Rule: testRule ( {Token.kind == "word"} {Token.kind == "word"}):annotate --> :annotate.TwoWords = { string = :annotate.Token.string }

输出是:

Found annotations of the following types: [SpaceToken, TwoWords, Token]

如果您能提供您的 JAPE 语法,我会详细说明您的问题。

或者,您可以在 GATE Developer 中使用您的 JAPE 语法,直到它开始符合您的要求。之后,您的 Java 程序就可以正常工作了。

【讨论】:

  • 不,先生,语法与 GUI 配合得很好,而且我解决了 java 代码相关的问题。
【解决方案2】:

这里,你给你的注释起的名字,你可以使用它。 所以,你可以使用这个方法。

doc.getAnnotations().get("Name of the annotations which you want to get");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多