# 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
		else:
			d = editdistance.eval(s1_chars, s2_chars)
			required_matches = len(s1_chars) / 2.0
			matches_in_percent = 0

		match = d <= required_matches

		logger.add("{}. {}Match".format(index, "" if match else "No "))
		logger.add("'{}' has lev-dist {} ({:.1f}%).".format(current_subtitle.text, d, matches_in_percent))
		logger.add("'{}'\n'{}'\n\nactual match:\n'{}'\n'{}'".format(s1_chars, s2_chars, fs1_chars, fs2_chars))
		logger.add("\n\n")

		if match:
			script = s2_matches[0][1]
			current_subtitle.character = script.character

		current_subtitle = subtitle
		index += 1
		s1_index = i

	if logger.verbose:
		subtitles_length = len(subtitles)
		merged_subtitles_count = len([subtitle for subtitle in subtitles if subtitle.character is not None])
		success_rate = merged_subtitles_count / subtitles_length * 100
		logger.add("Success Rate: {} of {} ~ {:.1f}%".format(merged_subtitles_count, subtitles_length, success_rate))

	return alignment


def prepare_text(text):

# 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

		else:
			d = editdistance.eval(s1_chars, s2_chars)
			required_matches = len(s1_chars) / 2.0
			matches_in_percent = 0

		match = d <= required_matches

		logger.add("{}. {}Match".format(index, "" if match else "No "))
		logger.add("'{}' has lev-dist {} ({:.1f}%).".format(current_subtitle.text, d, matches_in_percent))
		logger.add("'{}'\n'{}'\n\nactual match:\n'{}'\n'{}'".format(s1_chars, s2_chars, fs1_chars, fs2_chars))
		logger.add("\n\n")

		if match:
			script = s2_matches[0][1]
			current_subtitle.character = script.character

		current_subtitle = subtitle
		index += 1
		s1_index = i

	if logger.verbose:
		subtitles_length = len(subtitles)
		merged_subtitles_count = len([subtitle for subtitle in subtitles if subtitle.character is not None])
		success_rate = merged_subtitles_count / subtitles_length * 100
		logger.add("Success Rate: {} of {} ~ {:.1f}%".format(merged_subtitles_count, subtitles_length, success_rate))

	return alignment


def prepare_text(text):

	t = remove_punctuation(text)