def show_dict_mem_usage(dict_path=None, verbose=False): """ Show dictionary memory usage. """ initial_mem = get_mem_usage() initial_time = time.time() morph = morpho_analyzer.MorphAnalyzer(dict_path) end_time = time.time() mem_usage = get_mem_usage() logger.info( 'Memory usage: %0.1fM dictionary, %0.1fM total (load time %0.2fs)', (mem_usage - initial_mem) / (1024 * 1024), mem_usage / (1024 * 1024), end_time - initial_time) if verbose: try: from guppy import hpy hp = hpy() logger.debug(hp.heap()) except ImportError: logger.warn( 'guppy is not installed, detailed info is not available')
def _parse(dict_path, in_filename, out_filename): morph = morpho_analyzer.MorphAnalyzer(dict_path) with codecs.open(in_filename, 'r', 'utf8') as in_file: with codecs.open(out_filename, 'w', 'utf8') as out_file: for line in in_file: word = line.strip() parses = morph.parse(word) parse_str = "|".join([p[1] for p in parses]) out_file.write(word + ": " + parse_str + "\n")
def test_plain_tuples(self): morph_plain = morpho_analyzer.MorphAnalyzer(result_type=None) self.assertAllTuples(morph_plain.parse('кот')) self.assertAllTuples(morph_plain.inflect('кот', set(['plur']))) self.assertAllTuples(morph_plain.decline('кот'))
def show_dict_meta(dict_path=None): morph = morpho_analyzer.MorphAnalyzer(dict_path) for key, value in morph.dict_meta.items(): logger.info("%s: %s", key, value)
# -*- coding: utf-8 -*- from __future__ import absolute_import import morpho_analyzer morph = morpho_analyzer.MorphAnalyzer()