def main():
    print(
        "Hello this is the Edit Distance Program that performs the distance of words in three different tests cases.\nTest 1 performs it on two distinct ones that so happen to be my favorite phrase together.\nTest 2 performs it on the same word.\nTest 3 performs it on one word and an empty string."
    )
    print("")
    print("Then allow you to compare your own words.\nLet's initiate: ")
    print("")
    print("Test 1: ")
    #Test case 1
    word_1 = "fire"
    word_2 = "dynasty"
    print("Words being compared are '", word_1, "' and '", word_2, "'.")
    print("\t\t...calculating their distance...\n")
    print("Distance between them: ", end='')
    print(ed.EditDistance(word_1, word_2, len(word_1), len(word_2)))
    print("")
    print("Test 2: ")
    #Test case 2
    word_1 = "elvis"
    word_2 = "elvis"
    print("Words being compared are '", word_1, "' and '", word_2, "'.")
    print("\t\t...calculating their distance...\n")
    print("Distance between them: ", end='')
    print(ed.EditDistance(word_1, word_2, len(word_1), len(word_2)))
    print("")
    print("Test 3: ")
    #Test case 3
    word_1 = "styles"
    word_2 = ""
    print("The two words being compared are '", word_1, "' and '", word_2,
          "'.")
    print("\t\t...calculating their distance...\n")
    print("Distance between them: ", end='')
    print(ed.EditDistance(word_1, word_2, len(word_1), len(word_2)))
    print("")
    print("Now that the test are completed...")
    print("Would you like to try two words for yourself? Yes or No")
    user_sel = input()
    if (user_sel == 'yes' or user_sel == 'Yes' or user_sel == 'YES'):
        print("Excellent! Now, which two words would you like to try?")
        print("Word 1: ")
        word_1 = input()
        print("Word 2: ")
        word_2 = input()
        print("The two words being compared are '", word_1, "' and '", word_2,
              "'.")
        print("\t\t...calculating their distance...\n")
        print("Distance between them: ", end='')
        print(ed.EditDistance(word_1, word_2, len(word_1), len(word_2)))
        print("")
        print("Program complete!\nThank you for participating")
    elif (user_sel == 'no' or user_sel == 'No' or user_sel == 'NO'):
        print("Okay.")
        print("See you again soon!")
    else:
        print("ERROR!\nInput invalid!")
        print("Terminating...\nGoodbye!")
 def test_almost_right(self):
     targeted_score = comment_score["almost right"]
     assert ed.LevenshteinMethod(
         "flocinaucinihilipilification",
         "floccinaucinihilipilification") == targeted_score, error_toast
     assert ed.LevenshteinMethod("owll",
                                 "owl") == targeted_score, error_toast
     assert ed.LevenshteinMethod(
         "pseudopseudohipoparathyroidism",
         "pseudopseudohypoparathyroidism") == targeted_score, error_toast
 def test_a_bit_confusing(self):
     targeted_score = comment_score["a bit confusing"]
     assert ed.LevenshteinMethod("plez",
                                 "please") == targeted_score, error_toast
     assert ed.LevenshteinMethod("cnoke",
                                 "knock") == targeted_score, error_toast
     assert ed.LevenshteinMethod("reqid",
                                 "required") == targeted_score, error_toast
     assert ed.LevenshteinMethod(
         "pneumonoultramicroscopiccilikovolkanokoniosis",
         "pneumonoultramicroscopicsilicovolcanokoniosis"
     ) == targeted_score, error_toast
Example #4
0
def normalize_recursion(function, s1, s2, *args):
    result = 0
    time = np.zeros(5)
    for i in range(0, time.size):
        temp1, temp2 = ed.calc_runtime(function, s1, s2, *args)
        time[i] = temp1
        result = temp2
    return result, np.average(time)
 def load_channel_model(self, fp):
     ''' Takes in a file pointer as input
     and should initialize the SpellChecker object’s 
     channel_model data member to a default EditDistanceFinder 
     and then load the stored language model (e.g. ed.pkl) 
     from fp into that data member. '''
     self.channel_model = EditDistance.EditDistanceFinder()
     self.channel_model.load(fp)
