テクニカルプア

備忘録と若干の補足

megamをpacmanで管理したいのでPKGBUILD書いた

2013-04-08 追記

本文中のPKGBUILDを編集した。

 以前にも書いた「入門 自然言語処理」を読んだり読まなかったりしながらダラダラと過ごしている。

今日第7章を読み始めたのだが、第7章3節、7.3.3の以下の箇所で怒られた。

>>> chunker = ConsecutiveNPChunker(train_sents)
which: no megam.opt in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl:/usr/lib/qt4/bin)
which: no megam in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl:/usr/lib/qt4/bin)
which: no megam_686 in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl:/usr/lib/qt4/bin)
which: no megam_i686.opt in (/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl:/usr/lib/qt4/bin)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 6, in __init__
  File "<stdin>", line 12, in __init__
  File "/usr/lib/python2.7/site-packages/nltk/classify/maxent.py", line 319, in train
    gaussian_prior_sigma, **cutoffs)
  File "/usr/lib/python2.7/site-packages/nltk/classify/maxent.py", line 1522, in train_maxent_classifier_with_megam
    stdout = call_megam(options)
  File "/usr/lib/python2.7/site-packages/nltk/classify/megam.py", line 163, in call_megam
    config_megam()
  File "/usr/lib/python2.7/site-packages/nltk/classify/megam.py", line 59, in config_megam
    url='http://www.cs.utah.edu/~hal/megam/')
  File "/usr/lib/python2.7/site-packages/nltk/internals.py", line 528, in find_binary
    url, verbose)
  File "/usr/lib/python2.7/site-packages/nltk/internals.py", line 512, in find_file
    raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
LookupError: 

===========================================================================
NLTK was unable to find the megam file!
Use software specific configuration paramaters or set the MEGAM environment variable.

  For more information, on megam, see:
    <http://www.cs.utah.edu/~hal/megam/>
===========================================================================
>>>

 megamというプログラムがないらしい。困った

困った時のAURということで検索を掛けてみるとなんとAURに存在しない。更に困った。

 というわけでmegamをpacmanで管理できるように、makepkgでビルドすべくPKGBUILDを書いてみた。

 ちなみにmegamで検索掛けたりエラーメッセージのリンクを踏んでみたりしたがなかなか辿り着けなかったりリンクが死んでたりして苦労したので下の方にmegamのページのリンクを書いておく。ひとつめのリンクがそれに該当する。

 注意すべき点としてmegamの実行形式を作る場合、ソースを落としてきて解凍してmakeしてはい終了というわけにはいかない。実際にやってみると以下のようなエラーを吐く。

/usr/bin/ld: cannot find -lstr
collect2: error: ld returned 1 exit status
File "fastdot_c.c", line 1:
Error: Error while building custom runtime system
make: *** [megam] Error 2

 そのあたりも含めてパッチもつくってみたので以下に置いておく。ちなみにこの問題の具体的な原因及び解決法は下のほうのリンク先を参照してもらいたい。

  • PKGBUILD
pkgname=megam
pkgver=0.92
pkgrel=3
pkgdesc="MEGA Model Optimization Package"
url='http://www.umiacs.umd.edu/~hal/megam/'
arch=('i686' 'x86_64')
license=('custom')
depends=('ocaml')
optdepends=()
makedepends=()
conflicts=()
replaces=()
backup=()
source=('http://hal3.name/megam/megam_src.tgz'
        'megam.patch')                          # Makefileへのパッチ
md5sums=('a8b02d3b62933e2a7fb1f4412840a431'
         '0d79ac56e89615028895b8f5a4df4c27')

build() {
    cd "${srcdir}/megam_${pkgver}"
	patch < "${srcdir}/megam.patch"
	sed -n '/This code/,/ webpage./p' README > LICENSE
	make
	# READMEによると、makeで実行形式をつくるとsafe(安全?確実?)だが遅いものが生成される
	# safeじゃなくていいから速い実行形式が欲しいのなら以下をコメントアウトする
	#make opt
}

package() {
	cd "${srcdir}/megam_${pkgver}"
	install -D -m775 megam "${pkgdir}/usr/bin/megam"
	install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}
  • パッチ
--- Makefile.orig    2007-10-09 02:06:04.000000000 +0900
+++ Makefile	2013-03-16 23:45:19.420694775 +0900
@@ -55,19 +55,19 @@
 
 # Default setting of the WITH* variables. Should be changed if your
 # local libraries are not found by the compiler.
-WITHGRAPHICS =graphics.cma -cclib -lgraphics -cclib -L/usr/X11R6/lib -cclib -lX11
+WITHGRAPHICS =graphics.cma 
 
-WITHUNIX =unix.cma -cclib -lunix
+WITHUNIX =unix.cma 
 
-WITHSTR =str.cma -cclib -lstr
+WITHSTR =str.cma 
 
-WITHBIGARRAY =bigarray.cma -cclib -lbigarray
+WITHBIGARRAY =bigarray.cma 
 
-WITHNUMS =nums.cma -cclib -lnums
+WITHNUMS =nums.cma 
 
-WITHTHREADS =threads.cma -cclib -lthreads
+WITHTHREADS =threads.cma 
 
-WITHDBM =dbm.cma -cclib -lmldbm -cclib -lndbm
+WITHDBM =dbm.cma 
 
 #WITHCLIBS =-I /usr/lib/ocaml/3.09.2/caml
 WITHCLIBS =-I /usr/lib/ocaml/caml
@@ -84,12 +84,12 @@
 
 opt : $(EXEC).opt
 
-#ocamlc -custom other options graphics.cma other files -cclib -lgraphics -cclib -lX11
-#ocamlc -thread -custom other options threads.cma other files -cclib -lthreads
-#ocamlc -custom other options str.cma other files -cclib -lstr
-#ocamlc -custom other options nums.cma other files -cclib -lnums
-#ocamlc -custom other options unix.cma other files -cclib -lunix
-#ocamlc -custom other options dbm.cma other files -cclib -lmldbm -cclib -lndbm
+#ocamlc -custom other options graphics.cma other files
+#ocamlc -thread -custom other options threads.cma other files 
+#ocamlc -custom other options str.cma other files 
+#ocamlc -custom other options nums.cma other files 
+#ocamlc -custom other options unix.cma other files 
+#ocamlc -custom other options dbm.cma other files 
 
 SOURCES1 = $(SOURCES:.mly=.ml)
 SOURCES2 = $(SOURCES1:.mll=.ml)

 AURにも公開済みなので普通に使うならそちらを使ったほうが良い。

 ちなみにmegamをインストールして、先程怒られた箇所を再び叩いてみたが、以下のようになって一向に終わる気配がなくこの問題は解決したようには見えない。中途半端に終わってしまった。

>>>chunker = ConsecutiveNPChunker(train_sents)
optimizing with lambda = 0 
optimizing with lambda = 0
optimizing with lambda = 0
optimizing with lambda = 0
optimizing with lambda = 0
...(以下エンドレス)

参考

# 以下のサイトの手順をただパッチとして起こしただけなのでもしかしたらいろいろと良くない記事なのかもしれない……。