csvgroovygate

gate: exporting gate to csv file with groovy


I hope somebody can help me and tell me what im doing wrong. Thanks in advance.

Im excecuting this script on the groovy console in gate

new File("../outfile.csv").withWriterAppend{ out ->doc.getAnnotations().each {anno ->
  if( anno.getFeatures() )
    anno.getFeatures().each{ fName, fValue ->
      out.writeLine(/"${doc.getName()}","${anno.getType()}","${doc.stringFor(anno)}",${anno.start()},${anno.end()},"${fName}","${fValue}"/)
    }
  else
    out.writeLine(/"${doc.getName()}","${anno.getType()}","${doc.stringFor(anno)}",${anno.start()},${anno.end()},,/)        
}}

But im havig this exception

groovy.lang.MissingPropertyException: No such property: doc for class: ConsoleScript0

at ConsoleScript0$_run_closure1.doCall(ConsoleScript0:2)

at ConsoleScript0.run(ConsoleScript0:1)

at gate.groovy.GroovySupport$1$1$1.run(GroovySupport.java:134)

Solution

  • I see you're using the first example from the GATE groovy recipes.

    The problem is that you're running your code in the groovy console. It should be run as part of a pipeline. Save your script in a groovy file and load it in a groovy PR.

    According to the docs in the groovy PR you have variables inputAS, outputAS, doc, corpus, etc.

    On the other hand, in the groovy console you have the "docs" variable so you can do something like:

    docs.each{doc ->
      doc.getAnnotations().each ...