2011-07-21 77 views
3

如何使用Wordnet获得给定单词的词条。我似乎无法在wordnet文档中找到我想要的内容。 http://wordnet.princeton.edu/wordnet/man/wn.1WN.html使用wordnet获取单词的词条

例如,对于单词“书本”我想“书”,骨灰=>灰,预订=>书,苹果=>苹果....等

我想要实现这个在命令行中使用wordnet,我找不到确切的选项来检索这种情况。

一个php解决方案也会有很大的帮助,因为我原本打算使用wordnet php API,但它似乎是目前在他们的网站不工作。

回答

1

我不确定WordNet本身实现它。 NLTK有Morphy,它可以精确地做你想做的事情,但它是用Python实现的。你可以编写一个小的Python程序来从命令行输入并返回引理。

在以下链接搜索 '莫菲': http://nltk.googlecode.com/svn/trunk/doc/api/nltk.corpus.reader.wordnet.WordNetCorpusReader-class.html

nltk.WordNetLemmatizer()还做这项工作。在下面的链接搜索“词形还原”: http://nltk.googlecode.com/svn/trunk/doc/book/ch03.html

NLTK网站:http://www.nltk.org/

2

莫菲是一个形态处理器原生共发现。 WordNet接口调用Morphy将单词作为查找过程的一部分进行解读(例如,您查询“开明”,它会返回“开明”和通过Morphy“开导”)的结果。

这些接口不包含允许用户直接访问Morphy的功能,因此只有在您使用WordNet API之一编写自己的程序时,才能在命令行中使用它。您可以在WordNet站点找到Morphy的documentation

尽我所知,尽管您可能需要使用WordNet 2.x,但PHP interface仍然可用。

2

如果您可以使用其他工具尝试TreeTagger

+0

http://stackoverflow.com/questions/15503388/treetagger-installation-successful-but-cannot-open-par -文件 – alvas

0

nltk库中的WordNetLemmatizer将执行您所需的操作。这里是python3代码:

#!Python3 -- this is lemmatize_s.py 
import nltk 
from nltk.stem import WordNetLemmatizer 
from nltk.tokenize import word_tokenize 
print ("This program will lemmatize your input until you ask for it to 'end'.") 
while True: 
    sentence = input("Type one or more words (or 'end') and press enter:") 
    if (sentence == "end"): 
     break 
    tokens = word_tokenize(sentence) 
    lemmatizer = WordNetLemmatizer() 
    Output=[lemmatizer.lemmatize(word) for word in tokens] 
    print (Output); 

在命令行中运行以下命令:

eyeMac2016:james$ python3 lemmatize_s.py 
This program will lemmatize your input until you ask for it to 'end'. 
Type one or more words (or 'end') and press enter:books ashes 
['book', 'ash'] 
Type one or more words (or 'end') and press enter:end 
eyeMac2016:james$