pymorphy2 / pymorphy2 / units /

The default branch has multiple heads

# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals, division

class BaseAnalyzerUnit(object):

    terminal = False

    def __init__(self, morph):
        :type morph: pymorphy2.analyzer.MorphAnalyzer
        :type self.dict: pymorphy2.analyzer.Dictionary
        self.morph = morph
        self.dict = morph.dictionary

    def parse(self, word, seen_parses):
        raise NotImplementedError()

    def tag(self, word, seen_tags):
        raise NotImplementedError()

    def get_lexeme(self, form, methods_stack):
        # be default, analyzer gets a lexeme from a previous analyzer:
        last_method = methods_stack[-1]
        assert last_method[0] is self

        # if len(methods_stack) == 1:
        #     return self.dict.get_lexeme(form, [])

        assert len(methods_stack) > 1, len(methods_stack)
        previous_predictor = methods_stack[-2][0]
        return previous_predictor.get_lexeme(form, methods_stack[:-1])

    def normalized(self, form):
        # default implementation is super-slow!
        methods_stack = form[-1]
        return self.get_lexeme(form, methods_stack)[0]

    def __repr__(self):
        return str("<%s>") % self.__class__.__name__
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.