#!/usr/local/bin/perl
#原作 mikado ◆TsukilTBuQ  http://www.myjavaserver.com/~tsuki/data/measure.html
#改変 Hina＠虞美人草配列 http://www20.atwiki.jp/poppy/pages/14.html
#元の部分は殆ど使ってませんが残してあります。但し、三連以上を正しく計測しない
#という誤りが有りましたので、修正してあります。
#こういう数値化がしたいのだという御意見が有りましたら配布元にリンクを貼ったどこかに
#書かれると、そのうち見に行きます。面白かったら、気が向いた時にやってみますので。。。
#
#ライセンスに関して
#かなり長大になってしまいましたので、一応はっきりさせておきます。
#原作者にコンタクトがとれないのですが、たぶん問題は無かろうと公開します。
#(不都合が御座いましたら、原作部分は削除致しますので御連絡下さい。)
#また、ローマ字変換テーブルはkeybord layout benchmark
# http://www.asahi-net.or.jp/~EZ3K-MSYM/charsets/laycomp.htm
#からお借りしました。
#私の書いた部分についてはGNU GENERAL PUBLIC RICENCEとします。
#2006-11-04版
#========================変数入力=====================================
$text_name	= "kana-sample.txt";	#解析するテキストファイル。
$output		= "result1.txt";	#出力ファイル名。
$output2	= "result2.txt";	#指運詳細
unlink $output;
unlink $output2;	#ここをコメントアウトする(先頭に#をつける)と追記モードになる。

&yomikomi;
&kutouten;	#ここをコメントアウトすると句読点区切り無し。
&japanese;
#&english;
&matome;
EOF;

sub japanese{
$_=$text_b;&nicola;&sokutei;#不要な分はコメントアウト
$_=$text_b;&asuka ;&sokutei;#追加する場合は同じ書式で。
$_=$text_b;&koume ;&sokutei;
$_=$text_b;&sara  ;&sokutei;
$_=$text_b;&poppy ;&sokutei;
$_=$text_b;&ga698 ;&sokutei;
$_=$text_b;&tuki  ;&sokutei;
$_=$text_b;&rome  ;&sokutei;
}
sub english{
$_=$text_b;&qwerty  ;&sokutei;
$_=$text_b;&dvorak  ;&sokutei;
}

