September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
81
Task/Soundex/360-Assembly/soundex.360
Normal file
81
Task/Soundex/360-Assembly/soundex.360
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
* Soundex 02/04/2017
|
||||
SOUNDEX CSECT
|
||||
USING SOUNDEX,R13 base register
|
||||
B 72(R15) skip savearea
|
||||
DC 17F'0' savearea
|
||||
STM R14,R12,12(R13) save previous context
|
||||
ST R13,4(R15) link backward
|
||||
ST R15,8(R13) link forward
|
||||
LR R13,R15 set addressability
|
||||
LA R6,1 i=1
|
||||
DO WHILE=(C,R6,LE,=A(NTT)) do i=1 to hbound(tt)
|
||||
LR R1,R6 i
|
||||
BCTR R1,0 -1
|
||||
MH R1,=AL2(L'TT) *length(tt)
|
||||
LA R4,TT(R1) @tt(i)
|
||||
MVC S,0(R4) s=tt(i)
|
||||
LA R1,S @s
|
||||
LA R2,L'S length(s)
|
||||
LOOP OI 0(R1),C' ' loop s[l]=ucase(s[l])
|
||||
LA R1,1(R1) @s++
|
||||
BCT R2,LOOP endloop
|
||||
MVC CODE,=C'0000' code='0000'
|
||||
MVC CODE(1),S code[1]=s[1]
|
||||
LA R8,1 k=1
|
||||
LA R7,1 j=1
|
||||
DO WHILE=(C,R7,LE,=A(L'S)) do j=1 to length(s)
|
||||
LA R4,S-1 @s[0]
|
||||
AR R4,R7 +j
|
||||
MVC CCUR,0(R4) ccur=s[j]
|
||||
TR CCUR,TABLE ccur=translate(ccur,table)
|
||||
IF C,R7,EQ,=F'1' THEN if j=1 then
|
||||
MVC CPREV,CCUR cprev=ccur
|
||||
ELSE , else
|
||||
* if ccur<>' ' and ccur<>'-'
|
||||
IF CLI,CCUR,NE,C' ',AND,CLI,CCUR,NE,C'-', *
|
||||
AND,CLC,CCUR,NE,CPREV THEN and ccur<>cprev then
|
||||
IF C,R8,LT,=F'4' THEN if k<4 then
|
||||
LA R8,1(R8) k=k+1
|
||||
LA R4,CODE-1(R8) @code[k]
|
||||
MVC 0(1,R4),CCUR code[k]=ccur
|
||||
ENDIF , endif
|
||||
ENDIF , endif
|
||||
IF CLI,CCUR,NE,C'-' THEN if ccur<>'-' then
|
||||
MVC CPREV,CCUR cprev=ccur
|
||||
ENDIF , endif
|
||||
ENDIF , endif
|
||||
LA R7,1(R7) j++
|
||||
ENDDO , enddo j
|
||||
XDECO R6,XDEC edit i
|
||||
MVC PG(2),XDEC+10 i
|
||||
MVC PG+3(L'S),S s
|
||||
MVC PG+15(L'CODE),CODE code
|
||||
XPRNT PG,L'PG print
|
||||
LA R6,1(R6) i++
|
||||
ENDDO , enddo i
|
||||
L R13,4(0,R13) restore previous savearea pointer
|
||||
LM R14,R12,12(R13) restore previous context
|
||||
XR R15,R15 rc=0
|
||||
BR R14 exit
|
||||
TT DC CL12'ashcraft',CL12'ashcroft',CL12'gauss',CL12'ghosh'
|
||||
DC CL12'hilbert',CL12'heilbronn',CL12'lee',CL12'lloyd'
|
||||
DC CL12'moses',CL12'pfister',CL12'robert',CL12'rupert'
|
||||
DC CL12'rubin',CL12'tymczak',CL12'soundex',CL12'example'
|
||||
TTEND EQU *
|
||||
NTT EQU (TTEND-TT)/L'TT hbound(tt)
|
||||
S DS CL12
|
||||
CCUR DS CL1 current
|
||||
CPREV DS CL1 previous
|
||||
CODE DS CL4
|
||||
PG DC CL80' '
|
||||
XDEC DS CL12
|
||||
TABLE DC CL256' ' translation table
|
||||
ORG TABLE+C'A'
|
||||
DC CL9' 123 12- ' ABCDEFGHI
|
||||
ORG TABLE+C'J'
|
||||
DC CL9'22455 126' JKLMNOPQR
|
||||
ORG TABLE+C'S'
|
||||
DC CL9'23 1-2 2' STUVWXYZ
|
||||
ORG
|
||||
YREGS
|
||||
END SOUNDEX
|
||||
58
Task/Soundex/Crystal/soundex.crystal
Normal file
58
Task/Soundex/Crystal/soundex.crystal
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
# version 0.21.1
|
||||
|
||||
def get_code(c : Char)
|
||||
case c
|
||||
when 'B', 'F', 'P', 'V'
|
||||
"1"
|
||||
when 'C', 'G', 'J', 'K', 'Q', 'S', 'X', 'Z'
|
||||
"2"
|
||||
when 'D', 'T'
|
||||
"3"
|
||||
when 'L'
|
||||
"4"
|
||||
when 'M', 'N'
|
||||
"5"
|
||||
when 'R'
|
||||
"6"
|
||||
when 'H', 'W'
|
||||
"-"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
def soundex(s : String)
|
||||
return "" if s == ""
|
||||
s = s.upcase
|
||||
result = s[0,1]
|
||||
prev = get_code s[0]
|
||||
s.lchop.each_char {|c|
|
||||
curr = get_code c
|
||||
result += curr if curr != "" && curr != "-" && curr != prev
|
||||
prev = curr unless curr == "-"
|
||||
}
|
||||
result.ljust(4, '0')[0, 4]
|
||||
end
|
||||
|
||||
pairs = [
|
||||
["Ashcraft" , "A261"],
|
||||
["Ashcroft" , "A261"],
|
||||
["Gauss" , "G200"],
|
||||
["Ghosh" , "G200"],
|
||||
["Hilbert" , "H416"],
|
||||
["Heilbronn" , "H416"],
|
||||
["Lee" , "L000"],
|
||||
["Lloyd" , "L300"],
|
||||
["Moses" , "M220"],
|
||||
["Pfister" , "P236"],
|
||||
["Robert" , "R163"],
|
||||
["Rupert" , "R163"],
|
||||
["Rubin" , "R150"],
|
||||
["Tymczak" , "T522"],
|
||||
["Soundex" , "S532"],
|
||||
["Example" , "E251"]
|
||||
]
|
||||
|
||||
pairs.each { |pair|
|
||||
puts "#{pair[0].ljust(9)} -> #{pair[1]} -> #{soundex(pair[0]) == pair[1]}"
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
import Text.PhoneticCode.Soundex
|
||||
import Control.Arrow
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
*Main> mapM_ print $ map (id &&& soundexSimple) ["Soundex", "Example", "Sownteks", "Ekzampul"]
|
||||
("Soundex","S532")
|
||||
("Example","E251")
|
||||
("Sownteks","S532")
|
||||
("Ekzampul","E251")
|
||||
6
Task/Soundex/Haskell/soundex.hs
Normal file
6
Task/Soundex/Haskell/soundex.hs
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import Text.PhoneticCode.Soundex
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
mapM_ print $
|
||||
((,) <*> soundexSimple) <$> ["Soundex", "Example", "Sownteks", "Ekzampul"]
|
||||
|
|
@ -28,7 +28,10 @@ private static String getCode(char c){
|
|||
public static String soundex(String s){
|
||||
String code, previous, soundex;
|
||||
code = s.toUpperCase().charAt(0) + "";
|
||||
previous = "7";
|
||||
|
||||
// EDITED : previous = "7";
|
||||
previous = getCode(s.toUpperCase().charAt(0));
|
||||
|
||||
for(int i = 1;i < s.length();i++){
|
||||
String current = getCode(s.toUpperCase().charAt(i));
|
||||
if(current.length() > 0 && !current.equals(previous)){
|
||||
|
|
|
|||
48
Task/Soundex/Kotlin/soundex.kotlin
Normal file
48
Task/Soundex/Kotlin/soundex.kotlin
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
// version 1.1.2
|
||||
|
||||
fun getCode(c: Char) = when (c) {
|
||||
'B', 'F', 'P', 'V' -> "1"
|
||||
'C', 'G', 'J', 'K', 'Q', 'S', 'X', 'Z' -> "2"
|
||||
'D', 'T' -> "3"
|
||||
'L' -> "4"
|
||||
'M', 'N' -> "5"
|
||||
'R' -> "6"
|
||||
'H', 'W' -> "-"
|
||||
else -> ""
|
||||
}
|
||||
|
||||
fun soundex(s: String): String {
|
||||
if (s == "") return ""
|
||||
val sb = StringBuilder().append(s[0].toUpperCase())
|
||||
var prev = getCode(sb[0])
|
||||
for (i in 1 until s.length) {
|
||||
val curr = getCode(s[i].toUpperCase())
|
||||
if (curr != "" && curr != "-" && curr != prev) sb.append(curr)
|
||||
if (curr != "-") prev = curr
|
||||
}
|
||||
return sb.toString().padEnd(4, '0').take(4)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val pairs = arrayOf(
|
||||
"Ashcraft" to "A261",
|
||||
"Ashcroft" to "A261",
|
||||
"Gauss" to "G200",
|
||||
"Ghosh" to "G200",
|
||||
"Hilbert" to "H416",
|
||||
"Heilbronn" to "H416",
|
||||
"Lee" to "L000",
|
||||
"Lloyd" to "L300",
|
||||
"Moses" to "M220",
|
||||
"Pfister" to "P236",
|
||||
"Robert" to "R163",
|
||||
"Rupert" to "R163",
|
||||
"Rubin" to "R150",
|
||||
"Tymczak" to "T522",
|
||||
"Soundex" to "S532",
|
||||
"Example" to "E251"
|
||||
)
|
||||
for (pair in pairs) {
|
||||
println("${pair.first.padEnd(9)} -> ${pair.second} -> ${soundex(pair.first) == pair.second}")
|
||||
}
|
||||
}
|
||||
27
Task/Soundex/PicoLisp/soundex-2.l
Normal file
27
Task/Soundex/PicoLisp/soundex-2.l
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
(de soundex (Str)
|
||||
(let (Str (chop Str) Last)
|
||||
(pack
|
||||
(pad
|
||||
-4
|
||||
(cons
|
||||
(uppc (car Str))
|
||||
(head
|
||||
3
|
||||
(filter
|
||||
gt0
|
||||
(cdr
|
||||
(mapcar
|
||||
'((C)
|
||||
(and
|
||||
(setq C
|
||||
(case (uppc C)
|
||||
(`(chop "AEIOUY") 0)
|
||||
(`(chop "BFPV") 1)
|
||||
(`(chop "CGJKQSXZ") 2)
|
||||
(("D" "T") 3)
|
||||
("L" 4)
|
||||
(("M" "N") 5)
|
||||
("R" 6) ) )
|
||||
(<> Last C)
|
||||
(setq Last C) ) )
|
||||
Str ) ) ) ) ) ) ) ) )
|
||||
81
Task/Soundex/PowerShell/soundex-1.psh
Normal file
81
Task/Soundex/PowerShell/soundex-1.psh
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
function Get-Soundex
|
||||
{
|
||||
[CmdletBinding()]
|
||||
[OutputType([PSCustomObject])]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
Position=0)]
|
||||
[string[]]
|
||||
$InputObject
|
||||
)
|
||||
|
||||
Begin
|
||||
{
|
||||
$characterGroup = [PSCustomObject]@{
|
||||
1 = @('B','F','P','V')
|
||||
2 = @('C','G','J','K','Q','S','X','Z')
|
||||
3 = @('D','T')
|
||||
4 = @('L')
|
||||
5 = @('M','N')
|
||||
6 = @('R')
|
||||
}
|
||||
|
||||
function ConvertTo-SoundexDigit ([char]$Character)
|
||||
{
|
||||
switch ($Character)
|
||||
{
|
||||
{$_ -in $characterGroup.1} {return 1}
|
||||
{$_ -in $characterGroup.2} {return 2}
|
||||
{$_ -in $characterGroup.3} {return 3}
|
||||
{$_ -in $characterGroup.4} {return 4}
|
||||
{$_ -in $characterGroup.5} {return 5}
|
||||
{$_ -in $characterGroup.6} {return 6}
|
||||
Default {return 0}
|
||||
}
|
||||
}
|
||||
}
|
||||
Process
|
||||
{
|
||||
foreach ($String in $InputObject)
|
||||
{
|
||||
$originalString = $String
|
||||
$String = $String.ToUpper()
|
||||
$isHorWcharacter = $false
|
||||
$soundex = New-Object -TypeName System.Text.StringBuilder
|
||||
|
||||
$soundex.Append($String[0]) | Out-Null
|
||||
|
||||
for ($i = 1; $i -lt $String.Length; $i++)
|
||||
{
|
||||
$currentCharacterDigit = ConvertTo-SoundexDigit $String[$i]
|
||||
|
||||
if ($currentCharacterDigit -ne 0)
|
||||
{
|
||||
if ($i -eq (ConvertTo-SoundexDigit $String[$i-1]))
|
||||
{
|
||||
continue
|
||||
}
|
||||
|
||||
if (($i -gt 2) -and ($isHorWcharacter) -and ($currentCharacterDigit -eq (ConvertTo-SoundexDigit $String[$i-2])))
|
||||
{
|
||||
continue
|
||||
}
|
||||
|
||||
$soundex.Append($currentCharacterDigit) | Out-Null
|
||||
}
|
||||
|
||||
$isHorWcharacter = $String[$i] -in @('H','W')
|
||||
}
|
||||
|
||||
$soundexTail = ($soundex.ToString().Substring(1)).TrimStart((ConvertTo-SoundexDigit $String[0]).ToString())
|
||||
|
||||
[PSCustomObject]@{
|
||||
String = $originalString
|
||||
Soundex = ($soundex[0] + $soundexTail).PadRight(4,"0").Substring(0,4)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Task/Soundex/PowerShell/soundex-2.psh
Normal file
2
Task/Soundex/PowerShell/soundex-2.psh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"Ashcraft", "Ashcroft", "Gauss", "Ghosh", "Hilbert", "Heilbronn", "Lee", "Lloyd",
|
||||
"Moses", "Pfister", "Robert", "Rupert", "Rubin", "Tymczak", "Soundex", "Example" | Get-Soundex
|
||||
5
Task/Soundex/Stata/soundex.stata
Normal file
5
Task/Soundex/Stata/soundex.stata
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
. display soundex_nara("Ashcraft")
|
||||
A261
|
||||
|
||||
. display soundex_nara("Tymczak")
|
||||
T522
|
||||
|
|
@ -1,3 +1,16 @@
|
|||
' Soundex
|
||||
tt=array( _
|
||||
"Ashcraft","Ashcroft","Gauss","Ghosh","Hilbert","Heilbronn","Lee","Lloyd", _
|
||||
"Moses","Pfister","Robert","Rupert","Rubin","Tymczak","Soundex","Example")
|
||||
tv=array( _
|
||||
"A261","A261","G200","G200","H416","H416","L000","L300", _
|
||||
"M220","P236","R163","R163","R150","T522","S532","E251")
|
||||
For i=lbound(tt) To ubound(tt)
|
||||
ts=soundex(tt(i))
|
||||
If ts<>tv(i) Then ok=" KO "& tv(i) Else ok=""
|
||||
Wscript.echo right(" "& i ,2) & " " & left( tt(i) &space(12),12) & " " & ts & ok
|
||||
Next 'i
|
||||
|
||||
Function getCode(c)
|
||||
Select Case c
|
||||
Case "B", "F", "P", "V"
|
||||
|
|
@ -12,22 +25,19 @@ Function getCode(c)
|
|||
getCode = "5"
|
||||
Case "R"
|
||||
getCode = "6"
|
||||
Case "W","H"
|
||||
getCode = "-"
|
||||
End Select
|
||||
End Function
|
||||
End Function 'getCode
|
||||
|
||||
Function soundex(s)
|
||||
Dim code, previous
|
||||
Dim code, previous, i
|
||||
code = UCase(Mid(s, 1, 1))
|
||||
previous = 7
|
||||
For i = 2 to (Len(s) + 1)
|
||||
previous = getCode(UCase(Mid(s, 1, 1)))
|
||||
For i = 2 To Len(s)
|
||||
current = getCode(UCase(Mid(s, i, 1)))
|
||||
If Len(current) > 0 And current <> previous Then
|
||||
code = code & current
|
||||
End If
|
||||
previous = current
|
||||
Next
|
||||
soundex = Mid(code, 1, 4)
|
||||
If Len(code) < 4 Then
|
||||
soundex = soundex & String(4 - Len(code), "0")
|
||||
End If
|
||||
End Function
|
||||
If current <> "" And current <> "-" And current <> previous Then code = code & current
|
||||
If current <> "-" Then previous = current
|
||||
Next 'i
|
||||
soundex = Mid(code & "000", 1, 4)
|
||||
End Function 'soundex
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue