我有一个包含如下行的文件
ted 1-1 1.0 politicians do not have permission to do what needs to be
done.
राजनीतिज्ञों के पास जो कार्य करना चाहिए, वह करने कि अनुमति नहीं है.
我必须编写一个程序,逐行读取文件并在仅包含印地语部分的文件中给出输出。这里的第一个词表示最后两段的来源。另外,最后两句是互译的。 基本上,我正在尝试从该文件创建一个平行语料库。
最佳答案
您可以通过检查 Unicode 字符来做到这一点。
import codecs,string
def detect_language(character):
maxchar = max(character)
if u'\u0900' <= maxchar <= u'\u097f':
return 'hindi'
with codecs.open('letter.txt', encoding='utf-8') as f:
input = f.read()
for i in input:
isEng = detect_language(i)
if isEng == "hindi":
#Hindi Character
#add this to another file
print(i,end="\t")
print(isEng)
希望对你有帮助
关于python - 从同时包含印地语和英语的文件中仅提取印地语文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44474085/