OSDN Git Service

* lib/plugins/32address: Address matching plugin\r * lib/plugins/33distinct: Ad-hoc...
authormorimoto <morimoto@180c8125-5b33-4295-ad04-72a68a15b4cc>
Sun, 3 Aug 2008 02:36:48 +0000 (02:36 +0000)
committermorimoto <morimoto@180c8125-5b33-4295-ad04-72a68a15b4cc>
Sun, 3 Aug 2008 02:36:48 +0000 (02:36 +0000)
ChangeLog
lib/plugins/10url
lib/plugins/11url_session
lib/plugins/30prefectures [deleted file]
lib/plugins/31distinct [deleted file]
lib/plugins/32address
lib/plugins/33distinct [new file with mode: 0644]

index 8a2aaa2..453509c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2008-08-03  Jun Morimoto  <morimoto@mrmt.net>
 
+       * lib/plugins/32address: Address matching plugin
+       * lib/plugins/33distinct: Ad-hoc matching plugin for address that
+       starts from Tokyo special wards, Tokyo cities
+       * lib/plugins/30prefectures: switch to 32address
+       * lib/plugins/31distinct: switch to 33distinct
+       * lib/plugins/10url: URL::Escape::uri_escape()
+       * lib/plugins/11url_session: URL::Escape::uri_escape()
        * added t/test_suites, Makefile.PL, MANIFEST
 
 2008-08-02  Jun Morimoto  <morimoto@mrmt.net>
index 042cd3f..3d5a96c 100644 (file)
@@ -1,7 +1,7 @@
 # -*- mode: perl; coding: utf-8 -*-
 # keitairc/lib/plugins/10url
 # URL処理
-# $Id: 10url,v 1.7 2008-06-29 09:20:49 morimoto Exp $
+# $Id: 10url,v 1.8 2008-08-03 02:36:48 morimoto Exp $
 # $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/plugins/10url,v $
 
 # The line number (1 incremented) and filename below must be
@@ -25,13 +25,13 @@ $plugin = {
        },
 
        action_imprementation => sub {
-               my ($request, $name, $session_id, $param_string) = @_;
+               my ($request, $name, $session_id, $param) = @_;
                my $ci = new Keitairc::ClientInfo($request);
                my $view = new Keitairc::View($::cf, $ci);
                return $view->render('url.html', {
-                       url => $param_string,
+                       url => $param,
                        session_id => $session_id,
-                       escaped_url => ::uri_escape($param_string),
+                       escaped_url => URI::Escape::uri_escape($param),
                             });
        }
 };
index b08b166..f310f46 100644 (file)
@@ -1,7 +1,7 @@
 # -*- mode: perl; coding: utf-8 -*-
 # keitairc/lib/plugins/11url_session
 # URL処理(セッション更新してリファラ逆探知防御)
-# $Id: 11url_session,v 1.3 2008-06-29 09:20:49 morimoto Exp $
+# $Id: 11url_session,v 1.4 2008-08-03 02:36:48 morimoto Exp $
 # $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/plugins/11url_session,v $
 
 # The line number (1 incremented) and filename below must be
