#======================================================================
#
# NAME
#   tw_geta_themes.pl -- 文書要約プログラム（GETA_THEMES用）
#
# DESCRIPTION
#   外部テキストファイル（EUC）の文書から連想検索。
#
# AUTHOR
#   Ryuhei Aoki <ryuhei@secondbrain.co.jp>
#   Secondbrain Ltd.
#======================================================================
  BEGIN{
      use File::Basename;
      my $config_file  = dirname($0)."/config.pl";
      require $config_file;
      unshift(@INC, "$LIB", "$LIB/blib/lib", "$LIB/blib/arch");
  };

  use wam ('WAM_ROW', 'WAM_COL');

  &wam::init($GETAROOT) == 0 or die "ERROR: cannot initialize\n";

  $input = "";

#引数１  検索対象文書ファイル名
  $infile = shift @ARGV;

  open (FILE, $infile) or die "ERROR: cannot open search_text\n";
  while ($line = <FILE>)  {
   $input .= $line;
  }
  close (FILE);
  
#引数２  検索対象WAMハンドルショートネーム
  $handle = shift @ARGV;

  ($w = &wam::open($handle)) != 0 or die "ERROR: cannot open\n";
  
#引数３  形態素分析スクリプトパス
  $ma = shift @ARGV;

  $rq = &wam::wstem($input, $w, WAM_COL, $ma);

#引数４  検索結果取得件数
  $max = shift @ARGV;
#引数５  検索結果取得開始件数（検索結果の先頭からこの数未満の件数を無視）
  $start = shift @ARGV;
  if ($start < 1) {$start = 1;}
  
  $max = $max + $start - 1;

  $rd = &wam::wsh($rq, $w, WAM_COL, &wam::WT_SMART, $max, 0, $w);

  $rc = &wam::wsh($rd, $w, WAM_ROW, &wam::WT_SMART, $max, 0, $w);

  for (my $i = $start-1; $i < @$rc; $i++) {
      printf "%s\n", $rc->[$i]{"name"};
  }
