Created
June 5, 2018 09:39
-
-
Save naoyaikeda/6270898a57df4e9a76055067e90a5dcd to your computer and use it in GitHub Desktop.
Watson API from PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 | |
$account = @{ | |
"username" = "****" | |
"password" = "****" | |
} | |
$texts = @("ColorfulのSSDめっちゃヤバいwww Galaxy S6や廃棄品のSSDから剥がしたフラッシュやIntelの偽物が搭載されているのが確認されてるらしいwww 安価なNVMe CN600もリマークチップを使ってるとのこと、、、 最近めっちゃ秋葉原で売ってるけど買わない方が良さそうだな、、、") | |
$endPoint = "https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-16" | |
$pass = ConvertTo-SecureString $account.password -AsPlainText -Force | |
$user = $account.username | |
$cred = New-Object System.Management.Automation.PSCredential $user, $pass | |
$texts | ForEach-Object { | |
$text = $_ | |
$obj = @{ | |
text = $text | |
features = @{ | |
sentiment = @{ | |
} | |
categories = @{ | |
} | |
} | |
} | |
$json = ConvertTo-Json $obj | |
$result = Invoke-RestMethod $endPoint -Credential $cred -Body $json -Method Post -ContentType "application/json; charset=utf-8" | |
$sentiment = $result.sentiment.document.score | |
$category = $result.categories[0] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment