Trying to write a code that will compare multiple files and return the highest fuzzratio between multiple options.
Problem is I’m getting an error message:
WARNING:root:Applied processor reduces input query to empty string, all comparisons will have score 0. [Query: ‘/’] WARNING:root:Applied processor reduces input query to empty string, all comparisons will have score 0. [Query: ‘.’]
And the exported file is essentially blank. Any clue why this is happening?
from fuzzywuzzy import fuzz, process import csv def readfile( filen ): with open(filen,'r') as f: contents = f.readlines() return contents def write_fuzzy( fileo, file1, file2 ): matches=[] for item1 in file1: matches.append(process.extract( str(item1), file2, limit=2 )[0][0]) with open( fileo, 'w' ) as f: w = csv.writer( f, delimiter = ',' ) w.writerows( matches ) filenames = ['Documents/test_CSV_1.csv', 'Documents/test_CSV_2.csv'] file_contents = [] for filen in filenames: file_contents.append( readfile( filen ) ) write_fuzzy( 'out.csv', filenames[0], filenames[1] )
Advertisement
Answer
Sorry for the late answer. I am facing a similar issue and found your question.
The problem is not really one it’s just a warning and wont actually result in any differences in your matches.
WARNING:root:Applied processor reduces input query to empty string, all comparisons will have score 0. [Query: '/']
Means that the query string for process.extract()
didn’t contain any common characters of a natural language: [Query: '/']
.
After digging into fuzzywuzzy, i found that a string processor reduces input query to empty string
, which wont match any pattern in the search text you provide.
My approach to get rid of these warnings is to validate the query string with that string processor before doing the fuzzy search.
from fuzzywuzzy import utils invalid_query = " ... // " if utils.full_process(invalid_query): # wont execute and not produce a warning process.extract(invalid_query, patterns)