Skip to content

Instantly share code, notes, and snippets.

@phuf
Created January 11, 2017 03:16
Show Gist options
  • Save phuf/8ba6027a5b678983ce0437a6eb19cc70 to your computer and use it in GitHub Desktop.
Save phuf/8ba6027a5b678983ce0437a6eb19cc70 to your computer and use it in GitHub Desktop.
$scriptPath = Join-Path (Get-Location) "TestEditDistance.sql";
$response = Invoke-WebRequest "https://raw.githubusercontent.com/GlobalNamesArchitecture/damerau-levenshtein/master/spec/files/damerau_levenshtein_test.txt" -UseBasicParsing;
$lines = $response.Content.Split() | Where-Object { $_ -like "*|*|*|*" };
@"
DECLARE @test_cases TABLE
(
Word1 NVARCHAR(128),
Word2 NVARCHAR(128),
ExpectedEditDistance INT
)
VALUES
"@ | Out-File $scriptPath -Encoding UTF8;
@(
$lines.ForEach({
$columns = $_.Split("|");
$rowValue = "`t(N'$($columns[0])', N'$($columns[0])', $($columns[3]))";
if ($_.Equals($lines[-1])) {
Write-Output "$rowValue;";
} else {
Write-Output "$rowValue,"
}
});
) | Out-File $scriptPath -Append -Encoding UTF8;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment