Paranoid text spacing as a service
https://github.com/vinta/pangu.space.git
Paranoid text spacing for good readability, to automatically insert whitespace between CJK (Chinese, Japanese, Korean) and half-width characters (alphabetical letters, numerical digits and symbols).
Current APIs:
https://api.pangu.space/v1/spacing-text?t=YOUR-TEXT$ curl https://api.pangu.space/v1/spacing-text -G --data-urlencode "t=็ถไฝ ๅ่ฆ่bug๏ผbugไนๅ่ฆ่ไฝ " -H "x-api-key: TiEeVInyGza4ta0kougRH4MBBfdGe2Q91TjrbQLm" -w "\n"
็ถไฝ ๅ่ฆ่ bug๏ผbug ไนๅ่ฆ่ไฝ
in Python:
import requests
r = requests.get('https://api.pangu.space/v1/spacing-text?t=็ถไฝ ๅ่ฆ่bug๏ผbugไนๅ่ฆ่ไฝ ', headers={'x-api-key': 'TiEeVInyGza4ta0kougRH4MBBfdGe2Q91TjrbQLm'})
print(r.content.decode('utf-8'))
# ็ถไฝ ๅ่ฆ่ bug๏ผbug ไนๅ่ฆ่ไฝ
You must request the API with a HTTP header x-api-key: TiEeVInyGza4ta0kougRH4MBBfdGe2Q91TjrbQLm. Yeah, you are free to use the API key for accessing the service. Although it has a quota of 100000 requests per month.
pangu.space is built on AWS Lambda and Amazon API Gateway. I use Apex to manage and deploy Lambda functions.
# deploy all functions
$ apex deploy
# view logs
$ apex logs -f
# invoke a function directly
$ apex invoke spacing_text --logs
{
"statusCode": 400,
"headers": null,
"body":"{\"message\": \"No text was provided in HTTP query string\"}"
}
# invoke a function with an API Gateway event
$ cat fixtures/spacing_text_event.json
{
"queryStringParameters": {"t": "่PMๆฐ้ฌฅ็ไบบ๏ผๆ็ถๅฐๅฟ่ชๅทฑไธ่ฆๆ็บPM"}
}
$ apex invoke spacing_text --logs < fixtures/spacing_text_event.json
{
"statusCode": 200,
"headers": {"content-type": "text/plain; charset=utf-8"},
"body": "่ PM ๆฐ้ฌฅ็ไบบ๏ผๆ็ถๅฐๅฟ่ชๅทฑไธ่ฆๆ็บ PM"
}