| ... | ... |
@@ -44,6 +44,10 @@ int test_scoring(){
|
| 44 | 44 |
/* Prefer shorter matches */ |
| 45 | 45 |
assert(match("test", "tests") > match("test", "testing"));
|
| 46 | 46 |
|
| 47 |
+ /* Prefer shorter matches */ |
|
| 48 |
+ assert(match("abc", " a b c ") > match("abc", " a b c "));
|
|
| 49 |
+ assert(match("abc", " a b c ") > match("abc", " a b c "));
|
|
| 50 |
+ |
|
| 47 | 51 |
return 0; |
| 48 | 52 |
} |
| 49 | 53 |
|
| ... | ... |
@@ -29,9 +29,9 @@ void mat_print(score_t *mat, int n, int m){
|
| 29 | 29 |
for(j = 0; j < m; j++){
|
| 30 | 30 |
score_t val = mat[i*m + j]; |
| 31 | 31 |
if(val == SCORE_MIN){
|
| 32 |
- fprintf(stderr, " -inf"); |
|
| 32 |
+ fprintf(stderr, " -inf"); |
|
| 33 | 33 |
}else{
|
| 34 |
- fprintf(stderr, " %.2f", val); |
|
| 34 |
+ fprintf(stderr, " % .2f", val); |
|
| 35 | 35 |
} |
| 36 | 36 |
} |
| 37 | 37 |
fprintf(stderr, "\n"); |
| ... | ... |
@@ -65,8 +65,8 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio |
| 65 | 65 |
* M[][] Stores the best possible score at this position. |
| 66 | 66 |
*/ |
| 67 | 67 |
|
| 68 |
-#define SCORE_GAP_LEADING -0.01 |
|
| 69 |
-#define SCORE_GAP_TRAILING -0.01 |
|
| 68 |
+#define SCORE_GAP_LEADING -0.005 |
|
| 69 |
+#define SCORE_GAP_TRAILING -0.005 |
|
| 70 | 70 |
#define SCORE_GAP_INNER -0.01 |
| 71 | 71 |
#define SCORE_MATCH_CONSECUTIVE 1.0 |
| 72 | 72 |
#define SCORE_MATCH_SLASH 1.5 |
| ... | ... |
@@ -129,8 +129,10 @@ double calculate_score(const char *needle, const char *haystack, size_t *positio |
| 129 | 129 |
} |
| 130 | 130 |
|
| 131 | 131 |
#if 0 |
| 132 |
+ printf("\"%s\" =~ \"%s\"\n", needle, haystack);
|
|
| 132 | 133 |
mat_print(&D[0][0], n, m); |
| 133 | 134 |
mat_print(&M[0][0], n, m); |
| 135 |
+ printf("\n");
|
|
| 134 | 136 |
#endif |
| 135 | 137 |
|
| 136 | 138 |
/* backtrace to find the positions of optimal matching */ |