aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ass1/editdist.py27
-rw-r--r--ass1/output_editdist.txt4
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