cognitive services系列 -- 使用微软机器学习cognitive-services中的文本分析模块

Cognitive Services系列 -- 使用TextAnalytic模块完成文本智能分析
1. 进入Cognitive中的TextAnalytic的Console页面:
https://westus.dev.cognitive.microsoft.com/docs/services/TextAnalytics.V2.0/operations





api:语言识别
https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/languages




2. HTTP请求:
{
  "documents": [
    {
      "id": "string",
      "text": "字符串"
    }
  ]
}




3.点击‘Send’ 返回的http response: 
Transfer-Encoding: chunked
x-aml-ta-request-id: d57e7e16-0d1c-40bc-a32d-6ab97434704c
X-Content-Type-Options: nosniff
apim-request-id: a0584ddc-e5c3-4331-9c8f-1fcbe5619fb9
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Date: Sun, 15 Jan 2017 13:02:38 GMT
Content-Type: application/json; charset=utf-8


{
  "documents": [
    {
      "id": "string",
      "detectedLanguages": [
        {
          "name": "Chinese",
          "iso6391Name": "zh",
          "score": 1.0
        }
      ]
    }
  ],
  "errors": []
}





api : Detect Topic(确定主题)
https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/topics?minDocumentsPerWord=3&maxDocumentsPerWord=100





输入很多字符串,返回这些字符串的主题是什么。
请求:
{
  "stopWords": [
    "string"
  ],
  "topicsToExclude": [
    "string"
  ],
  "documents": [
    {
      "id": "string",
      "text": "string"
    }
...
至少100个document
  ]
}






返回的Response:
{
        "topics" : [{
            "id" : "string",
            "score" : "number",
            "keyPhrase" : "string"
        }
...],
        "topicAssignments" : [{
            "documentId" : "string",
            "topicId" : "string",
            "distance" : "number"
        }...],
        "errors" : [{
            "id" : "string",
            "message" : "string"
        }]
    }



是azure machine learning中score模块运行后的结果,需要手动选出topics->score中最大的那个key phrase。




api: 关键短语提取
https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/keyPhrases






请求:
POST https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/keyPhrases HTTP/1.1
Content-Type: application/json
Host: westus.api.cognitive.microsoft.com
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••


{
  "documents": [
    {
      "language": "en",
      "id": "1",
      "text": "I had a wonderful experience! The rooms were wonderful and the staff were helpful."
    }
  ]
}




返回:
Transfer-Encoding: chunked
x-aml-ta-request-id: 13e1b89b-2411-4d1c-bf31-c04168e438c2
X-Content-Type-Options: nosniff
apim-request-id: 31bc77ec-9b08-40e2-85dc-fbf2164258d8
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Date: Sun, 15 Jan 2017 13:30:21 GMT
Content-Type: application/json; charset=utf-8


{
  "documents": [
    {
      "keyPhrases": [
        "staff",
        "wonderful experience",
        "rooms"
      ],
      "id": "1"
    }
  ],
  "errors": []
}






api : Sentiment(情绪分析)
https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment




请求:
POST https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment HTTP/1.1
Content-Type: application/json
Host: westus.api.cognitive.microsoft.com
Ocp-Apim-Subscription-Key: ••••••••••••••••••••••••••••••••


{
  "documents": [
    {
      "language": "en",
      "id": "1",
      "text": "I like this line of code"
    },
    {
      "language": "en",
      "id": "2",
      "text": "Please stop write this kind of code"
    },
    {
      "language": "en",
      "id": "3",
      "text": "I am sick of working on this project"
    },
    {
      "language": "en",
      "id": "4",
      "text": "I hope you like it"
    },
  ]
}





返回:
Transfer-Encoding: chunked
x-aml-ta-request-id: 0805b7fd-cdcc-4fce-a322-b9ca5156afee
X-Content-Type-Options: nosniff
apim-request-id: 7ea30647-c751-4dbe-bdef-64892540a645
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Date: Sun, 15 Jan 2017 13:37:12 GMT
Content-Type: application/json; charset=utf-8


{
  "documents": [
    {
      "score": 0.5730513,
      "id": "1"
    },
    {
      "score": 0.3784115,
      "id": "2"
    },
    {
      "score": 0.02821607,
      "id": "3"
    },
    {
      "score": 0.8721114,
      "id": "4"
    }
  ],
  "errors": []
}



返回值为0-1的小数,越小表示情绪越消极;反之,接近于1表示情绪越积极。

你可能感兴趣的:(Machine,Learning)