python 中单词的动名词形式
gerund form of a word in python
我想要获取字符串的动名词形式。我还没有找到调用库来获取动名词的直接方法。
我对以“ing”结尾的单词应用了规则,但是因为异常导致我收到一些错误。然后,我正在检查 cmu 词以确保生成的动名词词是正确的。代码如下所示:
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
是否有更有效的方法来获取字符串的动名词(如果存在)?
谢谢
也许这就是您要找的。 Library 叫 pyinflect
A python module for word inflections that works as a spaCy extension. To use standalone, import the method getAllInflections and/or getInflection and call them directly. The method getInflection takes a lemma and a Penn Treebank tag and returns a tuple of the specific inflection(s) associated with it.
有多种标签可用于获取词形变化,包括您要查找的 '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]
[('leading',),
('taking',),
('hitting',),
('beginning',),
('stopping', 'stoping'),
('referring',),
('visiting',)]
注意: 作者已经建立了一个更复杂的基准库,它可以进行词形还原和变形,称为 LemmInflect
。如果您想要比上述库更可靠的东西,请检查 this。语法与上面几乎相同。
我想要获取字符串的动名词形式。我还没有找到调用库来获取动名词的直接方法。
我对以“ing”结尾的单词应用了规则,但是因为异常导致我收到一些错误。然后,我正在检查 cmu 词以确保生成的动名词词是正确的。代码如下所示:
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
是否有更有效的方法来获取字符串的动名词(如果存在)?
谢谢
也许这就是您要找的。 Library 叫 pyinflect
A python module for word inflections that works as a spaCy extension. To use standalone, import the method getAllInflections and/or getInflection and call them directly. The method getInflection takes a lemma and a Penn Treebank tag and returns a tuple of the specific inflection(s) associated with it.
有多种标签可用于获取词形变化,包括您要查找的 '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]
[('leading',),
('taking',),
('hitting',),
('beginning',),
('stopping', 'stoping'),
('referring',),
('visiting',)]
注意: 作者已经建立了一个更复杂的基准库,它可以进行词形还原和变形,称为 LemmInflect
。如果您想要比上述库更可靠的东西,请检查 this。语法与上面几乎相同。