#========================キーボード変換===============================
sub qwerty{
$hairetumei="qwerty";
s/[A-Z]/1$&/g;
tr/A-Z/a-z/;
s/\?/L\//g;
s/1/L/g;
}
sub dvorak{
$hairetumei="dvorak";
s/[A-Z]/1$&/g;
tr/a-z/A-Z/;
s/\?/1\//g;
tr/,\.PYFGCRL\//wertyuiop`/;
tr/AOEUIDHTNS/asdfghjkl\;/;
tr/\;QJKXBMWVZ/zxcvbnm,\.\//;
s/1/R/g;
}
sub nicola{
$hairetumei="NICOLA";
s/。/q/g;s/か/w/g;s/た/e/g;s/こ/r/g;s/さ/t/g;s/ら/y/g;s/ち/u/g;s/く/i/g;s/つ/o/g;s/つ/p/g;s/、/`/g;
s/う/a/g;s/し/s/g;s/て/d/g;s/け/f/g;s/せ/g/g;s/は/h/g;s/と/j/g;s/き/k/g;s/い/l/g;s/ん/;/g;s/ん/:/g;
s/ん/z/g;s/ひ/x/g;s/す/c/g;s/ふ/v/g;s/へ/b/g;s/め/n/g;s/そ/m/g;s/ね/,/g;s/ほ/./g;s/・/\//g;s/・/\//g;

#要は打鍵列に置き換えるという事。LRはシフト。a-zのほか@;:.,/に対応。ただし「@」は「`」。
#「/」に置換するには「\/」である事に注意。(※QWERTY並びです。)

s/か/Rq/g;s/が/Rw/g;s/だ/Re/g;s/ご/Rr/g;s/ざ/Rt/g;s/ぱ/Ly/g;s/ぢ/Lu/g;s/ぐ/Li/g;s/づ/Lo/g;s/ぴ/Lp/g;s/ぴ/L`/g;
s/ヴ/Ra/g;s/じ/Rs/g;s/で/Rd/g;s/げ/Rf/g;s/ぜ/Rg/g;s/ば/Lh/g;s/ど/Lj/g;s/ぎ/Lk/g;s/ぽ/Ll/g;s/ぽ/L;/g;s/ぴ/Lo/g;
s/ぴ/Rz/g;s/び/Rx/g;s/ず/Rc/g;s/ぶ/Rv/g;s/べ/Rb/g;s/ぷ/Ln/g;s/ぞ/Lm/g;s/ぺ/L,/g;s/ぼ/L./g;s/ぼ/L\//g;
 
s/ぁ/Lq/g;s/え/Lw/g;s/り/Le/g;s/ゃ/Lr/g;s/れ/Lt/g;s/よ/Ry/g;s/に/Ru/g;s/る/Ri/g;s/ま/Ro/g;s/ぇ/Rp/g;
s/を/La/g;s/あ/Ls/g;s/な/Ld/g;s/ゅ/Lf/g;s/も/Lg/g;s/み/Rh/g;s/お/Rj/g;s/の/Rk/g;s/ょ/Rl/g;s/っ/R;/g;
s/ぅ/Lz/g;s/\Qー\E/Lx/g;s/ろ/Lc/g;s/や/Lv/g;s/ぃ/Lb/g;s/ぬ/Rn/g;s/ゆ/Rm/g;s/む/R,/g;s/わ/R./g;s/ぉ/R\//g;
s/「/e/g;s/」/r/g;s/？/R\//g;
$_;
}

sub ga698{
$hairetumei="2ch-698";
s|が|かDD|g;	s|ぎ|きDD|g;	s|ぐ|くDD|g;	s|げ|けDD|g;	s|ご|こDD|g;
s|ざ|さDD|g;	s|じ|しDD|g;	s|ず|すDD|g;	s|ぜ|せDD|g;	s|ぞ|そDD|g;
s|だ|たDD|g;	s|ぢ|ちDD|g;	s|づ|つDD|g;	s|で|てDD|g;	s|ど|とDD|g;
s|ば|はDD|g;	s|び|ひDD|g;	s|ぶ|ふDD|g;	s|べ|へDD|g;	s|ぼ|ほDD|g;
s|ぱ|はPP|g;	s|ぴ|ひPP|g;	s|ぷ|ふPP|g;	s|ぺ|へPP|g;	s|ぽ|ほPP|g;
s|ヴ|うDD|g;
#DD,PPはローカル
s/こ/q/g;s/な/w/g;s/と/e/g;s/け/r/g;s/ろ/t/g;s/む/y/g;s/る/u/g;s/い/i/g;s/の/o/g;s/れ/p/g;s/め/`/g;
s/た/a/g;s/て/s/g;s/て/d/g;s/か/f/g;s/は/g/g;s/っ/h/g;s/ん/j/g;s/ん/k/g;s/DD/l/g;s/し/;/g;s/\Qー\E/:/g;
s/す/z/g;s/ょ/x/g;s/せ/c/g;s/き/v/g;s/さ/b/g;s/く/n/g;s/う/m/g;s/、/,/g;s/。/./g;s/PP/\//g;s/・/\//g;

s/ぁ/kq/g;s/ね/kw/g;s/ゃ/ke/g;s/ほ/kr/g;s/ゆ/kt/g;s/ぬ/dy/g;s/わ/du/g;s/あ/di/g;s/に/do/g;s/ぇ/dp/g;s/「/d`/g;
s/ぃ/ka/g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g;s/ぜ/Rb/g;s/ね/Rn/g;s/み/Rm/g;s/ぢ/R,/g;s/ず/./g;s/げ/R\//g;
$_;
}
sub poppy{
$hairetumei="虞美人草3.1";
s|つ|o|g;	s|や|z|g;	s|ゆ|x|g;	s|よ|c|g;
s|が|Lか|g;	s|ぎ|Lき|g;	s|ぐ|Lく|g;	s|げ|Lk|g;	s|ご|Ll|g;
s|ざ|La|g;	s|じ|Lし|g;	s|ず|Ld|g;	s|ぜ|Lh|g;	s|ぞ|Lそ|g;
s|だ|Lた|g;	s|ぢ|Lち|g;	s|づ|Lっ|g;	s|で|Lて|g;	s|ど|Lと|g;
s|ば|Lj|g;	s|び|Lm|g;	s|ぶ|L;|g;	s|べ|Lr|g;	s|ぼ|Lv|g;

s/「/q/g;s/て/w/g;s/た/e/g;s/ま/r/g;s/へ/t/g;s/・/y/g;s/ち/u/g;s/し/i/g;s/っ/o/g;s/？/p/g; 
s/の/a/g;s/か/s/g;s/・/d/g;s/と/f/g;s/な/g/g;s/く/h/g;s/う/j/g;s/・/k/g;s/い/l/g;s/ん/;/g;s/\Qー\E/:/g;
s/ゃ/z/g;s/ゅ/x/g;s/ょ/c/g;s/に/v/g;s/そ/b/g;s/き/n/g;s/る/m/g;s/。/,/g;s/、/./g;s/」/\//g;
          s/れ/kw/g;s/あ/ke/g;s/え/kr/g;s/・/Lt/g;s/・/Ly/g;s/ぬ/du/g;s/り/di/g;s/お/do/g;s/・/dp/g;
s/さ/ka/g;s/も/ks/g;s/す/kd/g;s/ら/kf/g;s/せ/kg/g;s/み/dh/g;s/は/dj/g;s/け/dk/g;s/こ/dl/g;s/ふ/d;/g;
s/・/Lz/g;s/・/Lx/g;s/・/Lc/g;s/ほ/kv/g;s/・/Lb/g;s/・/dn/g;s/ひ/dm/g;
s/を/ds/g;s/わ/df/g;s/む/dv/g;s/め/kj/g;s/ろ/kl/g;s/ね/km/g;


s|ふぁ|dj|g;	s|ふぃ|dm|g;		s|ふぇ|t|g;	s|ふぉ|kv|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s|ぅ|kz|g;	s|ぇ|dp|g;	s|ぉ|d/|g;
s|ゃ|kb|g;	s|ゅ|kv|g;	s|ょ|t|g;	s|ヴ|jl|g;
s|っ|n|g;
s|「|d`|g;	s|」|d:|g;
s|、|,|g;	s|。|.|g;	s|\Qー\E|d.|g;
s|？|Ld/|g;	s|・|/|g;
$_;
}
sub rome{
$hairetumei="ローマ字";
	s/？/L\//g;
 s/きゃ/kya/g;  s/ぎゃ/gya/g;  s/しゃ/sha/g;  s/じゃ/ja/g;
    s/きゅ/kyu/g;  s/ぎゅ/gyu/g;  s/しゅ/shu/g;  s/じゅ/ju/g;
    s/きぇ/kye/g;  s/ぎぇ/gye/g;  s/しぇ/she/g;  s/じぇ/je/g;
    s/きょ/kyo/g;  s/ぎょ/gyo/g;  s/しょ/sho/g;  s/じょ/jo/g;

    s/ちゃ/cha/g;  s/ぢゃ/dya/g;  s/にゃ/nya/g;  s/ひゃ/hya/g;
    s/ちゅ/chu/g;  s/ぢゅ/dyu/g;  s/にゅ/nyu/g;  s/ひゅ/hyu/g;
    s/ちぇ/che/g;  s/ぢぇ/dye/g;  s/にぇ/nye/g;  s/ひぇ/hye/g;
    s/ちょ/cho/g;  s/ぢょ/dyo/g;  s/にょ/nyo/g;  s/ひょ/hyo/g;

    s/びゃ/bya/g;  s/ぴゃ/pya/g;  s/ふゃ/fya/g;  s/ヴゃ/vya/g;
    s/びゅ/byu/g;  s/ぴゅ/pyu/g;  s/ふゅ/fyu/g;  s/ヴゅ/vyu/g;
    s/びぇ/bye/g;  s/ぴぇ/pye/g;  s/ふぇ/fye/g;  s/ヴぇ/vye/g;
    s/びょ/byo/g;  s/ぴょ/pyo/g;  s/ふょ/fyo/g;  s/ヴょ/vyo/g;

    s/みゃ/mya/g;  s/りゃ/rya/g;
    s/みゅ/myu/g;  s/りゅ/ryu/g;
    s/みぇ/mye/g;  s/りぇ/rye/g;  s/いぇ/ye/g;
    s/みょ/myo/g;  s/りょ/ryo/g;

    s/てゃ/tha/g;  s/でゃ/dha/g;
    s/てぃ/thi/g;  s/でぃ/dhi/g;
    s/てゅ/thu/g;  s/でゅ/dhu/g;
    s/てぇ/the/g;  s/でぇ/dhe/g;
    s/てょ/tho/g;  s/でょ/dho/g;

    s/つぁ/tsa/g;  s/ふぁ/fa/g;  s/ヴぁ/va/g;
    s/つぃ/tsi/g;  s/ふぃ/fi/g;  s/ヴぃ/vi/g;  s/うぃ/wi/g;
    s/つぇ/tse/g;  s/ふぇ/fe/g;  s/ヴぇ/ve/g;  s/うぇ/we/g;
    s/つぉ/tso/g;  s/ふぉ/fo/g;  s/ヴぉ/vo/g;

    s/とぅ/twu/g;
    s/どぅ/dwu/g;

# not common conversions
#   s/すぃ/swi/g;
#   s/うぉ/who/g;
#   s/とぃ/twi/g;  s/どぃ/dwi/g;

    s/あ/a/g;  s/か/ka/g;  s/が/ga/g;  s/さ/sa/g;  s/ざ/za/g;
    s/い/i/g;  s/き/ki/g;  s/ぎ/gi/g;  s/し/si/g;  s/じ/ji/g;
    s/う/u/g;  s/く/ku/g;  s/ぐ/gu/g;  s/す/su/g;  s/ず/zu/g;
    s/え/e/g;  s/け/ke/g;  s/げ/ge/g;  s/せ/se/g;  s/ぜ/ze/g;
    s/お/o/g;  s/こ/ko/g;  s/ご/go/g;  s/そ/so/g;  s/ぞ/zo/g;

    s/た/ta/g; s/だ/da/g;  s/な/na/g;  s/は/ha/g;  s/ば/ba/g;
    s/ち/ti/g; s/ぢ/di/g;  s/に/ni/g;  s/ひ/hi/g;  s/び/bi/g;
    s/つ/tu/g; s/づ/du/g;  s/ぬ/nu/g;  s/ふ/fu/g;  s/ぶ/bu/g;
    s/て/te/g; s/で/de/g;  s/ね/ne/g;  s/へ/he/g;  s/べ/be/g;
    s/と/to/g; s/ど/do/g;  s/の/no/g;  s/ほ/ho/g;  s/ぼ/bo/g;

    s/ぱ/pa/g; s/ま/ma/g; s/ら/ra/g; s/や/ya/g;  s/わ/wa/g;
    s/ぴ/pi/g; s/み/mi/g; s/り/ri/g; 
    s/ぷ/pu/g; s/む/mu/g; s/る/ru/g; s/ゆ/yu/g;
    s/ぺ/pe/g; s/め/me/g; s/れ/re/g; 
    s/ぽ/po/g; s/も/mo/g; s/ろ/ro/g; s/よ/yo/g;  s/を/wo/g;

    s/ぁ/xa/g; s/ゃ/xya/g;
    s/ぃ/xi/g; s/ゅ/xyu/g;
    s/ぅ/xu/g; s/ょ/xyo/g; s/ヴ/vu/g;
    s/ぇ/xe/g;
    s/ぉ/xo/g;

    s/。/./g;
    s/、/,/g;
    s/・/\//g;
    s/「/`/g;
    s/」/:/g;
    s/　/ /g;

# not common conversions 
#   s/ゎ/xwa/g;

    if (/っ/) {
        s/っ([kgszjtchbpfrvw])/$1$1/g; # ccha, not tcha.
        s/っ/xtu/g;   # 「あっ」 etc.
    }

    s/ん([aiueonyん])/nn$1/g;
    s/ん/n/g;

    s/\Qー\E/;/g;
$_;
}

#========================読み込み=====================================
sub yomikomi{
#↓「異手」「同手同段」以外で押しやすい指運（特殊良指運）。
#　「|」で区切って入力してください。
$goodkey	= "ef|ra|ta|ar|at|av|ab|sv|sb|dv|sr|st|fq|fw|fe|fz|gq|gw|ge|gz|zf|zg|ca|va|vs|ba|bs|bd|uk|ul|u;|ij|i;|oj|pj|hi|ho|hp|ji|jo|jp|kp|;n|;m|ni|no|np|mo|mp";
unlink "measure_temp.txt";
open (FH,"<$text_name");
@textc=<FH>;
close(FH);
foreach (@textc) {$text_b .= $_;}
$text_b=~s/[0-9]/ /g;
$_;
}
sub kutouten{
$_=$text_b;
s/「/ 「/g;#句読点区切り
s/・/ ・/g;
s/。/。 /g;
s/、/、 /g;
s/？/？ /g;
s/」/」 /g;
$text_b=$_;
$_;
}
#===============================測定====================
sub sokutei{
print "$_\n\n$hairetumeiを計測中\n";	#うまく変換できているか目視で確認。
s|[^a-zA-Z,\./`;:]| |g;	#変換できなかった部分の除去。打鍵の切れ目とする。
s/(　| ){1,}/S/g;
$text=$_;s|[^RL]|0|g;	#親指打鍵のカウント
$s='';$u='';
for($t=0;$t<length($_);$t+=2){
$s.=substr($_,$t,1);
$u.=substr($_,$t+1,1);
}
$_=$s."SS".$u;
s/LL/L1/g;s/1L/11/g;
s/RR/R2/g;s/2R/22/g;
s/[^12]//g;
$shift2=length($_);
$_=$text;
s|[^RL]||g;
$shift=length($_);
$_=$text;
s/R|L//g;
$text = $_;

