blog/content/post/2009-06-27-00001182.md

125 lines
9.2 KiB
Markdown
Raw Normal View History

2019-03-31 11:00:21 +00:00
---
title: 日本語の中から住所を抽出
author: kazu634
date: 2009-06-27
url: /2009/06/27/_1279/
wordtwit_post_info:
- 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:4669;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}'
categories:
- Perl
---
<div class="section">
<p>
<a href="http://blog.cgfm.jp/cota/archives/54" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://blog.cgfm.jp/cota/archives/54', 'Geography::AddressExtract::Japanを使って住所抽出 : cotalog');" target="_blank">Geography::AddressExtract::Japanを使って住所抽出 : cotalog</a>」で紹介されているGeography::AddressExtract::Japanをインストールしてみました。
</p>
<p>
基本的には下記のログの通りで大丈夫です。ただし事前にModule::installをCPANからインストールする必要があります。
</p>
<pre class="syntax-highlight">
~/working/tmp_perl/lib on simoom634 <span class="synStatement">[</span><span class="synConstant">579</span><span class="synStatement">]</span> $: svn checkout http://svn.coderepos.org/share/lang/perl/Geography-AddressExtract-Japan
A Geography-AddressExtract-Japan/trunk
A Geography-AddressExtract-Japan/trunk/MANIFEST
A Geography-AddressExtract-Japan/trunk/META.yml
A Geography-AddressExtract-Japan/trunk/lib
A Geography-AddressExtract-Japan/trunk/lib/Geography
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan.pm
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan/Address.pm
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan/Filter
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan/Regexp
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan/Regexp/City.pm
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan/Regexp/Number.pm
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan/Regexp/Aza.pm
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan/Regexp/Dupe.pm
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan/Map
A Geography-AddressExtract-Japan/trunk/lib/Geography/AddressExtract/Japan/Map/City.pm
A Geography-AddressExtract-Japan/trunk/Makefile.PL
A Geography-AddressExtract-Japan/trunk/bin
A Geography-AddressExtract-Japan/trunk/bin/make_maps.pl
A Geography-AddressExtract-Japan/trunk/<span class="synStatement">test</span>.pl
A Geography-AddressExtract-Japan/branches
A Geography-AddressExtract-Japan/tags
U Geography-AddressExtract-Japan
Checked out revision <span class="synConstant">34168</span>.
~/working/tmp_perl/lib on simoom634 <span class="synStatement">[</span><span class="synConstant">580</span><span class="synStatement">]</span> $: <span class="synStatement">cd</span> Geography-AddressExtract-Japan/
~/working/tmp_perl/lib/Geography-AddressExtract-Japan on simoom634 <span class="synStatement">[</span><span class="synConstant">581</span><span class="synStatement">]</span> $: <span class="synStatement">ls</span>
branches/ tags/ trunk/
~/working/tmp_perl/lib/Geography-AddressExtract-Japan on simoom634 <span class="synStatement">[</span><span class="synConstant">582</span><span class="synStatement">]</span> $: <span class="synStatement">cd</span> trunk
~/working/tmp_perl/lib/Geography-AddressExtract-Japan/trunk on simoom634 <span class="synStatement">[</span><span class="synConstant">583</span><span class="synStatement">]</span> $: <span class="synStatement">ls</span>
MANIFEST META.yml Makefile.PL bin/ lib/ <span class="synStatement">test</span>.pl
~/working/tmp_perl/lib/Geography-AddressExtract-Japan/trunk on simoom634 <span class="synStatement">[</span><span class="synConstant">584</span><span class="synStatement">]</span> $: perl Makefile.PL
include /Users/simoom634/working/tmp_perl/lib/Geography-AddressExtract-Japan/trunk/inc/Module/Install.pm
include inc/Module/Install/Metadata.pm
include inc/Module/Install/Base.pm
Cannot determine perl version info from lib/Geography/AddressExtract/Japan.pm
Cannot determine license info from lib/Geography/AddressExtract/Japan.pm
include inc/Module/Install/Include.pm
include inc/Test/More.pm
include inc/Module/Install/AutoInstall.pm
include inc/Module/AutoInstall.pm
*** Module::AutoInstall version <span class="synConstant">1</span>.<span class="synConstant">03</span>
*** Checking <span class="synStatement">for</span> Perl dependencies...
<span class="synStatement">[</span>Core Features<span class="synStatement">]</span>
- Test::More ...loaded. <span class="synStatement">(</span><span class="synConstant"></span>.<span class="synConstant">88</span> <span class="synStatement">&#62;=</span> <span class="synConstant"></span>.<span class="synConstant">42</span><span class="synStatement">)</span>
*** Module::AutoInstall configuration finished.
include inc/Module/Install/Makefile.pm
include inc/Module/Install/WriteAll.pm
include inc/Module/Install/Win32.pm
include inc/Module/Install/Can.pm
include inc/Module/Install/Fetch.pm
Checking <span class="synStatement">if</span> your kit is <span class="synStatement">complete</span>...
Warning: the following files are missing in your kit:
lib/Geography/AddressExtract/Japan/Normalize.pm
Please inform the author.
Writing Makefile <span class="synStatement">for</span> Geography::AddressExtract::Japan
Writing META.yml
No license specified, setting license <span class="synStatement">=</span> <span class="synConstant">'unknown'</span>
~/working/tmp_perl/lib/Geography-AddressExtract-Japan/trunk on simoom634 <span class="synStatement">[</span><span class="synConstant">585</span><span class="synStatement">]</span> $: sudo Make <span class="synStatement">install</span>
sudo: Make: command not found
~/working/tmp_perl/lib/Geography-AddressExtract-Japan/trunk on simoom634 <span class="synStatement">[</span><span class="synConstant">586</span><span class="synStatement">]</span> $: sudo make <span class="synStatement">install</span>
cp lib/Geography/AddressExtract/Japan/Address.pm blib/lib/Geography/AddressExtract/Japan/Address.pm
cp lib/Geography/AddressExtract/Japan/Map/City.pm blib/lib/Geography/AddressExtract/Japan/Map/City.pm
cp lib/Geography/AddressExtract/Japan.pm blib/lib/Geography/AddressExtract/Japan.pm
cp lib/Geography/AddressExtract/Japan/Regexp/Number.pm blib/lib/Geography/AddressExtract/Japan/Regexp/Number.pm
cp lib/Geography/AddressExtract/Japan/Regexp/Dupe.pm blib/lib/Geography/AddressExtract/Japan/Regexp/Dupe.pm
cp lib/Geography/AddressExtract/Japan/Regexp/City.pm blib/lib/Geography/AddressExtract/Japan/Regexp/City.pm
cp lib/Geography/AddressExtract/Japan/Regexp/Aza.pm blib/lib/Geography/AddressExtract/Japan/Regexp/Aza.pm
Manifying blib/man3/Geography::AddressExtract::Japan::Map::City.3pm
Manifying blib/man3/Geography::AddressExtract::Japan::Regexp::Dupe.3pm
Manifying blib/man3/Geography::AddressExtract::Japan::Regexp::City.3pm
Appending installation info to /opt/<span class="synStatement">local</span>/lib/perl5/<span class="synConstant">5</span>.<span class="synConstant">8</span>.<span class="synConstant">9</span>/darwin-2level/perllocal.pod
</pre>
<h4>
サンプル
</h4>
<pre class="syntax-highlight">
<span class="synPreProc">#!/usr/local/bin/perl</span>
<span class="synComment"># === Libraries ===</span>
<span class="synStatement">use strict</span>;
<span class="synStatement">use warnings</span>;
<span class="synStatement">use </span>Data::Dumper;
<span class="synComment"># === Main part ===</span>
<span class="synStatement">use strict</span>;
<span class="synStatement">use </span>Geography::AddressExtract::Japan;
<span class="synStatement">use </span>encoding <span class="synConstant">&#34;utf8&#34;</span>, <span class="synConstant">STDOUT </span>=&#62; <span class="synConstant">&#34;utf8&#34;</span>;
<span class="synStatement">my</span> <span class="synIdentifier">$addr</span> = <span class="synConstant">&#34;千葉県市川市八幡2-6-15川長ビル地下1階&#34;</span>;
<span class="synStatement">my</span> <span class="synIdentifier">$t</span> = Geography::AddressExtract::Japan-&#62;extract(<span class="synIdentifier">$addr</span>);
<span class="synStatement">print</span> <span class="synStatement">map</span> { <span class="synIdentifier">$_</span>-&#62;{<span class="synConstant">&#34;city&#34;</span>} . <span class="synIdentifier">$_</span>-&#62;{<span class="synConstant">&#34;aza&#34;</span>} . <span class="synIdentifier">$_</span>-&#62;{<span class="synConstant">&#34;number&#34;</span>} . <span class="synConstant">&#34;</span>
<span class="synConstant">&#34;</span>; }@{<span class="synIdentifier">$t</span>};
</pre>
<h4>
実行例
</h4>
<pre class="syntax-highlight">
~/working/tmp_perl/projects/scrape/starbucks on simoom634 <span class="synStatement">[</span><span class="synConstant">591</span><span class="synStatement">]</span> $: perl address.pl
千葉県市川市八幡<span class="synConstant">2-6-15</span>
</pre>
</div>