commuterjoy / yeti-witch

Automatically exported from code.google.com/p/yeti-witch
Other
1 stars 0 forks source link

A few small bugs #1

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

A few issues to report on an otherwise very well-functioning metaphone()...

1) 

Line 239 has a bug. Instead of:

code.append('F'); break ;

...it should be:

code += 'F'; break ;

2) 

This code at the end of String.prototype.metaphone seems it will have no
effect:
if (code.length >= maxCodeLen) {
                code.substring(0, maxCodeLen);
            }

I believe you want:
if (code.length >= maxCodeLen) {
                code = code.substring(0, maxCodeLen);
            }

3)

If you want to follow the PHP/Perl implementation (not sure if you care to,
as I'm not clear that it was any part of the original metaphone()
algorithm), you can change lines 145-148 to add an extra 'if' which may
treat 'gh' at the end, not only potentially as silent (as you have it now),
but also as 'f' (as in "cough"), if it doesn't follow the pattern b--gh,
d--gh, h--gh, or h---gh:

if (isLastChar(wdsz, n + 1) &&
                        isNextChar(local, n, 'H')) {
                        if (!(isPreviousChar(local, n - 2, 'B') ||
isPreviousChar(local, n - 2, 'D') || isPreviousChar(local, n - 2, 'H') ||
isPreviousChar(local, n - 3, 'H'))) {
                            code += 'F';
                        }
                        break;
                    }

Original issue reported on code.google.com by bret...@gmail.com on 28 Jun 2009 at 3:05

GoogleCodeExporter commented 8 years ago
Hi, sorry I only just spotted this in my inbox. Thanks for spotting this, I'll 
patch 
the code. with your fix.

Out of interest are you using the code for anything interesting or just 
browsing?

Original comment by commuter...@gmail.com on 10 Jul 2009 at 8:43

GoogleCodeExporter commented 8 years ago
Np... Someone had submitted an implementation to our site of PHP-JavaScript
equivalents: http://phpjs.org/contributions/add . As I recall, I adapted your 
code
for our purposes, I think because I was unclear whether his code fit the PHP
implementation or not, but ended up going with his implementation. I don't 
remember
if I benchmarked it, or I just went with his because he was the original 
submitter.
In any case, you can see our latest at http://phpjs.org/functions/metaphone . 
The
experience led me to file 2 bugs to PHP (since their own version was a little 
buggy);
one of them the team fixed, and the other one I need to prepare another patch 
for
them, so thanks for inspiring that too.

Original comment by bret...@gmail.com on 9 Aug 2009 at 4:55