def demo3():
from nltk import Production
(S, VP, NP, PP, P, N, Name, V, Det) = \
nonterminals('S, VP, NP, PP, P, N, Name, V, Det')
productions = (
# Syntactic Productions
Production(S, [NP, VP]),
Production(NP, [Det, N]),
Production(NP, [NP, PP]),
Production(VP, [VP, PP]),
Production(VP, [V, NP, PP]),
Production(VP, [V, NP]),
Production(PP, [P, NP]),
Production(PP, []),
Production(PP, ['up', 'over', NP]),
# Lexical Productions
Production(NP, ['I']), Production(Det, ['the']),
Production(Det, ['a']), Production(N, ['man']),
Production(V, ['saw']), Production(P, ['in']),
Production(P, ['with']), Production(N, ['park']),
Production(N, ['dog']), Production(N, ['statue']),
Production(Det, ['my']),
)
t = Tk()
def destroy(e, t=t): t.destroy()
t.bind('q', destroy)
p = ProductionList(t, productions)
p.pack(expand=1, fill='both')
p.add_callback('select', p.markonly)
p.add_callback('move', p.markonly)
p.focus()
p.mark(productions[2])
p.mark(productions[8])
cfg.py 文件源码
python
阅读 21
收藏 0
点赞 0
评论 0
评论列表
文章目录