本文整理汇总了Python中nltk.stem.wordnet.WordNetLemmatizer.lower方法的典型用法代码示例。如果您正苦于以下问题:Python WordNetLemmatizer.lower方法的具体用法?Python WordNetLemmatizer.lower怎么用?Python WordNetLemmatizer.lower使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nltk.stem.wordnet.WordNetLemmatizer
的用法示例。
在下文中一共展示了WordNetLemmatizer.lower方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: countexp_noun
# 需要导入模块: from nltk.stem.wordnet import WordNetLemmatizer [as 别名]
# 或者: from nltk.stem.wordnet.WordNetLemmatizer import lower [as 别名]
def countexp_noun(para, searchText):
cnt = 0
searchWords = [WordNetLemmatizer().lemmatize(s.lower(), 'n') for s in searchText]
for stxt in searchWords:
for word in para.split():
w1 = WordNetLemmatizer().lemmatize(word.lower(), 'n')
if stxt.lower() == w1.lower():
cnt = cnt + 1
break
return cnt
示例2: extractSubjectObject
# 需要导入模块: from nltk.stem.wordnet import WordNetLemmatizer [as 别名]
# 或者: from nltk.stem.wordnet.WordNetLemmatizer import lower [as 别名]
def extractSubjectObject(self, sentence):
sub = None
obj = None
for word in sentence:
if sub == None and word[7] == "nsubj":
sub = word[2].translate(string.maketrans("",""), string.punctuation)
sub = sub.lower()
sub = WordNetLemmatizer().lemmatize(sub, pos="n")
if obj == None and word[7] == "dobj":
obj = word[2].translate(string.maketrans("",""), string.punctuation)
obj = obj.lower()
obj = WordNetLemmatizer().lemmatize(obj, pos="n")
# The sentence did not contain a verb, so we need to back-off to
# using the tokens tagged with NN (word[4]). Brute-force take the first
# two tokens tagged with NN.
#
# Example use : A big cow in a field. -> cow, field.
if sub == None:
for word in sentence:
if word[4] == "NN":
sub = word[2].translate(string.maketrans("",""), string.punctuation)
sub = sub.lower()
sub = WordNetLemmatizer().lemmatize(sub, pos="n")
break
if obj == None:
for word in sentence:
if word[4] == "NN":
proposal = word[2].translate(string.maketrans("",""), string.punctuation)
proposal = proposal.lower()
proposal = WordNetLemmatizer().lemmatize(proposal, pos="n")
if proposal != sub:
obj = proposal
break
return sub, obj