def __init__(self, path='WordNet-3.0'):
""" Opens the WordNet database from the given path
(that contains dict/index.noun, dict/data.noun, ...)
"""
self._f = {} # {'n': <open file 'dict/index.noun'>}
for k, v in (('n', 'noun'), ('v', 'verb'), ('a', 'adj' ), ('r', 'adv' )):
f = cd(path, 'dict', 'data.%s' % v)
f = open(f, 'rb')
self._f[k] = f
f = cd(path, 'dict', 'index.%s' % v)
f = open(f, 'r')
for s in f:
if not s.startswith(' '):
s = s.strip()
s = s.split(' ')
p = s[-int(s[2]):]
w = s[0]
w = w.replace('_', ' ')
self[w, k] = p # {('grasp', 'n'): (offset1, ...)}
f.close()
评论列表
文章目录