Foma ~finite-state compiler and C library~
ちょっと前から自分の研究内容にFomaというFST構築ツールを使っている.
何をするのか?というと,要は「FSTネットワークを作ってくれますよ」 以上!
何に使うかと言うと,代表例「形態素形跡」 以上!
で,すめば良いのだが,Foma scriptというのを定義しないといけなく,ちと仕様を覚えるまで面倒くさい.
そこで,覚書を残しておく.
ちなみに形態素解析に関しては簡単なTurtorialがあって,MorphologicalAnalysisTutorial - foma - A self-contained tutorial for building morphological analyzers. - finite-state compiler and C library - Google Project Hosting
を見ればよいかと.
きょうの覚書は,「定義済みのlexcを連結させてネットワークを構築するには?」のケーススタディ.
「なぜこんなクソめんどくさいことをするのか?」というと,ペルシア語には「前置詞と名詞と名詞屈折辞と後置詞がすべてくっついて一つの語を成す言語現象が存在する」から.
今,
pšt 前置詞 〜の後ろに
bwm 名詞 屋根
ānea 代名詞 彼ら
ra 後置詞 Φ
という語が存在している.これがすべてくっついて
pštbwmšnw
という一語を成す現象が発生する.
この形態素解析をfomaで実現するならば,「品詞ごとにlexiconを定義して,後で定義済みのlexiconをくっつけて,文字遷移のFSTネットワークを構成する」という作業を要する.
で,以下がそのfoma script
!!! This is test foma script ! read lexc foma_lexicon read lexc lexc_file/N.lexc define n; read lexc lexc_file/P.lexc define p; ! Combine lexica into single lexicon regex p""n | p | n; define Lexicon; ! Morphophonemic rules !define YeInsertion [..] -> ی || و | ا _ {^ان} ; !define GafReplacement ی -> گ || ﻩ _ {^ان} ; !define NDeletion n -> 0 || _ "^"; ! Cleanup: remove morpheme boundaries define Cleanup1 "^" -> 0; ! replace "^" with nothing define Cleanup2 "~" -> "‌"; ! replace "~" with ZWNJ ! Compose lexicon with rules and cleanup rule to build grammar define Grammar Lexicon .o. Cleanup1 .o. Cleanup2 ; regex Grammar; ! Save into farsi.bin and exit save stack ./farsi.bin exit;
read lexc lexc_file/N.lexc define n;
で名詞のlexiconを読み込み,定義している.
同じく,前置詞のlexiconも読み込み,定義.
そして,名詞のlexiconと前置詞のlexiconをくっつけてひとつのネットワークを構築するのに
regex p""n | p | n; define Lexicon;
という命令を書く.
こうすると, p""n で「前置詞lexiconと名詞lexiconをくっつけたネットワーク」を意味する.ちなみにパイプライン(|)は論理和記号.
なので,目的を達成するのは,この後に後置詞のlexiconを接続すればよいことになる(名詞の屈折辞は名詞のlexiconの中に含まれているので,改めてくっつけなおす必要はない).