#======================================================================
#
# NAME
#   s_geta_products.pl -- 文書連想検索プログラム（GETA_PRODUCTS用）
#
# DESCRIPTION
#   商品ID（行name）から該当文書を要約し、それをもとに連想検索。
#
# 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 = "";

#引数１  検索対象nameファイル名
  $infile = shift @ARGV;
  
#引数２  検索対象WAMハンドルショートネーム
  $handle = shift @ARGV;

  ($w = &wam::open($handle)) != 0 or die "ERROR: cannot open\n";

  open (FILE, $infile) or die "ERROR: cannot open name_text\n";
  while ($line = <FILE>)  {
   #nameからidを取得
   $id = &wam::name2id($w, WAM_ROW, $line);
   if ($id) {
     %tx = ("name" => $line, "id" => $id, "TF" => 0, "TF_d" => 1, "weight" => 0);
     push (@rq, { %tx });
   }
  }
  close (FILE);
  
#引数３  特徴語取得件数
  $row_max = shift @ARGV;

  $rd = &wam::wsh(\@rq, $w, WAM_ROW, &wam::WT_SMART, $row_max, 0, $w);

#引数４  検索結果取得件数
  $col_max = shift @ARGV;

  $rc = &wam::wsh($rd, $w, WAM_COL, &wam::WT_SMART, $col_max, 0, $w);

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