我一直在嘗試在Groovy(使用Eclipse)中構建一個簡單的應用程序,該應用程序調用GATE並打亂了編譯器錯誤 - 幾年前我在GATE用戶面前看到類似的問題,但沒有任何解決方案爲我解決了這個錯誤。GATE 8.0編譯器問題
代碼:
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。使用只是碧玉編譯器生成: java.lang.NoClassDefFoundError:門/ UTIL /編譯器/月食/ JDT /內部/編譯器/ ENV/INameEnvironment
所以我不得不包括柵編譯器JDT的一個產生上述第一個錯誤的罐子。
據我所知,其餘的jar文件都與GATE 8.0正確關聯。任何人都可以指出錯誤可能在哪裏,或哪一組編譯器可以正確使用?
非常感謝!
正確使用gate-compiler-jdt jar將始終是您獲得gate.jar的GATE分佈的一部分。或者,如果您從Maven中心拉取GATE,那麼正確的編譯器jar將作爲依賴關係存在。 –
Ian - 通過將GATE_HOME/lib目錄中的編譯器顯式添加到類路徑並刪除其他目錄,甚至是已經添加了整個lib目錄,從而使其工作。我相信我現在明白這個問題。謝謝! –