diff options
| author | akiyamn | 2021-03-24 19:59:16 +1100 |
|---|---|---|
| committer | akiyamn | 2021-03-24 19:59:16 +1100 |
| commit | 5a14cf3b85939838369123aca555bb9f9d9f80b1 (patch) | |
| tree | 5f0810fe607799c26154c691e838285587d69a17 /ass1 | |
| parent | 8383d43a76d3d6b9eb47500f1920ddd08fff4df3 (diff) | |
| download | fit3155-5a14cf3b85939838369123aca555bb9f9d9f80b1.tar.gz fit3155-5a14cf3b85939838369123aca555bb9f9d9f80b1.zip | |
Fixed output of edit distance program
Diffstat (limited to 'ass1')
| -rw-r--r-- | ass1/editdist.py | 27 | ||||
| -rw-r--r-- | ass1/output_editdist.txt | 4 |
2 files changed, 17 insertions, 14 deletions
diff --git a/ass1/editdist.py b/ass1/editdist.py index c00fb69..44e9efd 100644 --- a/ass1/editdist.py +++ b/ass1/editdist.py @@ -1,7 +1,5 @@ import sys -OUTPUT_PATH = "output_editdist.txt" - def compare(string, i, end): for j in range(end): if i+j == end or string[i+j] != string[j]: @@ -38,11 +36,6 @@ def gusfield(string): def reverse(string): return string[::-1] - # new = " " * len(string) - # for i in range(len(new)): - # new[i] = string[-i] - - # return [string[c] for c in range(len(string)-1, -1, -1)] def comapre_zs(z_prefix, z_suffix, pat_length): @@ -83,13 +76,18 @@ def match(z_prefix, z_suffix, pat_length): def edit_distance(txt, pat): forwards = pat + "$" + txt backwards = reverse(pat) + "$" + reverse(txt) - print(list(forwards)) - print(list(backwards)) - print(gusfield(forwards)) - print(gusfield(backwards)) - print("="*15) - # comapre_zs(gusfield(forwards), gusfield(backwards), len(pat)) - print(match(gusfield(forwards), gusfield(backwards), len(pat))) + tuples = match(gusfield(forwards), gusfield(backwards), len(pat)) + print(f"Found {len(tuples)} matches of edit distance <= 1.") + output(tuples) + print("Done.") + + +def output(tuples): + OUTPUT_PATH = "output_editdist.txt" + with open(OUTPUT_PATH, "w") as file: + for pair in tuples: + file.write(f"{pair[0]} {pair[1]}\n") + def read_args(): with open(sys.argv[1], "r") as txt_file: @@ -98,6 +96,7 @@ def read_args(): pat = pat_file.read() return txt, pat + def main(): if len(sys.argv) < 3: print("Not enough arguments!") diff --git a/ass1/output_editdist.txt b/ass1/output_editdist.txt index e69de29..4075252 100644 --- a/ass1/output_editdist.txt +++ b/ass1/output_editdist.txt @@ -0,0 +1,4 @@ +0 1 +6 0 +11 1 +15 1 |
