Exemple #1
0
        id1 = str(edge[0][0])
        label1 = str(edge[0][1])
        id2 = str(edge[1][0])
        label2 = str(edge[1][1])

        graph.add_node(
            pydot.Node(id1,
                       label='<<font face="MS Gothic">%s</font>>' %
                       label1.rstrip("\r\n")))
        graph.add_node(
            pydot.Node(id2,
                       label='<<font face="MS Gothic">%s</font>>' %
                       label2.rstrip("\r\n")))

        graph.add_edge(pydot.Edge(id1, id2))

    return graph


for chunks in build_morphs(fname):
    edges = []
    for i, chunk in enumerate(chunks):
        if chunk.dst != -1:
            src = clean_sym(chunk)
            dst = clean_sym(chunks[chunk.dst])
            if src != '' and dst != '':
                edges.append(((i, src), (chunk.dst, dst)))
    if len(edges) > 0:
        graph = make_graph(edges, directed=True)
        graph.write_png('graph.png')
Exemple #2
0
from lib import build_morphs,Morph,Chunk,clean_sym,chk_pos,morphs_pos,find_kaku,find_sa
result = 'result.txt'

with open(result, mode='w',encoding='utf-8') as out_file:
    for chunks in build_morphs():
        for chunk in chunks:

            if (len(morphs_pos(chunk,'名詞')) > 0):

                # print(clean_sym(chunk),end='')

                # 根へのパスを出力
                dst = chunk.dst
                while dst != -1:
                    # print(' -> ' + clean_sym(chunks[dst]),end='')
                    out_file.write(' -> ' + clean_sym(chunks[dst]))
                    dst = chunks[dst].dst
                # print('')
                out_file.write('\n')
Exemple #3
0
from lib import build_morphs,Morph,Chunk

fname = 'neko.txt.cabocha'

for i, chunks in enumerate(build_morphs(), 1):

    # 8文目を表示
    if i == 8:
        for j, chunk in enumerate(chunks):
            print('[{}]{}'.format(j, chunk))
        break