X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fstrgrp%2Fstrgrp.c;h=bab8d334a99eb6b0216c22cb806ea61f5b77b624;hp=12119a1f276c7e4c4a9776cf061d1b8dfc77eddf;hb=e8f7a978bf4eb41c1877958e31a1a7213680335b;hpb=911a66a7893ca7c8b225a1b5fd5ec55569b12632 diff --git a/ccan/strgrp/strgrp.c b/ccan/strgrp/strgrp.c index 12119a1f..bab8d334 100644 --- a/ccan/strgrp/strgrp.c +++ b/ccan/strgrp/strgrp.c @@ -108,10 +108,18 @@ strcossim(const int16_t ref[CHAR_N_VALUES], const int16_t key[CHAR_N_VALUES]) { /* Low-cost filter functions */ +static inline double +cossim_correction(const double s) +{ + return -((s - 0.5) * (s - 0.5)) + 0.33; +} + static inline bool should_grp_score_cos(const struct strgrp *const ctx, struct strgrp_grp *const grp, const char *const str) { - return ctx->threshold <= strcossim(ctx->pop, grp->pop); + const double s1 = strcossim(ctx->pop, grp->pop); + const double s2 = s1 + cossim_correction(s1); + return ctx->threshold <= s2; } static inline bool