#ここから計算
s|S||g;
$dtext =$_;

#========================打鍵数計測===================================
$daken = length($dtext);
$p_daken= length($dtext)-(length($text)-length($dtext))-1;

#========================交互計測===================================
$ttext = $text;
$ttext =~ s|[qwertyasdfgzxcvb]|0|g;
$ttext =~ s|[yuiop\`hjkl;:nm,\./]|1|g;

#左手→右手
$lrtext = $ttext;
$lrtext =~ s/01/a/g;
$lrtext =~ s/[^a]//g;
$lratext = length($lrtext);

#右手→左手
$rltext = $ttext;
$rltext =~ s/10/a/g;
$rltext =~ s/[^a]//g;
$rlatext = length($rltext);

#左手→左手
$lltext = $ttext;
$lltext =~ s/10/a/g;
$lltext =~ s/S0/a/g;
$lltext =~ s/[^0]//g;
$llatext = length($lltext);

#右手→右手
$rrtext = $ttext;
$rrtext =~ s/01/a/g;
$rrtext =~ s/S1/a/g;
$rrtext =~ s/[^1]//g;
$rratext = length($rrtext);

$kougo = $lratext+$rlatext;			#交互打鍵数 = (右手→左手)+(左手→右手)
$p_kougo = int $kougo/$p_daken*1000;	#交互率 = (交互打鍵/全打鍵)。※小数点以下切捨ての為1000倍した。
$p_kougo = $p_kougo/10;				#桁合わせ

#片手三連以上を計測。
$_=$ttext;
s/0000000000000000000000000000000/a/g;#31
s/000000000000000000000000/b/g;#24
s/000000000000000000/c/g;#18
s/0000000000000/d/g;#13
s/000000000/e/g;#9
s/000000/f/g;#6
s/0000/g/g;#4
s/000/h/g;#3
s/00/i/g;#2
s/1111111111111111111111111111111/j/g;#31
s/111111111111111111111111/k/g;#24
s/111111111111111111/l/g;#18
s/1111111111111/m/g;#13
s/111111111/n/g;#9
s/111111/o/g;#6
s/1111/p/g;#4
s/111/q/g;
s/11/r/g;
s/g0/g/g;s/p1/p/g;
s/f0|fi/f/g;s/o1|or/o/g;
s/e0|ei|eh/e/g;s/n1|nr|nq/n/g;
s/d[0ihg]/d/g;s/m[1rqp]/m/g;
s/c[0ihg]/c/g;s/l[1rqp]/l/g;
s/b[0ihgf]/b/g;s/k[1rqpo]/k/g;
s/aa/a/g;s/jj/j/g;
s/a[0ihgfedcba]/a/g;s/j[1rqponmlkj]/j/g;
#94連以上は計測がおかしくなりますが、まあ良いでしょうw

$t=$_;	s/[^0]//g;	$l1t=length($_);
$_=$t;	s/[^1]//g;	$r1t=length($_);
$_=$t;	s/[^a]//g;	$l31t=length($_);
$_=$t;	s/[^b]//g;	$l24t=length($_);
$_=$t;	s/[^c]//g;	$l18t=length($_);
$_=$t;	s/[^d]//g;	$l13t=length($_);
$_=$t;	s/[^e]//g;	$l9t=length($_);
$_=$t;	s/[^f]//g;	$l6t=length($_);
$_=$t;	s/[^g]//g;	$l4t=length($_);
$_=$t;	s/[^h]//g;	$l3t=length($_);
$_=$t;	s/[^i]//g;	$l2t=length($_);
$_=$t;	s/[^j]//g;	$r31t=length($_);
$_=$t;	s/[^k]//g;	$r24t=length($_);
$_=$t;	s/[^l]//g;	$r18t=length($_);
$_=$t;	s/[^m]//g;	$r13t=length($_);
$_=$t;	s/[^n]//g;	$r9t=length($_);
$_=$t;	s/[^o]//g;	$r6t=length($_);
$_=$t;	s/[^p]//g;	$r4t=length($_);
$_=$t;	s/[^q]//g;	$r3t=length($_);
$_=$t;	s/[^r]//g;	$r2t=length($_);
#==================外縁を挟む連打==================
$_=$text;
s/[qtgbzxc]/0/g;
s/[yh,\.\/p`:]/1/g;
s/[werasdfv]/2/g;
s/[uiojkl\;nm]/3/g;
s/[02]0[02]/($1)4($2)/g;s/[13]1[13]/($1)5($2)/g;
s/[02]0[02]/($1)4($2)/g;s/[13]1[13]/($1)5($2)/g;
s/[^45]//g;
$gaiengaien=length($_);

