php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48711 metaphone() and sch, ch, gh
Submitted: 2009-06-29 04:00 UTC Modified: 2013-02-18 00:33 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: brettz9 at yahoo dot com Assigned: pajoye (profile)
Status: No Feedback Package: Strings related
PHP Version: 5.3 OS: Windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: brettz9 at yahoo dot com
New email:
PHP Version: OS:

 

 [2009-06-29 04:00 UTC] brettz9 at yahoo dot com
Description:
------------
Below are a few bugs remaining in metaphone()--they are both useful and follow the original implementation. I haven't tested them (a newbie to C), but they seem to follow the precise pattern.

1) SCH: There seems to be no way for the 'traditional' argument in metaphone() to be triggered (it is called on line 44 with '1' which disables those items depending on it). Shouldn't it be set to '0' in the call on line 44 (or have the requirement removed entirely)? For example, line 314 is not working now for treating items like "ch" in "school" as "K". If there's no way to trigger the behavior (and the behavior should be standard), it seems to me best to remove the requirement.

2) CH: should check for first position 'C': if the next char is 'H' and then a vowel, it should produce 'K'

To fix, in the switch beginning at 205 for initial character (e.g., could put before 219):
case 'C':
    if (Next_Letter == 'H' && isvowel(After_Next_Letter)) { // 'character'
        Phonize('K');
        w_idx += 2;
    }
    break;

3) GH: should be pronounced as 'K' if at the beginning (and if then followed by a vowel), not as 'F';

The case for initial 'G' on line 219 could be changed to:

    case 'G':
        if (Next_Letter == 'H' && isvowel(After_Next_Letter)) { // 'ghent'
            Phonize('K');
            w_idx += 2;
            break;
        } else

4) GH: should be silent in the likes of 'knight'/'wright', not 'F'

    under the 2nd 'G' case (insert right after line 341):

                if (After_Next_Letter != '\0' && !isvowel(After_Next_Letter) { // 'gh' followed by consonant, as in 'knight'
                    /* silent */
                } else 

Thanks!

Reproduce code:
---------------
<?php

echo metaphone('school'), '<br />';
echo metaphone('character'), '<br />';
echo metaphone('ghent'), '<br />';
echo metaphone('knight'), '<br />';

?>

Expected result:
----------------
SKL
KRKTR
KNT
NT

Actual result:
--------------
SXL
XRKTR
FNT
NFT

Patches

bug48711.patch (last revision 2011-02-26 17:48 UTC by jthijssen at noxlogic dot nl)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-29 04:06 UTC] brettz9 at yahoo dot com
My apologies, I was off by one line number in item #4; it should instead say:

inside the first 'if' of the 2nd 'G' case (insert right after line 342):
 [2009-07-26 19:36 UTC] jani@php.net
Please provide patches against all current branches, I don't think this 
is just an issue with HEAD?
 [2009-08-03 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2011-02-26 19:54 UTC] jthijssen at noxlogic dot nl
I've added a patch with the 4 items as described by brettz9.

The first one introduces a "traditional" boolean flag in metaphone as a third optional parameter. I'm not 100% sure why this parameter is here. Either we should always convert CHR/SCH to X or to K. It makes the function much more complicated this way for end-users.
 [2011-02-26 20:18 UTC] pajoye@php.net
-Status: No Feedback +Status: Feedback -PHP Version: 6CVS-2009-06-29 (snap) +PHP Version: 5.3 -Assigned To: +Assigned To: pajoye
 [2011-02-26 20:18 UTC] pajoye@php.net
hi,

Thanks for the patch!

Can you add a test case for it please?
 [2011-02-26 20:24 UTC] jthijssen at noxlogic dot nl
Pierre, I've added a phpt testcase inside the patch (bug48711.phpt). Or do you mean a phpt for the extra metaphone parameter (probably a metaphone_variation.phpt)?
 [2011-05-06 09:03 UTC] brettz9 at yahoo dot com
The "traditional" flag was based on existing code (though not exposed publicly), presumably to distinguish which metaphone() algorithm was intended: the original BASIC implementation or later versions (see http://aspell.net/metaphone/)/PHP's own innovations.
 [2013-02-18 00:33 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 22:01:29 2024 UTC