# Path: analyzer/alignment_utils.py
# class Alignment(object):
# 	old_vertical_index = None
# 	old_horizontal_index = None
# 
# 	def __init__(self, alignment_list, vertical_index, horizontal_index, grid, traceback, subtitles=None):
# 		self.alignment_list = alignment_list
# 		self.vertical_index = vertical_index
# 		self.horizontal_index = horizontal_index
# 		self.grid = grid
# 		self.traceback = traceback
# 		self.subtitles = subtitles
# 
# Path: analyzer/string_utils.py
# def remove_punctuation(text):
# 	exclude = set(string.punctuation)
# 	exclude.add("'")
# 
# 	characters = []
# 	for character in text:
# 		if character not in exclude:
# 			characters.append(character)
# 		else:
# 			characters.append(" ")
# 
# 	cleaned_text = "".join(characters)
# 	var = re.sub(' +', ' ', cleaned_text)
# 
# 	return var


import editdistance
from enum import Enum
from tqdm import tqdm
from copy import deepcopy
from analyzer.alignment_utils import Alignment
from analyzer.string_utils import remove_punctuation
	alignment = []

	i, j = m - 1, n - 1
	alignment.append((i, j))
	new_subtitle_index = []
	new_script_index = []

	while (i != 0) or (j != 0):
		x, y = traceback[i][j]
		alignment.append((x, y))

		s1_char, subtitle = subtitle_index[i - 1]
		s2_char, script = script_index[j - 1]

		if x < i and y < j:  # match
			new_subtitle_index.append((s1_char, subtitle))
			new_script_index.append((s2_char, script))
		elif x < i and y == j:  # up == insert in s2
			new_subtitle_index.append((s1_char, subtitle))
			new_script_index.append(("_", script))
		elif y < j and x == i:  # left == insert in s1
			new_subtitle_index.append(("_", subtitle))
			new_script_index.append((s2_char, script))

		i, j = x, y

	alignment.reverse()
	new_subtitle_index.reverse()
	new_script_index.reverse()


# Path: analyzer/alignment_utils.py
# class Alignment(object):
# 	old_vertical_index = None
# 	old_horizontal_index = None
# 
# 	def __init__(self, alignment_list, vertical_index, horizontal_index, grid, traceback, subtitles=None):
# 		self.alignment_list = alignment_list
# 		self.vertical_index = vertical_index
# 		self.horizontal_index = horizontal_index
# 		self.grid = grid
# 		self.traceback = traceback
# 		self.subtitles = subtitles
# 
# Path: analyzer/string_utils.py
# def remove_punctuation(text):
# 	exclude = set(string.punctuation)
# 	exclude.add("'")
# 
# 	characters = []
# 	for character in text:
# 		if character not in exclude:
# 			characters.append(character)
# 		else:
# 			characters.append(" ")
# 
# 	cleaned_text = "".join(characters)
# 	var = re.sub(' +', ' ', cleaned_text)
# 
# 	return var


# Path: analyzer/needleman_wunsch.py
import editdistance
from enum import Enum
from tqdm import tqdm
from copy import deepcopy
from analyzer.alignment_utils import Alignment
from analyzer.string_utils import remove_punctuation

	alignment = []

	i, j = m - 1, n - 1
	alignment.append((i, j))
	new_subtitle_index = []
	new_script_index = []

	while (i != 0) or (j != 0):
		x, y = traceback[i][j]
		alignment.append((x, y))

		s1_char, subtitle = subtitle_index[i - 1]
		s2_char, script = script_index[j - 1]

		if x < i and y < j:  # match
			new_subtitle_index.append((s1_char, subtitle))
			new_script_index.append((s2_char, script))
		elif x < i and y == j:  # up == insert in s2
			new_subtitle_index.append((s1_char, subtitle))
			new_script_index.append(("_", script))
		elif y < j and x == i:  # left == insert in s1
			new_subtitle_index.append(("_", subtitle))
			new_script_index.append((s2_char, script))

		i, j = x, y

	alignment.reverse()
	new_subtitle_index.reverse()
	new_script_index.reverse()


	a = Alignment(alignment, new_subtitle_index, new_script_index, grid, traceback)