Watson APIのテキスト分析をPowerShellから叩く
PowerShellからWatsonのテキスト分析を叩いてみた。 $account = @{ “username” = **** “password” = **** } $spass = ConvertTo-SecureString $account.password -AsPlainText -Force $user = $account.username $cred = New-Object System.Management.Automation.PSCredential $user, $spass $endPoint = “https://gateway.watsonplatform.net/natural-language-understanding/api/v1/analyze?version=2018-03-16” $text = “ColorfulのSSDめっちゃヤバいwww Galaxy S6や廃棄品のSSDから剥がしたフラッシュやIntelの偽物が搭載されているのが確認されてるらしいwww 安価なNVMe CN600もリマークチップを使ってるとのこと、、、 最近めっちゃ秋葉原で売ってるけど買わない方が良さそうだな、、、” $targets = @(“stocks”, “stocks”) $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]