I'd like to use the Link Grammar Python3 bindings for a simple grammar checker. While the linkage API is relatively well-documented, there doesn't seem to be way to access all tokens that prevent linkages.
This is what I have so far:
#!/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)
(I used link-grammar-5.4.3 for my tests.)
When I analyzed the invalid sample sentence using the Link Parser command line tool, I got the following output:
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[!] ?
How do I get all potentially invalid tokens marked with [!] or [?] with Python3?