Skip to content

Instantly share code, notes, and snippets.

@PrateekKumarSingh
Created February 28, 2016 06:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrateekKumarSingh/9baad26ab1bc28fa724c to your computer and use it in GitHub Desktop.
Save PrateekKumarSingh/9baad26ab1bc28fa724c to your computer and use it in GitHub Desktop.
Function Break-IntoWords()
{
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true,Position=0,ValueFromPipeline=$true)]
[string] $String
)
Process{
Foreach($S in (Clean-String $String))
{
$SplatInput = @{
Uri= "https://api.projectoxford.ai/text/weblm/v1.0/breakIntoWords?model=anchor&text=$S&maxNumOfCandidatesReturned=5"
Method = 'Post'
}
$Headers = @{
'Ocp-Apim-Subscription-Key' = "2c40da8ae13a4bd1b3b7b8ee77f5fb34"
}
Try{
$Data = Invoke-RestMethod @SplatInput -Headers $Headers
Return new-object psobject -Property @{
Original=$String;
Formatted =($data.candidates |select words, Probability|sort -Descending)[0].words
}|select Original, Formatted
}
Catch{
Write-Host "Something went wrong, please try running the script again" -fore Cyan
}
}
}
}
Function Clean-String($Str)
{
Foreach($Char in [Char[]]"!@#$%^&*(){}|\/?><,.][+=-_"){$str=$str.replace("$Char",'')}
Return $str
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment