【问题标题】:getting the lemma of a word using wordnet使用 wordnet 获取单词的引理
【发布时间】:2011-07-21 22:39:50
【问题描述】:
如何使用 Wordnet 获取给定单词的引理。我似乎无法在 wordnet 文档中找到我想要的东西。 http://wordnet.princeton.edu/wordnet/man/wn.1WN.html
例如对于单词“books”,我想得到“book”,ashes => ash,booking => book,apples => apple .... 等等。
我想在命令行中使用 wordnet 来实现这一点,但我找不到准确的选项来检索这种情况。
php 解决方案也会有很大帮助,因为我最初打算使用 wordnet php API,但他们网站上的当前 API 似乎无法正常工作。
【问题讨论】:
标签:
php
nlp
wordnet
lemmatization
morphological-analysis
【解决方案1】:
Morphy 是 WordNet 原生的形态处理器。作为查找过程的一部分,WordNet 接口调用 Morphy 对单词进行词形还原(例如,您查询“enlightened”,它会返回“enlightened”和通过 Morphy 的“enlighten”的结果)。
这些界面不包含允许用户直接访问 Morphy 的功能,因此只有在使用 WordNet API 之一编写自己的程序时才能在命令行中使用它。您可以在 WordNet 网站上找到 Morphy 的 documentation。
据我所知,PHP interface 仍然可用,但您可能需要使用 WordNet 2.x。
【解决方案4】:
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$