我有一个Hindi WordNet的数据库和API,如何将其添加到NLTK中?
我有一个数据库和API,用于处理印地语的词网(wordnet)。我想通过NLTK这个Python库来访问这个词网,这样我就可以用NLTK的词网功能来处理我们的词网。请问有没有办法把我们自己的词网添加到NLTK里?或者,有没有什么工具可以用来处理印地语的词义消歧(也就是在不同的词义中找出最合适的那个),并且可以稍微修改后与任何语言的词网一起使用?
1 个回答
1
如果你查看一下你的nltk_data文件夹,你会发现wordnet和其他NLTK语料库一样,都是一堆普通的文本文件。所以,肯定有办法把你的印地语wordnet格式化成和NLTK的那种格式,这样才能使用相关的功能。下面是从nltk.corpus.reader.wordnet对象中读取这些文件的代码片段:
#: A list of file identifiers for all the fileids used by this
#: corpus reader.
_FILES = ('cntlist.rev', 'lexnames', 'index.sense',
'index.adj', 'index.adv', 'index.noun', 'index.verb',
'data.adj', 'data.adv', 'data.noun', 'data.verb',
'adj.exc', 'adv.exc', 'noun.exc', 'verb.exc', )
def __init__(self, root):
"""
Construct a new wordnet corpus reader, with the given root
directory.
"""
super(WordNetCorpusReader, self).__init__(root, self._FILES,
encoding=self._ENCODING)
我想你其实不需要生成所有这些文件,但更重要的是要使用“index.sense”文件来进行词义消歧。这不是NLTK生成的,而是需要在此之前进行预处理,或者你的印地语wordnet应该以以下格式提供 - http://wordnet.princeton.edu/wordnet/man/senseidx.5WN.html。
完成所有步骤后,我建议你去../nltk/corpus/reader/wordnet.py文件,创建一个副本,在那里你可以更改根目录和文件名,可能还需要调整其他一些依赖项,但仍然可以使用原有的功能,或者在现有类中修改你需要的部分(不推荐这样做)。
附言:稍微搜索了一下,我找到了这个链接 http://www.cs.utexas.edu/~rashish/cs365ppt.pdf,里面提到了很多相关的其他资料。