null+****@clear*****
null+****@clear*****
2011年 8月 18日 (木) 19:18:30 JST
Kouhei Sutou 2011-08-18 10:18:30 +0000 (Thu, 18 Aug 2011)
New Revision: 62a3680a31093ea4a0940525064899a23d6796cc
Log:
[suggest] add 'p' parameter for conditional probability.
Modified files:
src/suggest/groonga_suggest_httpd.c
src/suggest/groonga_suggest_learner.c
src/suggest/util.c
src/suggest/util.h
Modified: src/suggest/groonga_suggest_httpd.c (+16 -9)
===================================================================
--- src/suggest/groonga_suggest_httpd.c 2011-08-18 09:52:59 +0000 (3e2da20)
+++ src/suggest/groonga_suggest_httpd.c 2011-08-18 10:18:30 +0000 (f3c72ad)
@@ -98,7 +98,8 @@ static uint32_t n_lines_per_log_file = 1000000;
static int
suggest_result(struct evbuffer *res_buf, const char *types, const char *query,
- const char *target_name, int threshold, int limit,
+ const char *target_name, int frequency_threshold,
+ double conditional_probability_threshold, int limit,
grn_obj *cmd_buf, grn_ctx *ctx)
{
if (target_name && types && query) {
@@ -109,8 +110,10 @@ suggest_result(struct evbuffer *res_buf, const char *types, const char *query,
grn_text_urlenc(ctx, cmd_buf, types, strlen(types));
GRN_TEXT_PUTS(ctx, cmd_buf, "&query=");
grn_text_urlenc(ctx, cmd_buf, query, strlen(query));
- GRN_TEXT_PUTS(ctx, cmd_buf, "&threshold=");
- grn_text_itoa(ctx, cmd_buf, threshold);
+ GRN_TEXT_PUTS(ctx, cmd_buf, "&frequency_threshold=");
+ grn_text_itoa(ctx, cmd_buf, frequency_threshold);
+ GRN_TEXT_PUTS(ctx, cmd_buf, "&conditional_probability_threshold=");
+ grn_text_ftoa(ctx, cmd_buf, conditional_probability_threshold);
GRN_TEXT_PUTS(ctx, cmd_buf, "&limit=");
grn_text_itoa(ctx, cmd_buf, limit);
{
@@ -135,12 +138,14 @@ log_send(struct evkeyvalq *output_headers, struct evbuffer *res_buf,
thd_data *thd, struct evkeyvalq *get_args)
{
uint64_t millisec;
- int threshold, limit;
+ int frequency_threshold, limit;
+ double conditional_probability_threshold;
const char *callback, *types, *query, *client_id, *target_name,
*learn_target_name;
parse_keyval(get_args, &query, &types, &client_id, &target_name,
- &learn_target_name, &callback, &millisec, &threshold, &limit);
+ &learn_target_name, &callback, &millisec, &frequency_threshold,
+ &conditional_probability_threshold, &limit);
/* send data to learn client */
if (thd->zmq_sock && millisec && client_id && query && learn_target_name) {
@@ -215,15 +220,17 @@ log_send(struct evkeyvalq *output_headers, struct evbuffer *res_buf,
evbuffer_add(res_buf, callback, content_length);
evbuffer_add(res_buf, "(", 1);
content_length += suggest_result(res_buf, types, query, target_name,
- threshold, limit,
- &(thd->cmd_buf), thd->ctx) + 3;
+ frequency_threshold,
+ conditional_probability_threshold,
+ limit, &(thd->cmd_buf), thd->ctx) + 3;
evbuffer_add(res_buf, ");", 2);
} else {
evhttp_add_header(output_headers,
"Content-Type", "application/json; charset=UTF-8");
content_length = suggest_result(res_buf, types, query, target_name,
- threshold, limit,
- &(thd->cmd_buf), thd->ctx);
+ frequency_threshold,
+ conditional_probability_threshold,
+ limit, &(thd->cmd_buf), thd->ctx);
}
if (content_length >= 0) {
char num_buf[16];
Modified: src/suggest/groonga_suggest_learner.c (+1 -1)
===================================================================
--- src/suggest/groonga_suggest_learner.c 2011-08-18 09:52:59 +0000 (2c7952b)
+++ src/suggest/groonga_suggest_learner.c 2011-08-18 10:18:30 +0000 (26bfbb4)
@@ -543,7 +543,7 @@ read_log_line(suggest_log_file **list)
*eol = '\0';
evhttp_parse_query(line_buf, &get_args);
parse_keyval(&get_args, &query, &types, &client_id, NULL,
- &learn_target_name, NULL, &(t->millisec), NULL, NULL);
+ &learn_target_name, NULL, &(t->millisec), NULL, NULL, NULL);
if (query && client_id && learn_target_name && t->millisec) {
t->query = evhttp_decode_uri(query);
t->submit = (types && !strcmp(types, "submit"));
Modified: src/suggest/util.c (+17 -5)
===================================================================
--- src/suggest/util.c 2011-08-18 09:52:59 +0000 (cc6352a)
+++ src/suggest/util.c 2011-08-18 10:18:30 +0000 (6852760)
@@ -28,7 +28,8 @@
#include "util.h"
-#define DEFAULT_THRESHOLD 100
+#define DEFAULT_FREQUENCY_THRESHOLD 100
+#define DEFAULT_CONDITIONAL_PROBABILITY_THRESHOLD 0.2
int
print_error(const char *format, ...)
@@ -100,7 +101,8 @@ parse_keyval(struct evkeyvalq *get_args,
const char **learn_target_name,
const char **callback,
uint64_t *millisec,
- int *threshold,
+ int *frequency_threshold,
+ double *conditional_probability_threshold,
int *limit)
{
struct evkeyval *get;
@@ -112,7 +114,12 @@ parse_keyval(struct evkeyvalq *get_args,
if (learn_target_name) { *learn_target_name = NULL; }
if (callback) { *callback = NULL; }
if (millisec) { *millisec = 0; }
- if (threshold) { *threshold = DEFAULT_THRESHOLD; }
+ if (frequency_threshold) {
+ *frequency_threshold = DEFAULT_FREQUENCY_THRESHOLD;
+ }
+ if (conditional_probability_threshold) {
+ *conditional_probability_threshold = DEFAULT_CONDITIONAL_PROBABILITY_THRESHOLD;
+ }
if (limit) { *limit = -1; }
TAILQ_FOREACH(get, get_args, next) {
@@ -155,8 +162,13 @@ parse_keyval(struct evkeyvalq *get_args,
}
break;
case 'h':
- if (threshold) {
- *threshold = atoi(get->value);
+ if (frequency_threshold) {
+ *frequency_threshold = atoi(get->value);
+ }
+ break;
+ case 'p':
+ if (conditional_probability_threshold) {
+ *conditional_probability_threshold = strtod(get->value, NULL);
}
break;
case 'm':
Modified: src/suggest/util.h (+2 -1)
===================================================================
--- src/suggest/util.h 2011-08-18 09:52:59 +0000 (dafc8eb)
+++ src/suggest/util.h 2011-08-18 10:18:30 +0000 (831c5b7)
@@ -29,7 +29,8 @@ void parse_keyval(struct evkeyvalq *get_args,
const char **learn_target_name,
const char **callback,
uint64_t *millisec,
- int *threshold,
+ int *frequency_threshold,
+ double *conditional_probability_threshold,
int *limit);
#endif /* GRN_SUGGEST_UTIL_H */