Skip to content

Instantly share code, notes, and snippets.

@PrateekKumarSingh
Created December 18, 2019 14:48
Show Gist options
  • Save PrateekKumarSingh/8d8c62b0f6476d2437e1aaf688b688f6 to your computer and use it in GitHub Desktop.
Save PrateekKumarSingh/8d8c62b0f6476d2437e1aaf688b688f6 to your computer and use it in GitHub Desktop.
# installation
Install-Module PSCognitiveService -Verbose -Force -Confirm:$false -Scope CurrentUser
# import module
Import-Module PSCognitiveService
# create cognitive service accounts in azure
$Params1 = @{
AccountType = 'Bing.Search.v7'
ResourceGroupName = 'demo-resource-group'
SKUName = 'F1'
Location = 'Global'
}
New-CognitiveServiceAccount @Params1 | Out-Null
$Params2 = @{
AccountType = 'TextAnalytics'
ResourceGroupName = 'demo-resource-group'
SKUName = 'F0'
Location = 'CentralIndia'
}
New-CognitiveServiceAccount @Params2 | Out-Null
# add subscription keys & location from azure
# to $profile as $env variables
# and load them in them in current session
$null = New-LocalConfiguration -FromAzure `
-AddKeysToProfile `
-Verbose
# web search a keyword to get snippets
$Snippets = Search-Web "Trade War" |
ForEach-Object {$_.webpages.value.snippet}
# extract keywords from snippets
$Words = $snippets.ForEach({
Get-KeyPhrase -Text $_ -ErrorAction SilentlyContinue
}).documents.keyphrases.split(' ')
Install-Module PSWordCloud -Scope CurrentUser
Import-Module PSWordCloud
# build a word cloud from these key phrases
$Path = "$env:TEMP\wordcloud.svg"
$Params = @{`
Path = $Path
Typeface = 'Consolas'
ImageSize = '3000x2000'
AllowRotation = 'None'
Padding = 5
StrokeWidth = 1
}
# generate word cloud using 'PSWordCloud' module
$Words | New-WordCloud @Params
Start-Process Chrome $Path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment