Esempio n. 1
0
def save_dictionary_words(dictionary_id):
    dictionary = Dictionary.objects.get(pk=dictionary_id)
    words = get_dictionary_words(dictionary_id)
    words = set(words)  # todo: sorting?
    filename = "%s_%s.txt" % (dictionary.name, dictionary.source)
    path = join(DICTIONARIES_DIR, filename)
    save_lines(path, words, 'utf-8')
Esempio n. 2
0
    def after(self):
        content = u"""== Описание ==
Здесь представлены статьи в русском разделе с отсутствующими значениями в семантической секции.

Обсудить можно '''[[Обсуждение Викисловаря:Отчёты|здесь]]'''.

== Список результатов ==
"""
        # items = sorted(self.empty_mining_ru)
        # for title in items:
        #     content += u"# [[{0}]]\n".format(title)
        title = u"Индексы/ru/Розовые ссылки"
        count = len(self.empty_mining_ru)
        content += (
            u"Список результатов слишком велик (%d), поэтому для них был создан отдельный индекс: "
            u"[[Участник:Vitalik/Индекс/Розовые ссылки/Итого]]." % count
        )
        self.process_report(title, content, count)
        lines = [line.encode("utf8") for line in self.empty_mining_ru]
        save_lines(join(settings.FILES_PATH, "reports", "pink_links_ru"), sorted(lines))
        create_index(
            self.empty_mining_ru,
            u"Индекс/Розовые ссылки",
            desc=u"Обновление списка розовых ссылок",
            push=True,
            debug=False,
            header=u"Розовые ссылки",
        )
        super(EmptyMiningRu, self).after()
Esempio n. 3
0
def save_dictionaries_words_db(name):
    dictionaries = Dictionary.objects.filter(name=name)
    dictionaries_data = dict()
    for dictionary in dictionaries:
        dictionaries_data[dictionary.pk] = dictionary.source
    words = get_dictionaries_words(dictionaries_data)
    words = set(words)  # todo: sorting?
    filename = "db_%s.txt" % name
    path = join(DICTIONARIES_DIR, filename)
    save_lines(path, words, 'utf-8')
Esempio n. 4
0
def save_mystem_to_file():
    i = 0
    lines = list()
    for word in MyStem.objects.filter(wrong=False, unknown=False, noun=True).exclude(result__contains=u'сокр'):
        if 2 < len(word.value) < 8:
            i += 1
            lines.append("%s:%s" % (word.value, word.freq))
            MyStemBK.objects.create(word=word.value, length=len(word.value),
                                    freq=word.freq)
            print i, word.value
    save_lines('data/mystem.txt', lines, encode='utf-8')
Esempio n. 5
0
 def b(self):
     items = MyStemNoun.objects.filter(not_wikt=False).order_by('value')
     words_0 = []
     words_1 = []
     for item in items:
         if item.freq > 0:
             words_1.append(item.value)
         else:
             words_0.append(item.value)
     save_lines('words_0.txt', words_0, encode='utf-8')
     save_lines('words_1.txt', words_1, encode='utf-8')
Esempio n. 6
0
def generate_red_links_index():
    ignore_words_content = get_wiki_page_content(u'Участник:Vitalik/Индекс/Красные ссылки/Игнорируемые слова')
    ignore_words = list()
    for line in ignore_words_content.split('\n'):
        m = re.match('^\* \[\[(.*)\]\]$', line)
        if not m:
            print u'ERROR in ignore_words: %s' % line
        ignore_words.append(m.group(1).encode('utf8'))
    # print '\n'.join(ignore_words)
    # exit()

    page_names = [
        u'Участник:Vitalik/Индекс/Красные ссылки/Дополнительные источники/Cinematique',
        u'Участник:Vitalik/Индекс/Красные ссылки/Дополнительные источники/Cinematique/Недостающие глаголы из причастий',
    ]
    cin_words = list()
    for page_name in page_names:
        cin_words_content = get_wiki_page_content(page_name)
        for line in cin_words_content.split('\n'):
            m = re.match('^[*#] \[\[(.*)\]\]$', line)
            if not m:
                print u'ERROR in cin_words: %s' % line
            cin_words.append(m.group(1).encode('utf8'))
        # print '\n'.join(cin_words)
    # exit()

    index_words = load_lines(join(settings.DATA_PATH, 'wikt_words',
                                  'ru+redirects.txt'))
    dict_words = load_from_dictionaries()
    red_words = list((set(dict_words) | set(cin_words)) - set(index_words) - set(ignore_words))
    print "Red count: ", len(red_words)
    # exit()

    # bos_words = load_from_dictionaries(['bos_barhudarov_filtering_words.txt'])
    # new_words = list(set(bos_words) - set(red_words) - set(index_words))
    # for word in sorted(new_words):
    #     print word
    # exit()

    # save_lines(join(settings.DATA_PATH, 'words_red_a.txt'), red_words)
    save_lines(join(settings.FILES_PATH, 'reports', 'red_links_ru'),
               sorted(red_words))

    # create_index(red_words, u'Индекс/Красные ссылки (без подстраниц)',
    create_index(red_words, u'Индекс/Красные ссылки',
                 desc=u'Обновление списка красных ссылок',
                 push=True, debug=False,
                 header=u'Красные ссылки',
    )
