【发布时间】:2021-01-27 13:18:33
【问题描述】:
所以我有来自http://www.manythings.org/anki/ 的这个 text_data 看起来像这样
['Hi.\tHallo!\tCC-BY 2.0 (France) Attribution: tatoeba.org #538123 (CM) & #380701 (cburgmer)\n',
'Hi.\tGrüß Gott!\tCC-BY 2.0 (France) Attribution: tatoeba.org #538123 (CM) & #659813 (Esperantostern)\n',
'Run!\tLauf!\tCC-BY 2.0 (France) Attribution: tatoeba.org #906328 (papabear) & #941078 (Fingerhut)\n',
'Wow!\tPotzdonner!\tCC-BY 2.0 (France) Attribution: tatoeba.org #52027 (Zifre) & #2122382 (Pfirsichbaeumchen)\n',
'Wow!\tDonnerwetter!\tCC-BY 2.0 (France) Attribution: tatoeba.org #52027 (Zifre) & #2122391 (Pfirsichbaeumchen)\n',
'Fire!\tFeuer!\tCC-BY 2.0 (France) Attribution: tatoeba.org #1829639 (Spamster) & #1958697 (Tamy)\n',
'Help!\tHilfe!\tCC-BY 2.0 (France) Attribution: tatoeba.org #435084 (lukaszpp) & #575889 (MUIRIEL)\n',
...
]
我做了这个
English = []
for sent in data_examples:
pattern = re.compile(r'.+?\t')
matches = pattern.finditer(sent)
for match in matches:
English.append(match)
如何捕捉文本中的英语?我的不是真的工作。
【问题讨论】:
-
首先,您可以将
pattern=...移到循环之外,因为它没有改变。 -
mine is not really working - 不是一个详细的问题陈述......如果你只想要第一个词,为什么要使用
finditer?为什么不pattern.match(sent)? -
你的例子中没有英文。
-
顺便说一句,为什么是 Tatoeba?你认为你可以信任这些语料库吗?它们看起来是用户贡献的,没有进行适当的本地化质量保证。
-
谢谢大家的cmets。我很新,我在 youtube 上查看过,人们使用 finditer,我猜 Tomerikoo 使用 match 提出了一个很好的观点。我正在努力学习,质量不是我的首要考虑因素