Search code examples
groovygate

Gate : breakline after each loop in groovy


i have this code that prints in the same line after each loop. For example:

"categorie=extragraphique","remarque=confusion_consonne","mot=article","categorie=logogrammique","remarque=aposthrophe","mot=conjonction"

i would like a linebreak after each loop but /n doesnt work and writeLine will do a different thing.

The wanted output is: "categorie=extragraphique","remarque=confusion_consonne","mot=article" "categorie=logogrammique","remarque=aposthrophe","mot=conjonction"

  new File("/outfile.txt").withWriterAppend{ out ->
  (doc.getNamedAnnotationSets() + [Default:(doc.getAnnotations())]).each{ setName, set ->
    set.each{ anno ->
      if( anno.getFeatures() )
        anno.getFeatures().each{ fValue ->
          out.write(/"${fValue}",/)
        }
      else
        out.write(/"${anno.getId()},,/)        
    }
  }
}

Thnaks in advance


Solution

  • What about:

      new File("/outfile.txt").withWriterAppend{ out ->
      (doc.getNamedAnnotationSets() + [Default:(doc.getAnnotations())]).each{ setName, set ->
        set.each{ anno ->
          if( anno.getFeatures() )
            anno.getFeatures().each{ fValue ->
              out.write(/"${fValue}",/)
            }
          else
            out.write(/"${anno.getId()},,/)        
    
          out.write('\n') //this line is new
        }
      }
    }