2

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.?

  • Does it work when you use the same JAPE grammar in the GUI? If so try saving the known-working application state from there and load it in your embedded code using the `PersistenceManager`, that's likely to be easier than trying to build up the pipeline by hand in code. – Ian Roberts Mar 10 '14 at 13:22
  • thank you for the response sir.! Instead of using this i jus used the annieTransducer. I used the following to intialize and it worked: if("gate.creole.ANNIETransducer".equals(ANNIEConstants.PR_NAMES[i])) { File temp_value= new File("E:\\GATE_Developer_7.1\\plugins\\ANNIE\\resources\\NE"); URL temp_url =temp_value.toURL(); params1.put( "grammarURL",temp_url); params1.put("encoding", "UTF-8"); pr = ( ProcessingResource) gate.Factory . createResource ( ANNIEConstants . PR_NAMES [i],params ); } – user3243453 Mar 11 '14 at 08:39

2 Answers2

1

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.

andrey
  • 842
  • 4
  • 6
1

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