user3243453
user3243453

Reputation: 21

Embedding jape rules in java (Gate)

I am trying to write my own rule that annotates Author (From author,jape) in my java code i have initialized my new processing resource.The code runs fine but does not annotates ma text: input: who is the author of xyz output: it should get annotated as author and shd save the name of book in some temporary variable. my java code:

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

in output it only gives token,space token Can anyone help me to workout the problem.?

Upvotes: 2

Views: 1541

Answers (2)

user5124079
user5124079

Reputation:

Here , The name which you have given to your Annotations , you can use it . So , you can use this method .

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

Upvotes: 1

andrey
andrey

Reputation: 842

Problem is in your JAPE grammar, not in Java code. Your Java code works fine with following JAPE grammar:

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

Output is:

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

I would say more about your problem if you will provide your JAPE grammar.

Alternatively you can play with your JAPE grammar in GATE Developer until it start to match what you want. After this your Java program will work just fine.

Upvotes: 1

Related Questions