]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Use the result of the fuzzy search in the current list as a lower bound for
authorBruno Haible <bruno@clisp.org>
Mon, 15 Sep 2008 00:48:04 +0000 (00:48 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:15:50 +0000 (12:15 +0200)
the fuzzy search in the compendiums.

gettext-tools/src/ChangeLog
gettext-tools/src/msgl-fsearch.c
gettext-tools/src/msgl-fsearch.h
gettext-tools/src/msgmerge.c

index 68e3bd515cfe6e0fc885bb82db56f1b7d052044e..bfed4904bd8acebf0842c565c0744a222a8a2ad9 100644 (file)
@@ -1,3 +1,12 @@
+2008-09-14  Bruno Haible  <bruno@clisp.org>
+
+       * msgl-fsearch.h (message_fuzzy_index_search): Add 'lower_bound'
+       argument.
+       * msgl-fsearch.c (message_fuzzy_index_search): Likewise.
+       * msgmerge.c (definitions_search_fuzzy): Use the result of the fuzzy
+       search in the current list as a lower bound for the fuzzy search in the
+       compendiums.
+
 2008-09-14  Bruno Haible  <bruno@clisp.org>
 
        * message.h (message_list_search_fuzzy, FUZZY_THRESHOLD): Clarify
index 8d7d5410e3f73a9432ff81b8123b22cdfe076ec4..e612f0172888f4ee5340bfe61349448bd4919565 100644 (file)
@@ -484,10 +484,13 @@ mult_index_list_free (struct mult_index_list *accu)
 }
 
 /* Find a good match for the given msgctxt and msgid in the given fuzzy index.
-   The match does not need to be optimal.  */
+   The match does not need to be optimal.
+   Ignore matches for which the fuzzy_search_goal_function is < LOWER_BOUND.
+   LOWER_BOUND must be >= FUZZY_THRESHOLD.  */
 message_ty *
 message_fuzzy_index_search (message_fuzzy_index_ty *findex,
-                           const char *msgctxt, const char *msgid)
+                           const char *msgctxt, const char *msgid,
+                           double lower_bound)
 {
   const char *str = msgid;
 
@@ -547,7 +550,7 @@ message_fuzzy_index_search (message_fuzzy_index_ty *findex,
                    if (count > accu.nitems)
                      count = accu.nitems;
 
-                   best_weight = FUZZY_THRESHOLD;
+                   best_weight = lower_bound;
                    best_mp = NULL;
                    for (ptr = accu.item; count > 0; ptr++, count--)
                      {
@@ -589,7 +592,7 @@ message_fuzzy_index_search (message_fuzzy_index_ty *findex,
     if (!(lmax <= SHORT_MSG_MAX))
       abort ();
 
-    best_weight = FUZZY_THRESHOLD;
+    best_weight = lower_bound;
     best_mp = NULL;
     for (l = lmin; l <= lmax; l++)
       {
index 6793cefef3e258abc7212db2b6b3920466e155dd..d5f7962519a2135eb456ed498c6105103200bb06 100644 (file)
@@ -1,5 +1,5 @@
 /* Fast fuzzy searching among messages.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2008 Free Software Foundation, Inc.
    Written by Bruno Haible <bruno@clisp.org>, 2006.
 
    This program is free software: you can redistribute it and/or modify
@@ -39,10 +39,13 @@ extern message_fuzzy_index_ty *
                                  const char *canon_charset);
 
 /* Find a good match for the given msgctxt and msgid in the given fuzzy index.
-   The match does not need to be optimal.  */
+   The match does not need to be optimal.
+   Ignore matches for which the fuzzy_search_goal_function is < LOWER_BOUND.
+   LOWER_BOUND must be >= FUZZY_THRESHOLD.  */
 extern message_ty *
        message_fuzzy_index_search (message_fuzzy_index_ty *findex,
-                                  const char *msgctxt, const char *msgid);
+                                  const char *msgctxt, const char *msgid,
+                                  double lower_bound);
 
 /* Free a fuzzy index.  */
 extern void
index b8df6a913737b4f7c0a3779002754a8c5af18d18..be765e9045651a3847b49130558917a261c86e42 100644 (file)
@@ -767,20 +767,31 @@ definitions_search_fuzzy (definitions_ty *definitions,
                               msgctxt, msgid);
   if (compendiums != NULL)
     {
+      double lower_bound_for_mp2;
       message_ty *mp2;
 
+      lower_bound_for_mp2 =
+       (mp1 != NULL
+        ? fuzzy_search_goal_function (mp1, msgctxt, msgid, 0.0)
+        : FUZZY_THRESHOLD);
+      /* This lower bound must be >= FUZZY_THRESHOLD.  */
+      if (!(lower_bound_for_mp2 >= FUZZY_THRESHOLD))
+       abort ();
+
       /* Create the fuzzy index lazily.  */
       if (definitions->comp_findex == NULL)
        definitions_init_comp_findex (definitions);
 
       mp2 = message_fuzzy_index_search (definitions->comp_findex,
-                                       msgctxt, msgid);
+                                       msgctxt, msgid,
+                                       lower_bound_for_mp2);
 
       /* Choose the best among mp1, mp2.  */
       if (mp1 == NULL
          || (mp2 != NULL
-             && (fuzzy_search_goal_function (mp2, msgctxt, msgid, 0.0)
-                 > fuzzy_search_goal_function (mp1, msgctxt, msgid, 0.0))))
+             && (fuzzy_search_goal_function (mp2, msgctxt, msgid,
+                                             lower_bound_for_mp2)
+                 > lower_bound_for_mp2)))
        mp1 = mp2;
     }