当前位置: 首页>>代码示例>>Python>>正文


Python Util.reverse方法代码示例

本文整理汇总了Python中utils.Util.reverse方法的典型用法代码示例。如果您正苦于以下问题:Python Util.reverse方法的具体用法?Python Util.reverse怎么用?Python Util.reverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.Util的用法示例。


在下文中一共展示了Util.reverse方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_basic_form

# 需要导入模块: from utils import Util [as 别名]
# 或者: from utils.Util import reverse [as 别名]
    def find_basic_form(self, strange_form):
        """
        Method finds basic form for given inflectional form
        :param strange_form: inflectional form of word
        :return: basic form of given word
        """
        similar_words = self.find_similar_words(strange_form)
        how_many_forms = dict()
        word_labels = dict()
        for word in similar_words:
            form = self.atergo_trie[word]
            if form[0] in how_many_forms:
                how_many_forms[form[0]] += 1
            else:
                how_many_forms[form[0]] = 1
            if not form[0] in word_labels:
                word_labels[form[0]] = []
            word_labels[form[0]].append(Util.reverse(word))
        max_form = max(how_many_forms.iteritems(), key=operator.itemgetter(1))[0]

        max_form0 = max_form[0].split('\x00')[0].decode('utf-8')
        max_form1 = max_form[1].split('\x00')[0].decode('utf-8')
        result = collections.namedtuple('result', ['basic_form', 'word_labels'])
        result.basic_form = strange_form[:len(strange_form) - len(max_form0)] + max_form1
        result.word_labels = word_labels[max_form]
        return result
开发者ID:mslawin,项目名称:Magisterka,代码行数:28,代码来源:stemmer.py

示例2: prepare

# 需要导入模块: from utils import Util [as 别名]
# 或者: from utils.Util import reverse [as 别名]
    def prepare(self, word_type):
        """
        Generates trie structure containing all words from clp
        :param word_type: part of speech of which kind read words from clp data
        :return: None
        """
        old = ""
        index = 0
        keys = []
        values = []
        for i in range(16777231, 18663982):
            if Util.is_word_unneeded(i):
                continue
            if Util.is_word_appropriate_type(self.plp.label(i)[0], word_type):
                continue
            form = self.plp.bform(i)

            if old != form:
                for s in self.plp.forms(i):
                    if len(s) > 0:
                        a = Util.substring(s, form)
                        to_remove = s[len(a): len(s)]
                        to_add = form[len(a): len(form)]
                        keys.append(Util.reverse(s))
                        a = unicode(to_remove).encode('utf-8')
                        b = unicode(to_add).encode('utf-8')
                        values.append((a, b))
                index += 1

            old = self.plp.bform(i)
        return zip(keys, values)
开发者ID:mslawin,项目名称:Magisterka,代码行数:33,代码来源:stemmer.py

示例3: find_similar_words

# 需要导入模块: from utils import Util [as 别名]
# 或者: from utils.Util import reverse [as 别名]
 def find_similar_words(self, strange_form):
     """
     Method finds words in trie structure which has longest coomon part with given word
     :param strange_form: inflectional form of given word
     :return: list of words which has longest common part of given word
     """
     reversed_strange_form = Util.reverse(strange_form)
     index = 0
     while index < len(strange_form) and \
             self.atergo_trie.has_keys_with_prefix(unicode(reversed_strange_form[:index])):
         index += 1
     return self.atergo_trie.keys(unicode(reversed_strange_form[:index - 1]))
开发者ID:mslawin,项目名称:Magisterka,代码行数:14,代码来源:stemmer.py


注:本文中的utils.Util.reverse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。