Example #6
0
def iterator(head_start, end, function, function2, s1, s2, *args):
    result = np.zeros(end)
    time = np.zeros(end)
    for i in range(head_start, end):
        temp1, temp2 = ed.calc_runtime(function, function2, s1[i], s2[i],
                                       *args)
        time[i] = temp1
        result[i] = temp2[0]
    return np.average(result), np.delete(time, np.arange(0, head_start))
Example #7
0
def recursion(path2, folder):
    for root, subdirs, files in os.walk(path2):
        for filename in files:
            if filename[-4:] == ".xml":
                path = os.path.join(root, filename)
                text, emails = out1_pro.callMe(path)
                if text != None:
                    w = EditDistance.textToMapping(text, emails)
                    for item in w:
                        # print(item, w[item],filename[:-4], folder)
                        try:
                            fire(w[item], item, filename[:-4], folder)
                        except Exception as e:
                            print("Exception in database updation " + str(e))
Example #8
0
def recursion(path2, folder):
    for root, subdirs, files in os.walk(path2):
        for filename in  files:
            if filename[-4:] == ".xml":
                path = os.path.join(root, filename)
                text,emails = out1_pro.callMe(path)
                if text != None:
                    w = EditDistance.textToMapping(text,emails)
                    for item in w:
                        # print(item, w[item],filename[:-4], folder)
                        try:
                            fire(w[item], item, filename[:-4], folder)
                        except Exception as e:
                            print("Exception in database updation " + str(e))
Example #9
0
def recurse(folder):
    for root, subdirs, files in os.walk(folder):
        for filename in files:
            if filename[-4:] == ".xml":
                path = os.path.join(root, filename)
                path = os.path.join(root, filename)
                text, emails = out1_pro.callMe(path)
                if text != None:
                    w = EditDistance.textToMapping(text, emails)
                    print "\n---from FINAL----"  #, w#text,'\n\n ----  ',w
                    # if len(Emails)!=0:
                    #     print "$$$$$$",Emails
                    for item in w:
                        print item, w[item], filename[:-4]
                        fire(w[item], item, filename[:-4])
                    # print os.path.abspath(os.path.join(path, os.pardir))
                    # print os.pardir
                    print "-----------------------xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Example #10
0
def recurse(folder):
    for root, subdirs, files in os.walk(folder):
        for filename in files:
            if filename[-4:] == ".xml":
                path = os.path.join(root, filename)
                path = os.path.join(root, filename)
                text,emails = out1_pro.callMe(path)
                if text != None:
                    w = EditDistance.textToMapping(text,emails)
                    print "\n---from FINAL----"#, w#text,'\n\n ----  ',w
                    # if len(Emails)!=0:
                    #     print "$$$$$$",Emails
                    for item in w:
                        print item, w[item],filename[:-4]
                        fire(w[item], item, filename[:-4])
                    # print os.path.abspath(os.path.join(path, os.pardir))
                    # print os.pardir
                    print"-----------------------xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
