NAME
Text::Phonetic - A module implementing various phonetic algorithms
SYNOPSIS
use Text::Phonetic;
my $phonetic = Text::Phonetic::Metaphone->new();
$encoded_string = $phonetic->encode($string);
@encoded_list = $phonetic->encode(@list);
my $same = $phonetic->compare($string1,$string2);
This module provides an easy and convinient way to encode names with various phonetic algorithms. It acts as a wrapper arround other phonetic algorithm modules like Text::Metaphone, Text::DoubleMetaphone, Text::Soundex and also implements some other algorithms such as Text::Phonetic::DaitchMokotoff, Text::Phonetic::Koeln and Text::Phonetic::Phonix.
The module can easily be subclassed.
DESCRIPTION
new
$obj = Text::Phonetic::SUBCLASS->new({ %PARAMETERS })
You can pass arbitrary attributes to the constructor. The only global attribute is unidecode
which defaults to 1 if not set. This attribute controlls if non-latin characters should be transliterated to A-Z.
Additional attributes may be defined by subclasses.
encode
$RETURN_STRING = $obj->encode($STRING);
OR
@RETURN_LIST = $obj->encode(@LIST);
OR
$RETURN_LIST_REF = $obj->encode(@LIST);
Encodes the given string or list of strings. Returns a single value, array or array reference depending on the caller context and parameters.
compare
$RETURN_CODE = $obj->compare($STRING1,$STRING2);
The return code is an integer between 100 and 0 indicating the likelihood that the to results are the same. 100 usually means that the strings are completely identical. 90 means that the strings match after all non-latin characters have been transliterated. Values in between 90 and 0 mean that the given strings likely match. 0 means that the used alogorithm couldn't match the two strings at all. compare
is a shortcut to the $obj->_do_compare($CODE1,$CODE2)
method.
SUBLCASSING
You can easily subclass Text::Phonetic and add your own phonetic algorithm. All subclasses have to use Text::Phonetic as their base class, and the following methods need to be implemented:
_do_encode
$RESULT = $obj->_do_encode($STRING);
This method does the actual encoding. It should return only one element. (eg. string or some kind of reference)
_do_compare
$RETURN_STRING = $obj->_do_compare($RESULT1,$RESULT2);
If your _do_encode
method doesn't return a single string you also might need to implement a comparison method. It takes two results as returned by _do_encode
and returns an integer value between 90 and 0 (see "compare").
Object structure
The object is a simple Hash reference containing all parameters passed during construction.
Helper functions
- _is_inlist
-
Text::Phonetic::_is_inlist($STRING,@LIST); OR Text::Phonetic::_is_inlist($STRING,$LIST_REF);
Returns a true value if $STRING is in the supplied list. Otherwise return false.
- _compare_list
-
Text::Phonetic::_compare_list($LIST1_REF,$LIST2_REF);
Compares the two arrays and returns true if at least one element is equal (ignoring the position) in both lists.
SUPPORT
Please report any bugs or feature requests to text-phonetic@rt.cpan.org
, or through the web interface at http://rt.cpan.org. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
AUTHOR
Maroš Kollár
CPAN ID: MAROS
maros [at] k-1.com
http://www.k-1.com
COPYRIGHT � Text::Phonetic is Copyright (c) 2006,2007 Maroš. Kollár. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 238:
Non-ASCII character seen before =encoding in 'Maroš'. Assuming UTF-8