MeCab + Senna + Tritonn で MySQL 全文検索を試す

以前、自作 N-gram の php プログラムを書いて、日本語全文検索を MySQL の標準機能で試したが、文をまるごと突っ込んで検索するといった場合、AND検索が著しく行われるため、速度が落ちることがわかった。メジャーな組み込み型全文検索を試してみる。 を参考にした。 ダウンロードしてきたパッケージ mecab-0.96.tar.gz mecab-ipadic-2.7.0-20070801.tar.gz senna-1.0.9.tar.gz MySQL-5.0.45-tritonn-1.0.6.tar.gz MeCab のビルドとインストール $ ./configure –prefix=/usr –with-charset=utf8 $ make $ sudo make install Mecab-ipadic のインストール $ ./configure –prefix=/usr –with-charset=utf8 $ make $ sudo make install Senna のビルドとインストール $ ./configure –prefix=/usr $ make $ sudo make install Tritonn (MySQL) のビルドとインストール $ ./configure –prefix=/usr/local/mysql-5.0.45 –localstatedir=/usr/local/mysql-5.0.45/data –libexecdir=/usr/local/mysql-5.0.45/bin –enable-thread-safe-client –enable-local-infile –enable-assembler –with-pic –with-fast-mutexes –with-zlib-dir=bundled –with-big-tables –with-yassl –with-readline –with-archive-storage-engine –with-blackhole-storage-engine –with-example-storage-engine –with-federated-storage-engine –with-innodb –with-charset=utf8 –with-extra-charsets=all –with-mysqld-user=mysql –with-senna –with-mecab $ make $ make bin-dist ...

2007年9月29日 · Toshimitsu Takahashi

Mac OS X で system_profiler を使ってシステムプロファイルを調べる

system_profiler コマンドを使うと、詳細なシステムプロファイル情報をターミナルで確認することができる。ご覧のとおり、長いので | less した方がいい。 $ system_profiler Hardware: Hardware Overview: Machine Name: Mac mini Machine Model: PowerMac10,1 CPU Type: PowerPC G4 (1.2) Number Of CPUs: 1 CPU Speed: 1.42 GHz L2 Cache (per CPU): 512 KB Memory: 512 MB Bus Speed: 167 MHz Boot ROM Version: 4.8.9f4 Serial Number: YM********* Network: Bluetooth: Type: PPP (PPPSerial) Hardware: Modem BSD Device Name: Bluetooth-Modem Has IP Assigned: No IPv4: Configuration Method: PPP IPv6: Configuration Method: Automatic Proxies: Proxy Configuration Method: Manual ExcludeSimpleHostnames: 0 FTP Passive Mode: Yes Auto Discovery Enabled: No 内蔵 Ethernet: Type: Ethernet Hardware: Ethernet BSD Device Name: en0 Has IP Assigned: Yes IPv4 Addresses: 2001:0c90:12f1:0ae2:0214:51ff:fe09:7a1c IPv4: Addresses: 192.168.1.11 Configuration Method: Manual Interface Name: en0 Router: 192.168.1.1 Subnet Masks: 255.255.255.0 IPv6: Addresses: 2001:0c90:12f1:0ae2:0214:51ff:fe09:7a1c Configuration Method: Automatic Flags: 32832 Interface Name: en0 Prefix Length: 64 Router: fe80:0000:0000:0000:0212:daff:fe43:081a DNS: Server Addresses: 192.168.1.1 Proxies: FTP Proxy Enabled: No FTP Passive Mode: Yes Gopher Proxy Enabled: No HTTP Proxy Enabled: No HTTPS Proxy Enabled: No RTSP Proxy Enabled: No SOCKS Proxy Enabled: No Ethernet: MAC Address: 00:14:51:09:7a:1c Media Options: Full Duplex Media Subtype: 100baseTX 内蔵 FireWire: Type: FireWire Hardware: FireWire BSD Device Name: fw0 Has IP Assigned: No IPv4: Configuration Method: DHCP IPv6: Configuration Method: Automatic Proxies: Proxy Configuration Method: Manual ExcludeSimpleHostnames: 0 FTP Passive Mode: Yes Auto Discovery Enabled: No Ethernet: MAC Address: --:--:--:--:--:--:--:-- Media Options: Full Duplex Media Subtype: autoselect AirMac: Type: AirPort Hardware: AirPort BSD Device Name: en1 Has IP Assigned: Yes IPv4 Addresses: 2001:0c90:12f1:0ae2:0211:24ff:fea0:3324 IPv4: Addresses: 192.168.1.11 Configuration Method: Manual Interface Name: en1 Router: 192.168.1.1 Subnet Masks: 255.255.255.0 IPv6: Addresses: 2001:0c90:12f1:0ae2:0211:24ff:fea0:3324 Configuration Method: Automatic Flags: 32832 Interface Name: en1 Prefix Length: 64 Router: fe80:0000:0000:0000:0212:daff:fe43:081a DNS: Server Addresses: 192.168.1.1 Proxies: Proxy Configuration Method: Manual ExcludeSimpleHostnames: 0 FTP Passive Mode: Yes Auto Discovery Enabled: No Ethernet: MAC Address: 00:11:24:a0:33:24 Media Options: Media Subtype: autoselect Software: System Software Overview: System Version: Mac OS X 10.4.10 (8R218) Kernel Version: Darwin 8.10.0 Boot Volume: Macintosh HD Computer Name: host User Name: □□□□ (user) ATA: ATA Bus: ST9808210A: Capacity: 74.53 GB Model: ST9808210A Revision: 3.04 Serial Number: 3LF17HVC Removable Media: No Detachable Drive: No BSD Name: disk0 Protocol: ATA Unit Number: 0 Socket Type: Internal OS9 Drivers: No S.M.A.R.T. status: Verified Volumes: Macintosh HD: Capacity: 74.41 GB Available: 50.08 GB Writable: Yes File System: Journaled HFS+ BSD Name: disk0s3 Mount Point: / Volumes: disk0s3: Capacity: 74.41 GB Available: 50.08 GB Writable: Yes File System: Journaled HFS+ MATSHITACD-RW CW-8124: Model: MATSHITACD-RW CW-8124 Revision: DACD Serial Number: Detachable Drive: No Protocol: ATAPI Unit Number: 1 Socket Type: Internal Audio (Built In): Built In Sound Card: Devices: LoadToonie: Inputs and Outputs: Headphones: Controls: Mute, Left, Right PluginID: Toonie Internal Speakers: Controls: Mute, Master PluginID: Toonie Formats: PCM 16: Bit Depth: 16 Bit Width: 16 Channels: 2 Mixable: Yes Sample Rates: 32 KHz, 44.1 KHz, 48 KHz, 88.2 KHz, 96 KHz PCM 24: Bit Depth: 24 Bit Width: 32 Channels: 2 Mixable: Yes Sample Rates: 32 KHz, 44.1 KHz, 48 KHz, 88.2 KHz, 96 KHz Bluetooth: Apple Bluetooth Software Version: 1.7.14f14 Services: Bluetooth File Transfer: Folder other devices can browse: ~/Public Requires Authentication: Yes State: Disabled Bluetooth File Exchange: Folder for accepted items: ~/Documents Requires Authentication: No When other items are accepted: Ask When PIM items are accepted: Ask When receiving items: Prompt for each file State: Enabled Incoming Serial Ports: Serial Port 1: Name: Bluetooth-PDA-Sync RFCOMM Channel: 3 Requires Authentication: No Outgoing Serial Ports: Serial Port 1: Address: Name: Bluetooth-Modem RFCOMM Channel: 0 Requires Authentication: No Diagnostics: Power On Self-Test: Last Run: 07/09/29 15:45 Result: Passed Disc Burning: MATSHITA CD-RW CW-8124: Firmware Revision: DACD Interconnect: ATAPI Burn Support: Yes (Apple Shipped/Supported) Cache: 2048 KB Reads DVD: Yes CD-Write: -R, -RW Burn Underrun Protection CD: Yes Write Strategies: CD-TAO, CD-SAO, CD-Raw Media: No FireWire: FireWire Bus: Maximum Speed: Up to 400 Mb/sec Graphics/Displays: ATI Radeon 9200: Chipset Model: ATY,RV280 Type: Display Bus: AGP VRAM (Total): 32 MB Vendor: ATI (0x1002) Device ID: 0x5962 Revision ID: 0x0001 ROM Revision: 113-xxxxx-120 Displays: RDT1711S: Resolution: 1280 x 1024 @ 60 Hz Depth: 32-bit Color Core Image: Not Supported Main Display: Yes Mirror: Off Online: Yes Quartz Extreme: Supported Rotation: Supported Memory: DIMM0/J11: Size: 512 MB Type: DDR SDRAM Speed: PC3200U-30330 Status: OK Power: System Power Settings: AC Power: System Sleep Timer (Minutes): 180 Disk Sleep Timer (Minutes): 10 Display Sleep Timer (Minutes): 10 Sleep On Power Button: Yes Automatic Restart On Power Loss: No Wake On AC Change: No Wake On LAN: Yes Wake On Modem Ring: Yes USB: USB High-Speed Bus: Host Controller Location: Built In USB Host Controller Driver: AppleUSBEHCI PCI Device ID: 0x00e0 PCI Revision ID: 0x0004 PCI Vendor ID: 0x1033 Bus Number: 0x5b USB Bus: Host Controller Location: Built In USB Host Controller Driver: AppleUSBOHCI PCI Device ID: 0x003f PCI Revision ID: 0x0000 PCI Vendor ID: 0x106b Bus Number: 0x1a Bluetooth HCI: Version: 15.86 Bus Power (mA): 500 Speed: Up to 12 Mb/sec Product ID: 0x8204 Vendor ID: 0x05ac (Apple Computer, Inc.) USB Bus: Host Controller Location: Built In USB Host Controller Driver: AppleUSBOHCI PCI Device ID: 0x0035 PCI Revision ID: 0x0043 PCI Vendor ID: 0x1033 Bus Number: 0x1b Hub in Apple Pro Keyboard: Version: 4.10 Bus Power (mA): 500 Speed: Up to 12 Mb/sec Manufacturer: Mitsumi Electric Product ID: 0x1003 Vendor ID: 0x05ac (Apple Computer, Inc.) Logitech USB Optical Mouse: Version: 43.00 Bus Power (mA): 100 Speed: Up to 1.5 Mb/sec Manufacturer: Logitech Product ID: 0xc019 Vendor ID: 0x046d Apple Pro Keyboard: Version: 4.10 Bus Power (mA): 250 Speed: Up to 12 Mb/sec Manufacturer: Mitsumi Electric Product ID: 0x020d Vendor ID: 0x05ac (Apple Computer, Inc.) USB Bus: Host Controller Location: Built In USB Host Controller Driver: AppleUSBOHCI PCI Device ID: 0x0035 PCI Revision ID: 0x0043 PCI Vendor ID: 0x1033 Bus Number: 0x3b AirPort Card: AirPort Card Information: Wireless Card Type: AirPort Extreme Wireless Card Locale: Japan Wireless Card Firmware Version: 405.1 (3.90.34.0.p18) Current Wireless Network: ********** Wireless Channel: 1 Locations: Automatic: Active Location: Yes Services: Bluetooth: Type: PPP IPv4: Configuration Method: PPP IPv6: Configuration Method: Automatic Proxies: Proxy Configuration Method: 2 ExcludeSimpleHostnames: 0 FTP Passive Mode: 1 Auto Discovery Enabled: 0 PPP: ACSP Enabled: 0 Display Terminal Window: 0 Redial Count: 1 Redial Enabled: 1 Redial Interval: 5 Use Terminal Script: 0 Dial On Demand: 0 Disconnect On Fast User Switch: 1 Disconnect On Idle: 1 Disconnect On Idle Timer: 600 Disconnect On Logout: 1 Disconnect On Sleep: 1 Idle Reminder: 0 Idle Reminder Time: 1800 IPCP Compression VJ: 1 LCP Echo Enabled: 0 LCP Echo Failure: 4 LCP Echo Interval: 10 Log File: /var/log/ppp.log Verbose Logging: 0 内蔵 Ethernet: Type: Ethernet BSD Device Name: en0 Hardware (MAC) Address: 00:14:51:09:7a:1c IPv4: Addresses: 192.168.1.11 Configuration Method: Manual Router: 192.168.1.1 Subnet Masks: 255.255.255.0 IPv6: Configuration Method: Automatic AppleTalk: Configuration Method: Node DNS: Server Addresses: 192.168.1.1 Proxies: FTP Proxy Enabled: 0 FTP Passive Mode: 1 Gopher Proxy Enabled: 0 HTTP Proxy Enabled: 0 HTTPS Proxy Enabled: 0 RTSP Proxy Enabled: 0 SOCKS Proxy Enabled: 0 内蔵 FireWire: Type: FireWire BSD Device Name: fw0 Hardware (MAC) Address: 00:14:51:ff:fe:09:7a:1c IPv4: Configuration Method: DHCP IPv6: Configuration Method: Automatic AppleTalk: Configuration Method: Node Proxies: Proxy Configuration Method: 2 ExcludeSimpleHostnames: 0 FTP Passive Mode: 1 Auto Discovery Enabled: 0 AirMac: Type: IEEE80211 BSD Device Name: en1 Hardware (MAC) Address: --:--:--:--:--:-- IPv4: Addresses: 192.168.1.11 Configuration Method: Manual Router: 192.168.1.1 Subnet Masks: 255.255.255.0 IPv6: Configuration Method: Automatic AppleTalk: Configuration Method: Node DNS: Server Addresses: 192.168.1.1 Proxies: Proxy Configuration Method: 2 ExcludeSimpleHostnames: 0 FTP Passive Mode: 1 Auto Discovery Enabled: 0 IEEE80211: AllowNetCreation: 1 JoinMode: Ranked MAC Address: --:--:--:--:--:--