@@ -11,7 +11,7 @@
 $plugin = {
        name => 'url_session',
        action_imprementation => sub {
-               my ($request, $name, $session_id, $param_string) = @_;
+               my ($request, $name, $session_id, $param) = @_;
                my $ci = new Keitairc::ClientInfo($request);
                my $view = new Keitairc::View($::cf, $ci);
 
@@ -19,9 +19,9 @@ $plugin = {
                $::sm->delete($session_id);
                my $new_session = $::sm->add($ci->{header}->{user_agent}, $ci->serial_key());
                return $view->render('url_session.html', {
-                       url => $param_string,
+                       url => $param,
                        session_id => $new_session->{id},
-                       escaped_url => ::uri_escape($param_string),
+                       escaped_url => URI::Escape::uri_escape($param),
                             });
        }
 };
diff --git a/lib/plugins/30prefectures b/lib/plugins/30prefectures
deleted file mode 100644 (file)
index 43bf839..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-# -*- mode: perl; coding: utf-8 -*-
-# keitairc/lib/plugins/30prefectures
-# 県名から始まる文字列を携帯版Google Mapにリンク
-# $Id: 30prefectures,v 1.4 2008-06-29 09:20:49 morimoto Exp $
-# $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/plugins/30prefectures,v $
-
-# The line number (1 incremented) and filename below must be
-# actual. see perlsyn.
-# line 10 "keitairc/lib/plugins/30prefectures"
-
-$plugin = {
-       name => 'prefectures',
-
-       message_replace_regexp => '((?:北海道|京都府|大阪府|東京都|青森県|岩手県|宮城県|秋田県|山形県|福島県|茨城県|栃木県|群馬県|埼玉県|千葉県|神奈川県|新潟県|富山県|石川県|福井県|山梨県|長野県|岐阜県|静岡県|愛知県|三重県|滋賀県|兵庫県|奈良県|和歌山県|鳥取県|島根県|岡山県|広島県|山口県|徳島県|香川県|愛媛県|高知県|福岡県|佐賀県|長崎県|熊本県|大分県|宮崎県|鹿児島県|沖縄県)(?:.+)(?:市|区|町|郡|村)(.*))',
-       message_replace_imprementation => sub {
-               my ($session_id, $str) = @_;
-               my $tmp = Encode::decode($::cf->web_charset(), $str);
-               $tmp = ::uri_escape($tmp);
-               return sprintf('<a href="%s%s/address/%s">%s</a>',
-                              $::cf->web_root(), $session_id, $tmp, $str);
-       },
-};
-
-1;
diff --git a/lib/plugins/31distinct b/lib/plugins/31distinct
deleted file mode 100644 (file)
index 11667dc..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-# -*- mode: perl; coding: utf-8 -*-
-# keitairc/lib/plugins/31distinct
-# 区名から始まる文字列を携帯版Google Mapにリンク
-# TODO: 東京都しかはいってないよ
-# $Id: 31distinct,v 1.4 2008-06-29 09:20:49 morimoto Exp $
-# $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/plugins/31distinct,v $
-
-# The line number (1 incremented) and filename below must be
-# actual. see perlsyn.
-# line 11 "keitairc/lib/plugins/31distinct"
-
-my $tokyo_special_wards = '千代田区|中央区|港区|新宿区|文京区|台東区|墨田区|江東区|品川区|目黒区|大田区|世田谷区|渋谷区|中野区|杉並区|豊島区|北区|荒川区|板橋区|練馬区|足立区|葛飾区|江戸川区';
-my $tokyo_cities = '昭島市|あきる野市|稲城市|青梅市|清瀬市|国立市|小金井市|国分寺市|小平市|狛江市|立川市|多摩市|調布市|西東京市|八王子市|羽村市|東久留米市|東村山市|東大和市|日野市|府中市|福生市|町田市|三鷹市|武蔵野市|武蔵村山市';
-
-$plugin = {
-       name => 'distinct',
-
-       message_replace_regexp => '((?:' . $tokyo_special_wards . '|' . $tokyo_cities . ')(?:.+)(?:[1-9]|一|二|三|四|五|六|七|八|九|〇|号|町|字|番地))',
-       message_replace_imprementation => sub {
-               my ($session_id, $str) = @_;
-               my $tmp = Encode::decode($::cf->web_charset(), $str);
-               $tmp = ::uri_escape($tmp);
-               return sprintf('<a href="%s%s/address/%s">%s</a>',
-                              $::cf->web_root(), $session_id, $tmp, $str);
-       },
-};
-
-1;
index 0e21a1e..30c7510 100644 (file)
@@ -3,7 +3,7 @@
 # based on 'Add link to google maps japan on address-like texts'
 # by twk, from http://nonn-et-twk.net/twk/node/51
 # 
-# $Id: 32address,v 1.4 2008-08-02 18:38:53 morimoto Exp $
+# $Id: 32address,v 1.5 2008-08-03 02:36:48 morimoto Exp $
 # $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/plugins/32address,v $
 
 # The line number (1 incremented) and filename below must be
 use Encode;
 use utf8;
 
-
-$plugin = {
-       name => 'address',
-       message_replace_regexp => '',
-       message_replace_imprementation => sub { '' },
-};
-
-1;
-
-__END__
-
 my $WHITESPACE_ex = q/[\s ::()\[\][]「」()、。]/;
 my $NO_WHITESPACE_ex = q/[^\s ::()\[\][]「」()、。]/;
-my $TODOFUKEN_ex = q/(?:東京都|練馬区|北海道|(?:大阪|京都)府|(?:青森|岩手|宮城|秋田|山形|福島|茨城|栃木|群馬|埼玉|千葉|神奈川|新潟|富山|石川|福井|山梨|長野|岐阜|静岡|愛知|三重|滋賀|兵庫|奈良|和歌山|鳥取|島根|岡山|広島|山口|徳島|香川|愛媛|高知|福岡|佐賀|長崎|熊本|大分|宮崎|鹿児島|沖縄)県)(?![\d0-9])/;
+my $TODOFUKEN_ex = q/(?:東京都|北海道|(?:大阪|京都)府|(?:青森|岩手|宮城|秋田|山形|福島|茨城|栃木|群馬|埼玉|千葉|神奈川|新潟|富山|石川|福井|山梨|長野|岐阜|静岡|愛知|三重|滋賀|兵庫|奈良|和歌山|鳥取|島根|岡山|広島|山口|徳島|香川|愛媛|高知|福岡|佐賀|長崎|熊本|大分|宮崎|鹿児島|沖縄)県)(?![\d0-9])/;
 my $CITY_SEPARATE_CHAR_ex = '(?:^|' . $WHITESPACE_ex . ')';
 my $SHICHOSON_ex = $NO_WHITESPACE_ex . '{1,4}[郡市区]';
 my $AZA_ex = $NO_WHITESPACE_ex . '{1,20}';
@@ -49,106 +38,34 @@ my $re = {
                building2 => $BUILDING2_re,
 };
 
-for my $s (
-       '京都市中京区六角通東洞院東入ル',
-       '北海道札幌市中央区南3条西2丁目狸小路2丁目',
-       '神奈川県足柄下郡箱根町小涌谷503',
-       '静岡県下田市一丁目12-17',
-       '大阪府大阪市中央区上町A番23号',
-       '東京都渋谷区恵比寿1-19-15 ウノサワ東急ビル5階',
-       '紫波郡矢巾町大字南矢幅第13地割123番地',
-       '練馬区石神井台3-2-4',
-       ){
-
-       my $m = 'ここって' . $s . 'ですよね';
-       warn 'mes -> [' . $m . ']';
-
-       if($m =~ s/.*($re->{general}).*/$1/){
-               warn 'src -> [' . $m . ']';
-       }
-
-       # remove building names since google maps rarely recognize them
-       if($m =~ s/($re->{building1}).*/$1/){
-               warn 'building1 -> [' . $m . ']';
-       }
-       if($m =~ s/$re->{building2}.*/$1/){
-               warn 'building2 -> [' . $m . ']';
-       }
-
-
-       warn "\n";
-}
-
-
-__END__
-
 $plugin = {
        name => 'address',
-       message_replace_regexp => $re->{general},
-       message_replace_imprementation => sub {
-               my ($session_id, $m) = @_;
-               my $m = Encode::decode($::cf->web_charset(), $m);
-
-
+       message_replace_regexp => '(' . $re->{general} . ')',
 
-               $text = ::uri_escape($text);
+       message_replace_imprementation => sub {
+               my ($session_id, $src) = @_;
+               my $s = $src;
+               $s =~ s/.*($re->{general}).*/$1/;
+               # remove building names since google maps rarely recognize them
+               $s =~ s/($re->{building1}).*/$1/;
+               $s =~ s/$re->{building2}.*/$1/;
                return sprintf('<a href="%s%s/address/%s">%s</a>',
-                              $::cf->web_root(), $session_id, $tmp, $str);
+                              $::cf->web_root(), $session_id,
+                              URI::Escape::uri_escape_utf8($s), $src);
        },
-};
-
-                       var building = m.match(re.building1);
-                       if (building)
-                               m = building[0];
-                       var building2 = m.match(re.building2);
-                       if (building2)
-                               m = building2[1];
-
-                       // split at first matched place
-                       var matchedNode = node.splitText(text.indexOf(m));
-                       MakeLink(matchedNode, m);
 
-                       ++arguments.callee.count;
-               }
+       action_imprementation => sub {
+               my ($request, $name, $session_id, $param) = @_;
+               my $ci = new Keitairc::ClientInfo($request);
+               my $view = new Keitairc::View($::cf, $ci);
+               my $address = URI::Escape::uri_unescape($param);
+               # $address is utf8 string w/o utf flag, so we use from_to()
+               Encode::from_to($address, 'utf8', $::cf->web_charset());
+               return $view->render('address.html', {
+                       session_id => $session_id,
+                       address => $address,
+                            });
        }
-
-       function MakeLink(matchedNode, matchedText)
-       {
-               matchedNode.splitText(matchedText.length);
-               var anchorNode = document.createElement('A');
-               anchorNode.style.backgroundColor = '#66bb4a'; // google maps arrow color
-               anchorNode.style.color = '#000000';
-               anchorNode.title = 'Googleマップ';
-               anchorNode.href = 'http://maps.google.co.jp/?hl=ja&q='
-                       + encodeURI(matchedNode.data.replace(/[\s ::、。]/, ''));
-               anchorNode.appendChild(matchedNode.cloneNode(true));
-               matchedNode.parentNode.replaceChild(anchorNode, matchedNode);
-       }
-} // AddressLink
-
-
-
-
+};
 
 1;
-
-__END__
-群馬県館林市楠町3648-1
-群馬県高崎市中尾町字鳥羽前44-7
-群馬県太田市石原町81番地イオン太田1階
-長野県茅野市中沖12-4
-三重県四日市市泊小柳町4-5
-青森県十和田市三本木字千歳森169-1
-青森県上北郡おいらせ町住吉4-50-33
-埼玉県川越市泉町3-1
-埼玉県川越市泉町3丁目1
-埼玉県川越市泉町3丁目1番地なんですが
-埼玉県川越市泉町3丁目1番が
-埼玉県川越市泉町3丁目1番です
-埼玉県川越市泉町三丁目一番です
-東京都武蔵野市吉祥寺北町1-1-1桜井ビル1階
-東京都新宿区喜久井町10イプセ新宿夏目坂
-東京都中央区佃1-11-8 リバーシティー21ピアウェスト
-東京都品川区西大井1-4-25コアスターレ西大井第一ビル
-東京都渋谷区円山町26-7 TKフラッツ渋谷
-帯広市稲田町南8線西10-1
diff --git a/lib/plugins/33distinct b/lib/plugins/33distinct
new file mode 100644 (file)
index 0000000..652a7a0
--- /dev/null
@@ -0,0 +1,53 @@
+# -*- mode: perl; coding: utf-8 -*-
+# keitairc/lib/plugins/33distinct
+# based on 'Add link to google maps japan on address-like texts'
+# by twk, from http://nonn-et-twk.net/twk/node/51
+# 
+# $Id: 33distinct,v 1.1 2008-08-03 02:36:48 morimoto Exp $
+# $Source: /home/ishikawa/work/keitairc/tmp/keitairc/lib/plugins/33distinct,v $
+
+# The line number (1 incremented) and filename below must be
+# actual. see perlsyn.
+# line 12 "keitairc/lib/plugins/32address"
+
+use Encode;
+use utf8;
+
+my $tokyo_special_wards = '(?:千代田区|中央区|港区|新宿区|文京区|台東区|墨田区|江東区|品川区|目黒区|大田区|世田谷区|渋谷区|中野区|杉並区|豊島区|北区|荒川区|板橋区|練馬区|足立区|葛飾区|江戸川区)';
+my $tokyo_cities = '(?:昭島市|あきる野市|稲城市|青梅市|清瀬市|国立市|小金井市|国分寺市|小平市|狛江市|立川市|多摩市|調布市|西東京市|八王子市|羽村市|東久留米市|東村山市|東大和市|日野市|府中市|福生市|町田市|三鷹市|武蔵野市|武蔵村山市)';
+
+my $NO_WHITESPACE_ex = q/[^\s ::()\[\][]「」()、。]/;
+my $SHICHOSON_ex = '(?:' . $tokyo_special_wards . '|' . $tokyo_cities . ')';
+my $AZA_ex = $NO_WHITESPACE_ex . '{1,20}';
+my $BANCHI_ex = q/[\d0-9]/ . '{1,8}'; # 一二三四五六七八九十東西南北無ABC
+my $BUILDING1_re = q/^[^\d0-9]+[\d0-9]+(?:(?:[-―-ー]|丁目|番地?|号)[\d0-9]+)+/;
+my $BUILDING2_re = q/^(.*(?:丁目|番地?|号))[^地\d0-9]+(?:ビル|$)/;
+
+my $re = {
+       general =>
+               '(?:' . $SHICHOSON_ex . ')' . '[ \t ]*' .
+               '(?:' . $AZA_ex . '[ \t ]*' .
+                 '(?:' . $BANCHI_ex . '(?:丁目|番地?|号)?[-―-ー]?)' . '{1,4}' .
+               ')',
+               building1 => $BUILDING1_re,
+               building2 => $BUILDING2_re,
+};
+
+$plugin = {
+       name => 'distinct',
+       message_replace_regexp => '(' . $re->{general} . ')',
+
+       message_replace_imprementation => sub {
+               my ($session_id, $src) = @_;
+               my $s = $src;
+               $s =~ s/.*($re->{general}).*/$1/;
+               # remove building names since google maps rarely recognize them
+               $s =~ s/($re->{building1}).*/$1/;
+               $s =~ s/$re->{building2}.*/$1/;
+               return sprintf('<a href="%s%s/address/%s">%s</a>',
+                              $::cf->web_root(), $session_id,
+                              URI::Escape::uri_escape_utf8($s), $src);
+       },
+};
+
+1;