#========================アルペジオ計測=============================
#アルペジオ = （同列打鍵）-（同列同指打鍵）
#まずは「同列同指打鍵」数
$_ = $text;
s/aa|bb|cc|dd|ee|ff|gg|hh|ii|jj|kk|ll|mm|nn|oo|pp|qq|rr|ss|tt|uu|vv|ww|xx|yy|zz|,,|\.\.|;;|\/\/|``|::|rt|tr|fg|gf|vb|bv|yu|uy|hj|jh|nm|mn|p`|`p|;:|:;/7/g;
s/[^7]//g;				#一旦「7」と置いてから関係無いものを取り除く
$btext = length($_);	#同列同指打鍵数（同列だけどアルペジオでない）

#次に「同列打鍵」数
$_ = $text;
s|[qwert]|0|g;	s|[asdfg]|1|g;	s|[zxcvb]|2|g;
s|[yuiop`]|3|g;	s|[hjkl;:]|4|g;	s|[nm,\./]|5|g;

s/(00)|(11)|(22)|(33)|(44)|(55)/7/g;	#同列打鍵を「7」と置いておく
s/[^7]//g;								#「7」以外を取り除いたものが同列数
$barp = length($_);						#同列打鍵数（アルペジオ＋同指）


#アルペジオ = （同列打鍵）-（同列同指打鍵）
$arpeggio = $barp - $btext; #アルペジオ数

$arpeggio = length($_);					#アルペジオ数
$p_arpeggio = int $arpeggio/$p_daken*1000;
$p_arpeggio = $p_arpeggio/10;			#アルペジオ率
#=====================片手良指運測定=====================

$_=$text;
s/re|rw|ra|fe|fw|fd|fs|fa|vd|vs|va|vc|vx|vz|ui|uo|u;|ji|jo|jk|jl|j;|mk|ml|m;|m,|m\.|m\//0/g;
s/[^0]//g;
$goodconv=length($_);#人差指から
$_=$text;
s/er|ef|ew|ea|df|ds|da|dv|cv|cx|cz|iu|io|ij|i;|kj|kl|k;|km|,m|,\.|,\//0/g;
s/[^0]//g;
$goodconv+=length($_);#中指から
$_=$text;
s/wr|we|wf|sf|sd|sv|xv|xc|ou|oi|oj|lj|lk|lm|\.m|\.,/0/g;
s/[^0]//g;
$goodconv+=length($_);#薬指から
$_=$text;
s/ae|ar|ad|af|av|zd|zf|zc|zv|;i|;j|;k|;n|;m|\/j|\/k|\/m|\/,/0/g;
s/[^0]//g;
$goodconv+=length($_);#小指から



#========================特殊良指運計測=============================
$good = $text;
$good =~ s/$goodkey/7/g;
$good =~ s/[^7]//g;

$good = length($good);	#特殊良指運数
$p_good = int $good/$p_daken*1000;
$p_good = $p_good/10;	#特殊良指運率

#=================連接詳細測定====================================
#|で区切られた区間が一つの鍵からの連接。
#先頭はその鍵自身、次の四つは同指異鍵に予約、あと五つまで設定できます。スペースで区切ります。
$_ ='q a z   wer f t sdgv xcb|w s x   erf t adg v qzcb|e d c   wf ar tsgv q zxb|r f t g vb we a q sdz xc|t f r g vb wea q sd z xc|a z q   edf wrsgv t xc b|s x w   df agv er tcb qz|d c e   sfv ag qwrt zx b|f v gr b t we asd z q xc|g f v b rt wea sd z q xc|z a q   dfv g xcb we rt|x s w   cv fzb adg e qrt|c d e   xv zb asf werg qt|v f b g rt asd zxc w e q|b f v g rt asd z xc we q|y j u h nm io\; p kl \,\.\/ \`\:|u j h y nm oi p\; kl \,\.\/ \`\:|i k \,   oj\; hnm up\: y\` \,\.\/|o l \.   ij hnm\; up y\`\: \,\.\/|p \; \` \: \/ ij uoh nmk yl \,\.|\` \; p \: \/ ioj uh nm kl y\,\.|h j n m uy io\; kl \,\.\/ p \`\:|j m n h yu io kl\; p \`\: \,\.\/|k \, i   jlm h\;n o yup\:\` \.\/|l \. o   jk\; nm hi\: yup\` \,\/|\; \: / p \` ijk ol nm huy \,\.\/|\: \; p \` \/ jklm io yuh n \,\.|n j m h yu io kl\; p \`\: \,\.\/|m j n h yu kl\; io \,\.\/ p \`\:|\, k i   m\.\/ nl\; j\: hio yup\`|\. l o   m\,\/ njk hui\; p y\`\:|\/ \; \: p \` m\,\. nkl j hio yu';
@rensetu=split(/\|/,$_);
@rensetu_r=@rensetu;
$ren_all='';
foreach(@rensetu){
@x=split(/ /,$_);
$y=@x[0];
$_=$text;
s|$y$y|0($y)|g;	s|($y)0|00|g;s|$y$y|0($y)|g;
s|[^0]||g;
$_=length($_);
$ren{$y}="\|$y\|$_\|";
$doukagi_from{$y}=$_;
$douyubi_from{$y}=0;
for($z=1;$z<5;$z+=1){
if(@x[$z] eq ''){@x[$z]=' ';$_=' '}else{
$_=$text;
s|($y)[@x[$z]]|0|g;
s/[^0]//g;
$_=length($_);
$douyubi_from{$y}+=$_;
}
$ren{$y}.=@x[$z]."\|$_\|";
}
$doute_from{$y}=0;
$ren_2{$y}='';
for($z=5;$z<@x;$z+=1){
$_=$text;
s|($y)[@x[$z]]|0|g;
s/[^0]//g;$_=length($_);
$doute_from{$y}+=$_;
$ren_2{$y}.="@x[$z]\|$_\|";
}
$_=$text;
s/[^$y]//g;
$_=length($_);
$t=$_-$doukagi_from{$y}-$douyubi_from{$y}-$doute_from{$y};
$ren{$y}.="$douyubi_from{$y}\|$t\|$_\|$doute_from{$y}\|$ren_2{$y}";
$ren_all.=$ren{$y}."\n";
}

$doute_from_gaien=$doute_from{'q'}+$doute_from{'t'}+$doute_from{'y'}+$doute_from{'p'}+$doute_from{'\`'}+$doute_from{'g'}+$doute_from{'h'}+$doute_from{'\:'}+$doute_from{'z'}+$doute_from{'x'}+$doute_from{'c'}+$doute_from{'b'}+$doute_from{'\,'}+$doute_from{'\.'}+$doute_from{'\/'};
$douyubi_from_gaien=$douyubi_from{'q'}+$douyubi_from{'t'}+$douyubi_from{'y'}+$douyubi_from{'p'}+$douyubi_from{'\`'}+$douyubi_from{'g'}+$douyubi_from{'h'}+$douyubi_from{'\:'}+$douyubi_from{'z'}+$douyubi_from{'x'}+$douyubi_from{'c'}+$douyubi_from{'b'}+$douyubi_from{'\,'}+$douyubi_from{'\.'}+$douyubi_from{'\/'};
$doukagi_from_gaien=$doukagi_from{'q'}+$doukagi_from{'t'}+$doukagi_from{'y'}+$doukagi_from{'p'}+$doukagi_from{'\`'}+$doukagi_from{'g'}+$doukagi_from{'h'}+$doukagi_from{'\:'}+$doukagi_from{'z'}+$doukagi_from{'x'}+$doukagi_from{'c'}+$doukagi_from{'b'}+$doukagi_from{'\,'}+$doukagi_from{'\.'}+$doukagi_from{'\/'};
$douyubi_from_gaien+=$doukagi_from_gaien;
$doute_from_gaien+=$douyubi_from_gaien;
#連接元計測
$ren_r_all='';
$douyubi_ikagi=0;
$douyubi_doukagi=0;
foreach(@rensetu_r){
@x=split(/ /,$_);
$y=@x[0];

$_=$text;
s|$y$y|($y)0|g;	s|0$y|00|g;
s|[^0]||g;
$_=length($_);
$ren_r{$y}="\|$y\|$_\|";
$doukagi_to{$y}=$_;
$douyubi_to{$y}=0;
for($z=1;$z<5;$z+=1){
if(@x[$z] eq ''){@x[$z]=' ';$_=' '}else{
$_=$text;
s|[@x[$z]]$y|0|g;
s/[^0]//g;
$_=length($_);
$douyubi_to{$y}+=$_;
}
$ren_r{$y}.=@x[$z]."\|$_\|";
}
$doute_to{$y}=0;
$ren_r2{$y}='';
for($z=5;$z<@x;$z+=1){
$_=$text;
s|[@x[$z]]$y|0|g;
s/[^0]//g;$_=length($_);
$doute_to{$y}+=$_;
$ren_r2{$y}.="@x[$z]\|$_\|";
}
$_=$text;
s/[^$y]//g;
$_=length($_);
$t=$_-$doukagi_to{$y}-$douyubi_to{$y}-$doute_to{$y};
$ren_r{$y}.="$douyubi_to{$y}\|$t\|$_\|$doute_to{$y}\|$ren_r2{$y}";
$ren_r_all.=$ren_r{$y}."\n";
$douyubi_ikagi+=$douyubi_to{$y};
$douyubi_doukagi+=$doukagi_to{$y};
}

$douyubi_to_outer=$douyubi_to{'q'}+$douyubi_to{'w'}+$douyubi_to{'e'}+$douyubi_to{'r'}+$douyubi_to{'t'}+$douyubi_to{'g'}+$douyubi_to{'b'}+$douyubi_to{'y'}+$douyubi_to{'u'}+$douyubi_to{'i'}+$douyubi_to{'o'}+$douyubi_to{'p'}+$douyubi_to{'\`'}+$douyubi_to{'h'}+$douyubi_to{'\:'};
$douyubi_to_home=$douyubi_to{'a'}+$douyubi_to{'s'}+$douyubi_to{'d'}+$douyubi_to{'f'}+$douyubi_to{'j'}+$douyubi_to{'k'}+$douyubi_to{'l'}+$douyubi_to{'\;'};
$douyubi_to_bot=$douyubi_to{'z'}+$douyubi_to{'x'}+$douyubi_to{'c'}+$douyubi_to{'v'}+$douyubi_to{'n'}+$douyubi_to{'m'}+$douyubi_to{'\,'}+$douyubi_to{'\.'}+$douyubi_to{'\/'};
$douyubi_Lko=$douyubi_to{'q'}+$douyubi_to{'a'}+$douyubi_to{'z'};
$douyubi_Lkusuri=$douyubi_to{'w'}+$douyubi_to{'s'}+$douyubi_to{'x'};
$douyubi_Lnaka=$douyubi_to{'e'}+$douyubi_to{'d'}+$douyubi_to{'c'};
$douyubi_Lsasi=$douyubi_to{'r'}+$douyubi_to{'t'}+$douyubi_to{'f'}+$douyubi_to{'g'}+$douyubi_to{'v'}+$douyubi_to{'b'};
$douyubi_Rsasi=$douyubi_to{'y'}+$douyubi_to{'u'}+$douyubi_to{'h'}+$douyubi_to{'j'}+$douyubi_to{'n'}+$douyubi_to{'m'};
$douyubi_Rnaka=$douyubi_to{'i'}+$douyubi_to{'k'}+$douyubi_to{'\,'};
$douyubi_Rkusuri=$douyubi_to{'o'}+$douyubi_to{'l'}+$douyubi_to{'\.'};
$douyubi_Rko=$douyubi_to{'p'}+$douyubi_to{'\`'}+$douyubi_to{'\;'}+$douyubi_to{'\:'}+$douyubi_to{'\/'};
$doute_to_gaien=$doute_to{'q'}+$doute_to{'t'}+$doute_to{'y'}+$doute_to{'p'}+$doute_to{'\`'}+$doute_to{'g'}+$doute_to{'h'}+$doute_to{'\:'}+$doute_to{'z'}+$doute_to{'x'}+$doute_to{'c'}+$doute_to{'b'}+$doute_to{'\,'}+$doute_to{'\.'}+$doute_to{'\/'};
$douyubi_to_gaien=$douyubi_to{'q'}+$douyubi_to{'t'}+$douyubi_to{'y'}+$douyubi_to{'p'}+$douyubi_to{'\`'}+$douyubi_to{'g'}+$douyubi_to{'h'}+$douyubi_to{'\:'}+$douyubi_to{'z'}+$douyubi_to{'x'}+$douyubi_to{'c'}+$douyubi_to{'b'}+$douyubi_to{'\,'}+$douyubi_to{'\.'}+$douyubi_to{'\/'};
$doukagi_to_gaien=$doukagi_to{'q'}+$doukagi_to{'t'}+$doukagi_to{'y'}+$doukagi_to{'p'}+$doukagi_to{'\`'}+$doukagi_to{'g'}+$doukagi_to{'h'}+$doukagi_to{'\:'}+$doukagi_to{'z'}+$doukagi_to{'x'}+$doukagi_to{'c'}+$doukagi_to{'b'}+$doukagi_to{'\,'}+$doukagi_to{'\.'}+$doukagi_to{'\/'};
$douyubi_to_gaien+=$doukagi_to_gaien;
$doute_to_gaien+=$douyubi_to_gaien;
#========================同指打鍵計測=============================

$douyubi=$douyubi_doukagi+$douyubi_ikagi;
#&douy;
$p_douyubi = int $douyubi/$p_daken*1000;
$p_douyubi = $p_douyubi/10;	#同指打鍵率
$p_douyubi_ikagi = int $douyubi_ikagi/$p_daken*1000;
$p_douyubi_ikagi = $p_douyubi_ikagi/10;
sub douy{#検算のためにつくったルーチン
$_=$text;
s/[qaz]/1/g;
s/[wsx]/2/g;
s/[edc]/3/g;
s/[rfvtgb]/4/g;
s/[yhnujm]/5/g;
s/[ik,]/6/g;
s/[ol\.]/7/g;
s/[p\;\/`:]/8/g;
for($t=1;$t<9;$t+=1){
s/($t)($t)/($t)9/g;
s/9($t)/99/g;
s/9/9 /g;
}
s/[^9]//g;
$douyubi=length($_);
$douyubi_ikagi=$douyubi-$douyubi_doukagi;
$_=$text;
}
#========================同手跳躍計測=============================
#同手跳躍
$_ = $text;
s|[qwert][zxcvb]|7|g;
s|[yuiop`][nm,\./]|7|g;
s/[^7]//g;
$jump_qz = length($_);

$_ = $text;
s|[zxcvb][qwert]|7|g;
s|[nm,\./][yuiop`]|7|g;
s/[^7]//g;
$jump_zq = length($_);

