X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fstrgrp%2Fstrgrp.c;h=bab8d334a99eb6b0216c22cb806ea61f5b77b624;hb=2d17aeeecc0ae1f16398960bd41a2e7047e57c60;hp=111e592edb8920cb5a9c27ea184d6d97be98d0ff;hpb=44c0274ac8f2a16c981e706d4386f899c5e206f5;p=ccan diff --git a/ccan/strgrp/strgrp.c b/ccan/strgrp/strgrp.c index 111e592e..bab8d334 100644 --- a/ccan/strgrp/strgrp.c +++ b/ccan/strgrp/strgrp.c @@ -103,15 +103,23 @@ strcossim(const int16_t ref[CHAR_N_VALUES], const int16_t key[CHAR_N_VALUES]) { sai2 += ref[i] * ref[i]; sbi2 += key[i] * key[i]; } - return saibi / (sqrt(sai2) * sqrt(sbi2)); + return 1.0 - (2 * acos(saibi / sqrt(sai2 * sbi2)) / M_PI); } /* 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