Skip to content

Instantly share code, notes, and snippets.

View MNie's full-sized avatar
🎯
#dd

Michał Niegrzybowski MNie

🎯
#dd
View GitHub Profile
@MNie
MNie / program.fs
Last active August 14, 2016 15:07
Azure text analytics, sentiment, createjson
type requestJson =
{
documents: seq<document>
}
and document =
{
language: string
id: string
text: string
}
@MNie
MNie / request.json
Last active August 14, 2016 15:18
Azure, text analytics, sentiment
{
"documents": [
{
"language": "pl",
"id": "32",
"text": "ggfdgdfgd"
}
]
}
@MNie
MNie / program.fs
Created August 14, 2016 14:56
AzureTextAnalytics, sentiment function
let getSentimentScore json =
let serializeJson = JsonConvert.SerializeObject json
let response = Http.RequestString("https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment",
body = TextRequest serializeJson,
headers = [ContentType HttpContentTypes.Json; "Ocp-Apim-Subscription-Key", "api_key"])
response
@MNie
MNie / response.json
Last active August 14, 2016 15:18
AzureTextAnalytics, sentiment, response
{
"documents": [
{
"id": "43",
"score": 0.5432
}
]
}
@MNie
MNie / program.fs
Last active August 14, 2016 15:08
AzureTextAnalytics, semantic, concat function
type responseJson =
{
documents: seq<responseDoc>
errors: string list
}
and responseDoc =
{
score: double
id: string
}
[{
"Id": "4",
"Text": "bad",
"Score": 0.06886895
},
{
"Id": "5",
"Text": "very bad",
"Score": 0.09467509
},
{
"_type": "SpellCheck",
"flaggedTokens": [
{
"offset": 60,
"token": "english",
"type": "UnknownToken",
"suggestions": [
{
"suggestion": "English",
let loadFile path =
File.ReadAllText path
let getSpellCheck text mode =
let response = Http.RequestString(sprintf "https://api.cognitive.microsoft.com/bing/v5.0/spellcheck/?mode=%s" mode,
body = TextRequest (sprintf "Text=%s" text),
headers = [ContentType "application/x-www-form-urlencoded"; "Ocp-Apim-Subscription-Key", "{api-key}"])
JsonConvert.DeserializeObject<responseJson>(response)
{
"_type": "type",
"flaggedTokens": [
{
"offset": 23,
"token": "word",
"type": "type",
"suggestions": [
{
"suggestion": "word1",
type responseJson =
{
_type: string
flaggedTokens: flaggedToken list
}
and flaggedToken =
{
offset: int
token: string
``type``: string