Created
March 22, 2017 15:17
-
-
Save psibre/5b469f06b3e740ce1a52e344930c679a to your computer and use it in GitHub Desktop.
Convert CSV to YAML with Gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
jcenter() | |
} | |
dependencies { | |
classpath 'com.xlson.groovycsv:groovycsv:1.1' | |
classpath 'org.yaml:snakeyaml:1.18' | |
} | |
} | |
task csv2yaml { | |
def csvFile = file('utterances.csv') // CSV should contain tmin and tmax columns | |
def yamlFile = file('utterances.yaml') | |
inputs.files csvFile | |
outputs.files yamlFile | |
doLast { | |
def csv = com.xlson.groovycsv.CsvParser.parseCsv(csvFile.newReader()).collect { | |
[start: it.tmin as float, end: it.tmax as float] | |
} | |
def opts = new org.yaml.snakeyaml.DumperOptions() | |
opts.defaultFlowStyle = org.yaml.snakeyaml.DumperOptions.FlowStyle.BLOCK | |
def yaml = new org.yaml.snakeyaml.Yaml(opts) | |
yaml.dump(csv, yamlFile.newWriter()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment