Cognitive Servicesのテキスト分析にPowerShellから投げてみる

PowerShellからCognitive Servicesのネガポジ分析をたたいてみました。 $apiKey = “************************” $texts = @(“ColorfulのSSDめっちゃヤバいwww Galaxy S6や廃棄品のSSDから剥がしたフラッシュやIntelの偽物が搭載されているのが確認されてるらしいwww 安価なNVMe CN600もリマークチップを使ってるとのこと、、、 最近めっちゃ秋葉原で売ってるけど買わない方が良さそうだな、、、”) $headers = @{ ‘Ocp-Apim-Subscription-Key’ = $apiKey } $endPoint = “https://eastasia.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment” $texts | ForEach-Object { $text = $_ $obj = @{ documents = @(@{ language = “ja” id = “1” text = $text }) } $json = ConvertTo-Json $obj $result = Invoke-RestMethod -Uri $endPoint -Headers $headers -Body $json -ContentType ‘application/json; charset=utf-8’ -Method Post $items = $result.documents $item = $items[0] $item.score }

6月 5, 2018 · 1 分 · 73 文字 · Me

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]

6月 5, 2018 · 1 分 · 83 文字 · Me