<commit_before>#!/usr/bin/env python
# encoding: utf-8

import sys

WIKI_SOURCE = 'http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/includes/ZhConversion.php'
WIKI_SOURCE_LOCAL_FILE = 'ZhConversion.php'

# 最大正向匹配
def conv(string,dic):
    i = 0
    while i < len(string):
        for j in range(len(string) - i, 0, -1):
            if string[i:][:j] in dic:
                t = dic[string[i:][:j]]
                string = string[:i] + t + string[i:][j:]
                i += len(t) - 1
                break
        i += 1
    return string
 
# 生成转换字典
def mdic():    
    table = open(WIKI_SOURCE_LOCAL_FILE,'r').readlines()
    dic = {}
    name = []
    for line in table:
        if line[0] == '$':
            name.append(dic)
            dic = {}
        if line[0] == "'":
            word = line.split("'")
            dic[word[1]] = word[3]
    name.append(dic)
            
    name[3].update(name[1]) # 简繁通用转换规则(zh2Hant)加上台湾区域用法(zh2TW)
    name[4].update(name[1]) # 简繁通用转换规则(zh2Hant)加上香港区域用法(zh2HK)
    name[6].update(name[1]) # 简繁通用转换规则(zh2Hant)加上新加坡区域用法(zh2SG)
    name[5].update(name[2]) # 繁简通用转换规则(zh2Hans)加上大陆区域用法(zh2CN)<commit_msg>Update dict generator.<commit_after>#!/usr/bin/env python
# encoding: utf-8

import sys

WIKI_SOURCE = 'http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/includes/ZhConversion.php'
WIKI_SOURCE_LOCAL_FILE = 'ZhConversion.php'

# 生成转换字典
def mdic():    
    table = open(WIKI_SOURCE_LOCAL_FILE,'r').readlines()
    dic = {}
    name = []
    for line in table:
        if line[0] == '$':
            name.append(dic)
            dic = {}
        if line[0] == "'":
            word = line.split("'")
            dic[word[1]] = word[3]
    name.append(dic)
            
    name[3].update(name[1]) # 简繁通用转换规则(zh2Hant)加上台湾区域用法(zh2TW)
    name[4].update(name[1]) # 简繁通用转换规则(zh2Hant)加上香港区域用法(zh2HK)
    name[6].update(name[1]) # 简繁通用转换规则(zh2Hant)加上新加坡区域用法(zh2SG)
    name[5].update(name[2]) # 繁简通用转换规则(zh2Hans)加上大陆区域用法(zh2CN)
{'fraction_non_alphanumeric': 0.1662455785750379, 'fraction_numerical': 0.024759979787771603, 'mean_word_length': 2.504424778761062, 'pattern_counts': {'":': 2, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5359196', 'n_tokens_mistral': 895, 'n_tokens_neox': 968, 'n_words': 114}