IBM Cloud Docs
開始使用 Natural Language Understanding

開始使用 Natural Language Understanding

這個簡短的指導教學簡介了 Natural Language Understanding API,其中包含範例要求和其他資源的鏈結。

如需開始使用 Natural Language Understanding 服務的視覺化摘要,請觀看下列視訊。

開始之前

  • 建立服務的實例:
    1. 移至 IBM Cloud 型錄中的 Natural Language Understanding 頁面。
    2. 註冊免費的 IBM Cloud 帳戶,或者登入。
    3. 按一下建立
  • 複製認證以便向服務實例進行鑑別:
    1. 管理頁面上,按一下顯示認證
    2. 複製 API KeyURL 值。
  • 確定您有 curl 指令。
    • 測試是否已安裝 curl。 請在指令行上執行下列指令。 如果輸出裡列出了具有 SSL 支援的 curl 版本,則您已準備好進入指導教學。

      curl -V
      
    • 必要的話,請從 curl.haxx.se安裝已啟用 SSL 的版本。 如果您要從任何指令行位置執行 curl,則請將檔案的位置新增至 PATH 環境變數。

本指導教學教您如何從指令行介面使用 Natural Language Understanding API。 若要下載各種程式設計語言的用戶端程式庫,請參閱 Watson SDK

步驟 1:分析網頁

執行下列指令來分析網頁,以取得觀感、概念、種類、實體及關鍵字。 {apikey}{url} 取代為您的服務認證。

curl -X POST -u "apikey:{apikey}" \
--header "Content-Type: application/json" \
--data '{
  "url": "http://newsroom.ibm.com/Guerbet-and-IBM-Watson-Health-Announce-Strategic-Partnership-for-Artificial-Intelligence-in-Medical-Imaging-Liver",
  "features": {
    "sentiment": {},
    "categories": {},
    "concepts": {},
    "entities": {},
    "keywords": {}
  }
}' \
"{url}/v1/analyze?version=2019-07-12"

Windows 使用者: 此指令可能不會在 Windows 上執行。 請改為執行下列指令:

curl -X POST -u "apikey:{apikey}" --header "Content-Type: application/json" --data "{\"url\":\"http://newsroom.ibm.com/Guerbet-and-IBM-Watson-Health-Announce-Strategic-Partnership-for-Artificial-Intelligence-in-Medical-Imaging-Liver\",\"features\":{\"sentiment\":{},\"categories\":{},\"concepts\":{},\"entities\":{},\"keywords\":{}}}" "{url}/v1/analyze?version=2019-07-12"

下一步示範如何指定選項,以自訂每個特性的分析。

步驟 2:分析目標詞組及關鍵字

Natural Language Understanding 可以分析周圍文字上下文中的目標詞組,以取得重點觀感及情緒結果。 下列範例中觀感的 targets 選項會告知服務搜尋 "apples"、"oranges" 及 "broccoli" 目標。 因為 "apples" 及 "oranges" 位於文字中,所以會針對這些目標傳回觀感評分。

您也可以針對文字中偵測到的實體和關鍵字,取得觀感及情緒結果。 在此範例中,關鍵字的 emotion 選項會指示服務分析每個偵測到的關鍵字,以取得情緒結果。

curl -X POST -u "apikey:{apikey}" \
--header "Content-Type: application/json" \
--data '{
  "text": "I love apples! I do not like oranges.",
  "features": {
    "sentiment": {
      "targets": [
        "apples",
        "oranges",
        "broccoli"
      ]
    },
    "keywords": {
      "emotion": true
    }
  }
}' \
"{url}/v1/analyze?version=2019-07-12"

適用於 Windows 使用者的可執行指令:

curl -X POST -u "apikey:{apikey}" --header "Content-Type: application/json" --data "{\"text\":\"I love apples! I do not like oranges.\",\"features\":{\"sentiment\":{\"targets\":[\"apples\",\"oranges\",\"broccoli\"]},\"keywords\":{\"emotion\":true}}}" "{url}/v1/analyze?version=2019-07-12"

後續步驟