from pyconll import load_from_file
data = load_from_file("filename.conll")
data
我正在关注the documentation of pyconll读取 .conll
文件,但出现以下错误,我不明白它的含义。该数据集应该是可读的,因为它是一个基准数据集。而且我没有看到文档中可以指定的任何其他 pyconll.load_from_file() 参数。有人可以帮我吗?
另外,有没有办法通过nltk
包读取.conll
文件?
ParseError Traceback (most recent call last)
<ipython-input-14-06859f7ce8b2> in <module>()
----> 1 data = load_from_file("filename.conll")
2 data
5 frames
/usr/local/lib/python3.6/dist-packages/pyconll/unit/token.py in __init__(self, source, empty)
661 error_msg = 'The number of columns per token line must be 10. Invalid token: {}'.format(
662 source)
--> 663 raise ParseError(error_msg)
664
665 # Assign all the field values from the line to internal equivalents.
ParseError: The number of columns per token line must be 10. Invalid token: @paulwalk O
最佳答案
问题在于“CoNLL”格式的列数、顺序和内容不同。根据错误,您的解析器似乎需要 CoNLL-U ( https://universaldependencies.org/format.html ) 或 CoNLL-X (原始网站已关闭)。无论您输入什么,错误都会声称未找到预期的列数 (10),请参阅 What is CoNLL data format? .
但是,如果您确实有 10 列,请尝试转义预期的标记,可能某些内部正则表达式替换失败。
关于用NLTK解析CoNLL的子问题,请参阅问题中的详细信息(!)Parsing CoNLL-U files with NLTK 。可以解析某些 CoNLL 格式,但 NLTK 似乎不支持更新的 CoNLL 格式,特别是 CoNLL-X 和 CoNLL-U。它可能适用于您的数据(因为这既不是 CoNLL-X 也不是 CoNLL-U)。
关于python - 为什么我无法使用 Python 读取 .conll 文件(令人困惑的解析错误)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64589517/