Difflib问题检测器Sequence_Matcher错误或故障?

时间:2018-10-02 03:08:05

标签: python python-2.7 difflib sequencematcher

我一直在使用在问题检测中发现的这段代码,因为我一直在努力。当我尝试代码时,我没有真正想到一些输出。有时我得到了预期的输出,但不是全部。

这是我的代码(已复制):

from difflib import *

Sample_Questions = [...]

value = 'why does it rain'


for Ran_Question in Sample_Questions:
    Question_Matcher = SequenceMatcher(None, Ran_Question, value).ratio()
    if Question_Matcher > 0.5:
        print (Question_Matcher)
        print ("Similar to Question: "+Ran_Question)
        print ("likely a Question")
else:
    print("Ran into some error... :(")

此后,我得到一个奇怪的输出...:

Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
0.529411764706
Similar to Question: why do you hate me
likely a Question
Ran into some error... :(
Ran into some error... :(
0.512820512821
Similar to Question: what do i do in an hour
likely a Question
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
0.536585365854
Similar to Question: who does all the shipping
likely a Question
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
0.55
Similar to Question: where did you say it was
likely a Question    
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
0.540540540541
Similar to Question: does it hurt everyday
likely a Question
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(
Ran into some error... :(

那太疯狂了,我现在想知道为什么它是如此混合。任何帮助,将不胜感激。如果您找到解决方法,请将其发布在答案栏中。谢谢。

P.S有时甚至不提供任何输出,仅给出错误语句。

0 个答案:

没有答案