Example #1
0
File: tp5.py Project: joelcn/uni
def task3():
    # Task 3
    words = fileMK.readFile(outputPath + "task1")
    inp = input(" Enter a Word\n")
    if len(inp) == 4:
        s = " "
        if (re.findall("\'(" + inp + ")\'", words)):
            print(" Word is written correctly")
            return
        for i in range(4):
            newInp = inp[:i] + "." + inp[i+1:]
            m = re.findall("\'(" + newInp + ")\'", words)
            if m:
                s += str(m)
                s += ", "
        if len(s) > 2:
            print(" Found the following words with replaced letters:")
            print(s.replace("[", "").replace("]", "").replace("'", "")[:-2])
        else:
            print(" No correction found with replaced letters")
        s = " "
        a = fileMK.permutationString(inp).split(" ")
        for i in range(len(a)):
            m = re.findall("\'(" + a[i] + ")\'", words)
            if m:
                s += str(m)
                s += ", "
        if len(s) > 2:
            mDict = fileMK.unsortedDictFromWords(s.split(" "))
            s = str(sorted(mDict.keys())).replace("\"", "")
            print(" Found the following words with switched letters:")
            print("", s.replace("[", "").replace("]", "").replace("'", ""))
        else:
            print(" No correction found with switched letters")
Example #2
0
File: tp5.py Project: joelcn/uni
def task1():
    # Task 1
    a = fileMK.stemText(t[0])
    m = re.findall("[ \(\)<>]([a-zA-Z]{4})[ \(\)<>]", a)
    if m:
        mDict = fileMK.unsortedDictFromWords(m)   
        p = outputPath + "task1"
        fileMK.writeTextToFile(str(sorted(mDict.keys())), p)
Example #3
0
File: tp3.py Project: joelcn/uni
def task2():
    # Task 2
    w = []
    for i in range(len(t)):
        w += t[i].split(" ")
    unsorted_dict = fileMK.unsortedDictFromWords(w)
    s = "There are " + str(len(unsorted_dict)) + " different Terms"
    print(s)
    path = outputPath + "task2.txt"
    fileMK.writeTextToFile(s, path)
Example #4
0
File: tp5.py Project: joelcn/uni
def task2():
    # Task 2
    words = fileMK.readFile(outputPath + "task1")
    inp = input(" Enter a Word\n")
    s = " "
    if len(inp) == 3:
        for i in range(4):
            newInp = inp[:i] + "." + inp[i:]
            m = re.findall("\'(" + newInp + ")\'", words)
            if m:
                s += str(m)
                s += ", "
        if len(s) > 2:
            print(" Found the following words with an additional letter:")
            print(s.replace("[", "").replace("]", "").replace("'", "")[:-2])
        else:
            print(" No correction found with an additional letter")
    if len(inp) == 4:
        if (re.findall("\'(" + inp + ")\'", words)):
            print(" Word is written correctly")
            return
        newInp = []
        for i in range(4):
            l = len(inp)
            for j in range(4):
                a = list(inp)
                a[i] = inp[l - j - 1]
                a[l - j - 1] = inp[i]
                out = "".join(a)
                if out != inp:
                    newInp.append(out)
        for k in range(len(newInp)):
            m = re.findall("\'(" + newInp[k] + ")\'", words)
            if m:
                s += str(m)
                s += ", "
        if len(s) > 2:
            mDict = fileMK.unsortedDictFromWords(s.split(" "))
            s = str(sorted(mDict.keys())).replace("\"", "")
            print(" Found the following words with 2 switched letters:")
            print("", s.replace("[", "").replace("]", "").replace("'", ""))
        else:
            print(" No correction found with 2 switched letters")
Example #5
0
File: tp3.py Project: joelcn/uni
def task3():
    # Task 3
    words = []
    for i in range(len(t)):
        words += t[i].lower().split(" ")
    unsorted_dict = fileMK.unsortedDictFromWords(words)
    try:
        i = int(input(" How many times should the term appear?\n"))
    except ValueError:
        print(" Invalid Value, assuming 51\n")
        i = 51
    times = [key for key, value in unsorted_dict.items() if value == i]
    s = ""
    for j in range(len(times)):
        s += str(times[j]) + "; "
    n = str(len(s.split("; "))-1)
    print(" " + n + " Words found occuring " + str(i) + " time(s)")
    path = outputPath + "task3-" + str(i) + ".txt"
    fileMK.writeTextToFile(s, path)