예제 #1
0
print('前処理を行います')
PREPROCESSOR.load_text(sorted(glob.glob(text_folder_path + '/*')))
whitelist = PREPROCESSOR.investigate_whitelist(thesaurus_path)
print('保存します')
PREPROCESSOR.save(auto_text_path)
PARSER = Parser()
print('かかり受け解析を行います..')
PARSER.t2f(sorted(glob.glob(auto_text_path + '/*')),
           kytea_model=kytea_path,
           eda_model=eda_path)  # text_pathのファイルをかかり受け解析
print('結果を保存します')
PARSER.save(tree_path)  # かかり受け解析したものをファイルに保存
INDEX = Index(unigram=1, dep_trigram=1, bigram=1,
              dep_bigram=1)  # Indexをunigramとbigramの素性を、treeから読み出すことでIndexを作成する
print('Treeを読み込みます')
INDEX.add_index(sorted(glob.glob(tree_path +
                                 '/*')))  # tree_pathのフォルダ以下のファイルからインデックスを作る
print('INDEXを保存します...')
INDEX.save(index_path)  # index_pathにインデックスを保存
print(index_path)
print("Indexを読み込みます...")
VECTORIZER = Vectorizer(index_path, t=1, list=whitelist)  # Indexの読み込み  # 閾値は1
print('Treeを読み込みます')
vectors = VECTORIZER.get_vector(sorted(glob.glob(tree_path + '/*')),
                                filter=3)  # ベクトルを生成
print(vectors)
print('Vectorを保存します')
filename_list = sorted(glob.glob(tree_path + '/*'))
vector_path_list = []
for filename in filename_list:
    base_name = os.path.basename(filename)  # A.text
    root = os.path.splitext(base_name)[0]  # A