我想将Link Grammar Python3 绑定用于简单的语法检查器。虽然链接 API 的文档相对完善,但似乎没有办法访问所有阻止链接的令牌。
这是我到目前为止所拥有的:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from linkgrammar import Sentence, ParseOptions, Dictionary, __version__
print('Link Grammar Version:', __version__)
for sentence in ['This is a valid sample sentence.', 'I Can Has Cheezburger?']:
sent = Sentence(sentence, Dictionary(), ParseOptions())
linkages = sent.parse()
if len(linkages) > 0:
print('Valid:', sentence)
else:
print('Invalid:', sentence)
(我使用 link-grammar-5.4.3 进行测试。)
当我使用 Link Parser 命令行工具分析无效的例句时,我得到以下输出:
linkparser> I Can Has Cheezburger?
No complete linkages found.
Found 1 linkage (1 had no P.P. violations) at null count 1
Unique linkage, cost vector = (UNUSED=1 DIS= 0.10 LEN=7)
+------------------Xp------------------+
+------------->Wa--------------+ |
| +---G--+-----G----+ |
| | | | |
LEFT-WALL [I] Can[!] Has[!] Cheezburger[!] ?
如何使用 Python3 获取所有标有 [!] 或 [?] 的潜在无效标记?