我一直在尝试在Groovy(使用Eclipse)中构建一个简单的应用程序,该应用程序调用GATE并且遇到混乱的编译器错误 - 几年前我在GATE用户身上看到了类似的问题,但没有一个解决方案为我修好了错误。
代码:
import gate.*
import gate.creole.*
import gate.creole.SerialAnalyserController
import gate.util.persistence.PersistenceManager
class AnnieExtraction {
static main(args) {
println "--Initializing GATE--"
Gate.init()
Gate.getCreoleRegister().registerDirectories(new File("C:/apps/GATE_Developer_8.0/plugins/ANNIE").toURI().toURL())
println "--GATE initialized--"
SerialAnalyserController pipeline = (SerialAnalyserController) Factory.createResource("gate.creole.SerialAnalyserController")
println "--Initializing PR--"
ProcessingResource token = (ProcessingResource) Factory.createResource("gate.creole.tokeniser.DefaultTokeniser", Factory.newFeatureMap())
}
}
错误返回:
Error: The type postprocessCannotActionClass4 must implement the inherited abstract method RhsAction.doit(Document, Map, AnnotationSet, AnnotationSet, Ontology) at line 10 in japeactionclasses.postprocessCannotActionClass4
Error: The type Map is not generic; it cannot be parameterized with arguments <String, AnnotationSet> at line 18 in japeactionclasses.postprocessCannotActionClass4
Error: Syntax error, parameterized types are only available if source level is 5.0 at line 18 in japeactionclasses.postprocessCannotActionClass4
Error: Type mismatch: cannot convert from Object to Annotation at line 24 in japeactionclasses.postprocessCannotActionClass4
Error: The operator + is undefined for the argument type(s) Long, long at line 31 in japeactionclasses.postprocessCannotActionClass4
The offending input was:
1 // postprocessCannotActionClass4
2 package japeactionclasses;
3 import gate.*;
4 import java.io.*;
5 import java.util.*;
6 import gate.util.*;
7 import gate.jape.*;
8 import gate.creole.ontology.*;
9
10 public class postprocessCannotActionClass4
11 implements java.io.Serializable, gate.jape.RhsAction {
12 private gate.jape.ActionContext ctx;
13 public java.lang.String ruleName() { return "Cannot"; }
14 public java.lang.String phaseName() { return "postprocess"; }
15 public void setActionContext(gate.jape.ActionContext ac) { ctx = ac; }
16 public gate.jape.ActionContext getActionContext() { return ctx; }
17 public void doit(gate.Document doc,
18 java.util.Map<java.lang.String, gate.AnnotationSet> bindings,
19 gate.AnnotationSet inputAS, gate.AnnotationSet outputAS,
20 gate.creole.ontology.Ontology ontology) throws gate.jape.JapeException {
21 gate.AnnotationSet cannotAnnots = bindings.get("cannot");
22 if(cannotAnnots != null && cannotAnnots.size() != 0) {
23
24 Annotation cannot = cannotAnnots.iterator().next();
25 String cannotStr = cannot.getFeatures().get("string").toString();
26 String canStr = cannotStr.substring(0,3);
27 String notStr = cannotStr.substring(3,6);
28
29 Long start = cannot.getStartNode().getOffset();
30 Long end = cannot.getEndNode().getOffset();
31 Long middle = start + 3L;
32
33 /* Copy orth, &c., from the original Token;
34 * overwrite the others appropriately. */
35 FeatureMap canFM = Factory.newFeatureMap();
36 FeatureMap notFM = Factory.newFeatureMap();
37 canFM.putAll(cannot.getFeatures());
38 notFM.putAll(cannot.getFeatures());
39
40 canFM.put("string", canStr);
41 notFM.put("string", notStr);
42 canFM.put("length", Integer.toString(3));
43 notFM.put("length", Integer.toString(3));
44
45 try {
46 outputAS.add(start, middle, "Token", canFM);
47 outputAS.add(middle, end, "Token", notFM);
48 }
49 catch (InvalidOffsetException e) {
50 /* This should never happen */
51 e.printStackTrace();
52 }
53
54 outputAS.remove(cannot);
55
56 }
57 }
58 }
我尝试了很多编译器,JDK版本,甚至尝试过GATE 7.1而不是8.0。
目前正在使用Java版本1.7,因为我已经读过jasper-compiler-jdt.jar与Java 1.8不兼容。编译器版本也是1.7。
我知道问题必须与编译器jar类型有关,但它们似乎都在GATE本身和Eclipse之间匹配。 GATE GUI指向正确的JDK。使用jasper编译器生成: java.lang.NoClassDefFoundError:gate / util / compilers / eclipse / jdt / internal / compiler / env / INameEnvironment
所以我必须包含一个gate-compiler-jdt jar,它会产生上面的第一个错误。
据我所知,所有其他jar文件都与GATE 8.0正确关联。任何人都可以指出错误的位置或使用哪组编译器是正确的吗?
提前多多谢谢!
答案 0 :(得分:0)
正如你和伊恩所说,我通过设置&#39; gate-compiler-jdt&#39;的编译器版本让我与GATE 8.1
合作。 POM.XML中的方式与GATE_HOME/lib
'C:\Program Files\GATE_Developer_8.2\lib'