Skip to content
Snippets Groups Projects
Commit 04fa3bfd authored by Verbeek, J.M. (Janneke)'s avatar Verbeek, J.M. (Janneke) :speech_balloon:
Browse files

It works, so I'll put in the merge request. Intended to make prints...

It works, so I'll put in the merge request. Intended to make prints disable-able, but too much effort right now. Will try later
parent 902ff0ba
No related branches found
No related tags found
1 merge request!61Sc 145/multisource
......@@ -117,14 +117,10 @@ class Controller:
else:
self._view.update_message('files ok')
self._view.button_status("save", "normal")
if len(self._shadow_files) > 1:
self._read_folder("shadow")
else:
self._read_files(self._shadow_files[0], "shadow") # TODO: Path is temp fix
if len(self._source_files) > 1:
self._read_folder("source")
else:
self._read_files(self._source_files[0], "source")
self._read_folder("shadow")
self._read_folder("source")
self._model.compare()
if self._model.analysis_complete:
self._view.update_message('comparison complete')
......@@ -137,14 +133,8 @@ class Controller:
if not self._model.analysis_complete():
self._view.update_message('no comparison')
else:
if self._model.analysis_results:
print(self._model.analysis_results)
path = self._view.ask_save_location()
results = self._model.analysis_results
self._filewriter.write(path, results)
self._view.update_message('saved')
elif self._model.multi_results:
print(self._model.multi_results)
if self._model.multi_results:
path = self._view.ask_save_location()
results = self._model.multi_results
self._filewriter.write_multiple(path, results)
......@@ -153,19 +143,20 @@ class Controller:
and not self._model.analysis_results:
self._view.update_message('nonexistent')
"""
def _read_files(self, path, type):
Read data from file paths and save to model.
def _read_files(self, path, type):
"""Read data from file paths and save to model.
Args:
type (str): Role of file ('source' or 'shadow')
Args:
type (str): Role of file ('source' or 'shadow')
"""
data = self._filereader.read(path, type)
if type == "source":
self._model.data_source = data
self._model.id = ut.id_regex(path)
else:
self._model.data_shadow = data
data = self._filereader.read(path, type)
if type == "source":
self._model.data_source = data
self._model.id = ut.id_regex(path)
else:
self._model.data_shadow = data
"""
def _read_folder(self, type):
"""
......
......@@ -110,10 +110,12 @@ class Model:
def analysis_complete(self):
"""Check whether self._analysis_results has a value."""
print(self.analysis_results, self.multi_results)
return self._analysis_results or self._multi_results
def get_multi_data(self, type):
"""
Get data according to type
"""
if type == "source":
return self._multi_data_source
else:
......@@ -133,10 +135,8 @@ class Model:
for key, source in self._multi_data_source.items():
for key2, shadow in self._multi_data_shadow.items():
if key == ut.filter_key(key2):
print([str(s) for s in source])
print([str(s) for s in shadow])
result = self._stats.analyze(source, shadow)
ut.add_to_dict(key+"_res",
result, self._multi_results)
......
......@@ -41,35 +41,36 @@ class Statistics:
source: the words in the source file
shadow: the words in the shadow file
"""
# Make a deepcopy such that the testing is equal for both strategies:
source_em = copy.deepcopy(source)
shadow_em = copy.deepcopy(shadow)
# Alignment 0
print('Needleman-Wunsch')
results = 'Needleman-Wunsch\n'
discrete_start_time = time.time()
self._strategy = NeedlemanWunsch(self._seman_checker)
source_align, shadow_align = self._strategy.align(source, shadow)
for s_word in shadow_align:
for s_word in shadow_align:
if s_word.has_source():
print(f'source: {s_word.source} shadow: {s_word}')
results += f'source: {s_word.source} shadow: {s_word}\n'
correctness = self._strategy.correctly_shadowed(source)
discrete_time = time.time() - discrete_start_time
print(f'taken time:{discrete_time}')
results += f'taken time:{discrete_time}\n'
self._mistake_finder.start(source_align, shadow_align)
# Alignment 2
print('\nAnchor algorithm')
results += '\nAnchor algorithm\n'
discrete_start_time = time.time()
self._strategy = AnchorAlgorithm()
source_align_em, shadow_align_em = self._strategy.align(source_em,
shadow_em)
for s_word in shadow_align_em:
if s_word.has_source():
print(f'source: {s_word.source} shadow: {s_word}')
results += f'source: {s_word.source} shadow: {s_word}\n'
correctness = self._strategy.correctly_shadowed(source_em)
self._mistake_finder.start(source_align_em, shadow_align_em)
discrete_time = time.time() - discrete_start_time
print(f'taken time:{discrete_time}')
results += f'taken time:{discrete_time}\n'
return source_align_em, shadow_align_em, correctness
......@@ -42,6 +42,15 @@ class View:
# Message
self._create_label('message', self._frame, "", 5, 1)
self._spit = False
@property
def spit(self):
return self._spit
@spit.setter
def spit(self, boolean):
self._spit = boolean
def display(self):
"""Start main loop, displaying GUI elements."""
......@@ -200,8 +209,6 @@ class View:
frame,
'Delete all {} files'.format(type),
8, column)
self._create_button('select_folder {}'.format(type), frame,
'Select {} folder'.format(type),
6, column)
......@@ -280,6 +287,9 @@ class View:
button.bind('<Button>', action_function)
def dir_dialog(self):
"""
Do file dialog.
"""
return fd.askdirectory()
@property
......@@ -291,6 +301,9 @@ class View:
self._actionlistener = value
def selected(self, type):
"""
Return selected files.
"""
selected = self._elements['file {}'.format(type)].get()
if selected == "No file selected" or not selected:
return None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment