| 1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
| 2 |
use strict; |
use strict; |
| 3 |
|
use utf8; |
| 4 |
|
use CGI::Carp qw/fatalsToBrowser/; |
| 5 |
|
|
| 6 |
BEGIN { require 'common.pl' } |
BEGIN { require 'common.pl' } |
| 7 |
|
|
| 8 |
require Encode; |
require Encode; |
| 9 |
|
|
| 10 |
my $max_result = 30; |
my $max_result = 100; |
| 11 |
|
|
| 12 |
sub decode_url ($) { |
sub decode_url ($) { |
| 13 |
my $s = shift; |
my $s = shift; |
| 31 |
$param->{decode_url ($name)} = decode_url ($value); |
$param->{decode_url ($name)} = decode_url ($value); |
| 32 |
} |
} |
| 33 |
|
|
|
my $pattern = quotemeta normalize $param->{word}; |
|
| 34 |
my $eword = htescape $param->{word}; |
my $eword = htescape $param->{word}; |
| 35 |
|
|
| 36 |
|
my $pattern = quotemeta normalize $param->{word}; |
| 37 |
|
unless ($param->{cs}) { |
| 38 |
|
$pattern =~ s/([A-Za-z])/'[' . uc ($1) . lc ($1) . ']'/ge; |
| 39 |
|
} |
| 40 |
|
my $suffix_pattern = { |
| 41 |
|
ku => qr/(?>[かこきいっくけ])/, |
| 42 |
|
su => qr/(?>[さそしすせ])/, |
| 43 |
|
tsu => qr/(?>[たとちっつて])/, |
| 44 |
|
nu => qr/(?>[なのにんぬね])/, |
| 45 |
|
mu => qr/(?>[まもみんむめ])/, |
| 46 |
|
ru => qr/(?>[らろりっるれ])/, |
| 47 |
|
u => qr/(?>[わおいっうえ])/, |
| 48 |
|
gu => qr/(?>[がごぎいぐげ])/, |
| 49 |
|
bu => qr/(?>[ばぼびんぶべ])/, |
| 50 |
|
ichidan => qr/(?>[るれろよ])?/, |
| 51 |
|
kuru => qr/(?>[るれい])?/, |
| 52 |
|
suru => qr/(?>す[るれ]|しろ?|せよ?|さ)?/, |
| 53 |
|
i => qr/(?>か[ろっ]|く|い|けれ|う)?/, ## BUG: ありがたい -> ありがとう |
| 54 |
|
da => qr/(?>だ[ろっ]?|で|に|なら?)?/, |
| 55 |
|
dasuru => qr/(?>だ[ろっ]?|で|に|なら?|す[るれ]|しろ?|せよ?|さ)?/, |
| 56 |
|
}->{$param->{suffix}} || qr//; |
| 57 |
|
$pattern =~ s/$suffix_pattern$//; |
| 58 |
|
$pattern .= $suffix_pattern; |
| 59 |
|
$pattern = '\b' . $pattern . '\b' if $param->{aw}; |
| 60 |
|
|
| 61 |
print qq[Content-Type: text/html ; charset=utf-8 |
print qq[Content-Type: text/html ; charset=utf-8 |
| 62 |
|
|
| 63 |
<!DOCTYPE HTML> |
<!DOCTYPE HTML> |
| 66 |
<title>Search result for "$eword"</title> |
<title>Search result for "$eword"</title> |
| 67 |
<link rel=stylesheet href="/www/style/html/xhtml"> |
<link rel=stylesheet href="/www/style/html/xhtml"> |
| 68 |
<style> |
<style> |
| 69 |
|
td { |
| 70 |
|
vertical-align: top; |
| 71 |
|
} |
| 72 |
mark { |
mark { |
| 73 |
background-color: yellow; |
background-color: yellow; |
| 74 |
} |
} |
| 93 |
text-decoration: none; |
text-decoration: none; |
| 94 |
border-style: none; |
border-style: none; |
| 95 |
} |
} |
| 96 |
|
input[type=text] { |
| 97 |
|
width: 60%; |
| 98 |
|
} |
| 99 |
</style> |
</style> |
| 100 |
</head> |
</head> |
| 101 |
<body> |
<body> |
| 103 |
|
|
| 104 |
print_input_form (); |
print_input_form (); |
| 105 |
|
|
| 106 |
print q[<article>]; |
unless ('' =~ /$pattern/) { |
| 107 |
my $has_match; |
print q[<article>]; |
| 108 |
for_each_data_file (sub ($) { |
my $has_match; |
| 109 |
my $data_file_name = shift; |
for_each_data_file (sub ($) { |
| 110 |
load_data_file ($data_file_name, my $exact_data = {}, my $pattern_data = {}); |
my $data_file_name = shift; |
| 111 |
$pattern_data = unescape_patterns ($pattern_data); |
load_data_file ($data_file_name, my $exact_data = {}, my $pattern_data = {}); |
| 112 |
$has_match |= print_matches ($data_file_name, $exact_data, $pattern_data); |
$pattern_data = unescape_patterns ($pattern_data); |
| 113 |
}); |
$has_match |= print_matches ($data_file_name, $exact_data, $pattern_data); |
| 114 |
|
}); |
| 115 |
unless ($has_match) { |
|
| 116 |
print q[<p>No match found.</article>]; |
unless ($has_match) { |
| 117 |
} else { |
print q[<p>No match found.</article>]; |
| 118 |
print q[</article>]; |
} else { |
| 119 |
print_input_form (); |
print q[</article>]; |
| 120 |
|
print_input_form (); |
| 121 |
|
} |
| 122 |
} |
} |
| 123 |
|
|
| 124 |
sub unescape_patterns ($) { |
sub unescape_patterns ($) { |
| 198 |
sub print_input_form () { |
sub print_input_form () { |
| 199 |
print qq[<section><form action=find accept-charset=utf-8 method=get>]; |
print qq[<section><form action=find accept-charset=utf-8 method=get>]; |
| 200 |
print qq[<p><input type=text name=word value="@{[htescape $param->{word}]}">]; |
print qq[<p><input type=text name=word value="@{[htescape $param->{word}]}">]; |
| 201 |
|
print qq[<select name=suffix>]; |
| 202 |
|
for (qw/none ku su tsu nu mu ru u gu bu ichidan suru kuru i da dasuru/) { |
| 203 |
|
print qq[<option value="@{[htescape $_]}"]; |
| 204 |
|
print qq[ selected] if $param->{suffix} eq $_; |
| 205 |
|
print qq[>]; |
| 206 |
|
print htescape ({ |
| 207 |
|
none => 'No suffix', |
| 208 |
|
ku => 'Ka-gyou Godan (-ku)', |
| 209 |
|
su => 'Sa-gyou Godan (-su)', |
| 210 |
|
tsu => 'Ta-gyou Godan (-tsu)', |
| 211 |
|
nu => 'Na-gyou Godan (-nu)', |
| 212 |
|
mu => 'Ma-gyou Godan (-mu)', |
| 213 |
|
ru => 'Ra-gyou Godan (-ru)', |
| 214 |
|
u => 'Wa/a-gyou Godan (-u)', |
| 215 |
|
gu => 'Ga-gyou Godan (-gu)', |
| 216 |
|
bu => 'Ba-gyou Godan (-bu)', |
| 217 |
|
ichidan => 'Ichidan (-iru, -eru)', |
| 218 |
|
suru => 'Sahen (-suru)', |
| 219 |
|
kuru => 'Kahen (kuru)', |
| 220 |
|
i => 'Keiyoushi (-i)', |
| 221 |
|
da => 'Keiyou-doushi (-da)', |
| 222 |
|
dasuru => 'Kei-dou-sahen (-da, -suru)', |
| 223 |
|
}->{$_} || $_); |
| 224 |
|
} |
| 225 |
|
print qq[</select>]; |
| 226 |
|
print qq[<input type=submit value=Submit>]; |
| 227 |
print qq[<p><label><input type=checkbox name=cs @{[$param->{cs} ? 'checked' : '']}> Case-sensitive</label> |
print qq[<p><label><input type=checkbox name=cs @{[$param->{cs} ? 'checked' : '']}> Case-sensitive</label> |
| 228 |
<label><input type=checkbox name=aw @{[$param->{aw} ? 'checked' : '']}> As word(s)</label>]; |
<label><input type=checkbox name=aw @{[$param->{aw} ? 'checked' : '']}> As word(s)</label>]; |
| 229 |
print qq[</form></section>]; |
print qq[</form></section>]; |