Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
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
|
||||
18
Task/Soundex/PowerShell/soundex-3.psh
Normal file
18
Task/Soundex/PowerShell/soundex-3.psh
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# script Soundex.ps1
|
||||
Param([string]$Phrase)
|
||||
Process {
|
||||
$src = $Phrase.ToUpper().Trim()
|
||||
$coded = $src[0..($src.Length - 1)] | %{
|
||||
if('BFPV'.Contains($_)) { '1' }
|
||||
elseif('CGJKQSXZ'.Contains($_)) { '2' }
|
||||
elseif('DT'.Contains($_)) { '3' }
|
||||
elseif('L'.Contains($_)) { '4' }
|
||||
elseif('MN'.Contains($_)) { '5' }
|
||||
elseif('R'.Contains($_)) { '6' }
|
||||
elseif('AEIOU'.Contains($_)) { 'v' }
|
||||
else { '.' }
|
||||
} | Where { $_ -ne '.'}
|
||||
$coded2 = 0..($coded.Length - 1) | %{ if ($_ -eq 0 -or $coded[$_] -ne $coded[$_ - 1]) { $coded[$_] } else { '' } }
|
||||
$coded2 = if ($coded[0] -eq 'v' -or $coded2[0] -ne $coded[0]) { $coded2 } else { $coded2[1..($coded2.Length - 1)] }
|
||||
$src[0] + ((-join $($coded2 | Where { $_ -ne 'v'})) + "000").Substring(0,3)
|
||||
}
|
||||
15
Task/Soundex/PowerShell/soundex-4.psh
Normal file
15
Task/Soundex/PowerShell/soundex-4.psh
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Function t([string]$value, [string]$expect) {
|
||||
$result = .\Soundex.ps1 -Phrase $value
|
||||
New-Object –TypeName PSObject –Prop @{ "Value"=$value; "Expect"=$expect; "Result"=$result; "Pass"=$($expect -eq $result) }
|
||||
}
|
||||
@(
|
||||
(t "Ashcraft" "A261"); (t "Ashcroft" "A261"); (t "Burroughs" "B620"); (t "Burrows" "B620");
|
||||
(t "Ekzampul" "E251"); (t "Example" "E251"); (t "Ellery" "E460"); (t "Euler" "E460");
|
||||
(t "Ghosh" "G200"); (t "Gauss" "G200"); (t "Gutierrez" "G362"); (t "Heilbronn" "H416");
|
||||
(t "Hilbert" "H416"); (t "Jackson" "J250"); (t "Kant" "K530"); (t "Knuth" "K530");
|
||||
(t "Lee" "L000"); (t "Lukasiewicz" "L222"); (t "Lissajous" "L222"); (t "Ladd" "L300");
|
||||
(t "Lloyd" "L300"); (t "Moses" "M220"); (t "O'Hara" "O600"); (t "Pfister" "P236");
|
||||
(t "Rubin" "R150"); (t "Robert" "R163"); (t "Rupert" "R163"); (t "Soundex" "S532");
|
||||
(t "Sownteks" "S532"); (t "Tymczak" "T522"); (t "VanDeusen" "V532"); (t "Washington" "W252");
|
||||
(t "Wheaton" "W350");
|
||||
) | Format-Table -Property Value,Expect,Result,Pass
|
||||
Loading…
Add table
Add a link
Reference in a new issue