Okay thanks for the examples.

My suggestion that you look for matched using trimmed strings would find a
match of "International Federation of Red Cross and Red Crescent Societies"
with "International Federation of Red Cross and Red Crescent Societies
(IFRC)" the same for the warehouse example that you gave.

The last example is a little more problematic since the extra field has
been inserted in the middle of the string. First, how does the
find_max_match function do with this scenario? Well it will most likely
find goods donated by the "Australian Red Cross" but it will have
difficulty distinguishing between Blankets and Buckets which may have both
been donated by the Australian Red Cross. Maybe a better approach would be
to split the two strings are word boundaries and match all non trivial
strings (any word longer than length 1 so we don't match hyphens) Thus you
match the word set ["Blankets", "Australian", "Red", "Cross"] with ["
Blankets", "123457", "Australian", "Red", "Cross"] and get 4 exact word
matches which would be better than ["Buckets", "123458", "Australian", "Red",
"Cross"] which gives 3 exact word matches.

A strategy like this would be done in parts. If any part passes then the
result is returned. So any exact match would be done first on the whole
string if that passes no need to look for matches on trimmed strings, and
so on.

Graeme.



On 4 June 2013 17:34, Somay Jain <notifications@github.com> wrote:

> In modules/tests/web2unittest.py:
>
> > +            for i in range(n):
> > +                for j in range(m):
> > +                    if el_value[i] == text[j]:
> > +                        if i!=0 and j!=0:
> > +                            hash[i][j] = hash[i-1][j-1] + 1;
> > +                        else:
> > +                            hash[i][j] = 1
> > +                        if matched_len < hash[i][j]:
> > +                            matched_len = hash[i][j]
> > +
> > +            # Save the maximum matched option in matched_option.
> > +            # matched_len is the maximum matching length for the current option.
> > +            if matched_option == None or matched_len > max_len:
> > +                matched_option = option
> > +                max_len = matched_len
> > +
>
> The problem that I am trying to solve is -
> Say there is a test which has an autocomplete field with data
> "International Federation of Red Cross and Red Crescent Societies".
> This test runs successfully, it fills in "International Federation of Red
> Cross and Red Crescent Societies (IFRC)" in the field.
> Now, I wish to find the widget used in the form, say in the "default"
> template. Here, the organisation name is a dropdown. I want the same test
> to successfully run on both autocomplete and dropdown.
>
> Note that I have given test data as "International Federation of Red Cross
> and Red Crescent Societies" and it "International Federation of Red Cross
> and Red Crescent Societies (IFRC)" is present in the dropdown option.
>
> So, here the test will fail just because of missing (IFRC).
>
> Let len = length("International Federation of Red Cross and Red Crescent
> Societies")
>
> This commit does the following -
>
>    1. Looks for "International Federation of Red Cross and Red Crescent
>    Societies". (Because this is the longest possible match - exact match -
>    automatically handled by LCS)
>    2. Looks for "International Federation of Red Cross and Red Crescent
>    Societie" and "nternational Federation of Red Cross and Red Crescent
>    Societies" (because these are the substrings with length = len-1)
>    3. Looks for substrings with length = len - 2... ... so on.
>
> It stops wherever it gets the best match. (In this case, at step 1).
>
> It is assumed that the test data is written correctly and should match
> fully with the options field, but with moving development, if some minor
> changes are added, then the tests would not fail. Eg - This happens with
> tests with data "Lospalos Warehouse (Warehouse)". In some templates,
> (Warehouse) might not be present. Also, in SendItem test, "Blankets -
> Australian Red Cross" is used in the test data whereas "Blankets - 123457 -
> Australian Red Cross" is present in the options.
>
> SendItem used to pass before, but as I said, with minor changes in the
> options, this has started to fail.
>
> —
> Reply to this email directly or view it on GitHub<https://github.com/flavour/eden/pull/498/files#r4519519>
> .
>