from IPython import get_ipython ipython = get_ipython() ipython.magic('load_ext autoreload') ipython.magic('autoreload 2') config = confuse.Configuration('course_project') ONTO_BASE = '../ontologies/' CORRECT_INSTANCES_BASE = '../instances/' CORRECT_INSTANCES = correct_instances.parse_instances_from_txt( CORRECT_INSTANCES_BASE + config['correct_instances'].get()) # %% text_to_parse = input_reader.read(config) print(text_to_parse[:500]) # %% sentences = nlp.tokenize_text(text_to_parse) words_amount = sum([len(sent) for sent in sentences]) print(f'Кол-во предложений: {str(len(sentences))}') print(f'Кол-во слов: {str(words_amount)}') # %% morph = pymorphy2.MorphAnalyzer() sentences = [[morph.parse(word)[0].normal_form for word in sent]
from input_reader import read import datetime data = read(__file__) test_data = read(__file__, name='test') def parse_data(input_data): output_list = list() for idx, line in enumerate(input_data): parsed_line = line.rstrip().replace('#', '').split(' ') time_date = ' '.join(parsed_line[0:2])[1:-1] time_stamp = datetime.datetime.fromisoformat(time_date) output_list.append([time_stamp.timestamp(), time_stamp.minute, parsed_line[3]]) return output_list def sort_list(input_data): sorted_list = sorted(input_data, key=lambda x: x[0]) # TODO wrong direction return [x[1:] for x in sorted_list] def task_one(input_data): sleep = [None, None] sorted_data = sort_list(parse_data(input_data)) big_dict = dict() dict_key = '' for entry in sorted_data: minute = entry[0] value = entry[1] if value.isdigit() and dict_key == '':
from input_reader import read data = read(__file__) def task_one(input_data): return sum([int(x) for x in input_data]) def task_two(input_data): current_freq = 0 seen_set = set() while True: for row in input_data: current_freq += int(row) if current_freq not in seen_set: seen_set.add(current_freq) else: return current_freq print('Task one: ', task_one(data)) print('Task two: ', task_two(data))