-
-
Save psibre/05eaa6b584ed970177bd04e2a3d66f5f to your computer and use it in GitHub Desktop.
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
dependencies { | |
classpath group: "org.codehaus.groovy.modules.http-builder", name: "http-builder", version: "0.7" | |
} | |
import groovyx.net.http.HTTPBuilder | |
import static groovyx.net.http.ContentType.URLENC | |
import static groovyx.net.http.Method.POST | |
import static groovyx.net.http.ContentType.JSON | |
def configuration = """ | |
# How to extract the input | |
input_serializer=marytts.io.TextSerializer | |
# How to render the output | |
output_serializer=marytts.io.XMLSerializer | |
# Current locale | |
locale=en_GB | |
# List of modules | |
modules=marytts.language.en.Preprocess \ | |
marytts.language.en.JTokenizer \ | |
marytts.modules.nlp.OpenNLPPosTagger \ | |
marytts.modules.nlp.JPhonemiser | |
""" | |
def http = new HTTPBuilder('http://falken-3:59126/') | |
def result = http.request(POST, JSON) { req -> | |
uri.path = '/process' | |
requestContentType = URLENC | |
body = [input: input_file.text, configuration:configuration] // will be url-encoded | |
response.success = { resp -> | |
String text = resp.entity.content.text | |
String contentType = resp.headers."Content-Type" | |
if (contentType?.startsWith("application/json")) { | |
def json = slurper.parseText(text) | |
if (json.exception) | |
{ | |
print(json.exception) | |
} | |
else | |
{ | |
output_file.text = json.result | |
} | |
} | |
else { | |
// FIXME: error | |
} | |
} | |
response.failure = { resp -> | |
println "Unexpected error: ${resp.status} : ${resp.statusLine.reasonPhrase}" | |
resp.headers.each { println "${it.name} : ${it.value}" } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment