Example #1
0
    def __init__(self, path=None, lang=None, result_type=Parse, units=None,
                 probability_estimator_cls=auto, char_substitutes=auto):

        # save arguments for pickling/unpickling
        self._path = path
        self._lang = lang

        if path is None and lang is None:
            lang = 'ru'

        path = self.choose_dictionary_path(path, lang)

        with self._lock:
            self.dictionary = opencorpora_dict.Dictionary(path)
            self.lang = self.choose_language(self.dictionary, lang)

            self.prob_estimator = self._get_prob_estimator(
                probability_estimator_cls, self.dictionary, path
            )

            if result_type is not None:
                # create a subclass with the same name,
                # but with _morph attribute bound to self
                res_type = type(
                    result_type.__name__,
                    (result_type,),
                    {'_morph': self, '_dict': self.dictionary}
                )
                self._result_type = res_type
            else:
                self._result_type = None

            self._result_type_orig = result_type
            self._init_char_substitutes(char_substitutes)
            self._init_units(units)
Example #2
0
    def __init__(self,
                 path=None,
                 result_type=Parse,
                 units=None,
                 probability_estimator_cls=SingleTagProbabilityEstimator):
        path = self.choose_dictionary_path(path)
        with threading.RLock():
            self.dictionary = opencorpora_dict.Dictionary(path)
            if probability_estimator_cls is None:
                probability_estimator_cls = DummySingleTagProbabilityEstimator
            self.prob_estimator = probability_estimator_cls(path)

            if result_type is not None:
                # create a subclass with the same name,
                # but with _morph attribute bound to self
                res_type = type(result_type.__name__, (result_type, ), {
                    '_morph': self,
                    '_dict': self.dictionary
                })
                self._result_type = res_type
            else:
                self._result_type = None

            self._result_type_orig = result_type
            self._init_units(units)
Example #3
0
    def __init__(self, path=None, lang='ru', result_type=Parse, units=None,
                 probability_estimator_cls=auto, char_substitutes=auto):

        self._path = path
        self._lang = lang

        self.lang = None if path is None else lang
        path = self.choose_dictionary_path(path, lang)

        with threading.RLock():
            self.dictionary = opencorpora_dict.Dictionary(path)
            if self.lang is None:
                # When path is passed explicitly, set language
                # to dict language.
                self.lang = self.dictionary.lang
            elif self.dictionary.lang != self.lang:
                warnings.warn("Dictionary language (%r) doesn't match "
                  "analyzer language (%r)." % (self.dictionary.lang, self.lang))

            self.prob_estimator = self._get_prob_estimator(
                probability_estimator_cls, self.dictionary, path
            )

            if result_type is not None:
                # create a subclass with the same name,
                # but with _morph attribute bound to self
                res_type = type(
                    result_type.__name__,
                    (result_type,),
                    {'_morph': self, '_dict': self.dictionary}
                )
                self._result_type = res_type
            else:
                self._result_type = None

            self._result_type_orig = result_type
            self._init_char_substitutes(char_substitutes)
            self._init_units(units)
Example #4
0
    def __init__(self, path=None, result_type=Parse, units=None):

        path = self.choose_dictionary_path(path)
        self.dictionary = opencorpora_dict.Dictionary(path)

        if result_type is not None:
            # create a subclass with the same name,
            # but with _morph attribute bound to self
            res_type = type(result_type.__name__, (result_type, ), {
                '_morph': self,
                '_dict': self.dictionary
            })
            self._result_type = res_type
        else:
            self._result_type = None

        self._result_type_orig = result_type

        # initialize units
        if units is None:
            units = self.DEFAULT_UNITS

        self._unit_classes = units
        self._units = [cls(self) for cls in units]