2007年9月27日 · Toshimitsu Takahashi

Mac OS X で hostinfo を使ってホスト情報を調べる

hostinfo コマンドを使うと、カーネルバージョン、CPU プロセッサの情報、ロードアベレージなどのホスト情報を調べることができる。 $ hostinfo Mach kernel version: Darwin Kernel Version 8.10.0: Wed May 23 16:50:59 PDT 2007; root:xnu-792.21.3~1/RELEASE_PPC Kernel configured for a single processor only. 1 processor is physically available. Processor type: ppc7450 (PowerPC 7450) Processor active: 0 Primary memory available: 512.00 megabytes Default processor set: 81 tasks, 259 threads, 1 processors Load average: 1.69, Mach factor: 0.18

2007年9月26日 · Toshimitsu Takahashi

C# でバイト配列と16進数文字列を相互変換するには

.NET にバイト配列を16進数文字列にエンコード/デコードする方法が用意されていなかったので、自作した。(Base64 なら Convert にある。) 文字列への変換は、BitConverter.ToString に Replace("-", String.Empty) とすることでもできなくはなさそうだが、効率が良さそうには思えないので止めた。 Convert.ToString(b, 16) で b が16進数で1桁のときの0補完でハマった。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 /// <summary> /// バイト配列と文字列との変換機能を提供する /// </summary> public class BytesConvert { /// <summary> /// バイト配列から16進数の文字列を生成します。 /// </summary> /// <param name="bytes">バイト配列</param> /// <returns>16進数文字列</returns> public static string ToHexString(byte\[\] bytes) { StringBuilder sb = new StringBuilder(bytes.Length * 2); foreach (byte b in bytes) { if (b < 16) sb.Append('0'); // 二桁になるよう0を追加 sb.Append(Convert.ToString(b, 16)); } return sb.ToString(); } /// <summary> /// 16進数の文字列からバイト配列を生成します。 /// </summary> /// <param name="str">16進数文字列</param> /// <returns>バイト配列</returns> public static byte\[\] FromHexString(string str) { int length = str.Length / 2; byte\[\] bytes = new byte\[length\]; int j = 0; for (int i = 0; i < length; i++) { bytes\[i\] = Convert.ToByte(str.Substring(j, 2), 16); j += 2; } return bytes; } }

