2

I've been trying to build a simple app in Groovy (using Eclipse) that calls GATE and have hit upon confusing compiler errors - I've seen similar questions on GATE-users a few years back, but none of the solutions have fixed the error for me.

The code:

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


    }

}

And the error returned:

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  }

I've tried a bunch of variations of compilers, JDK versions, and even tried GATE 7.1 instead of 8.0.

Currently using Java version 1.7 as I had read that the jasper-compiler-jdt.jar doesn't work well with Java 1.8. Compiler version is also at 1.7.

I know the issue has to be something to do with the compiler jar types, but they all appear to match between GATE itself and Eclipse. GATE GUI is pointed to the correct JDK. Using the just the jasper compiler produces: java.lang.NoClassDefFoundError: gate/util/compilers/eclipse/jdt/internal/compiler/env/INameEnvironment

So I have had to include one of the gate-compiler-jdt jars which produces the first error above.

And as far as I know all the rest of the jar files are correctly associated with GATE 8.0. Can anyone point me to where the error might be or which set of compilers are correct to use?

Thanks much in advance!

  • 1
    The correct gate-compiler-jdt jar to use will always be the one provided as part of the distribution of GATE that you got gate.jar from. Or if you're pulling GATE from Maven central then the right compiler jar will be there as a dependency. – Ian Roberts May 04 '15 at 17:28
  • 1
    Ian - got it working by explicitly adding the compiler from the GATE_HOME/lib directory to the classpath and removing others, even those the entire lib directory was already added. I believe I understand the issue now. Thank you! – Mark Ediger May 05 '15 at 15:58

1 Answers1

0

As you and Ian say, I got mine working with GATE 8.1 by setting the compiler version for 'gate-compiler-jdt' in POM.XML in a similar manner to the version in GATE_HOME/lib

'C:\Program Files\GATE_Developer_8.2\lib'
ti7
  • 16,375
  • 6
  • 40
  • 68
Saman
  • 1