diff --git a/README.md b/README.md index f40fb40..c190a79 100644 --- a/README.md +++ b/README.md @@ -57,4 +57,8 @@ done Send me your bugs (gently). --Luke ([@siriusfox](https://twitter.com/siriusfox)) \ No newline at end of file +-Luke ([@siriusfox](https://twitter.com/siriusfox)) + + +## Tofugu Examples +I did a small extension where I took the material from the (Tofugu Pronunciation Article)[https://www.tofugu.com/japanese/japanese-pronunciation/] and wrote a simple parser to generate graphics showing the pattern rather than using their LH letter convention to show pitch. The examples are available in tofugu_examples and tofugu_files. [2018-05-23] \ No newline at end of file diff --git a/parse_tofugu.py b/parse_tofugu.py new file mode 100755 index 0000000..f771960 --- /dev/null +++ b/parse_tofugu.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 +import punctCode + +# Given a file name, loop line by line and convert the string of a Key (filename), phonetic word, +# plus the pitch accent code to a big list. +def parseToneFile(fn): + # TODO: Handle empty/invalid lines gracefully + print("Parsing file: \"%s\"" % fn) + dat = []; + for line in open(fn,'r'): + [key,w,n]=line.split(':') + print(" => importing \"%s\"" % key) + pc = punctCode.parseToneString(key,w,n.strip()) + dat.append(pc) + return dat; + +# Parse the list, pucntList is now a list of objects containing grouped mora, and the individual +# mora's high/low filled/unfilled graph symbol. +punctList = parseToneFile('tofugu_files/example_codes_tofugu.txt') + +print("Saving svgs...") +# For each one, dump an SVG +for pc in punctList: + # using default sizing. Units are in pixels. + filename = ('tofugu_examples/%s.svg' % (pc.key)); + print(" => saving \"%s\" as \"%s\"" % (pc.key, filename)) + pc.toSVG(filename, style='font-weight:bold;',\ + padding_lr=30, padding_tb=15) + + diff --git a/tofugu_examples/1-1-名.svg b/tofugu_examples/1-1-名.svg new file mode 100644 index 0000000..1d26120 --- /dev/null +++ b/tofugu_examples/1-1-名.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-10-秋.svg b/tofugu_examples/1-10-秋.svg new file mode 100644 index 0000000..3bf7c8f --- /dev/null +++ b/tofugu_examples/1-10-秋.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-11-電気.svg b/tofugu_examples/1-11-電気.svg new file mode 100644 index 0000000..ba300bb --- /dev/null +++ b/tofugu_examples/1-11-電気.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-12-文学.svg b/tofugu_examples/1-12-文学.svg new file mode 100644 index 0000000..fdc7a88 --- /dev/null +++ b/tofugu_examples/1-12-文学.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-13-シャーベット.svg b/tofugu_examples/1-13-シャーベット.svg new file mode 100644 index 0000000..072b9ee --- /dev/null +++ b/tofugu_examples/1-13-シャーベット.svg @@ -0,0 +1,2 @@ + +しゃ \ No newline at end of file diff --git a/tofugu_examples/1-14-ケンモホロロ.svg b/tofugu_examples/1-14-ケンモホロロ.svg new file mode 100644 index 0000000..4b53d6c --- /dev/null +++ b/tofugu_examples/1-14-ケンモホロロ.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-15-呉越同舟.svg b/tofugu_examples/1-15-呉越同舟.svg new file mode 100644 index 0000000..9a9824c --- /dev/null +++ b/tofugu_examples/1-15-呉越同舟.svg @@ -0,0 +1,2 @@ + +しゅ \ No newline at end of file diff --git a/tofugu_examples/1-16-花.svg b/tofugu_examples/1-16-花.svg new file mode 100644 index 0000000..a4286af --- /dev/null +++ b/tofugu_examples/1-16-花.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-17-お菓子.svg b/tofugu_examples/1-17-お菓子.svg new file mode 100644 index 0000000..409b0d8 --- /dev/null +++ b/tofugu_examples/1-17-お菓子.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-18-雪国.svg b/tofugu_examples/1-18-雪国.svg new file mode 100644 index 0000000..5fb53fb --- /dev/null +++ b/tofugu_examples/1-18-雪国.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-19-普及率.svg b/tofugu_examples/1-19-普及率.svg new file mode 100644 index 0000000..c58f7b9 --- /dev/null +++ b/tofugu_examples/1-19-普及率.svg @@ -0,0 +1,2 @@ + +きゅ \ No newline at end of file diff --git a/tofugu_examples/1-2-水.svg b/tofugu_examples/1-2-水.svg new file mode 100644 index 0000000..485fe1c --- /dev/null +++ b/tofugu_examples/1-2-水.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-20-お巡りさん.svg b/tofugu_examples/1-20-お巡りさん.svg new file mode 100644 index 0000000..4975834 --- /dev/null +++ b/tofugu_examples/1-20-お巡りさん.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-21-男.svg b/tofugu_examples/1-21-男.svg new file mode 100644 index 0000000..c9ad0af --- /dev/null +++ b/tofugu_examples/1-21-男.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-22-歳時記.svg b/tofugu_examples/1-22-歳時記.svg new file mode 100644 index 0000000..caa89b8 --- /dev/null +++ b/tofugu_examples/1-22-歳時記.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-23-山登り.svg b/tofugu_examples/1-23-山登り.svg new file mode 100644 index 0000000..35afb20 --- /dev/null +++ b/tofugu_examples/1-23-山登り.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-24-金婚式.svg b/tofugu_examples/1-24-金婚式.svg new file mode 100644 index 0000000..6d38dd8 --- /dev/null +++ b/tofugu_examples/1-24-金婚式.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-25-副大統領.svg b/tofugu_examples/1-25-副大統領.svg new file mode 100644 index 0000000..5c90577 --- /dev/null +++ b/tofugu_examples/1-25-副大統領.svg @@ -0,0 +1,2 @@ + +りょ \ No newline at end of file diff --git a/tofugu_examples/1-26-弟.svg b/tofugu_examples/1-26-弟.svg new file mode 100644 index 0000000..bd2e477 --- /dev/null +++ b/tofugu_examples/1-26-弟.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-27-小型バス.svg b/tofugu_examples/1-27-小型バス.svg new file mode 100644 index 0000000..4eed1a3 --- /dev/null +++ b/tofugu_examples/1-27-小型バス.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-28-国語辞典.svg b/tofugu_examples/1-28-国語辞典.svg new file mode 100644 index 0000000..6690ff6 --- /dev/null +++ b/tofugu_examples/1-28-国語辞典.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-29-私立大学.svg b/tofugu_examples/1-29-私立大学.svg new file mode 100644 index 0000000..9df115b --- /dev/null +++ b/tofugu_examples/1-29-私立大学.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-3-会社.svg b/tofugu_examples/1-3-会社.svg new file mode 100644 index 0000000..3ed058b --- /dev/null +++ b/tofugu_examples/1-3-会社.svg @@ -0,0 +1,2 @@ + +しゃ \ No newline at end of file diff --git a/tofugu_examples/1-30-桃の花.svg b/tofugu_examples/1-30-桃の花.svg new file mode 100644 index 0000000..8e67763 --- /dev/null +++ b/tofugu_examples/1-30-桃の花.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-31-炭酸ガス.svg b/tofugu_examples/1-31-炭酸ガス.svg new file mode 100644 index 0000000..fb5b52f --- /dev/null +++ b/tofugu_examples/1-31-炭酸ガス.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-32-幼年時代.svg b/tofugu_examples/1-32-幼年時代.svg new file mode 100644 index 0000000..fee5bd4 --- /dev/null +++ b/tofugu_examples/1-32-幼年時代.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-33-大学院生.svg b/tofugu_examples/1-33-大学院生.svg new file mode 100644 index 0000000..e89e5bc --- /dev/null +++ b/tofugu_examples/1-33-大学院生.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-34-十一月.svg b/tofugu_examples/1-34-十一月.svg new file mode 100644 index 0000000..ea7046e --- /dev/null +++ b/tofugu_examples/1-34-十一月.svg @@ -0,0 +1,2 @@ + +じゅ \ No newline at end of file diff --git a/tofugu_examples/1-35-お願いします.svg b/tofugu_examples/1-35-お願いします.svg new file mode 100644 index 0000000..2fad16b --- /dev/null +++ b/tofugu_examples/1-35-お願いします.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-36-自動販売機.svg b/tofugu_examples/1-36-自動販売機.svg new file mode 100644 index 0000000..f8d4182 --- /dev/null +++ b/tofugu_examples/1-36-自動販売機.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-37-携帯ストラップ.svg b/tofugu_examples/1-37-携帯ストラップ.svg new file mode 100644 index 0000000..582bdfb --- /dev/null +++ b/tofugu_examples/1-37-携帯ストラップ.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-38-宜しくお願いします.svg b/tofugu_examples/1-38-宜しくお願いします.svg new file mode 100644 index 0000000..0e35d4f --- /dev/null +++ b/tofugu_examples/1-38-宜しくお願いします.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-4-大学.svg b/tofugu_examples/1-4-大学.svg new file mode 100644 index 0000000..04f5830 --- /dev/null +++ b/tofugu_examples/1-4-大学.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-5-中国語.svg b/tofugu_examples/1-5-中国語.svg new file mode 100644 index 0000000..324c2ce --- /dev/null +++ b/tofugu_examples/1-5-中国語.svg @@ -0,0 +1,2 @@ + +ちゅ \ No newline at end of file diff --git a/tofugu_examples/1-6-見物人.svg b/tofugu_examples/1-6-見物人.svg new file mode 100644 index 0000000..6c2b0ca --- /dev/null +++ b/tofugu_examples/1-6-見物人.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-7-五十音順.svg b/tofugu_examples/1-7-五十音順.svg new file mode 100644 index 0000000..277f69f --- /dev/null +++ b/tofugu_examples/1-7-五十音順.svg @@ -0,0 +1,2 @@ + +じゅじゅ \ No newline at end of file diff --git a/tofugu_examples/1-8-いい加減にしろ.svg b/tofugu_examples/1-8-いい加減にしろ.svg new file mode 100644 index 0000000..2eadfc7 --- /dev/null +++ b/tofugu_examples/1-8-いい加減にしろ.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/1-9-木.svg b/tofugu_examples/1-9-木.svg new file mode 100644 index 0000000..2d7b54c --- /dev/null +++ b/tofugu_examples/1-9-木.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/2-1-箸.svg b/tofugu_examples/2-1-箸.svg new file mode 100644 index 0000000..09db858 --- /dev/null +++ b/tofugu_examples/2-1-箸.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/2-2-橋.svg b/tofugu_examples/2-2-橋.svg new file mode 100644 index 0000000..59f4da6 --- /dev/null +++ b/tofugu_examples/2-2-橋.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/2-3-神.svg b/tofugu_examples/2-3-神.svg new file mode 100644 index 0000000..a3df37e --- /dev/null +++ b/tofugu_examples/2-3-神.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/2-4-紙.svg b/tofugu_examples/2-4-紙.svg new file mode 100644 index 0000000..b637333 --- /dev/null +++ b/tofugu_examples/2-4-紙.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/2-5-髪.svg b/tofugu_examples/2-5-髪.svg new file mode 100644 index 0000000..b637333 --- /dev/null +++ b/tofugu_examples/2-5-髪.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/2-6-酒.svg b/tofugu_examples/2-6-酒.svg new file mode 100644 index 0000000..90e6d46 --- /dev/null +++ b/tofugu_examples/2-6-酒.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/2-7-鮭.svg b/tofugu_examples/2-7-鮭.svg new file mode 100644 index 0000000..a312014 --- /dev/null +++ b/tofugu_examples/2-7-鮭.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/2-8-飴.svg b/tofugu_examples/2-8-飴.svg new file mode 100644 index 0000000..962336b --- /dev/null +++ b/tofugu_examples/2-8-飴.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_examples/2-9-雨.svg b/tofugu_examples/2-9-雨.svg new file mode 100644 index 0000000..29ee30c --- /dev/null +++ b/tofugu_examples/2-9-雨.svg @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/tofugu_files/convert_tofugu_list.sh b/tofugu_files/convert_tofugu_list.sh new file mode 100755 index 0000000..3dacab2 --- /dev/null +++ b/tofugu_files/convert_tofugu_list.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# First argument is input file +if [[ $# -ne 1 ]]; then + echo """\ +$0: +A tool to convert copy/paste source files from the Tofugu site's pitch +tables to more pretty graphics for humans. + +Incorrect usage: + $0 + +Format example: + LH 名 な + LHH 水 みず + LHHH 会社 かいしゃ + LHHHH 大学 だいがく + LHHHHH 中国語 ちゅうごくご + \\t\\t + + Input is proccessed with bash's \`read\` so spacing is not critical.""" + + exit +fi + +SRC="$1" +MODIFY_SET=(ゃ ゅ ょ ぁ ぃ ぅ ぇ ぉ) # these characters don't count towards a mora length +MARU='○' + +IND=0 +PFX="1-" +while read INPUT; do + IND=$(($IND+1)) + #echo "$INPUT" + ARGS=($INPUT) + CODE=${ARGS[0]} + NAME=${ARGS[1]} + KANA=${ARGS[2]} + + # Compute core word length + KANA_TMP=$KANA + for MiniMora in ${MODIFY_SET[@]}; do + KANA_TMP=$(sed "s/$MiniMora//g" <<< $KANA_TMP) + done + MORA_LENGTH=${#KANA_TMP} + # first find the length of the word, count the LH stuff + if [[ ${CODE:0:1} == 'H' ]]; then # 頭高 + DOWN_STEP=1 + else + CODE_TMP="${CODE:1}" + CODE_TMP=${CODE_TMP%H*} + DOWN_STEP=$((${#CODE_TMP}+2)) # downstep location + if [[ $DOWN_STEP -gt $MORA_LENGTH ]]; then + DOWN_STEP=0 + fi + fi + + # Lad when tofugu assumes more mora in their code (or a particle) + DELTA=$(($MORA_LENGTH-${#CODE})) + if [[ $DELTA -eq -1 ]]; then + KANA="$KANA$MARU" + elif [[ $DELTA -ne 0 ]]; then + echo "WARNING: Length error in line $IND: '$INPUT'" >&2 + fi + + #echo $DOWN_STEP/$MORA_LENGTH + echo ${PFX}${IND}-$NAME:$KANA:$DOWN_STEP/$MORA_LENGTH +done < "$SRC" + + + diff --git a/tofugu_files/example_codes_tofugu.txt b/tofugu_files/example_codes_tofugu.txt new file mode 100644 index 0000000..2b456af --- /dev/null +++ b/tofugu_files/example_codes_tofugu.txt @@ -0,0 +1,38 @@ +1-1-名:な○:0/1 +1-2-水:みず○:0/2 +1-3-会社:かいしゃ○:0/3 +1-4-大学:だいがく○:0/4 +1-5-中国語:ちゅうごくご○:0/5 +1-6-見物人:けんぶつにん○:0/6 +1-7-五十音順:ごじゅうおんじゅん○:0/7 +1-8-いい加減にしろ:いいかげんにしろ○:0/8 +1-9-木:き○:1/1 +1-10-秋:あき○:1/2 +1-11-電気:でんき○:1/3 +1-12-文学:ぶんがく○:1/4 +1-13-シャーベット:しゃーべっと○:1/5 +1-14-ケンモホロロ:けんもほろろ○:1/6 +1-15-呉越同舟:ごえつどうしゅう○:1/7 +1-16-花:はな○:2/2 +1-17-お菓子:おかし○:2/3 +1-18-雪国:ゆきぐに○:2/4 +1-19-普及率:ふきゅうりつ○:2/5 +1-20-お巡りさん:おまわりさん○:2/6 +1-21-男:おとこ○:3/3 +1-22-歳時記:さいじき○:3/4 +1-23-山登り:やまのぼり○:3/5 +1-24-金婚式:きんこんしき○:3/6 +1-25-副大統領:ふくだいとうりょう○:3/8 +1-26-弟:おとうと○:4/4 +1-27-小型バス:こがたばす○:4/5 +1-28-国語辞典:こくごじてん○:4/6 +1-29-私立大学:しりつだいがく○:4/7 +1-30-桃の花:もものはな○:5/5 +1-31-炭酸ガス:たんさんがす○:5/6 +1-32-幼年時代:ようねんじだい○:5/7 +1-33-大学院生:だいがくいんせい○:5/8 +1-34-十一月:じゅういちがつ○:6/6 +1-35-お願いします:おねがいします:6/7 +1-36-自動販売機:じどうはんばいき○:6/8 +1-37-携帯ストラップ:けいたいすとらっぷ:7/9 +1-38-宜しくお願いします:よろしくおねがいします:10/11 diff --git a/tofugu_files/src1.list b/tofugu_files/src1.list new file mode 100644 index 0000000..c31fd1b --- /dev/null +++ b/tofugu_files/src1.list @@ -0,0 +1,38 @@ +LH 名 な +LHH 水 みず +LHHH 会社 かいしゃ +LHHHH 大学 だいがく +LHHHHH 中国語 ちゅうごくご +LHHHHHH 見物人 けんぶつにん +LHHHHHHH 五十音順 ごじゅうおんじゅん +LHHHHHHHH いい加減にしろ いいかげんにしろ +HL 木 き +HLL 秋 あき +HLLL 電気 でんき +HLLLL 文学 ぶんがく +HLLLLL シャーベット しゃーべっと +HLLLLLL ケンモホロロ けんもほろろ +HLLLLLLL 呉越同舟 ごえつどうしゅう +LHL 花 はな +LHLL お菓子 おかし +LHLLL 雪国 ゆきぐに +LHLLLL 普及率 ふきゅうりつ +LHLLLLL お巡りさん おまわりさん +LHHL 男 おとこ +LHHLL 歳時記 さいじき +LHHLLL 山登り やまのぼり +LHHLLLL 金婚式 きんこんしき +LHHLLLLLL 副大統領 ふくだいとうりょう +LHHHL 弟 おとうと +LHHHLL 小型バス こがたばす +LHHHLLL 国語辞典 こくごじてん +LHHHLLLL 私立大学 しりつだいがく +LHHHHL 桃の花 もものはな +LHHHHLL 炭酸ガス たんさんがす +LHHHHLLL 幼年時代 ようねんじだい +LHHHHLLLL 大学院生 だいがくいんせい +LHHHHHL 十一月 じゅういちがつ +LHHHHHL お願いします おねがいします +LHHHHHLLL 自動販売機 じどうはんばいき +LHHHHHHLL 携帯ストラップ けいたいすとらっぷ +LHHHHHHHHHL 宜しくお願いします よろしくおねがいします diff --git a/tofugu_files/src2.list b/tofugu_files/src2.list new file mode 100644 index 0000000..b82089d --- /dev/null +++ b/tofugu_files/src2.list @@ -0,0 +1,9 @@ + HLL 箸 はし Chopsticks +LHL 橋 はし Bridge +HLL 神 かみ God +LHL 紙 かみ Paper +LHL 髪 かみ Hair +LHH 酒 さけ Alcohol +HLL 鮭 さけ Salmon +LHH 飴 あめ Candy +HLL 雨 あめ Rain