【问题标题】:How to extract full text from a list with fuzzywuzzy?如何使用fuzzywuzzy从列表中提取全文?
【发布时间】:2021-09-20 11:00:27
【问题描述】:

下面是我的代码:

from fuzzywuzzy import fuzz

check = open("text.txt","a")
    
MIN_MATCH_SCORE = 30
heard_word = 'i5-1135G7 '
possible_words = check

guessed_word = [word for word in possible_words if fuzz.ratio(heard_word, word) >= 
MIN_MATCH_SCORE]
print ('this one - ', guessed_word)

预期输出:

 11th Generation Intel® Core™ i5-1135G7 Processor

是否可以仅通过单独给出“i5-1135G7”来获得预期输出中的整个句子?有没有其他解决方案可以得到我的期望?提前谢谢你。

下面是 text.txt 的链接
https://drive.google.com/file/d/1Mo3qFmeOAqa3WPPyg8SpeFVSjDx7AQBj/view

【问题讨论】:

    标签: python machine-learning nlp nltk fuzzywuzzy


    【解决方案1】:

    为了抵消较长的句子并确保单词级别的重叠,您应该使用token_set_ratio。此外,如果您想要全字重叠,请将MIN_MATCH_SCORE 增加到接近 100。

    from fuzzywuzzy import fuzz
    
      
    MIN_MATCH_SCORE = 90
    heard_word = 'i5-1135G7'
    
    possible_words = ['11th Generation Intel® Core™ i5-1135G7 Processor (2.40 GHz,up to  4.20 GHz with Turbo Boost, 4 Cores, 8 Threads, 8 MB Cache)', 
                       'windows 10 64 bit', 'intel i7']
                       
    print ([word for word in possible_words 
            if fuzz.token_set_ratio(heard_word, word) >= MIN_MATCH_SCORE])
    

    输出:

    ['11th Generation Intel® Core™ i5-1135G7 Processor (2.40 GHz,up to  4.20 GHz with Turbo Boost, 4 Cores, 8 Threads, 8 MB Cache)']
    
    

    【讨论】:

    • 嘿,谢谢它的工作,但你能在可能的单词变量中试试这个 test.txt 吗? test.txt 链接drive.google.com/file/d/1Mo3qFmeOAqa3WPPyg8SpeFVSjDx7AQBj/…
    • 当我尝试使用 text.txt 时,我得到 '1'、'1'、'1'、'1'、'1'、'1'、'1'、'1'、' 1','1','1','1','1','Windows 10 Pro 64','Windows 10 Pro 64',当我在heard_word中给出'windows 10'时。
    • 检查更新,现在你应该有一个不错的结果。
    • 是的,我得到了很好的结果,但如果我以可能的话通过 test.txt,我就无法摆脱那个 1,1,1,1,1,1。我只想要那个 ---> ['第 11 代 Intel® Core™ i5-1135G7 处理器(2.40 GHz,最高 4.20 GHz,Turbo Boost,4 核,8 线程,8 MB 缓存)'] 请使用 test.txt 进行测试.
    【解决方案2】:

    #token_set_ratio 工作正常!
    从fuzzywuzzy导入fuzz

    s = []
    for l in df1.values:
        l = ', '.join(l)
        s.append(l)
    
    s = ', '.join(s)    
    main = [x for x in g if x]
    MIN_MATCH_SCORE = 60
    heard_word = 'i5-11th gen'
    guessed_word = [word for word in main if fuzz.token_set_ratio(heard_word, 
    word) >= MIN_MATCH_SCORE]
    print ('this one - ', guessed_word)
    

    【讨论】:

      猜你喜欢
      • 2019-03-06
      • 1970-01-01
      • 2013-11-06
      • 2011-09-25
      • 2020-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多