How to resolve the algorithm Soundex step by step in the Objeck programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Soundex step by step in the Objeck programming language
Table of Contents
Problem Statement
Soundex is an algorithm for creating indices for words based on their pronunciation.
The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling (from the soundex Wikipedia article). There is a major issue in many of the implementations concerning the separation of two consonants that have the same soundex code! According to the official Rules [[1]]. So check for instance if Ashcraft is coded to A-261.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Soundex step by step in the Objeck programming language
Source code in the objeck programming language
class SoundEx {
function : Main(args : String[]) ~ Nil {
SoundEx("Soundex")->PrintLine();
SoundEx("Example")->PrintLine();
SoundEx("Sownteks")->PrintLine();
SoundEx("Ekzampul")->PrintLine();
}
function : SoundEx(s : String) ~ String {
input := s->ToUpper()->Get(0);
code := input->ToString();
previous := GetCode(input);
for(i := 1; i < s->Size(); i += 1;) {
current := GetCode(s->ToUpper()->Get(i));
if(current->Size() > 0 & <>current->Equals(previous)) {
code += current;
};
previous := current;
};
soundex := String->New(code);
soundex += "0000";
return soundex->SubString(4);
}
function : GetCode(c : Char) ~ String {
select(c) {
label 'B': label 'F':
label 'P': label 'V': {
return "1";
}
label 'C': label 'G':
label 'J': label 'K':
label 'Q': label 'S':
label 'X': label 'Z': {
return "2";
}
label 'D': label 'T': {
return "3";
}
label 'L': {
return "4";
}
label 'M': label 'N': {
return "5";
}
label 'R': {
return "6";
}
other: {
return "";
}
};
}
}
You may also check:How to resolve the algorithm 100 doors step by step in the Egel programming language
You may also check:How to resolve the algorithm Church numerals step by step in the Phix programming language
You may also check:How to resolve the algorithm Introspection step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Inheritance/Multiple step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Ordered words step by step in the Arturo programming language