Ended TaskC05
This commit is contained in:
parent
bb0d611890
commit
96e7136c5e
@ -1 +1,2 @@
|
|||||||
dom
|
dom
|
||||||
|
biały
|
||||||
|
2
TaskC05/elem.out
Normal file
2
TaskC05/elem.out
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
dom;N
|
||||||
|
biały;ADJ
|
7
TaskC05/medium.out
Normal file
7
TaskC05/medium.out
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
arbuz;N
|
||||||
|
arbuza;N
|
||||||
|
arbuzowi;ADJ
|
||||||
|
arbuzowi;N
|
||||||
|
azylant;N
|
||||||
|
azylanci;N
|
||||||
|
azylantowie;OOV
|
2
TaskC05/multi.out
Normal file
2
TaskC05/multi.out
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
piła;N
|
||||||
|
piła;V
|
1
TaskC05/oov.out
Normal file
1
TaskC05/oov.out
Normal file
@ -0,0 +1 @@
|
|||||||
|
budynek;OOV
|
110
TaskC05/run.py
110
TaskC05/run.py
@ -1,66 +1,86 @@
|
|||||||
import sys
|
import sys
|
||||||
sys.setrecursionlimit(5000)
|
|
||||||
|
|
||||||
def write_answer(answer):
|
def write_answer(row, answer):
|
||||||
with open(output_file, 'a') as file:
|
with open(output_file, 'a', encoding='utf-8') as file:
|
||||||
file.write(answer+'\n')
|
file.write(row.strip()+';'+answer+'\n')
|
||||||
|
|
||||||
# def remove_first_symbol_from_the_list():
|
|
||||||
|
|
||||||
def line_checking(row, position):
|
def line_checking(row, position):
|
||||||
help_row = row
|
stack = [(row, position)]
|
||||||
help_position = position
|
help_row, help_position=row,position
|
||||||
next_character_array =[]
|
while stack:
|
||||||
bool_value = False
|
help_row, help_position = stack.pop()
|
||||||
for element in row:
|
if help_row == '':
|
||||||
if element=='\n':
|
help_row = '\n'
|
||||||
if position in what_is_the_ended_positions():
|
next_character_array = find_next_position(help_position, help_row[0])
|
||||||
return True
|
if next_character_array:
|
||||||
else:
|
for element_in_next_position_array in next_character_array:
|
||||||
return False
|
stack.append((help_row[1:], element_in_next_position_array))
|
||||||
next_character_array = find_next_position(help_position, element)
|
if help_row == '\n':
|
||||||
if next_character_array != []:
|
next_character_array = find_next_position(help_position, ';')
|
||||||
if len(next_character_array)>1:
|
if next_character_array:
|
||||||
for element_in_next_character_array in next_character_array:
|
help_position_array, character_array = find_character_after_semicolon(next_character_array[0])
|
||||||
if bool_value ==True:
|
character_array = sorted(character_array)
|
||||||
break
|
help_position_array = sorted(help_position_array)
|
||||||
else:
|
for i in range(len(character_array)):
|
||||||
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
|
|
||||||
|
|
||||||
|
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):
|
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 = []
|
take_all_possible_positions = []
|
||||||
for row_used_table in readed_used_table:
|
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 len(line) != 1:
|
||||||
|
|
||||||
if position == line[0] and character == line[2]:
|
if position == line[0] and character == line[2]:
|
||||||
take_all_possible_positions.append(line[1])
|
take_all_possible_positions.append(line[1])
|
||||||
|
|
||||||
return take_all_possible_positions
|
return take_all_possible_positions
|
||||||
|
|
||||||
def what_is_the_ended_positions():
|
def what_is_the_ended_positions():
|
||||||
array = []
|
array = []
|
||||||
with open(used_table, 'r') as file:
|
with open(used_table, 'r') as file:
|
||||||
for row in file:
|
for row in file:
|
||||||
line = row.strip().split('\t')
|
line = row.strip().split('\t')
|
||||||
if len(line)==1:
|
if len(line) == 1:
|
||||||
array += line
|
array += line
|
||||||
return array
|
return array
|
||||||
used_table = 'test.arg'
|
|
||||||
input_file = 'test.in'
|
used_table = 'multi.arg'
|
||||||
output_file = 'test.out'
|
input_file = 'multi.in'
|
||||||
# what_is_the_ended_positions()
|
output_file = 'multi.out'
|
||||||
with open(output_file, 'w') as readed_output_file:
|
# used_table = sys.argv[1]
|
||||||
with open(input_file, 'r') as readed_input_file:
|
# 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:
|
for row_input_file in readed_input_file:
|
||||||
if line_checking(row_input_file, '0')==True:
|
line_checking(row_input_file, '0')
|
||||||
write_answer('YES')
|
|
||||||
else:
|
|
||||||
write_answer('NO')
|
|
||||||
|
Loading…
Reference in New Issue
Block a user