Example #11
0
def callback():
    if var.get() == 1:

        result = (ed.calc_runtime_md(ed.med_classic_gui, e1.get(), e2.get()))
        var2.set("RUNNING TIME :  %s seconds" % result[0])
        var3.set("{} {}".format("MINIMUM EDIT DISTANCE :", result[1]))
        var4.set(result[2])
        var5.set(result[3])
        var6.set(result[4])
        #print("RUNNING TIME :  %s seconds" % result[0])
    # print(var2.set(ed.calc_runtime(ed.med_classic, )))
    if var.get() == 2:

        result1 = ed.hirschberge(e1.get(), e2.get())
        result = (ed.calc_runtime_md(ed.calcByRow, e1.get(), e2.get()))
        var2.set("RUNNING TIME :  %s seconds" % result[0])
        var3.set("{} {}".format("MINIMUM EDIT DISTANCE :", result[1]))
        var4.set(result1[0])
        var5.set(result1[1])
        var6.set(result1[2])
    if var.get() == 3:
        result = (ed.calc_runtime_md(ed.med_recursive, e1.get(), e2.get()))
        var2.set("RUNNING TIME :  %s seconds" % result[0])
        var3.set("{} {}".format("MINIMUM EDIT DISTANCE :", result[1]))

    if var.get() == 4:

        result = (ed.calc_runtime_md(ed.med_branch, e1.get(), e2.get(),
                                     int(E5.get()),
                                     abs(len(e1.get()) - len(e2.get())) + 1))
        var2.set("RUNNING TIME :  %s seconds" % result[0])
        var3.set("{} {}".format("MINIMUM EDIT DISTANCE :", result[1]))
    if var.get() == 5:

        result = (ed.calc_runtime_md(ed.med_k_gui, e1.get(), e2.get(),
                                     E3.get()))
        var2.set("RUNNING TIME :  %s seconds" % result[0])
        var3.set("{} {}".format("MINIMUM EDIT DISTANCE :", result[1]))
        var4.set(result[3])
        var5.set(result[4])
        var6.set(result[5])
    if var.get() == 6:

        result = (ed.calc_runtime_md(ed.med_greedy, e1.get(), e2.get(),
                                     int(E4.get())))
        var2.set("RUNNING TIME :  %s seconds" % result[0])
        var3.set("{} {}".format("MINIMUM EDIT DISTANCE :", result[1]))
 def test_quite_close(self):
     targeted_score = comment_score["quite close"]
     assert ed.LevenshteinMethod("ples",
                                 "please") == targeted_score, error_toast
     assert ed.LevenshteinMethod("reqird",
                                 "required") == targeted_score, error_toast
     assert ed.LevenshteinMethod("rnser",
                                 "answer") == targeted_score, error_toast
     assert ed.LevenshteinMethod(
         "antidisestablishmentaraniasm",
         "antidisestablishmentarianism") == targeted_score, error_toast
     assert ed.LevenshteinMethod("wol",
                                 "owl") == targeted_score, error_toast
     assert ed.LevenshteinMethod(
         "humuhumunukunukuapuaua‘a",
         "humuhumunukunukuapua‘a") == targeted_score, error_toast
Example #13
0
def protein_database_processor(data):
    result = np.arange(data.__len__())
    for i in range(0, data.__len__()):
        result[i] = ed.med_classic(data[0], data[i])[0]
        # print(result[i])
    return result
Example #14
0
import time
from EditDistance import *
str1 = 'miners'
str2 = 'money'

print('the first string (word) is:')
print(str1)
print()
print('the second string (word) is:')
print(str2)
print()
start = time.time()
EditDistance(str1, str2)
end = time.time()
print('Running time:')
print(end - start)
print('seconds.')

 def test_very_confusing(self):
     targeted_score = comment_score["very confusing"]
     assert ed.LevenshteinMethod(
         "mispeln", "misspelling") == targeted_score, error_toast
     assert ed.LevenshteinMethod("mestipenk",
                                 "mistyping") == targeted_score, error_toast
 def test_right(self):
     targeted_score = comment_score["totally correct"]
     assert ed.LevenshteinMethod("Jiang",
                                 "Jiang") == targeted_score, error_toast
     assert ed.LevenshteinMethod("Chibin",
                                 "Chibin") == targeted_score, error_toast
 def load_channel_model(self, fp):
     self.channel_model = EditDistance.EditDistanceFinder()
     self.channel_model.load(fp)
def classify_comment(rightspelling, *misspellings):
    score_comment = {value: key for key, value in comment_score.items()}
    for mis in misspellings:
        edit_dist = ed.LevenshteinMethod(mis, rightspelling)
        yield mis + "\t" + str(edit_dist) + "\t" + score_comment[edit_dist]