2007年9月23日 · Toshimitsu Takahashi

Apache で文字化けしたときの言語・文字エンコーディングの設定修正について

デフォルト設定では日本語コンテンツの場合、文字化けが発生することが多い。 httpd.conf を以下のように設定する。DefaultLanguage はコンテンツのデフォルト言語を指定する。AddDefaultCharset はデフォルトの文字コードを設定する。標準の記述が AddDefaultCharset は ISO-8859-1 や UTF-8 だったりするので、そうでないファイルがあると化けてしまう。コンテンツの文字コードが統一されているならそれを設定すると良い。 DefaultLanguage ja AddDefaultCharset off

2007年9月21日 · Toshimitsu Takahashi

find でサイズが 2GB を超えるファイルを探すには

$ find . -size +2147483648c c がないとブロックサイズになる。+ はより大きい(>)の意味。

2007年9月19日 · Toshimitsu Takahashi

Solaris Zone でグローバルゾーンのあるディレクトリをマウントするには

zonecfg で下記のように行う。dir はゾーン内のディレクトリ、special はグローバルゾーンのマウント対象ディレクトリ、options は rw にして読み書き可能にしている。 # zonecfg -z testzone zonecfg:testzone> add fs zonecfg:testzone:fs> set dir = /shared zonecfg:testzone:fs> set special = /export/shared zonecfg:testzone:fs> set type = lofs zonecfg:testzone:fs> set options = rw zonecfg:testzone:fs> end zonecfg:testzone> verify zonecfg:testzone> commit zonecfg:testzone> info fs fs: dir: /shared special: /export/shared raw not specified type: lofs options: [rw]

