2017-05-30 36 views
1

是否可以根據一組依賴於另一個上下文值的值的條件來設置上下文變量的值?我試圖將NLU(自然語言理解)服務與對話服務集成在一起,並希望根據NLU返回的值設置一些上下文變量。例如我正在以下實體從NLU:基於Watson對話服務中上下文變量的處理條件

{ 
... 
"context": { 
    ... 
    "nlu_response": { 
     "entities": [{ 
      "type": "Person", 
      "relevance": 0.5, 
      "count": 1, 
      "text": "Jon Doe", 
      "emotion": { 
       "anger": 0.082378, 
       "disgust": 0.033499, 
       "fear": 0.072588, 
       "joy": 0.100971, 
       "sadness": 0.147584 
      }, 
      "sentiment": { 
       "score": 0.409803 
      } 
     }, 
     { 
      "type": "Person", 
      "relevance": 0.5, 
      "count": 1, 
      "text": "Jane Doe", 
      "emotion": { 
       "anger": 0.140151, 
       "disgust": 0.091598, 
       "fear": 0.059244, 
       "joy": 0.046762, 
       "sadness": 0.165763 
      }, 
      "sentiment": { 
       "score": 0 
      } 
     }] 
    } 
} 

}

,並希望建立一個上下文變量EntityPerson_1用的「喬恩Doe的」僅當有類型爲實體對象值的值= 「人」。 換句話說是這樣的可能在響應節點:

{ 
... 
"context": { 
    ... 
    "EntityPerson_1": <? context.nlu_response.entities.size()>0 && context.nlu_response.entities.get(0).type.contains('Person')?context.nlu_response.entities.get(0).text:'' ?> 
} 

}

回答

0

是的,這是可能的。你的代碼幾乎是正確的。工作代碼爲:

{ 
... 
"context": { 
... 
"EntityPerson_1": "<? context.nlu_response.entities.size()>0 && context.nlu_response.entities.get(0).type.contains('Person')?context.nlu_response.entities.get(0).text:'' ?>" 
} 

enter image description here

相關問題