因此,我有一个基本的Pig Latin翻译器,只能翻译一个单词。
def Translate(Phrase):
Subscript = 0
while Phrase[Subscript] != "a" or Phrase[Subscript] != "e" or Phrase[Subscript] != "i" or
Phrase[Subscript] != "o" or Phrase[Subscript] != "u":
Subscript += 1
if Phrase[Subscript] == "a" or Phrase[Subscript] == "e" or Phrase[Subscript] == "i" or
Phrase[Subscript] == "o" or Phrase[Subscript] == "u":
return Phrase[Subscript:] + Phrase[:Subscript] + "ay"
有人可以协助我编辑此翻译器以使用多个单词吗?谢谢。
这是Pig Latin方言,考虑了单词的发音方式:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
sentences = ["Pig qoph an egg.",
"Quiet European rhythms.",
"My nth happy hour.",
"Herb unit -- a dynasty heir."]
for sent in sentences:
entsay = " ".join(["".join(map(to_piglatin, re.split("(\W+)", nonws)))
for nonws in sent.split()])
print(u'"{}" → "{}"'.format(sent, entsay))
“猪qoph一个鸡蛋。” →“ igpay ophqay anway鸡蛋路。”
“安静的欧洲节奏。” →“ ietquay uropeaneay ythmsrhay。”
“我的第n个欢乐时光。” →“ ymay nthway appyhay小时制。”
“草药单位-王朝继承人。” →“草帽itunay-离开ynastyday继承人”。
注意:
"-way"
后缀用于以元音开头的单词qu
在“安静”中被视为一个单位European
,unit
从辅音开始y
在“节奏”中,“王朝”是元音nth
,hour
,herb
,heir
开始以元音在哪里to_piglatin()
:
from nltk.corpus import cmudict # $ pip install nltk
# $ python -c "import nltk; nltk.download('cmudict')"
def to_piglatin(word, pronunciations=cmudict.dict()):
word = word.lower() #NOTE: ignore Unicode casefold
i = 0
# find out whether the word start with a vowel sound using
# the pronunciations dictionary
for syllables in pronunciations.get(word, []):
for i, syl in enumerate(syllables):
isvowel = syl[-1].isdigit()
if isvowel:
break
else: # no vowels
assert 0
if i == 0: # starts with a vowel
return word + "way"
elif "y" in word: # allow 'y' as a vowel for known words
return to_piglatin_naive(word, vowels="aeiouy", start=i)
break # use only the first pronunciation
return to_piglatin_naive(word, start=i)
def to_piglatin_naive(word, vowels="aeiou", start=0):
word = word.lower()
i = 0
for i, c in enumerate(word[start:], start=start):
if c in vowels:
break
else: # no vowel in the word
i += 1
return word[i:] + word[:i] + "w"*(i == 0) + "ay"*word.isalnum()
要将文本拆分为句子,可以使用nltk
标记符来分隔单词。可以修改代码以尊重字母的大小写(大写/小写),紧缩。
我试图创建一个Pig UDF,它使用通过sista Scala API接口的Stanford CoreNLP包提取tweet中提到的位置。它在本地使用“SBT run”运行时工作良好,但在从PIG调用时抛出“java.lang.NosuchMethodError”异常: 从标签器edu/stanford/nlp/models/pos-tagger/english-left3words/englis
您可使用 Google Translate™ 应用程式翻译词组: 按下侧边电源按钮打开应用程式菜单,找到并轻触Translate(翻译)。 您将看到翻译源语言与目标语言这两种语言。您可通过轻触某一语言的名称来更改语言。 轻触“麦克风”图标并说出您想翻译的词组。 译文将显示在屏幕上。
本文向大家介绍SVG 翻译,包括了SVG 翻译的使用技巧和注意事项,需要的朋友参考一下 示例 将矩形向右移动10个单位,向下移动20个单位: 将其水平移动0个单位,向上移动20个单位: 将其向左移动10个单位,垂直移动0个单位:
在学习计算机科学概念时,学生不必在学习英语的同时费劲。 如果您以英语以外的其他语言为母语,那么我们很感谢您为世界上95%的母语不是英语的人所提供的帮助。 Translatewiki Blockly和Blockly游戏的翻译均由Translatewiki处理。 注册成为translatewiki.net的翻译。 做一些测试翻译以获得翻译许可(在右上角选择一种语言)。 简要阅读Blockly的翻译风格
你可以在应用程序的启动方法中向本地化文本注册表(local text registry)添加翻译。 这些翻译可来源自数据库表、xml 文件、嵌入的资源等。 void Application_Start() { // ... var registry = Dependency.Resolve<ILocalTextRegistry>(); registry.Add("es",
我正在使用 我得到以下错误,我不明白我做错了什么
翻译是一门非常强调实践并依赖练习的手艺活,这本书是作者从翻译“票友”出发,走“野路”逐渐成长为翻译“熟手”的经验总结。 不同于传统的正经教材,这本书更强调实践经验。全书分三部分:翻译概论让大家对翻译有个全面的了解,译文讲习详细剖析热心网友提供的译文习作,实战经验好比软件开发中的设计模式,它讲解各种常见搭配、句型的处理之道,告诉读者:遇到这类问题,照着做就好了。
问题内容: 我遇到以下代码: 由于完成了Unicode替换,因此无法编译。 问题是,为什么 注释 ()不覆盖编译器完成的Unicode替换?我认为编译器应该先忽略注释,然后再执行代码翻译。 编辑: 不知道上面是否足够清楚。 我知道上面发生了什么,为什么会出错。我的期望是,在对代码进行任何翻译之前,编译器应忽略所有注释行。显然,这里不是这样。我期待这种行为的理由。 问题答案: 该规范指出,Java编