2007年9月14日 · Toshimitsu Takahashi

getent で /etc/nsswitch.conf に従ってネームサービスを検索する

getent コマンドを使うと、nsswitch.conf の構成に従って情報を検索できる。 hosts: files dns となっていれば、/etc/hosts, /etc/resolv.conf の設定従い DNS から順に探してくれる。 $ getent hosts d.hatena.ne.jp 59.106.108.77 d.hatena.ne.jp

2007年9月12日 · Toshimitsu Takahashi

echo で改行しないようにするには

基本的に -n オプションでよい。でも Solaris でシェルだと \c を付けないとダメ。 echo test echo -n test echo test\c クロスプラットフォームで動かすスクリプトは printf の方が良さそう。 printf "test\n" printf test

2007年9月10日 · Toshimitsu Takahashi

Windows Vista で インストーラがエラーコード 2738, 2739 を返す

カスタム動作をスクリプトで書こうとしたら、jscript.dll, vbscript.dll がシステムに登録されていないことがあるらしい。 error code 2738 - VBScript Engine が見つからない error code 2739 - JScript Engine が見つからない ということらしい。 C:\Windows\system32>regsvr32.exe vbscript.dll C:\Windows\system32>regsvr32.exe jscript.dll と登録したら動いたが…別の問題が…(スクリプトが実行できないと…やはり Vista がらみかな…)

2007年9月8日 · Toshimitsu Takahashi