Example Ecolect flow for natural language processing

This is a sample flow how you can set up and use the node-red-contrib-ecolect node to react to full sentence text queries.

This flow does not contain any actual processing, it just helps you to train and debug you Ecolect node for archive best results.

I also have a video explaining this flow if you need some help understanding the concept: https://youtu.be/Vz9qaUNLQ-E

[{"id":"36e9b43c.f831ec","type":"ecolect","z":"438d0e76.5f7bf","name":"Language Processing","topics":[{"name":"switch","phrases":"turn {state} the {device}\nturn the {device} {state}\nturn the {device} {state} in {timelapse} {timeunit}\nturn {state} the {device} in {timelapse} {timeunit}\nturn {state} the {device} at {time}\nturn the {device} {state} at {time}","values":[{"name":"device","type":"enumeration","enumerations":["christmas light","garden light","planter"]},{"name":"state","type":"enumeration","enumerations":["off","on"]},{"name":"timelapse","type":"integer","enumerations":[]},{"name":"timeunit","type":"enumeration","enumerations":["minute","minutes","hour","hours"]},{"name":"time","type":"time","enumerations":[]}]},{"name":"query","phrases":"what is the state of the {device}?\nis the {device} {state}?\ntell me the state of the {device}?","values":[{"name":"device","type":"enumeration","enumerations":["christmas light","garden tree","planter"]},{"name":"state","type":"enumeration","enumerations":["on","off"]}]}],"outputs":3,"x":556.6666717529297,"y":3976.6668157577515,"wires":[["ee8d6877.3088a8"],["ee8d6877.3088a8"],["59c2990f.072b98","f7f72a61.f907a8"]]},{"id":"c631face.abbcb8","type":"inject","z":"438d0e76.5f7bf","name":"turn off the christmas light","topic":"","payload":"turn off the christmas light","payloadType":"str","repeat":"","crontab":"","once":false,"x":206.6666717529297,"y":3616.6668157577515,"wires":[["6fef72b0.643a9c"]]},{"id":"42c15f76.90f85","type":"inject","z":"438d0e76.5f7bf","name":"turn the christmas light off","topic":"","payload":"turn the christmas light off","payloadType":"str","repeat":"","crontab":"","once":false,"x":206.6666717529297,"y":3656.6668157577515,"wires":[["6fef72b0.643a9c"]]},{"id":"aaf5b18d.405fd","type":"debug","z":"438d0e76.5f7bf","name":"","active":true,"console":"false","complete":"true","x":1026.6666717529297,"y":3876.6668157577515,"wires":[]},{"id":"f7f72a61.f907a8","type":"debug","z":"438d0e76.5f7bf","name":"","active":true,"console":"false","complete":"true","x":806.6666717529297,"y":4416.6668157577515,"wires":[]},{"id":"351931a9.6d73fe","type":"function","z":"438d0e76.5f7bf","name":"Topic","func":"msg.payload = msg.topic;\nnode.status({fill:\"blue\",shape:\"ring\",text:\"Value: \"+msg.topic});\nreturn msg;","outputs":1,"noerr":0,"x":1026.6666717529297,"y":3916.6668157577515,"wires":[["6f9b7852.0d2988"]]},{"id":"862580b4.16b8f","type":"function","z":"438d0e76.5f7bf","name":"Device","func":"var value = msg.values.device;\nif (value===undefined) {\n    node.status({fill:\"red\",shape:\"ring\",text:\"No value\"});\n    msg.payload = \"[No value]\";\n} else {\n    node.status({fill:\"blue\",shape:\"ring\",text:\"Value: \"+value});\n    msg.payload = value;\n}\nreturn msg;","outputs":1,"noerr":0,"x":1026.6666717529297,"y":3976.6668157577515,"wires":[["732d552c.86438c"]]},{"id":"48670c45.1fcd84","type":"function","z":"438d0e76.5f7bf","name":"State","func":"var value = msg.values.state;\nif (value===undefined) {\n    node.status({fill:\"red\",shape:\"ring\",text:\"No value\"});\n    msg.payload = \"[No value]\";\n} else {\n    node.status({fill:\"blue\",shape:\"ring\",text:\"Value: \"+value});\n    msg.payload = value;\n}\nreturn msg;","outputs":1,"noerr":0,"x":1026.6666717529297,"y":4036.6668157577515,"wires":[["3e0797d1.526b58"]]},{"id":"6fef72b0.643a9c","type":"function","z":"438d0e76.5f7bf","name":"Dummy","func":"\nreturn msg;","outputs":1,"noerr":0,"x":974.1666717529297,"y":3738.6668157577515,"wires":[["36e9b43c.f831ec"]]},{"id":"94571e24.18ca9","type":"inject","z":"438d0e76.5f7bf","name":"turn the christmas light off in 10 minutes","topic":"","payload":"turn the christmas light off in 10 minutes","payloadType":"str","repeat":"","crontab":"","once":false,"x":246.6666717529297,"y":3696.6668157577515,"wires":[["6fef72b0.643a9c"]]},{"id":"4657c865.d3acb8","type":"function","z":"438d0e76.5f7bf","name":"Time lapse","func":"var value = msg.values.timelapse;\nif (value===undefined) {\n    node.status({fill:\"red\",shape:\"ring\",text:\"No value\"});\n    msg.payload = \"[No value]\";\n} else {\n    node.status({fill:\"blue\",shape:\"ring\",text:\"Value: \"+value.value});\n    msg.payload = value.value;\n}\nreturn msg;","outputs":1,"noerr":0,"x":1046.6666717529297,"y":4096.6668157577515,"wires":[["b9d04b24.0e0db8"]]},{"id":"c4c4b916.c99ff8","type":"function","z":"438d0e76.5f7bf","name":"Time unit","func":"var value = msg.values.timeunit;\nif (value===undefined) {\n    node.status({fill:\"red\",shape:\"ring\",text:\"No value\"});\n    msg.payload = \"[No value]\";\n} else {\n    node.status({fill:\"blue\",shape:\"ring\",text:\"Value: \"+value});\n    msg.payload = value;\n}\nreturn msg;","outputs":1,"noerr":0,"x":1036.6666717529297,"y":4156.6668157577515,"wires":[["bc0f3476.d3e428"]]},{"id":"f2d1af5e.9f6ed","type":"function","z":"438d0e76.5f7bf","name":"Time","func":"var value = msg.values.time;\nif (value===undefined) {\n    node.status({fill:\"red\",shape:\"ring\",text:\"No value\"});\n    msg.payload = \"[No value]\";\n} else {\n    node.status({fill:\"blue\",shape:\"ring\",text:\"Value: \"+value.hour+\":\"+value.minute});\n    msg.payload = value.hour+\":\"+value.minute;\n}\nreturn msg;","outputs":1,"noerr":0,"x":1026.6666717529297,"y":4216.6668157577515,"wires":[["ede1af33.2f8fe"]]},{"id":"8d50a813.86bf48","type":"inject","z":"438d0e76.5f7bf","name":"turn the garden light on at 6:30","topic":"","payload":"turn the garden light on at 6:30","payloadType":"str","repeat":"","crontab":"","once":false,"x":216.6666717529297,"y":3736.6668157577515,"wires":[["6fef72b0.643a9c"]]},{"id":"ee8d6877.3088a8","type":"function","z":"438d0e76.5f7bf","name":"Dummy","func":"\nreturn msg;","outputs":1,"noerr":0,"x":856.6666717529297,"y":3976.6668157577515,"wires":[["aaf5b18d.405fd","351931a9.6d73fe","862580b4.16b8f","48670c45.1fcd84","4657c865.d3acb8","c4c4b916.c99ff8","f2d1af5e.9f6ed"]]},{"id":"a19cbf0.5246a4","type":"ui_text_input","z":"438d0e76.5f7bf","name":"","label":"Phrase","group":"70e4bcad.afdeb4","order":0,"width":0,"height":0,"passthru":true,"mode":"text","delay":"0","topic":"","x":181.09525190080913,"y":4043.523984772818,"wires":[["36e9b43c.f831ec"]]},{"id":"6f9b7852.0d2988","type":"ui_text","z":"438d0e76.5f7bf","group":"70e4bcad.afdeb4","order":0,"width":0,"height":0,"name":"","label":"Topic","format":"{{msg.payload}}","layout":"row-spread","x":1226.6666717529297,"y":3916.6668157577515,"wires":[]},{"id":"732d552c.86438c","type":"ui_text","z":"438d0e76.5f7bf","group":"70e4bcad.afdeb4","order":0,"width":0,"height":0,"name":"","label":"Device","format":"{{msg.payload}}","layout":"row-spread","x":1226.6666717529297,"y":3976.6668157577515,"wires":[]},{"id":"3e0797d1.526b58","type":"ui_text","z":"438d0e76.5f7bf","group":"70e4bcad.afdeb4","order":0,"width":0,"height":0,"name":"","label":"State","format":"{{msg.payload}}","layout":"row-spread","x":1226.6666717529297,"y":4036.6668157577515,"wires":[]},{"id":"b9d04b24.0e0db8","type":"ui_text","z":"438d0e76.5f7bf","group":"70e4bcad.afdeb4","order":0,"width":0,"height":0,"name":"","label":"Time lapse:","format":"{{msg.payload}}","layout":"row-spread","x":1246.6666717529297,"y":4096.6668157577515,"wires":[]},{"id":"bc0f3476.d3e428","type":"ui_text","z":"438d0e76.5f7bf","group":"70e4bcad.afdeb4","order":0,"width":0,"height":0,"name":"","label":"Time unit:","format":"{{msg.payload}}","layout":"row-spread","x":1236.6666717529297,"y":4156.6668157577515,"wires":[]},{"id":"ede1af33.2f8fe","type":"ui_text","z":"438d0e76.5f7bf","group":"70e4bcad.afdeb4","order":0,"width":0,"height":0,"name":"","label":"Time:","format":"{{msg.payload}}","layout":"row-spread","x":1226.6666717529297,"y":4216.6668157577515,"wires":[]},{"id":"59c2990f.072b98","type":"function","z":"438d0e76.5f7bf","name":"Collect unrecognized commands","func":"// Get the previously stored commands\nvar temp = context.get(\"commands\");\nif (temp===undefined) {\n    temp = [];\n}\n\nif (msg.topic===\"--ClearList--\") {\n    // Clear the current list\n    temp = [];\n} else {\n    // Add the new one \n    temp.push(msg.payload);\n}\ncontext.set(\"commands\",temp);\n\n\n//Format the output\nmsg.payload = \"\";\nfor (var i=0; i<temp.length; i++) {\n    msg.payload += temp[i] + \"<br/>\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":886.6666717529297,"y":4376.6668157577515,"wires":[["1db7c6cc.c6c4f9"]]},{"id":"1db7c6cc.c6c4f9","type":"ui_template","z":"438d0e76.5f7bf","group":"88fb57e1.106f98","name":"Log output","order":2,"width":0,"height":0,"format":"<div ng-bind-html=\"msg.payload\" height=\"600\" style=\"height: 600px;\"><br/></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":1286.6666717529297,"y":4376.6668157577515,"wires":[[]]},{"id":"e1d42b.4a39fbd8","type":"ui_button","z":"438d0e76.5f7bf","name":"","group":"88fb57e1.106f98","order":1,"width":0,"height":0,"passthru":false,"label":"Clear List","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"--ClearList--","x":561.0952519008091,"y":4338.095387186322,"wires":[["59c2990f.072b98"]]},{"id":"70e4bcad.afdeb4","type":"ui_group","z":"","name":"Test Suite","tab":"4711038f.e5a60c","order":1,"disp":true,"width":"6"},{"id":"88fb57e1.106f98","type":"ui_group","z":"","name":"Unrecognized Commands","tab":"4711038f.e5a60c","order":2,"disp":true,"width":"12"},{"id":"4711038f.e5a60c","type":"ui_tab","z":"","name":"Ecolect","icon":"mic"}]

Flow Info

Created 6 years, 9 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x2)
  • function (x9)
  • inject (x4)
Other
  • ecolect (x1)
  • ui_button (x1)
  • ui_group (x2)
  • ui_tab (x1)
  • ui_template (x1)
  • ui_text (x6)
  • ui_text_input (x1)

Tags

  • ecolect
  • language
  • processing
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option