使用“OR”语句检查单词是否与python2.7中的行内容匹配

2024-07-02 11:14:34 发布

您现在位置:Python中文网/ 问答频道 /正文

常见问题:

g3650 = "gerund_verb" g3660 = "linking_verb" g3670 = "auxiliary_verb"

里面有什么?它们由am、is、are、was、were等词组成。 我的意图是什么?我想有一种方法来检查多个步骤,如果这个词是动名词动词或链接动词,如果它是对任何单独的行,然后检查下一个词作为相同的方式。 我现在有什么问题?当我输入一个单词,其中包含了任何一个生词;当我输入任何不可用的单词时,它仍然显示找到它。 我试过在这里查看其他帖子,但即使这个问题看起来很相似,我还是无法从我的水平上找到可以理解的答案

这是我的密码:

df4 = pd.read_sql('select * from VERB',connection)
df5 = pd.read_sql('select * from ADVERB',connection)

df = pd.concat([df4,df5])

def word_list(text):
return list(filter(None, re.split('\W+', text)))

session = raw_input("Hi!")
feedback = session

dff = pd.DataFrame({'Sentence':[feedback]})
dff['1'] = dff['Sentence'].astype(str).str.split().str[0]
dff['2'] = dff['Sentence'].astype(str).str.split().str[1]
dff['3'] = dff['Sentence'].astype(str).str.split().str[2]

for pts1 in dff['1']:
 pts1 = df.columns[df.isin([pts1]).any()]
for pts2 in dff['2']:
 pts2 = df.columns[df.isin([pts2]).any()]
for pts3 in dff['3']:
 pts3 = df.columns[df.isin([pts3]).any()]

word_count = len(feedback.split())

g3650 = "gerund_verb"
g3660 = "linking_verb"
g3670 = "auxiliary_verb"

if word_count == 1:
 if pts1 == g3670 or g3660:
  print "found it"

Tags: indfforsentencefeedbackwordpdsplit