Esempio n. 7
0
def load_index():
    import pywikibot
    site = pywikibot.Site('ru')
    letters = [u'A', 'A/b', 'A/d', 'A/l', 'A/n', 'A/v', u'B', 'C', u'Č', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', u'Š', 'T', 'U', 'V', 'Z', u'Ž', 'Q', 'W', 'X', 'Y']
    words = list()
    for letter in letters:
        print letter
        title = u"Индекс:Словенский_язык/%s" % letter
        page = pywikibot.Page(site, title)
        lines = page.get().split('\n')
        for line in lines:
            if line and not re.search(u'^\{|\=|__NOTOC__|\<|см. \[\[', line, re.UNICODE):
                m = re.match('\*\[\[(?P<word>.*)\]\]', line)
                if m:
                    line = m.group('word')
                words.append(line)
                # print line
        # break
    save_lines(sl_index_filename, words, encode='utf-8')
Esempio n. 8
0
    def after(self):
        content = u"""== Описание ==
Здесь представлены статьи в русском разделе со старым шаблоном произношения.

Обсудить можно '''[[Обсуждение Викисловаря:Отчёты|здесь]]'''.

== Список результатов ==
"""
        # items = sorted(self.empty_mining_ru)
        # for title in items:
        #     content += u"# [[{0}]]\n".format(title)
        title = u'Индексы/ru/Старый шаблон произношения'
        count = len(self.transcription_tpl_not_ru)
        content += u'Список результатов слишком велик (%d), поэтому для них был создан отдельный индекс: ' \
                   u'[[Участник:Vitalik/Индекс/Старый шаблон произношения/Итого]].' % count
        self.process_report(title, content, count)
        lines = [line.encode('utf8') for line in self.transcription_tpl_not_ru]
        save_lines(join(settings.FILES_PATH, 'reports', 'old_transcription_ru'),
                   sorted(lines))
        create_index(self.transcription_tpl_not_ru, u'Индекс/Старый шаблон произношения',
                     desc=u'Обновление списка со старым шаблоном произношения',
                     push=True, debug=False, header=u'Старый шаблон произношения')
        super(TranscriptionTemplateNotRu, self).after()
Esempio n. 9
0
def process_names():
    lines = load_lines(join(settings.DATA_PATH, 'input', 'cin_names.txt'))
    data = dict()
    for line in lines:
        line = line.decode('utf-8').strip()
        # print line
        name, gender = line.split(',')
        if name[0] != '"' or name[-1] != '"' or gender[0] != '"' or gender[-1] != '"':
            print line
            # print name, gender
            # print name[0], name[-1], gender[0], gender[-1]
            print '#' * 100
        name = name[1:-1].strip()
        gender = gender[1:-1]
        if gender not in 'mf':
            print line
            print '#' * 100
        data.setdefault(name, dict())
        data[name][gender] = 1
        if not re.match(u'^[-А-ЯЁа-яё]+$', name, re.IGNORECASE):
            print name
            print repr(name)
    m_list = list()
    f_list = list()
    mf_list = list()
    for name, genders in data.items():
        m = genders.get('m')
        f = genders.get('f')
        if m and f:
            mf_list.append(name)
        elif m:
            m_list.append(name)
        elif f:
            f_list.append(name)
        else:
            print name
    save_lines(join(settings.DATA_PATH, 'input', 'cin_names_m.txt'),
               sorted(m_list), encode='utf-8')
    save_lines(join(settings.DATA_PATH, 'input', 'cin_names_f.txt'),
               sorted(f_list), encode='utf-8')
    save_lines(join(settings.DATA_PATH, 'input', 'cin_names_mf.txt'),
               sorted(mf_list), encode='utf-8')
Esempio n. 10
0
from os.path import join

from django.conf import settings

from dictionaries.utils.file import load_lines, save_lines
from reports.red_links.create_index import \
    create_index
from reports.red_links.load_from_dictionaries import \
    load_from_dictionaries


index_words = load_lines(join(settings.DATA_PATH, 'wikt_words',
                              'ru+redirects.txt'))

bukchina_words = load_from_dictionaries(['rus_orthography_academic.txt'])
print len(bukchina_words)
bukchina_red_words = list(set(bukchina_words) - set(index_words))
print len(bukchina_red_words)
bukchina_red_words_a = filter(lambda x: x.decode('utf-8').lower()[0] == u'а',# or x[0] == u'А',
                              bukchina_red_words)
print len(bukchina_red_words_a)

save_lines(join(settings.DATA_PATH, 'words_red_bukchina_a.txt'),
           bukchina_red_words_a)

create_index(bukchina_red_words_a, u'Индекс/Красные ссылки/Букчина',
             desc=u'Создание списка красных ссылок Букчиной',
             max_words_on_page=100000, use_other=False, force_letters=u'А',
             push=True
)
Esempio n. 11
0
def recreate_dictionaries_words(name):
    words = create_dictionaries_words(load_dictionaries_data(name))
    filename = "%s.txt" % name
    path = join(DICTIONARIES_DIR, filename)
    save_lines(path, words, 'utf-8')
Esempio n. 12
0
 def after(self):
     super(GetWordsIterator, self).after()
     save_lines(sl_db_filename, self.words, encode='utf-8')
Esempio n. 13
0
 def after(self):
     save_lines(ru_index_filename, self.words, encode='utf-8')