Ejemplo n.º 1
0
 def receive(self, signal, page):
     word = page.title
     if signal == 'page_deleted':
         pass  # print '@ inflection removed'
         WordInflection.objects.filter(word=word).delete()
     elif signal == 'page_content_changed':
         pass  # print '@ inflection changes check'
         old_items = WordInflection.objects.filter(word=word)
         old_tpls = [item.content for item in old_items]
         morph = u'сущ'
         lang = u'ru'
         parts = get_inflection_templates(page.content,
                                          morph, lang)
         new_tpls = [part['tpl'] for part in parts]
         if len(old_tpls) == len(new_tpls) and set(old_tpls) == set(new_tpls):
             pass  # print 'same'
         else:
             pass  # print 'different'
             WordInflection.objects.filter(word=word).delete()
             for part in parts:
                 template_title = part['title'].strip()
                 kind, gender, num = parse_template_title(template_title)
                 WordInflection.objects.bulk_add(
                     WordInflection(word=word, template=template_title,
                                    content=part['tpl'],
                                    gender=gender, kind=kind, num=num)
                 )
             WordInflection.objects.bulk_add()
             pass  # print '@@ inflection really changed', '+' * 40
             print '           @ inflection changed'
Ejemplo n.º 2
0
    def change_content_action(self, page, content, **kwargs):
        # print self.i
        self.save_step()
        title = page.title
        if u':' in title:
            return content
        new_content = content
        # morph = u'прил'
        morph = u'гл'
        lang = u'uk'
        parts = get_inflection_templates(content, morph, lang)

        if parts:
            # print title
            for part in parts:
                ok = False
                new_tpl = old_tpl = part['tpl']
                # print old_tpl
                if u'|слоги={{' not in old_tpl:
                    # if u'{{' in old_tpl[3:-3]:
                    #     print title
                    #     print old_tpl
                    # print title
                    # print old_tpl
                    # print
                    m = re.search(u'\|слоги=([^|}\s]*)', old_tpl)
                    if m:
                        value = m.group(1)
                        check_value = value.replace(u'́', u'').replace(u'-', u'')
                        if title.replace(u'-', u'') != check_value:
                            # print title, value
                            raise Exception()
                        else:
                            new_tpl = new_tpl.replace(
                                u'|слоги=%s' % value,
                                u'|слоги={{по-слогам|%s}}' % value
                            )
                            ok = True
                            # print title, value
                            # print title
                            # print old_tpl
                            # print new_tpl
                            # print u'---'
                if u'|соотв=' not in new_tpl:
                    new_tpl = new_tpl.replace(u'|show-text=1', u'|соотв=')
                if old_tpl != new_tpl: # and ok:
                    new_content = new_content.replace(old_tpl, new_tpl)
                    # print title
                #     print title
                #     print old_tpl
                #     print new_tpl
                #     print
            # print
        # return content
        if new_content != content:
            new_content = default_wikifier(new_content)
        return new_content
Ejemplo n.º 3
0
 def change_content_action(self, page, content, **kwargs):
     if u':' in page.title:
         return content
     morph = u'сущ|гл|прил|conj|Фам|прич|adv|interj'
     lang = u'ru'
     parts = get_inflection_templates(content, morph, lang)
     if not parts:
         return content
     new_content = content
     for part in parts:
         new_tpl = old_tpl = part['tpl']
         if u'show-text' in new_tpl:
             new_tpl = re.sub(u'\| *show-text *= *1\n?', u'', new_tpl)
             new_content = new_content.replace(old_tpl, new_tpl)
     return new_content