$jump = $jump_zq+$jump_qz;	#同手跳躍数
$p_jump = int $jump/$p_daken*1000;
$p_jump = $p_jump/10;	#同手跳躍計測率

#良跳躍
$_=$text;
s/in|on|im|om|wv|ev/7/g;
s/[^7]//g;
$g_jump=length($_);
$_=$text;
s/ni|mi|no|mo|vw|ve/7/g;
s/[^7]//g;
$g_jump+=length($_);
$p_g_jump = int $g_jump/$p_daken*1000;
$p_g_jump = $p_g_jump/10;	

#同指跳躍
$_ = $text;
s/qz|wx|ec|rv|tv|rb|tb|yn|un|ym|um|i,|o\.|p\/|`\//7/g;
s/[^7]//g;
$doujump_qz = length($_);

$_ = $text;
s/zq|xw|ce|vr|vt|br|bt|ny|nu|my|mu|,i|\.o|\/p|\/`/7/g;
s/[^7]//g;
$doujump_zq = length($_);

$doujump = $doujump_zq+$doujump_qz;	#同指跳躍数
$p_doujump = int $doujump/$p_daken*1000;
$p_doujump = $p_doujump/10;	#同指跳躍率


#========================左手縦連計測=============================
$_ = $text;
s/wz|ex|rc/7/g;
s/[^7]//g;
$juuren_qz = length($_);

