如何使用Python通过标题检测文本(.csv)的语言?

问题描述 投票:-1回答:1

对于研究用途,我应该:

  1. 读取.csv文件
  2. 按标题检测文本的语言
  3. [通过一些关键字识别文本的论点例如肺叶切除术->大脑

[我正在尝试使用Python及其库NLTK进行第二和第三点,如果您曾经做过类似的事情,可以给我一些提示吗?

谢谢您!

python text nlp nltk
1个回答
0
投票

这不是完全确定的,但是您可以尝试几种语言识别工具。

使用langid.py

langid.py https://github.com/saffsd/langid.py中最受欢迎和最容易使用的之一>

要安装:python -m pip install -U langid

>>> import langid

>>> text = "Hallo, wie gehts?"
>>> lang, log_prob = langid.classify(text)
>>> print(lang)
de

使用pyCLD2

pycld2chromium-compact-language-detector的包装,请参见https://github.com/aboSamoor/pycld2

安装:python -m pip install -U pycld2

>>> import pycld2 as cld2

>>> text = "Hallo, wie gehts?"

>>> isReliable, textBytesFound, details = cld2.detect(text)
>>> lang = details[0][1]
>>> print(lang)
de

使用cld3

安装:python -m pip install -U pycld3

>>> import cld3

>>> text = "Hallo, wie gehts?"

>>> prediction = cld3.get_language(text)
>>> print(prediction.language)
de

这是https://arxiv.org/pdf/1910.06748.pdf的一个不错的近期摘要(2019年)

© www.soinside.com 2019 - 2024. All rights reserved.