@speechly/js-config-api
Advanced tools
Comparing version 0.1.3 to 0.1.4
58
index.js
@@ -9,13 +9,19 @@ "use strict"; | ||
const yamlSkeleton = "templates: |\n"; | ||
const SUPPORTED_KEYS = ["color", "brand", "category", "department", "size"]; | ||
const SUPPORTED_KEYS = ["color", "brand", "category", "size"]; | ||
const PHRASE = { | ||
"color": "{in} ![{color} | $color(color)]", | ||
"brand": "{[from | by]} $brand(brand)", | ||
"brand": "{[from | by | brand]} $brand(brand)", | ||
"category": "$category(category)", | ||
"department": "for $department(department)", | ||
"size": "{in} ![{size} | $size(size)]" | ||
} | ||
"size": "{in} ![{size} | $size(size)]", | ||
"max_price": "$price_carrier $max_price" | ||
}; | ||
const TYPE = { | ||
"color": " - name: color\n type: string", | ||
"brand": " - name: brand\n type: string", | ||
"category": " - name: category\n type: string", | ||
"size": " - name: size\n type: string", | ||
"max_price": " - name: max_price\n type: number" | ||
}; | ||
function getConfigTemplate(configObject) { | ||
@@ -35,22 +41,38 @@ const configTemplate = []; | ||
// var price = ""; | ||
configTemplate.push("carrier_phrases = {0.1: now} [let's say|i'm interested in|i'm looking for|{[can you|will you]} show me|select|search {for}|display|filter by|find {me}|give me| [i want to | i'd like to | can i] [see|view|browse] | i want {to buy} | i need {to buy}]"); | ||
configTemplate.push("price_carrier = [[that have | with | having] a {highest} price {of} | not costing more than | [that cost | for] at most | {with {a}} maximum price {of}]"); | ||
configTemplate.push("max_price = [1..9999](max_price) [dollars | euros | pounds]"); | ||
// set entitty types | ||
var entity_types = []; | ||
for (var key of active_keys) { | ||
entity_types.push(TYPE[key]); | ||
} | ||
entity_types.push(TYPE["max_price"]); | ||
// make filter_first_part | ||
var tmp = []; | ||
for (var key of active_keys) { | ||
tmp.push("{0.33: " + PHRASE[key] + "}") | ||
tmp.push(PHRASE[key]); | ||
} | ||
tmp.push(PHRASE['max_price']); | ||
configTemplate.push("filter_first_part = ![" + tmp.join(" | ") + "]"); | ||
// make filter_second_part (use same as for 1st part for now) | ||
configTemplate.push("filter_second_part = ![" + tmp.join(" | ") + "]"); | ||
configTemplate.push("filter_second_part = ![" + tmp.join(" | ") + "]"); | ||
if (configObject.hasOwnProperty("category") && configObject["category"].length > 0) { | ||
configTemplate.push("*filter {$carrier_phrases {[a | some |new]}} {$filter_first_part} [0.9: $category | 0.1: [clothes | products | items]] $filter_second_part"); | ||
} | ||
else { | ||
configTemplate.push("*filter {$carrier_phrases {[a | some |new]}} {$filter_first_part}"); | ||
} | ||
return " " + configTemplate.join("\n "); | ||
// insert all templates in a list so that they can be re-weighted | ||
configTemplate.push("intents = ["); | ||
configTemplate.push(" 10: *filter {0.1: $carrier_phrases {[a | some |new]}} $filter_first_part"); | ||
// add a "clear" intent for re-setting the filters | ||
configTemplate.push(" 1: *clear [[clear | reset] {[all | filters]}]"); | ||
configTemplate.push(" 1: *clear [go back | take me to the [beginning | start] | new search]") | ||
configTemplate.push("]"); | ||
configTemplate.push("$intents"); | ||
const config_yaml = "entities:\n" + entity_types.join("\n") + "\ntemplates: |\n " + configTemplate.join("\n "); | ||
return config_yaml; | ||
} | ||
@@ -132,3 +154,3 @@ | ||
module.exports.deployApplication = async function (conn, configuration) { | ||
const configToDeploy = Buffer.from(yamlSkeleton + getConfigTemplate(configuration)).toString("base64"); | ||
const configToDeploy = Buffer.from(getConfigTemplate(configuration)).toString("base64"); | ||
const appId = await getApplicationId(conn); | ||
@@ -135,0 +157,0 @@ return new Promise((resolve, reject) => { |
{ | ||
"name": "@speechly/js-config-api", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "A library for accessing the Speechly Config API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -19,5 +19,12 @@ # Javascript Library for Speechly Config API | ||
- *show me blue jackets for men* | ||
- *show me blue jackets* | ||
- *can i see shirts by adidas in size large* | ||
The resulting application also has the default entity `max_price` for setting a maximum price, as well as the intent `clear` for re-setting the filters. These can be used as follows: | ||
- *show me blue jackets not costing more than two hundred dollars* | ||
- *maximum price fifty dollars* | ||
- *clear all filters* | ||
- *reset* | ||
```javascript | ||
@@ -51,4 +58,3 @@ const { setupConnection, createApplication, deployApplication } = require("@speechly/js-config-api"); | ||
"color": ["blue", "red", "green"], | ||
"size": ["small", "medium", "large"], | ||
"department": ["men", "women", "kids"]}; | ||
"size": ["small", "medium", "large"]}; | ||
@@ -76,3 +82,2 @@ // Deploy the configuration specified above. | ||
- category: the type of the product (e.g. jackets, shirts, shoes, etc) | ||
- department: useful if products from the same category should still be divided further (e.g. for fashion stores where one might have separate mens and womens departments) | ||
- brand: product brand | ||
@@ -79,0 +84,0 @@ - color: product color |
191228
4805
84