Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use utf8;
- use open qw(:utf8);
- use Encode qw(encode_utf8 decode_utf8);
- use JSON;
- BEGIN {
- binmode(STDIN, ":utf8");
- binmode(STDOUT, ":utf8");
- binmode(STDERR, ":utf8");
- # Load the 6-character term table.
- open $FH_6, "<", "ITDict_6_ts.json";
- binmode($FH_6, ":utf8");
- $IT_term_6_ts_ref = decode_json encode_utf8(<$FH_6>);
- %IT_term_6_ts = %$IT_term_6_ts_ref;
- $check_6 = join "|", keys %IT_term_6_ts;
- close $FH_6;
- # Load the 5-character term table.
- open $FH_5, "<", "ITDict_5_ts.json";
- binmode($FH_5, ":utf8");
- $IT_term_5_ts_ref = decode_json encode_utf8(<$FH_5>);
- %IT_term_5_ts = %$IT_term_5_ts_ref;
- $check_5 = join "|", keys %IT_term_5_ts;
- close $FH_5;
- # Load the 4-character term table.
- open $FH_4, "<", "ITDict_4_ts.json";
- binmode($FH_4, ":utf8");
- $IT_term_4_ts_ref = decode_json encode_utf8(<$FH_4>);
- %IT_term_4_ts = %$IT_term_4_ts_ref;
- $check_4 = join "|", keys %IT_term_4_ts;
- close $FH_4;
- # Load the 3-character term table.
- open $FH_3, "<", "ITDict_3_ts.json";
- binmode($FH_3, ":utf8");
- $IT_term_3_ts_ref = decode_json encode_utf8(<$FH_3>);
- %IT_term_3_ts = %$IT_term_3_ts_ref;
- $check_3 = join "|", keys %IT_term_3_ts;
- close $FH_3;
- # Load the 2-character term table.
- open $FH_2, "<", "ITDict_2_ts.json";
- binmode($FH_2, ":utf8");
- $IT_term_2_ts_ref = decode_json encode_utf8(<$FH_2>);
- %IT_term_2_ts = %$IT_term_2_ts_ref;
- $check_2 = join "|", keys %IT_term_2_ts;
- close $FH_2;
- # Load the character table.
- open $FH, "<", "tongwei_ts.json";
- binmode($FH, ":utf8");
- $tongwei_ts_ref = decode_json encode_utf8(join "", <$FH>);
- %tongwei_ts = %$tongwei_ts_ref;
- $check = join "|", keys %tongwei_ts;
- close $FH;
- }
- # Decode the input string.
- $_ = decode_utf8 $_;
- # Perform term-to-term conversion.
- s/($check_6)/$IT_term_6_ts{$1}/g;
- s/($check_5)/$IT_term_5_ts{$1}/g;
- s/($check_4)/$IT_term_4_ts{$1}/g;
- s/($check_3)/$IT_term_3_ts{$1}/g;
- s/($check_2)/$IT_term_2_ts{$1}/g;
- # Perform character-to-character conversion.
- s/($check)/$tongwei_ts{$1}/g;
- # Encode the output string.
- $_ = encode_utf8 $_;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement