Ознакомьтесь с алгоритмом Soundex в Википедии, вы не указали язык, но там есть ссылки на примеры реализации на нескольких языках. Очевидно, что это даст вам хеш-строку, которая одинакова для похожих звучащих слов, и вы захотите целое число, но затем вы можете применить метод хеширования string-> integer, который они используют в Boost.Hash .
Редактировать: Для пояснения, вот пример реализации C ++ ...
#include <boost/foreach.hpp>
#include <boost/functional/hash.hpp>
#include <algorithm>
#include <string>
#include <iostream>
char SoundexChar(char ch)
{
switch (ch)
{
case 'B':
case 'F':
case 'P':
case 'V':
return '1';
case 'C':
case 'G':
case 'J':
case 'K':
case 'Q':
case 'S':
case 'X':
case 'Z':
return '2';
case 'D':
case 'T':
return '3';
case 'M':
case 'N':
return '5';
case 'R':
return '6';
default:
return '.';
}
}
std::size_t SoundexHash(const std::string& word)
{
std::string soundex;
soundex.reserve(word.length());
BOOST_FOREACH(char ch, word)
{
if (std::isalpha(ch))
{
ch = std::toupper(ch);
if (soundex.length() == 0)
{
soundex.append(1, ch);
}
else
{
ch = SoundexChar(ch);
if (soundex.at(soundex.length() - 1) != ch)
{
soundex.append(1, ch);
}
}
}
}
soundex.erase(std::remove(soundex.begin(), soundex.end(), '.'), soundex.end());
if (soundex.length() < 4)
{
soundex.append(4 - soundex.length(), '0');
}
else if (soundex.length() > 4)
{
soundex = soundex.substr(0, 4);
}
return boost::hash_value(soundex);
}
int main()
{
std::cout << "Color = " << SoundexHash("Color") << std::endl;
std::cout << "Colour = " << SoundexHash("Colour") << std::endl;
std::cout << "Gray = " << SoundexHash("Gray") << std::endl;
std::cout << "Grey = " << SoundexHash("Grey") << std::endl;
return 0;
}