Esempio n. 1
0
def default_wikifier(content):
    content, changed = wikify_headers_spaces(content)
    content = wikify_empty_lists(content)
    content = wikify_line_before_header(content)
    content = wikify_frazeologismy_header(content)
    content = several_empty_lines(content)
    content = remove_square_brackets(content)
    content = content.replace(u"{{помета?|", u"{{помета.|")
    content = content.replace(u"|uk}}  {{пример|}}", u"|uk}} {{пример|}}")
    content = word_length_fix(content)
    return content
Esempio n. 2
0
 def lang_action(self, page, lang, content):
     content = page.content
     p = re.compile('\[\[[a-z]{2}:\]\]\n?')
     if p.search(content):
         print page.title
         content = get_wiki_page_content(page.title)
         new_content = p.sub('', content)
         if new_content != content:
             new_content, changed = wikify_headers_spaces(new_content)
             desc = u'Удаление пустышек interwiki'
             save_wiki_page(page.title, new_content, desc, wait=5)
             # self.stop()
     return content
Esempio n. 3
0
 def lang_action(self, page, lang, content):
     content = page.content
     if u'{{DEFAULTSORT:' in content:
         print page.title
         content = get_wiki_page_content(page.title)
         new_content = re.sub(u'^\{\{DEFAULTSORT:\w+\}\}\n', '', content,
                              flags=re.UNICODE)
         if new_content != content:
             new_content, changed = wikify_headers_spaces(new_content)
             desc = u'Удаление {{DEFAULTSORT}}'
             # save_wiki_page(page.title, new_content, desc, wait=5)
             # self.stop()
     return content
Esempio n. 4
0
 def lang_action(self, page, lang, content):
     content = page.content
     if u'{{Cf|Индекс:Русский язык/Женские имена}}' in content:
         print page.title
         content = get_wiki_page_content(page.title)
         new_content = content.replace(
             u'==== Значение ====\nЖенское имя\n{{Cf|Индекс:Русский язык/Женские имена}}',
             u'==== Значение ====\n# Женское имя {{пример|}}')
         if new_content != content:
             new_content, changed = wikify_headers_spaces(new_content)
             desc = u'Удаление {{Cf|Индекс:Русский язык/Женские имена}} из раздела "Значение"'
             save_wiki_page(page.title, new_content, desc, wait=5)
             # self.stop()
     return content
Esempio n. 5
0
 def lang_action(self, page, lang, content):
     content = page.content
     p = re.compile('\[\[(?:\w{2,3}|zh-min-nan):(?:[^]]+)\]\]')
     parts = p.findall(content)
     for part in parts:
         if p.search(content):
             print page.title
             content = get_wiki_page_content(page.title)
             new_content = p.sub('', content)
             if new_content != content:
                 new_content, changed = wikify_headers_spaces(new_content)
                 desc = u'Удаление пустышек interwiki'
                 save_wiki_page(page.title, new_content, desc, wait=5)
                 # self.stop()
     return content
