@@ -0,0 +1,1155 @@
+#!/usr/bin/env python%0A%22%22%22%0AScript to extract and then generate random queries for fuzzy searching.%0A%0AUsage:%0A    ./extract-random-queries.py %3Cinfile%3E %3Coutfile%3E%0A%22%22%22%0A%0Aimport os%0Afrom random import choice, randint, random%0Aimport string%0Afrom subprocess import call%0Aimport sys%0Afrom tempfile import mkstemp%0A%0A__author__ = %22Uwe L. Korn%22%0A__license__ = %22MIT%22%0A%0A%0Ainput_file = sys.argv%5B1%5D%0Aoutput_file = sys.argv%5B2%5D%0A%0A# Randomly select 1000 lines from the input file and store them temporarily.%0Atemp_f, temp_file = mkstemp()%0Acall(%5B'shuf', '-n', '1000', input_file, '-o', temp_file%5D)%0A%0A# Modifiy these queries so that they have a non-zero edit distance.%0Awith open(temp_file, 'r') as f:%0A    with open(output_file, 'w') as out:%0A        for line in f.readlines():%0A            if random() %3E 0.75:%0A                pos = randint(0, len(line) - 2)%0A                line = line%5B0:pos%5D + choice(string.ascii_lowercase) + line%5Bpos + 1:%5D%0A            if random() %3E 0.25:%0A                pos = randint(0, len(line) - 2)%0A                line = line%5B0:pos%5D + choice(string.ascii_lowercase) + line%5Bpos + 1:%5D%0A            out.write(line)%0A%0A# Remove the temporary file again.%0Aos.unlink(temp_file)%0A

Add script to generate random Levenshtein queries from a set of strings