0

蔭在哪裏我顯示基於用戶的「價格區間」產品在我的清單中的應用程序的工作..在沃森的談話如何提取多個值在輸入文本時

我需要知道如何提取值(價格)輸入的文字。

我嘗試使用系統實體@ SYS-貨幣& @ SYS - 數但我可以僅提取一個值(第一值)..

例如:

用戶請求爲「顯示器產品$ 200和$ 500" 之間

我怎樣才能提取兩個值與單個產品的價格進行比較,並顯示相關產品..

建議表示讚賞..

+0

請分享你的努力,到目前爲止代碼,向我們展示了一些努力,你在將問題發佈到SO之前做過(你做對了嗎?) –

回答

0

如果您使用的NodeJS,基於IBM開發者交談,簡單的例子,你可以這樣做:

enter image description here

和節點:

enter image description here

代碼訪問此值:

function updateMessage(input, data, req, res) { 

console.log("Entties: "+JSON.stringify(data.entities)); 
    //200 and 500 do something 
    if (data.entities[0].value == '200' && data.entities[1].value == '500') { 
     console.log("User choice value:" + data.entities) 
    // showProducts(data, req, res); do something inside this function 
    // or paste your code for do something here 
    } 

德布GG:

enter image description here

實驗值:如果用戶鍵入只有一個值(@ SYS-貨幣),你需要創建一個:與一個條件,併爲內做一些事情得到這個值的應用與我的例子:

data.entities //if have one value 
data.entities[i] //Watson return some array if have more than 1 value 

一個好主意是使用上下文變量,並加入了讓所有的值,比如:

{ "context": { 
    "result": "<? @sys-currency ?>" 
    } 
}, 

如果您在上下文通過其在股票和你想有輸出像我們有X,Y,Z庫存的所有項目,那麼您可以在沃森創建輸出

<? context.results.join(', ') ?> //all values return 

重要:您需要訪問data返回沃森對話呼叫conversation.message)用於訪問所有值,如實體,意圖和上下文變量等。像:

conversation.message(payload, function (err, data) { 
    console.log(data) 
    if (err) { 
     return res.status(err.code || 500).json(err); 
    } 
} 
0

在watson對話的節點中,您可以以數組的形式訪問實體。你的情況將是:

Currency 1: <? entities['sys-currency'] != null && entities['sys-currency'].size()> 0 ? entities['sys-currency'][0].value : "---" ?>; Currency 2: <? entities['sys-currency'] != null && entities['sys-currency'].size()> 1 ? entities['sys-currency'][1].value : "---" ?> 

您需要添加適當的null檢查,並檢查是否數組有多於一個進入貨幣