Add a basic feedback system
This commit is contained in:
parent
a4378fdaf2
commit
d73a3aa89a
5 changed files with 50 additions and 12 deletions
|
@ -71,8 +71,7 @@ struct _edge {
|
|||
node * child;
|
||||
/* the parent node */
|
||||
node * parent;
|
||||
uint64_t hits;
|
||||
float score;
|
||||
float score;
|
||||
bool has_slug:1;
|
||||
};
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ edge * r3_edge_create(char * pattern, int pattern_len, node * child) {
|
|||
child->parent_edge = e;
|
||||
|
||||
// default stats
|
||||
e->hits = 0;
|
||||
// e->hits = 0;
|
||||
e->score = 0;
|
||||
return e;
|
||||
}
|
||||
|
|
24
src/node.c
24
src/node.c
|
@ -116,9 +116,22 @@ edge * r3_node_add_child(node * n, char * pat , node *child) {
|
|||
}
|
||||
|
||||
void r3_tree_feedback(node *tree, node *end) {
|
||||
edge * e;
|
||||
while( (e = end->parent_edge) != NULL ) {
|
||||
edge * e = end->parent_edge;
|
||||
node * p = e->parent;
|
||||
while( p && e ) {
|
||||
e->score += 0.1;
|
||||
|
||||
|
||||
if (e->score > 100) {
|
||||
for (int i = 0 ; i < p->edge_len ; i++ ) {
|
||||
if ( p->edges[i]->score > 0 ) {
|
||||
p->edges[i]->score /= 100;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
e = p->parent_edge;
|
||||
p = e ? e->parent : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -564,10 +577,6 @@ void r3_tree_dump(node * n, int level) {
|
|||
printf(" regexp:%s", n->combined_pattern);
|
||||
}
|
||||
|
||||
if ( n->parent_edge ) {
|
||||
printf(" belongs to edge:%p", n->parent_edge);
|
||||
}
|
||||
|
||||
printf(" endpoint:%d", n->endpoint);
|
||||
|
||||
if (n->data) {
|
||||
|
@ -580,6 +589,9 @@ void r3_tree_dump(node * n, int level) {
|
|||
print_indent(level + 1);
|
||||
printf("|-\"%s\"", e->pattern);
|
||||
|
||||
// printf(" hits:%lld score:%.1f ", e->hits, e->score);
|
||||
printf(" score:%.1f ", e->score);
|
||||
|
||||
if ( e->child ) {
|
||||
printf("\n");
|
||||
r3_tree_dump( e->child, level + 1);
|
||||
|
|
|
@ -453,3 +453,19 @@
|
|||
1400749326,13242705.99
|
||||
1400749599,13245418.70
|
||||
1400749614,12494314.81
|
||||
1400749643,12690632.63
|
||||
1400749676,10154614.63
|
||||
1400749681,10313142.07
|
||||
1400749696,10511488.62
|
||||
1400749780,10359781.60
|
||||
1400749808,10187594.58
|
||||
1400749822,10446286.96
|
||||
1400749888,10342786.49
|
||||
1400749944,10491740.29
|
||||
1400749951,10544104.04
|
||||
1400750350,10391028.46
|
||||
1400750424,9445761.22
|
||||
1400750472,9248611.74
|
||||
1400750479,10757562.36
|
||||
1400750512,10126746.58
|
||||
1400750536,10568568.26
|
||||
|
|
|
|
@ -737,10 +737,20 @@ START_TEST(test_feedback)
|
|||
r3_tree_insert_path(t, "/garply/corge/grault", NULL);
|
||||
r3_tree_compile(t);
|
||||
|
||||
node * m = r3_tree_match(t, "/foo/grault/bar", NULL);
|
||||
ck_assert(m != NULL);
|
||||
node * m1 = r3_tree_match(t, "/foo/grault/bar", NULL);
|
||||
node * m2 = r3_tree_match(t, "/garply/corge/grault", NULL);
|
||||
ck_assert(m1 != NULL);
|
||||
ck_assert(m2 != NULL);
|
||||
|
||||
r3_tree_feedback(t, m);
|
||||
for ( int i = 0 ; i < 120 ; i++ ) {
|
||||
r3_tree_feedback(t, m1);
|
||||
}
|
||||
|
||||
for ( int i = 0 ; i < 200 ; i++ ) {
|
||||
r3_tree_feedback(t, m2);
|
||||
}
|
||||
|
||||
r3_tree_dump(t, 0);
|
||||
|
||||
r3_tree_free(t);
|
||||
}
|
||||
|
@ -764,6 +774,7 @@ Suite* r3_suite (void) {
|
|||
tcase_add_test(tcase, test_pcre_patterns_insert);
|
||||
tcase_add_test(tcase, test_pcre_patterns_insert_2);
|
||||
tcase_add_test(tcase, test_pcre_patterns_insert_3);
|
||||
tcase_add_test(tcase, test_feedback);
|
||||
tcase_add_test(tcase, benchmark_str);
|
||||
|
||||
suite_add_tcase(suite, tcase);
|
||||
|
|
Loading…
Reference in a new issue