Could anyone please guide me how can I create one custom JAPE file and configure it with GATE source code. I have tried with following code and getting exception like "Error while parsing the grammar :" and "Neither grammarURL or binaryGrammarURL parameters are set!"
try{
Document doc = new DocumentImpl();
String str = "This is test.";
DocumentContentImpl impl = new DocumentContentImpl(str);
doc.setContent(impl);
System.setProperty("gate.home", "C:\\Program Files\\GATE_Developer_7.1");
Gate.init();
gate.Corpus corpus = (Corpus) Factory
.createResource("gate.corpora.CorpusImpl");
File gateHome = Gate.getGateHome();
File pluginsHome = new File(gateHome, "plugins");
Gate.getCreoleRegister().registerDirectories(new File(pluginsHome, "ANNIE").toURI().toURL());
Transducer transducer = new Transducer();
transducer.setDocument(doc);
transducer.setGrammarURL(new URL("file:///D:/misc_workspace/gate-7.1-build4485-SRC/plugins/ANNIE/resources/NE/SportsCategory.jape"));
transducer.setBinaryGrammarURL(new URL("file:///D:/misc_workspace/gate-7.1-build4485-SRC/plugins/ANNIE/resources/NE/SportsCategory.jape"));
LanguageAnalyser jape = (LanguageAnalyser)Factory.createResource(
"gate.creole.Transducer", gate.Utils.featureMap(
"grammarURL", "D:/misc_workspace/gate-7.1-build4485-SRC/plugins/ANNIE/resources/NE/SportsCategory.jape",
"encoding", "UTF-8"));
Thank you Ian. These training courses material is helpful. But my problem was different and I have solved it. The following code snap is how to use custom jape file in GATE. Now my custom jape file is capable to produce new annotation.
System.setProperty("gate.home", "C:\\Program Files\\GATE_Developer_7.1");
Gate.init();
ProcessingResource token = (ProcessingResource) Factory.createResource("gate.creole.tokeniser.DefaultTokeniser",Factory.newFeatureMap());
String str = "This is a test. Myself Abhijit Nag sport";
Document doc = Factory.newDocument(str);
gate.Corpus corpus = (Corpus) Factory.createResource("gate.corpora.CorpusImpl");
corpus.add(doc);
File gateHome = Gate.getGateHome();
File pluginsHome = new File(gateHome, "plugins");
Gate.getCreoleRegister().registerDirectories(new File(pluginsHome, "ANNIE").toURI().toURL());
LanguageAnalyser jape = (LanguageAnalyser)Factory.createResource(
"gate.creole.Transducer", gate.Utils.featureMap(
"grammarURL", "file:///D:/misc_workspace/gate-7.1-build4485-SRC/plugins/ANNIE/resources/NE/SportsCategory.jape","encoding", "UTF-8"));
jape.setCorpus(corpus);
jape.setDocument(doc);
jape.execute();
pipeline = (SerialAnalyserController) Factory.createResource("gate.creole.SerialAnalyserController",
Factory.newFeatureMap(), Factory.newFeatureMap(),"ANNIE");
initAnnie();
pipeline.setCorpus(corpus);
pipeline.add(token);
pipeline.add((ProcessingResource)jape.init());
pipeline.execute();
AnnotationSetImpl ann = (AnnotationSetImpl) doc.getAnnotations();
System.out.println(" ...Total annotation "+ann.getAllTypes());