$_ = $text;
s/zw|xe|cr/7/g;
s/[^7]//g;
$juuren_zq = length($_);

$juuren = $juuren_zq+$juuren_qz;	#左手縦連数
$p_juuren = int $juuren/$p_daken*1000;
$p_juuren = $p_juuren/10;	#左手縦連率


#========================微悪指運計測=============================
$etc =$p_daken - $kougo - $arpeggio - $good - $jump;#上のどれにも含まれないのが微悪指運数
$p_etc = int $etc/$p_daken*1000;
$p_etc = $p_etc/10;	#微悪指運率


#========================良・中・悪指運まとめ=============================
$ryou = $kougo + $arpeggio + $good;
$p_ryou = $p_kougo + $p_arpeggio + $p_good;

#========================各指の使用頻度計測=============================
sub c{
	#各指の打鍵数
	$c{$_[0]} = $text;
	$c{$_[0]}=~s/[^($_[0])]//g;
	$c{$_[0]}=length($c{$_[0]});
	#各指の打鍵率
#	$d{$_[0]}=int $c{$_[0]}/$p_daken*1000;
#	$d{$_[0]}=$d{$_[0]}/10;
#	$d{$_[0]}.="%";
}
&c('a'); &c('b'); &c('c'); &c('d'); &c('e'); &c('f'); &c('g');
&c('h'); &c('i'); &c('j'); &c('k'); &c('l'); &c('m'); &c('n');
&c('o'); &c('p'); &c('q'); &c('r'); &c('s'); &c('t'); &c('u');
&c('v'); &c('w'); &c('x'); &c('y'); &c('z');
&c(','); &c('.'); &c(';'); &c('`'); &c(':'); &c('/');

