Python 3.x python中单词的动名词形式
我想知道字符串的动名词形式。我还没有找到一种直接的方法来调用库来获取动名词 我对以“ing”结尾的单词应用了这些规则,但由于异常,我遇到了一些错误。然后,我将对照cmu单词进行检查,以确保生成的动名词词是正确的。代码如下所示:Python 3.x python中单词的动名词形式,python-3.x,nlp,nltk,porter-stemmer,Python 3.x,Nlp,Nltk,Porter Stemmer,我想知道字符串的动名词形式。我还没有找到一种直接的方法来调用库来获取动名词 我对以“ing”结尾的单词应用了这些规则,但由于异常,我遇到了一些错误。然后,我将对照cmu单词进行检查,以确保生成的动名词词是正确的。代码如下所示: import cmudict import re ing= 'ing' vowels = "aeiou" consonants = "bcdfghjklmnpqrstvwxyz" words=['lead','take','hit
import cmudict
import re
ing= 'ing'
vowels = "aeiou"
consonants = "bcdfghjklmnpqrstvwxyz"
words=['lead','take','hit','begin','stop','refer','visit']
cmu_words= cmudict.words()
g_w = []
for word in words:
if word[-1] == 'e':
if word[:-1] + ing in cmu_words:
g_w.append(word[:-1] + ing)
elif count_syllables(word) == 1 and word[-2] in vowels and word[-1] in consonants:
if word.__len__()>2 and word[-3] in vowels:
if word + ing in cmu_words:
g_w.append(word + ing)
else:
if word + word[-1] + ing in cmu_words:
g_w.append(word + word[-1] + ing)
elif count_syllables(word)>1 and word[-2] in vowels and word[-1] in consonants:
if word + word[-1]+ ing in cmu_words:
g_w.append(word + word[-1]+ ing)
else:
if word + ing in cmu_words:
g_w.append(word + ing)
print(g_w)
规则如下:
when a verb ends in "e", drop the "e" and add "-ing". For example: "take + ing = taking".
when a one-syllable verb ends in vowel + consonant, double the final consonant and add "-ing". For example: "hit + ing = hitting".
When a verb ends in vowel + consonant with stress on the final syllable, double the consonant and add "-ing". For example: "begin + ing = beginning".
Do not double the consonant of words with more than one syllable if the stress is not on the final
如果存在字符串,是否有更有效的方法获取其动名词
谢谢也许这就是你要找的。称为Pyinfoct 用于单词屈折变化的python模块,用作空间扩展。要使用standalone,请导入方法getAllInflections和/或getInflection并直接调用它们。getInflection方法接受一个引理和一个Penn Treebank标记,并返回与之相关联的特定屈折变化的元组 有各种各样的标记可用于获取屈折变化,包括“VBG”标记动词,您正在寻找的动名词
pos_type = 'A'
* JJ Adjective
* JJR Adjective, comparative
* JJS Adjective, superlative
* RB Adverb
* RBR Adverb, comparative
* RBS Adverb, superlative
pos_type = 'N'
* NN Noun, singular or mass
* NNS Noun, plural
pos_type = 'V'
* VB Verb, base form
* VBD Verb, past tense
* VBG Verb, gerund or present participle
* VBN Verb, past participle
* VBP Verb, non-3rd person singular present
* VBZ Verb, 3rd person singular present
* MD Modal
下面是一个示例实现
#!pip install pyinflect
from pyinflect import getInflection
words = ['lead','take','hit','begin','stop','refer','visit']
[getInflection(i, 'VBG') for i in words]
注:作者已经建立了一个更复杂和基准化的库,该库同时进行lemmatization和屈折,称为LemmInflect。如果您想要比上述库更可靠的内容,请务必查看。语法与上面的基本相同。也许这就是您要找的。称为Pyinfoct 用于单词屈折变化的python模块,用作空间扩展。要使用standalone,请导入方法getAllInflections和/或getInflection并直接调用它们。getInflection方法接受一个引理和一个Penn Treebank标记,并返回与之相关联的特定屈折变化的元组 有各种各样的标记可用于获取屈折变化,包括“VBG”标记动词,您正在寻找的动名词
pos_type = 'A'
* JJ Adjective
* JJR Adjective, comparative
* JJS Adjective, superlative
* RB Adverb
* RBR Adverb, comparative
* RBS Adverb, superlative
pos_type = 'N'
* NN Noun, singular or mass
* NNS Noun, plural
pos_type = 'V'
* VB Verb, base form
* VBD Verb, past tense
* VBG Verb, gerund or present participle
* VBN Verb, past participle
* VBP Verb, non-3rd person singular present
* VBZ Verb, 3rd person singular present
* MD Modal
下面是一个示例实现
#!pip install pyinflect
from pyinflect import getInflection
words = ['lead','take','hit','begin','stop','refer','visit']
[getInflection(i, 'VBG') for i in words]
注:作者已经建立了一个更复杂和基准化的库,该库同时进行lemmatization和屈折,称为LemmInflect。如果您想要比上述库更可靠的内容,请务必查看。语法与上面的基本相同