diff --git a/TaskC05/elem.in b/TaskC05/elem.in index 6280a49..e4ce4e4 100644 --- a/TaskC05/elem.in +++ b/TaskC05/elem.in @@ -1 +1,2 @@ dom +biały diff --git a/TaskC05/elem.out b/TaskC05/elem.out new file mode 100644 index 0000000..05c264a --- /dev/null +++ b/TaskC05/elem.out @@ -0,0 +1,2 @@ +dom;N +biały;ADJ diff --git a/TaskC05/medium.out b/TaskC05/medium.out new file mode 100644 index 0000000..02bb455 --- /dev/null +++ b/TaskC05/medium.out @@ -0,0 +1,7 @@ +arbuz;N +arbuza;N +arbuzowi;ADJ +arbuzowi;N +azylant;N +azylanci;N +azylantowie;OOV diff --git a/TaskC05/multi.out b/TaskC05/multi.out new file mode 100644 index 0000000..9179d8e --- /dev/null +++ b/TaskC05/multi.out @@ -0,0 +1,2 @@ +piła;N +piła;V diff --git a/TaskC05/oov.out b/TaskC05/oov.out new file mode 100644 index 0000000..f13b79a --- /dev/null +++ b/TaskC05/oov.out @@ -0,0 +1 @@ +budynek;OOV diff --git a/TaskC05/run.py b/TaskC05/run.py index ad82a36..a820876 100644 --- a/TaskC05/run.py +++ b/TaskC05/run.py @@ -1,66 +1,86 @@ import sys -sys.setrecursionlimit(5000) -def write_answer(answer): - with open(output_file, 'a') as file: - file.write(answer+'\n') - -# def remove_first_symbol_from_the_list(): +def write_answer(row, answer): + with open(output_file, 'a', encoding='utf-8') as file: + file.write(row.strip()+';'+answer+'\n') def line_checking(row, position): - help_row = row - help_position = position - next_character_array =[] - bool_value = False - for element in row: - if element=='\n': - if position in what_is_the_ended_positions(): - return True - else: - return False - next_character_array = find_next_position(help_position, element) - if next_character_array != []: - if len(next_character_array)>1: - for element_in_next_character_array in next_character_array: - if bool_value ==True: - break - else: - bool_value =line_checking(help_row[1:], element_in_next_character_array) - else: - # remove_first_symbol_from_the_list() - help_row = help_row[1:] - bool_value = line_checking(help_row, next_character_array[0]) - else: - break - return bool_value + stack = [(row, position)] + help_row, help_position=row,position + while stack: + help_row, help_position = stack.pop() + if help_row == '': + help_row = '\n' + next_character_array = find_next_position(help_position, help_row[0]) + if next_character_array: + for element_in_next_position_array in next_character_array: + stack.append((help_row[1:], element_in_next_position_array)) + if help_row == '\n': + next_character_array = find_next_position(help_position, ';') + if next_character_array: + help_position_array, character_array = find_character_after_semicolon(next_character_array[0]) + character_array = sorted(character_array) + help_position_array = sorted(help_position_array) + for i in range(len(character_array)): + ended_answer = find_position_to_print_the_answer(help_position_array[i], character_array[i]) + write_answer(row,ended_answer) + else: + write_answer(row, 'OOV') + # return False +def find_position_to_print_the_answer(position, character): + with open(used_table, 'r', encoding='utf-8') as readed_used_table: + last_pos = position + word = character + # if last_pos == what_is_the_ended_positions(): + # return word + for row_used_table in readed_used_table: + line = row_used_table.strip().split('\t') + if len(line) != 1: + if last_pos == line[0]: + word+=line[2] + last_pos = line[1] + return word +def find_character_after_semicolon(position): + with open(used_table, 'r', encoding='utf-8') as readed_used_table: + last_position = [] + take_all_possible_characters = [] + for row_used_table in readed_used_table: + line = row_used_table.strip().split('\t') + if len(line) != 1: + if position == line[0]: + take_all_possible_characters.append(line[2]) + last_position.append((line[1])) + return last_position,take_all_possible_characters def find_next_position(position, character): - with open(used_table, 'r') as readed_used_table: + with open(used_table, 'r', encoding='utf-8') as readed_used_table: take_all_possible_positions = [] for row_used_table in readed_used_table: - line = row_used_table.strip().split(' ') + line = row_used_table.strip().split('\t') if len(line) != 1: + if position == line[0] and character == line[2]: take_all_possible_positions.append(line[1]) - return take_all_possible_positions + def what_is_the_ended_positions(): array = [] with open(used_table, 'r') as file: for row in file: line = row.strip().split('\t') - if len(line)==1: + if len(line) == 1: array += line return array -used_table = 'test.arg' -input_file = 'test.in' -output_file = 'test.out' -# what_is_the_ended_positions() -with open(output_file, 'w') as readed_output_file: - with open(input_file, 'r') as readed_input_file: + +used_table = 'multi.arg' +input_file = 'multi.in' +output_file = 'multi.out' +# used_table = sys.argv[1] +# input_file = sys.argv[2] +# output_file = sys.argv[3] +with open(output_file, 'w', encoding='utf-8') as readed_output_file: + with open(input_file, 'r', encoding='utf-8') as readed_input_file: for row_input_file in readed_input_file: - if line_checking(row_input_file, '0')==True: - write_answer('YES') - else: - write_answer('NO') + line_checking(row_input_file, '0') +