python-3.x - 检测动词是弱动词,否则是强动词
问题描述
描述:如果动词在结尾包含 d, ed,t 则我们称其为弱动词,如果动词中发生任何元音变化,则根据我的理解,我们将其称为强动词,并在此链接中也提到https ://www.thoughtco.com/difference-between-a-weak-verb-and-a-strong-verb-1691036。& https://writingexplained.org/grammar-dictionary/strong-verbs-vs-weak-verbs我已经实现并尝试涵盖检测弱动词或强动词的所有情况请帮助我创建一个算法来通过覆盖来检测弱动词所有测试用例
from collections import Counter
def is_vowel(char):
"""
check for char is vowel or not
"""
return 'aeiou'.__contains__(char.lower())
def LetterCount(text):
"""
Create the alphabet count dictionary using counter
"""
return dict(Counter(c for c in text.lower() if c.isalpha()))
def change_vowel_detect(verb1, verb3):
"""
Checking if the vowel is changing or not
input verb1 : verb base form (captured with lemmatization)
verb3 : verb 3rd form (captured from sentence)
return :
status of change_vowel_bool and is_key_mismatch
"""
change_vowel_bool = False
is_key_mismatch = False
verb1_count_dict = LetterCount(verb1)
verb3_count_dict = LetterCount(verb3)
print(verb1_count_dict,'\n',verb3_count_dict)
for key,value in verb1_count_dict.items():
#iterate over verb1 count dictionary
if is_vowel(key):
#checking verb character is vowel or not
if key in verb3_count_dict:
#checking same character is found in other verb dictionary or characters
if verb1_count_dict[key] != verb3_count_dict[key]:
#if both the key count mismatch then status changes
#print("word_count_missmatch")
change_vowel_bool = True
else:
change_vowel_bool = True
is_key_mismatch = True
return change_vowel_bool, is_key_mismatch
def is_weak_verb(verb1, verb3):
#change_vowel_bool = False
change_vowel_bool, is_key_mismatch = change_vowel_detect(verb1, verb3)
week_verb_bool = False
#if verb3.endswith('d') or verb3.endswith('t'):
#week_verb_bool = True
if verb1 == verb3:
week_verb_bool = True
if verb3.endswith('ed') and change_vowel_bool == False:
week_verb_bool = True
if (verb3.endswith('d') or verb3.endswith('t')) and is_key_mismatch == True :
week_verb_bool = True
return week_verb_bool
#testcases
print(is_weak_verb('Feed', 'Fed')) # strong verb
print(is_weak_verb('love', 'loved')) # Weak verb
print(is_weak_verb('meet', 'met')) # Weak verb
print(is_weak_verb('put', 'put')) # weak verb
print(is_weak_verb('wear', 'wore')) # Strong verb
print(is_weak_verb('bring', 'brought')) # strong verb
解决方案
由于您似乎需要英语,因此您可能需要考虑仅使用https://verbs.colorado.edu/~mpalmer/projects/verbnet.html 如果您想自己实现它,祝您好运并玩得开心,但很容易获得如果你真的想涵盖所有情况,就会迷失在一长串的例外中......
推荐阅读
- android - 如何在 Visual Studio 的 Android 共享库 (.so) 项目中正确使用 c++ 静态库 (.lib)?
- python - 使用 Matplotlib 旋转矩阵
- php - 支付网关重定向后会话被销毁 - WORDPRESS & PHP
- reactjs - React Native:无法从不同组件的函数体内更新组件
- css - 在融合中摆脱内联 CSS 样式属性
- c++ - 为什么我不能在声明中定义静态字段?
- python - 我们如何使用带有多个 _ 的 split 函数
- java - 如何在 gitlab-ci build 中跳过前面的 maven 目标?
- nlp - 如何用spacy获得依赖树的高度?
- vb.net - 暂停调试器时如何阻止“不包括 System.Windows.Forms.pdb”窗口打开?