#横合計
$et=$c{'q'}+$c{'w'}+$c{'e'}+$c{'r'}+$c{'t'}+$c{'y'}+$c{'u'}+$c{'i'}+$c{'o'}+$c{'p'}+$c{'`'};
$ee=$c{'a'}+$c{'s'}+$c{'d'}+$c{'f'}+$c{'g'}+$c{'h'}+$c{'j'}+$c{'k'}+$c{'l'}+$c{';'}+$c{':'};
$eb=$c{'z'}+$c{'x'}+$c{'c'}+$c{'v'}+$c{'b'}+$c{'n'}+$c{'m'}+$c{','}+$c{'.'}+$c{'/'};
$ea=$et+$ee+$eb;

$pt=int($et/$ea*1000)/10;
$pe=int($ee/$ea*1000)/10;
$pb=int($eb/$ea*1000)/10;
$pa=$pt+$pe+$pb;
#縦合計
$tq=$c{'q'}+$c{'a'}+$c{'z'}; $tw=$c{'w'}+$c{'s'}+$c{'x'}; $te=$c{'e'}+$c{'d'}+$c{'c'};
$tr=$c{'r'}+$c{'f'}+$c{'v'}; $tt=$c{'t'}+$c{'g'}+$c{'b'}; $ty=$c{'y'}+$c{'h'}+$c{'n'};
$tu=$c{'u'}+$c{'j'}+$c{'m'}; $ti=$c{'i'}+$c{'k'}+$c{','}; $to=$c{'o'}+$c{'l'}+$c{'.'};
$tp=$c{'p'}+$c{';'}+$c{'/'}; $tnob=$c{'`'}+$c{':'};
$trt=$tr+$tt;$tyu=$ty+$tu;$tp2=$tp+$tnob;
$pq=int($tq/$ea*1000)/10;
$pw=int($tw/$ea*1000)/10;
$pee=int($te/$ea*1000)/10;
$prt=int(($trt)/$ea*1000)/10;
$pyu=int(($tyu)/$ea*1000)/10;
$pi=int($ti/$ea*1000)/10;
$po=int($to/$ea*1000)/10;
$pp=int(($tp2)/$ea*1000)/10;
$xm=$c{'a'}+$c{'s'}+$c{'d'}+$c{'f'}+$c{'j'}+$c{'k'}+$c{'l'}+$c{';'};
$xn=$c{'w'}+$c{'e'}+$c{'i'}+$c{'o'};
$xo=$c{'v'}+$c{'n'}+$c{'m'};
$xp=$c{'g'}+$c{'h'};
$xq=$c{'r'}+$c{'t'}+$c{'u'};
$xr=$c{'z'}+$c{'x'}+$c{'c'}+$c{','}+$c{'.'}+$c{'/'};
$xs=$c{'b'}+$c{'q'}+$c{'p'}+$c{'y'}+$c{'`'}+$c{':'};

$not_xm=$ea-$xm;
$not_xn=$not_xm-$xn;
$not_xo=$not_xn-$xo;
$not_xp=$not_xo-$xp;
$not_xq=$not_xp-$xq;
$not_xr=$not_xq-$xr;
$not_xs=$not_xr-$xs;

