Open MarcMichalsky opened 1 year ago
Maybe that was a bit too cryptic. I'll try again here.
We are trying to find matching contacts for the account holder "Max and Marie Mustermann".
Here is the comparison of the results of the original algorithm compared to the results of the improvement.
Contact | Original Probability | New Probability | Ranking old | Ranking new |
---|---|---|---|---|
"Mustermann, Max" | 0.63936 | 0.63936 | 2 | 1 |
"Mustardman, Max" | 0.4091904 | 0.2045952 | 4 | 4 |
"Max" | 0.999 | 0.4995 | 1 | 2 |
"Zimmermann, Marie" | 0.26859259259259 | 0.1342962962963 | 6 | 6 |
"Meier, Marie" | 0.20640495867769 | 0.17283737024221 | 5 | 5 |
"Mustermann, Marc" | 0.59112426035503 | 0.29556213017751 | 3 | 3 |
"Mustermann" | 0.999 | 0.4995 | 1 | 2 |
We see that original algorithm always lets the shorter match win. That's a problem.
I have adapted the algorithm so that it takes into account the number of hits for the same contact for all name components (name_mutations
) in the weighting.
However, the search via getquick
is somewhat outdated, but the alternative search via SQL unfortunately has the same problem. The only problem is that the same solution cannot be applied there, as the result of the SQL query does not return the same contacts more than once. This means that it is not possible to weight them, at least not without making further queries. In addition, the SQL search only searches for name mutations that are at the beginning of the sort_name
:
https://github.com/Project60/org.project60.banking/blob/3d7172937fde04f4cfb9d4d4b0a595595fea9d12/api/v3/BankingLookup.php#L253
The algorithm that suggests contacts has a weakness.
When we search for a contact such as "Max Mustermann", we get a wrong probability if there are other contacts with partially matching but shorter names, such as "Max" or "Mustermann".
The problem is that the number of matches of all single name mutations with the same contact has no influence on the probability so far.
Also, I think that squaring the
$new_probability
should be done before comparing it to the old$probability
. Otherwise, there could be a small but unintended shift in each iteration.I did my best to find a better algorithm and if you like it, I can do a PR.
Here is my code for testing:
Result: