def test_lemma_graminfo(self): info = morph_ru.get_graminfo(u'СУСЛИКАМИ') self.assertEqual(len(info), 1) info = info[0] gram_form = GramForm(info['info']) self.assertEqual(gram_form.form, set([u'мр', u'тв', u'мн'])) self.assertEqual(info['norm'], u'СУСЛИК')
def assertHasInfo(self, word, norm=None, cls=None, method=None, scan=False, form=None, standard=False, has_info=True): def is_correct(frm): correct = True if norm: correct = frm['norm'] == norm if method: correct = correct and (method in frm['method']) if cls: correct = correct and (frm['class'] == cls) if form: gram_filter = GramForm(form) gram_form = GramForm(frm['info']) correct = correct and gram_form.match(gram_filter) return correct if scan: forms = get_graminfo_scan(morph_ru, word, standard=standard) else: forms = morph_ru.get_graminfo(word, standard=standard) self.assertEqual(any([is_correct(frm) for frm in forms]), has_info)
def main(): # print _gram_info_match('[imper,1p,pl]', '1p,pl,imper') # exit() all = 0 failed1 = 0 failed2 = 0 failed_words = {} for test_data in BASIC_TESTS: collection = parse_test_data(test_data) for word in collection: expected_results = collection[word] actual_results = morph_ru.get_graminfo(word, standard=True) actual_results_aot = morph_ru.get_graminfo(word) # проверяем, что все стандартные варианты разбора учтены for expected_form in expected_results: match = any([forms_match(expected_form, actual_form) for actual_form in actual_results]) if not match: failed1 += 1 print (' ----', word, expected_form['class'], expected_form['norm'], expected_form['info']) for actual_form in actual_results: print (" \____ %s %s %s %s" % (word, actual_form['class'], actual_form['norm'], actual_form['info'])) all += 1 # проверяем, нет ли у нас лишних (неправильных) вариантов разбора for actual_form, actual_form_aot in zip(actual_results, actual_results_aot): # для каждого варианта разбора смотрим, соответствует ли ему # хотя бы 1 разбор в стандарте match = any([forms_match(expected_form, actual_form) for expected_form in expected_results]) if not match: print (" ++++ %s %s %s %s" % (word, actual_form['class'], actual_form['norm'], actual_form['info'])) failed2 += 1 # else: # for expected_form in expected_results: # if forms_match(expected_form, actual_form): # print(_format_row(word, expected_form, actual_form_aot)) print (' total: %d, failed: %d, extra: %d' % (all, failed1, failed2))
if __name__ == '__main__': # print _gram_info_match(u'[imper,1p,pl]', u'1p,pl,imper') # exit() all = 0 failed1 = 0 failed2 = 0 failed_words = {} for test_data in BASIC_TESTS: collection = parse_test_data(test_data) for word in collection: expected_results = collection[word] actual_results = morph_ru.get_graminfo(word, True) # проверяем, что все стандартные варианты разбора учтены for expected_form in expected_results: match = any([forms_match(expected_form, actual_form) for actual_form in actual_results]) if not match: failed1 += 1 print ' ----', word, expected_form['class'], expected_form['norm'], expected_form['info'] for actual_form in actual_results: print u" \____ %s %s %s %s" % (word, actual_form['class'], actual_form['norm'], actual_form['info']) all += 1 # проверяем, нет ли у нас лишних (неправильных) вариантов разбора for actual_form in actual_results: # для каждого варианта разбора смотрим, соответствует ли ему # хотя бы 1 разбор в стандарте