読者です 読者をやめる 読者になる 読者になる

texのPDFに表を作るマン。

その他

表を作った時のやつ。

ちょっと昔過ぎて覚えてないので説明は割愛。

 

 

 このタイプのやつを表にするプログラムです。

f:id:alakialaca:20160805193958p:plain

 

# -*- coding:utf-8 -*-

import os,re,sys

target = re.compile("target=\"[\s\S]+?\"")
rel = re.compile("rel type=\"[\s\S]+?\"")
dash = re.compile("\"[\s\S]*\"")
kotoba = re.compile("[\s\S]*")
word = re.compile("[^\"]*")
infp = open(sys.argv[1])
#{}はディクショナリ型要素はキー:データで表す
mod = {}
word = {}
modifiers = {}
relbno = {}
list2 =
list3 =

targetlist =
for line in infp:
    line = line.strip()
    #print(line)
    ##や+があったらその文章ははじく
    if line[0] in ['#']: continue
    #print(line)
    if line[0] == '*':
    #print(line)
    #[2:]2番目から末尾まで
        (bno,dep) = line[2:].split()
    #print(bno,dep)
    #後ろから一つ目を抜き出す。
        dep = dep[:-1]
    #print(dep)
    #mod[bno] Dの左の数字
        mod[bno] = dep
    #print(mod[bno])
    #modefierの中にdepがなかったらmodifier[dep]を空っぽにする
        if not dep in modifiers: modifiers[dep] =

        modifiers[dep].append(bno)
        #print(modifiers[dep])
        word[bno] = ''
        continue
    if line.split()[0] != "+":
        word[bno] += line.split()[0]
    if line[0] == "+":
        #print(line)
        tar = target.findall(line)
        #print(tar)
        #print(tar[1])
        relar = rel.findall(line)
        #print(relar)
        for a in range(len(tar)):
            tardash = dash.findall(tar[a])
            reldash = dash.findall(relar[a])
            #for c in range(len(tardash)):
                #print(tardash[c])
                #reldash[c] = reldash[c][1:-1]
                #list3.append[reldash[c]]
            for b in range(len(reldash)):
                if("ノ" in reldash[b]):
                    for c in range(len(tardash)):
                        #print(tardash[c])
                        tardash[c] = tardash[c][1:-1]
                        list3.append(tardash[c])
                    list2.append(bno)
                if("ガ" in reldash[b]):
                    for c in range(len(tardash)):
                        #print(tardash[c])
                        tardash[c] = tardash[c][1:-1]
                        list3.append(tardash[c])
                    list2.append(bno)
                if("修飾" in reldash[b]):
                    for c in range(len(tardash)):
                        #print(tardash[c])
                        tardash[c] = tardash[c][1:-1]
                        list3.append(tardash[c])
                    list2.append(bno)
            #for c in range(len(tardash)):
                #tarkotoba = kotoba.findall(tardash[c])
                #print(tarkotoba[c])
#print(len(list2))
#print(list3)
#for d in range(len(list2)):
    #print(list2[d])
for bno in word:
    for d in range(len(list3)):
        if(list3[d] in word[bno]):
            #print(bno)
            #print(word[bno])
            targetlist.append(bno)
#print(targetlist)    
outfp = open('graph3.tex','w')
print >>outfp, r'\documentclass[dvipdfmx]{article}'
print >>outfp, r'\usepackage{tikz}'
print >>outfp, r'\usetikzlibrary{shapes.geometric}'
print >>outfp, r'\begin{document}'
print >>outfp, r'\begin{tikzpicture}[inner sep=0pt]'
for bno in word:
    #modifier[mod[bno]]のリストの中のbnoの位置を返す
    x = int(modifiers[mod[bno]].index(bno))
    #print(bno)
    #print(modifiers[mod[bno]])
    #print(x)
    #print(word[bno])
    print >>outfp, r'\node[ellipse,draw] at (%d, -%s) (B%s) {%s};' % (x,bno,bno,word[bno])
for bno in mod:
    if mod[bno] != '-1':
        print >>outfp, r'\draw[-latex](B%s) to[bend left] (B%s);' % (bno,mod[bno])
for e in range(len(list2)):
    #print(e)
    print >>outfp, r'\draw[-latex](B%s) to[bend right] (B%s);' % (targetlist[e],list2[e])
print >>outfp, r'\end{tikzpicture}'
print >>outfp, r'\end{document}'