python - 为什么我无法使用 Python 读取 .conll 文件(令人困惑的解析错误)?

标签 python parse-error conll

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/

相关文章:

Python复制文件到文件夹

python - 如何从 Doc 对象生成 .conllu?

python - 我怎样才能加快这个 django orm 生成的查询?

python - 在这种情况下如何使用 Assert?

python - 为什么 http 模块中的 http.server 在文档中被标记为 "not safe"?

php - 使用 php 5.3 解析错误 : syntax error, 意外 '['

python - 使用垃圾值读取错误的 csv 文件

php - 在 PHP5 中记录致命/解析错误

tags - 带有 CoNLL 2003 NER 任务描述的可能标签列表是什么?