小猪拉丁语翻译微服务
PigLatinTranslation的Python项目详细描述
一种基于烧瓶的微服务,用于将英语文本翻译成拉丁语。 Wikipedia Link。
Pig Latin is a language game in which words in English are altered. The objective is to conceal the words from others not familiar with the rules.
猪拉丁语只是一种有规则的行话。规则描述如下 稍后
演示
您可以在web表单上尝试自己的示例 here。
示例用法
开始的最快方法是从演示中请求此服务 API
卷曲
curl --request POST \ --url https://piglatin.jaichaudhary.com/api/translate \ --form 'text=How do you say ... in Pig Latin?'
Python
import requests url = "https://piglatin.jaichaudhary.com/api/translate" payload = {"text": "How do you say ... in Pig Latin?"} response = requests.request("POST", url, data=payload) print response.text
您应该看到这样的响应
{ "text": "Owhay oday ouyay aysay ... inyay Igpay Atinlay?" }
安装
如果要在本地运行该服务,有多种方法
文件
docker pull ja1chaudhary/pig-latin-translation-service docker run --name pig-latin-service -p 5000:5000 -d ja1chaudhary/pig-latin-translation-service
python包
要安装python包,只需
pip install piglatintranslation python -m piglatintranslation
来源
git clone https://github.com/Jai-Chaudhary/pig-latin-translation-microservice cd pig-latin-translation-microservice python setup.py install python run.py
规则
如果单词以辅音开头,则所有字母在首字母之前 元音位于单词序列的末尾。然后加上“ay”。
- 猪=>;igpay
- 香蕉=>;ananabay
- 垃圾桶=>;烟灰缸
- 快乐=>;快乐
- 鸭子=>;工作日
- 手套=>;手套
如果单词以元音或无声字母开头,只需加上“yay” 到最后。
- 吃=>;吃
- 煎蛋卷=>;煎蛋卷
- are=>;是的
无声字母
为了推断无声字母,cmu提供了134k个单词的发音语料库。 使用(http://www.nltk.org/_modules/nltk/corpus/reader/cmudict.html)。 带有无声首字母的单词被过滤成 无声的单词.json。其中最常见的前缀被选为 无声词的近似。其中包括(“pf”、“ph”、“ps”、“pn”, “pt”、“wr”、“ts”、“gn”、“kn”、“jo”、“he”)
测试
要运行测试用例,只需执行
python tests.py