暑いので、涼しくなるまで Anthy の作業は休もうと思います。

今、僕は DFA のブランチの実装を使っています。しばらく使ってみてどんなも
んか見てみたいと思います。

feature/trellis というブランチを作って、作業することにしました。

src-splitter/trellis.c を作りました。

現在、まだちゃんとした評価関数は作ってませんが、trellis を構成して、
Dynamic Programming で path を探索し、最小コストの道の iterator を返す
(複数あり得るので)という構成にしています。

それでもってこのメールの最後に添付のテストプログラムとリンクして、漢字
かな混じり文から、どのようにtrellis が構成されるか試しています。今のと
ころ、評価関数は文節の数なので文節数最小がでます。

テスト:
        $ ./a.out <test.txt | sort | uniq
-------------------------
<もともと><方式が><良くないのかも><。>
<実際の><ところ><この><方式><はどうなんでしょうか><。>
<実際の><ところ><この><方式は><どうなんでしょうか><。>
<実際の><ところ><この方><式><はどうなんでしょうか><。>
<実際の><ところ><この方><式は><どうなんでしょうか><。>
<方式は><良いとしても><実装に><問題あり><、><なのかも><。>
<方式も><実装も><良かったとしても><データが><集まってなくて><結果が><出ていないということも><ありえます><。>
-------------------------

これまでの感想ですが metaword を構成した後、同一の結果をもたらす
metaword は削る、という段階が必要なんじゃないかなぁ、と感じています。

これからですが、現在の lattice.c による文節区切りの演算と同等の評価関数
を作るのは、得策ではないと思います。暖かい目で lattice.c がやりたかった
であろうところを拾う、という感じでしょうか。評価関数の実装方針としては、
下記です。

(1) cmp_node で実装されている metaword の選択、adjusted_probability に
    反映されるmw->score による評価は、別の(前)段階で行う。
    (trellis の path の評価関数の演算では取り扱わない。)
(2) log の空間で足し算/引き算で演算。整数で。
    (確率 1.0 はコストに 0 を足すということ。)
(3) feature_set から値を取り出して使うのは(今のところしょうがないので)やってみる。
(4) ポアソン分布はやるとしても表を引く形で。(やらないかも)
(5) 文頭/文末の特別扱いはやるのかなぁ。

------------------------------
/*
 * gcc -DHAVE_CONFIG_H -I. -I.. -g -O2 -c test-trellis.c
 * gcc test-trellis.o ../src-main/.libs/libanthy.a 
../src-worddic/.libs/libanthydic.a -lm
 *
 * ./a.out <test.txt
 *
 * Written by NIIBE Yutaka, 2010-08-06
 *
 * This code is put under public domain.
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <anthy/anthy.h>
#include <anthy/splitter.h>
#include "src-main/main.h"

#define BUFSIZE 1024

struct node *trellis_init (struct splitter_context *sc, int from, int to);
void trellis_print_path (struct splitter_context *sc, struct node *node);
int trellis_next_path (struct node *node);
void trellis_free (struct node *node);

int
main (int argc, const char *argv[])
{
  anthy_context_t ac;
  char buf[BUFSIZE];
  char *s;

  anthy_init ();
  anthy_set_personality ("");
  ac = anthy_create_context ();
#if 0
  anthy_context_set_encoding (ac, ANTHY_UTF8_ENCODING);
#endif

  while (1)
    {
      xstr *xs;
      struct node *n;

      s = fgets (buf, BUFSIZE, stdin);
      if (s == NULL)
        break;

      s[strlen (s) - 1] = '\0';

      anthy_do_reset_context (ac);
      if (!ac->dic_session)
        ac->dic_session = anthy_dic_create_session ();
      if (!ac->dic_session)
        exit (1);
      anthy_dic_activate_session (ac->dic_session);
      anthy_reload_record ();
      xs = anthy_cstr_to_xstr (s, ac->encoding);
      ac->str.str = (xchar *)malloc (sizeof (xchar) * (xs->len + 1));
      if (ac->str.str == NULL)
        exit (1);
      anthy_xstrcpy (&ac->str, xs);
      ac->str.str[xs->len] = 0;

      anthy_init_split_context (&ac->str, &ac->split_info, 1); /* 1 for 
reverse*/
      n = trellis_init (&ac->split_info, 0, xs->len);
      do
        trellis_print_path (&ac->split_info, n);
      while (trellis_next_path (n) == 0);
      trellis_free (n);
      anthy_free_xstr (xs);
    }

  return 0;
}
-- 

_______________________________________________
Anthy-dev mailing list
Anthy-dev@lists.sourceforge.jp
http://lists.sourceforge.jp/mailman/listinfo/anthy-dev

メールによる返信