morita
morit****@razil*****
2008年 7月 29日 (火) 14:21:59 JST
森です。
はい。SISなしのsen_patではsuffix_searchは効かないのです。
頑張りが足らなくてすみません。。
Kouhei Sutou さんは書きました:
> 須藤です。
>
> SEN_PAT_WITH_SISを指定していないsen_patに対する
> sen_pat_suffix_search()では検索キーに対して後方部分一
> 致(?)したキーがヒットしないのですが、これはそうい
> うものなのでしょうか?suffix_searchとなっていたので、
> SEN_PAT_WITH_SISを指定していなくても頑張るのかと
> 思ってしまいました。
>
> ↓のプログラムの実行例です。
>
> key: ナ: 9
>
> key: セ: 9
>
> key: セナ: 0
> セナ
>
> key: ナセナ: 9
>
> 実験プログラム
> #include <stdio.h>
> #include <string.h>
>
> #include <pat.h>
> #include <hash.h>
>
> static sen_id
> add(sen_ctx *context, sen_pat *pat, const char *key)
> {
> sen_table_search_flags flags;
>
> flags = SEN_TABLE_ADD;
> return sen_pat_lookup(context, pat, key, strlen(key), NULL, &flags);
> }
>
> #define BUFFER_SIZE 4096
>
> static void
> dump(sen_ctx *context, sen_pat *pat, const char *key)
> {
> sen_id id;
> sen_hash *hash;
> sen_hash_cursor *cursor;
> sen_rc rc;
>
> hash = sen_hash_create(context, NULL, sizeof(sen_id),
> 0, SEN_HASH_TINY, sen_enc_utf8);
> rc = sen_pat_suffix_search(context, pat, key, strlen(key), hash);
>
> printf("key: %s: %d\n", key, rc);
>
> cursor = sen_hash_cursor_open(context, hash,
> NULL, 0, NULL, 0,
> SEN_CURSOR_DESCENDING);
> id = sen_hash_cursor_next(context, cursor);
> while (id != SEN_ID_NIL) {
> sen_id *pat_id;
> void *hash_key;
> char key[BUFFER_SIZE];
> int size;
>
> sen_hash_cursor_get_key(context, cursor, &hash_key);
> pat_id = hash_key;
> size = sen_pat_get_key(context, pat, *pat_id, key, sizeof(key));
> key[size] = '\0';
> printf("%s\n", key);
> id = sen_hash_cursor_next(context, cursor);
> }
>
> printf("\n");
>
> sen_hash_cursor_close(context, cursor);
> sen_hash_close(context, hash);
> }
>
> int
> main(int argc, char **argv)
> {
> sen_ctx *context;
> sen_pat *pat;
>
> sen_init();
>
> context = sen_ctx_open(NULL, SEN_CTX_USEQL);
> pat = sen_pat_create(context, "/tmp/xxx", 128, 64,
> 0, /* SEN_PAT_WITH_SIS, */
> sen_enc_utf8);
>
> add(context, pat, "セナ");
> add(context, pat, "ナセナセ");
> add(context, pat, "Senna");
> add(context, pat, "セナ + Ruby");
> add(context, pat, "セナセナ");
>
> dump(context, pat, "ナ");
> dump(context, pat, "セ");
> dump(context, pat, "セナ");
> dump(context, pat, "ナセナ");
>
> sen_pat_close(context, pat);
> sen_ctx_close(context);
>
> sen_fin();
>
> return 0;
> }
>
> _______________________________________________
> Senna-dev mailing list
> Senna****@lists*****
> http://lists.sourceforge.jp/mailman/listinfo/senna-dev
> バグ報告方法:http://qwik.jp/senna/bug_report.html
>