$pxm=int($xm/$ea*1000)/10;
$pxn=int(($xm+$xn)/$ea*1000)/10;
$pxo=int(($xm+$xn+$xo)/$ea*1000)/10;
$pxp=int(($xm+$xn+$xo+$xp)/$ea*1000)/10;
$pxq=int(($xm+$xn+$xo+$xp+$xq)/$ea*1000)/10;
$pxr=int(($xm+$xn+$xo+$xp+$xq+$xr)/$ea*1000)/10;
$pxs=int(($xm+$xn+$xo+$xp+$xq+$xr+$xs)/$ea*1000)/10;
$daken_s=$daken+$shift;
$not_kougo=$llatext+$rratext;
$taisyou=$kougo+$not_kougo;
$utikiri=$daken-$taisyou;
#========================書き出し=====================================
open (FH,">>measure_temp.txt");
print FH <<_HTML_;
配列	$hairetumei
文字領域	$daken
シフト	$shift
　連続	$shift2
打鍵数計	$daken_s
(打ち切り)	$utikiri
　連接性	$hairetumei
評価の対象	$taisyou
交互打鍵数	$kougo
　左→右	$lratext
　右→左	$rlatext
同手連打数	$not_kougo
　左→左	$llatext
　右→右	$rratext
片手良指運	$goodconv
片手連打	$hairetumei
　外縁から	$doute_from_gaien
　　同指	$douyubi_from_gaien
　外縁へ	$doute_to_gaien
　　同指	$douyubi_to_gaien
外縁を挟む	$gaiengaien
左単打	$l1t
左二連	$l2t
左三連	$l3t
左4-5連	$l4t
左6-8連	$l6t
左9-12連	$l9t
左13-17連	$l13t
左18-23連	$l18t
左24-30連	$l24t
左31以上	$l31t
片手連続	$hairetumei
右31以上	$r31t
右24-30連	$r24t
右18-23連	$r18t
右13-17連	$r13t
右9-12連	$r9t
右6-8連	$r6t
右4-5連	$r4t
右三連	$r3t
右二連	$r2t
右単打	$r1t
跳躍	$hairetumei
同手跳躍数	$jump
　良跳躍数	$g_jump
　左手縦連	$juuren
　同指跳躍	$doujump
同指打鍵	$hairetumei
同指打鍵数	$douyubi
　同指異鍵	$douyubi_ikagi
　　外側へ	$douyubi_to_outer
　ホームヘ	$douyubi_to_home
　　下段へ	$douyubi_to_bot
　　左小指	$douyubi_Lko
　　左薬指	$douyubi_Lkusuri
　　左中指	$douyubi_Lnaka
　右人差指	$douyubi_Lsasi
　右人差指	$douyubi_Rsasi
　　右中指	$douyubi_Rnaka
　　右薬指	$douyubi_Rkusuri
　　右小指	$douyubi_Rko
打鍵分布	$hairetumei
　上段	$et
　中段	$ee
　下段	$eb
指別	$hairetumei
　左小	$tq
　左薬	$tw
　左中	$te
　左指	$trt
　右指	$tyu
　右中	$ti
　右薬	$to
　右小	$tp2
鍵別	$hairetumei
ASDFJKL;	$xm
残り	$not_xm
ＷＥＩＯ	$xn
残り	$not_xn
ＶＮＭ	$xo
残り	$not_xo
ＧＨ	$xp
残り	$not_xp
ＲＴＵ	$xq
残り	$not_xq
ZXC,\./	$xr
残り	$not_xr
配 列	$hairetumei
_HTML_
close FH;
open (FH,">>$output");
print FH <<_HTML_;

$hairetumei	$text_name
|小|薬|中|人|伸　||伸|人|中|薬|小|伸|合計||
|$c{'q'}|$c{'w'}|$c{'e'}|$c{'r'}|$c{'t'}|上|$c{'y'}|$c{'u'}|$c{'i'}|$c{'o'}|$c{'p'}|$c{'`'}|$et|$pt%|
|$c{'a'}|$c{'s'}|$c{'d'}|$c{'f'}|$c{'g'}|中|$c{'h'}|$c{'j'}|$c{'k'}|$c{'l'}|$c{';'}|$c{':'}|$ee|$pe%|
|$c{'z'}|$c{'x'}|$c{'c'}|$c{'v'}|$c{'b'}|下|$c{'n'}|$c{'m'}|$c{','}|$c{'.'}|$c{'/'}|0|$eb|$pb%|
|$tq|$tw|$te|$tr|$tt|計|$ty|$tu|$ti|$to|$tp|$tnob|$ea|$pa%|
|$pq%|$pw%|$pee%|$prt%||||$pyu%|$pi%|$po%|$pp%|シフ|ト|$shift|

_HTML_
close FH;
open (FH,">>$output2");
print FH <<_HTML_;
$hairetumei	$text_name
連接(異動先)
|鍵|同鍵|||同|指|違|鍵|||小計|同手以外|合計|小計|||同|手|違|指||||| 
$ren_all

連接(異動元)
|鍵|同鍵|||同|指|違|鍵|||小計|同手以外|合計|小計|||同|手|違|指||||| 
$ren_r_all
_HTML_
close FH;
$_;
}
sub matome{
print "\n\n集計中\n";
open(FH,"<measure_temp.txt");
@a=<FH>;
close (FH);
$q=0;$p=0;
for($t=0;$t<@a;$t+=1){
if(@a[$t]=~/配列/){$q+=1;if($p<10){$p=$t-$p}}
}
open(OUT,"<$output");
@d=<OUT>;
close(OUT);
open(OUT,">$output");
print OUT "\n$text_name\n";
for($t=0;$t<$p;$t+=1){
$_="";
for($s=0;$s<$q;$s+=1){
$_.=@a[$t+$p*$s];
}
s|(\n)|\t|g;
s|\t\t|\t|g;
@b=split(/\t/,$_);
$c=@b[0];
for($s=1;$s<@b;$s+=2){
$c.="\t@b[$s]";
}

$_="\|$c\|";
s/\t/\|/g;
$_.="\n";
print OUT $_;
}
print OUT @d; 
close(OUT);
$_;
}