Esempio n. 6
0
 def lang_action(self, page, lang, content):
     if lang != 'ru':
         return content
     parts = re.findall(u'=== ?Морфологические и синтаксические свойства ?===\n(.*?)\n===',
                        content, flags=re.DOTALL)
     if parts:
         for part in parts:
             part = part.strip()
             if not re.search(u'Наречие', part):
                 continue
             # m = re.match(u"(?P<slogi>('''|<b>)([^'<]+)('''|</b>)\n\n)Наречие(, неизменяемое)?\.?(?P<sravn>( Сравнительная степень ?[-—:]|, сравн. форма) '''?[^']+'''?\.?)(?P<other>.*)", part)
             m = re.match(u"^(?P<slogi>('''|<b>)(?P<word>[^'<]*)('''|</b>)\s*\n\n)?Наречие(?P<or>(, (?P<or1>(вводн(ое|\.)|союзное) слово|союз|частица|предлог|числительное|предикатив))? или (?P<or2>(вводн(ое|\.)|союзное) слово|союз|частица|предлог|числительное|предикатив)|)([,;] неи[из]меняемое)?\.?(?P<sravn>( Ср(\.|авн(\.|ительная)) степень[\s ]?[-—:]?|, сравн. форма) ('''?|\[\[)?(?P<sravn_value>[^\n]+)('''?|\]\])?\.?\s*)?(?P<other>\s*\n\s*\n(\{\{морфо\s*\||приставка:).*)?$", part)
             if m:
                 self.counter += 1
                 other = m.group('other')
                 # print '=' * 100
                 # print '-' * 100
                 word = m.group('word')
                 if word and '{' in word:
                     continue
                 if word:
                     if '-' not in page.title:# and False:
                         # print page.title, self.counter#, u'—',
                         # print word
                         word = word.replace('-', '|').replace(u'·', u'|·|')
                         # print u"{{по-слогам|%s}}" % word
                         # print
                         pass
                     else:
                         word = word.replace(u'—', u'-')
                         part1, part2 = word.split('-', 1)
                         # print page.title
                         # print word
                         word = "%s-%s" % (part1, part2.replace('-', '|'))
                         # print word
                         # print
                 else:
                     word = page.title
                 slogi = u"|слоги={{по-слогам|%s}}\n" % word
                 or_value = m.group('or')
                 or1 = m.group('or1')
                 or2 = m.group('or2')
                 if or_value:
                     def get_value(or_val):
                         if or_val == u'союзное слово':
                             or_val = u'союз'
                         if or_val == u'вводн. слово':
                             or_val = u'вводное слово'
                         plural = {
                             u'предикатив': u'предикативы',
                             u'частица': u'частицы',
                             u'вводное слово': u'вводные слова',
                             u'числительное': u'числительные',
                             u'предлог': u'предлоги',
                             u'союз': u'союзы',
                         }
                         return or_val, plural.get(or_val, '')
                     # print page.title, self.counter#, u'—',
                     or2, or2p = get_value(or2)
                     or_params = u'|или=%s\n|или-кат=%s\n' % (or2, or2p)
                     # print or2, or2p
                     if or1:
                         or1, or1p = get_value(or1)
                         or_params += u'|или1=%s\n|или-кат1=%s\n' % \
                                      (or1, or1p)
                         # print or1, or1p
                     # print
                 else:
                     or_params = u'|или=\n|или-кат=\n'
                 sravn = m.group('sravn_value')
                 if sravn:
                     # print page.title, self.counter#, u'—',
                     remove_end_sravn = ["''.", ']]', "'''", "''", ".'''", "]].", '.']
                     for end in remove_end_sravn:
                         if sravn.endswith(end):
                             sravn = sravn[:-len(end)]
                     sravn = sravn.replace("'', ''", ", ").replace(';', ',')
                     # print sravn
                     # print
                 else:
                     sravn = ''
                 sravn = u"|степень=%s\n" % sravn
                 # print '-' * 100
                 # print part
                 print '=' * 100
                 print page.title
                 print '-' * 100
                 result = '{{adv ru\n'
                 result += slogi
                 result += u'|тип=\n'
                 result += u'|класс=\n'
                 result += sravn
                 result += or_params
                 result += '}}\n\n'
                 result += other.strip() if other else u'{{морфо||||}}'
                 print result
                 print '-' * 100
                 print part
                 print '=' * 100
                 print
                 pass
                 content = get_wiki_page_content(page.title)
                 content, changed = wikify_headers_spaces(content)
                 content = content.replace(part, result)
                 desc = u'Использование шаблона "adv ru"'
                 save_wiki_page(page.title, content, desc, wait=5)
             else:
                 # print '=' * 100
                 # print page.title, u'×' * 50
                 # print '-' * 100
                 # print part
                 # print '=' * 100
                 pass
     return content