@@ -0,0 +1,2257 @@
+# -*- coding: utf-8 -*-%0A%0Aimport codecs, os, shutil, json%0A#import pythai%0ADICT = u%22test_dict.json%22%0A%0Adef main():%0A    global DICT%0A    path_load = get_path() %0A    path_load = u%22c:%5C%5Ctest%22 #%D0%B2%D1%81%D1%82%D0%B0%D0%B2%D0%BA%D0%B0 %0A    dictionary = read_data(DICT)%0A    %0A    path_save = copy_repository(path_load)%0A    tag_repository (path_save, dictionary)%0A%0Adef get_path():%0A    path = raw_input(u%22Path: %22)%0A    return path%0A%0A#=========================================================%0A%0Adef copy_repository(path_load): ##DONE%0A    path_save = path_load + u%22_tagged%22%0A    index = 1%0A    changed = False%0A    if os.path.exists(path_save):%0A        changed = True%0A        while os.path.exists(path_save + %22 (%22 + unicode(index) + %22)%22):%0A            index += 1%0A    if changed:%0A        path_save = path_save + %22 (%22 + unicode(index) + %22)%22%0A    shutil.copytree(path_load, path_save)%0A        %0A    return path_save%0A%0Adef tag_repository(repository, dictionary): ##DONE%0A    for i in os.walk(repository):%0A        print i%0A        for j in i%5B-1%5D:%0A            tag_file(i%5B0%5D + u%22%5C%5C%5C%5C%22 + j, dictionary)%0A            %0Adef tag_file(path, dictionary): ##DONE%0A    new_file = codecs.open(path, %22r%22, %22utf-8%22)%0A    text = new_file.read()%0A    new_file.close()%0A    %0A    text = tag_text(text, dictionary)%0A%0A    new_file = codecs.open(path, %22w%22, %22utf-8%22)%0A    new_file.write(text)%0A    new_file.close()%0A    %0A    %0Adef tag_text(text, dictionary): ##hmmm...%0A    result = %5Bu%22%3Cbody%3E%22%5D%0A    sents = text.split()%0A    for i in sents:%0A        result.append(u%22%3Cse%3E%22)%0A        for j in pythai.split(i):%0A            result.append(tag_word(j, dictionary))%0A    return create_csv(result)%0A%0Adef tag_word(word, dictionary): #!!!%0A    if word in dictionary:%0A        for i in dictionary%5Bword%5D:%0A            for j in dictionary%5Bword%5D%5Bi%5D:%0A                pass%0A%0Adef create_csv(result):%0A    return %22OK%22%0A%0Adef write_repository(repository, path):%0A    pass%0A%0A#=============================================================%0Adef read_data (path):%0A    data_file = codecs.open(path, 'r', 'utf-8')%0A    data = json.load(data_file)%0A    data_file.close()%0A    return data       %0A%0Adef write_data (path, data):%0A    json_data = json.dumps(data, ensure_ascii=False, indent=1)  %0A    json_file = codecs.open (path, 'w', 'cp1251')%0A    json_file.write (json_data)%0A    json_file.close()%0A%0A%0Amain()%0A

Create thai_tagger.py