コード例 #1
0
if __name__ == '__main__':
    import os, sys
    sys.path.append(os.pardir)

    from chapter05.knock41 import get_neko_chunks
    from common.drawers import draw_dependency_graph

    import matplotlib.pyplot as plt
    from matplotlib.image import imread

    chunks = get_neko_chunks(7)

    draw_dependency_graph(chunks, 'knock44.png')

    img = imread('knock44.png')
    plt.imshow(img)
    plt.show()
コード例 #2
0
ファイル: knock42.py プロジェクト: ise-ab/100knock2018
if __name__ == '__main__':
    import os,sys
    sys.path.append(os.pardir)

    from chapter05.knock41 import get_neko_chunks

    line8 = get_neko_chunks(8)

    for chunk in line8:
        o = chunk.phrase(True)
        if chunk.dst > -1:
            dst_chunk = line8[chunk.dst]
            o += '\t' + dst_chunk.phrase(True)
            print(o)
コード例 #3
0
            src_chunk = chunks[src]
            src_particle = src_chunk.morph_of_pos('助詞', last=True)

            # 助詞を含まない場合は省略
            if src_particle is None:
                continue

            verb_phrase = chunk.phrase(True) + verb.base
            relations[verb_phrase].append(
                (src_particle.base, src_chunk.phrase(True)))

    return relations


if __name__ == '__main__':
    import os, sys
    sys.path.append(os.pardir)

    from chapter05.knock41 import get_neko_chunks

    chunks = get_neko_chunks(949)

    kakari = extract_sahen(chunks)

    for verb, values in sorted(kakari.items(), key=lambda item: item[0]):
        values = sorted(values, key=lambda v: v[0])
        o = verb
        o += '\t' + ' '.join(map(lambda v: v[0], values))
        o += '\t' + ' '.join(map(lambda v: v[1], values))
        print(o)