This is an automated email from the ASF dual-hosted git repository. sergeykamov pushed a commit to branch NLPCRAFT-160 in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit b8fe1fc590ae8bd8cfb0b33d001a9a253b90e442 Author: Sergey Kamov <[email protected]> AuthorDate: Mon Oct 19 12:12:12 2020 +0300 WIP. --- .../examples/lightswitch/LightSwitchModel.scala | 37 +++++++++++++++------- .../examples/lightswitch/lightswitch_model.yaml | 7 ++-- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala index 261b239..cb0afa5 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala @@ -35,17 +35,27 @@ class LightSwitchModel extends NCModelFileAdapter("org/apache/nlpcraft/examples/ /** * Intent and its on-match callback. * - * @param actTok Token from `act` term (guaranteed to be one). * @param locToks Tokens from `loc` term (zero or more). * @return Query result to be sent to the REST caller. */ - @NCIntentRef("ls") + @NCIntentRef("on") @NCIntentSample(Array( - "Turn the lights off in the entire house.", "Switch on the illumination in the master bedroom closet.", "Get the lights on.", + "Set the lights on in the entire house." + )) + def on(@NCIntentTerm("loc") locToks: List[NCToken]): NCResult = execute("on", locToks) + + /** + * Intent and its on-match callback. + * + * @param locToks Tokens from `loc` term (zero or more). + * @return Query result to be sent to the REST caller. + */ + @NCIntentRef("off") + @NCIntentSample(Array( "Please, put the light out in the upstairs bedroom.", - "Set the lights on in the entire house.", + "Turn the lights off in the entire house.", "Turn the lights off in the guest bedroom.", "Could you please switch off all the lights?", "Dial off illumination on the 2nd floor.", @@ -53,12 +63,17 @@ class LightSwitchModel extends NCModelFileAdapter("org/apache/nlpcraft/examples/ "Kill off all the lights now!", "No lights in the bedroom, please." )) - def onMatch( - @NCIntentTerm("act") actTok: NCToken, - @NCIntentTerm("loc") locToks: List[NCToken] - ): NCResult = { - val status = if (actTok.getId == "ls:on") "on" else "off" - val locations = + def off(@NCIntentTerm("loc") locToks: List[NCToken]): NCResult = execute("off", locToks) + + /** + * + * @param act + * @param locToks + * @return + */ + private def execute(act: String, locToks: List[NCToken]): NCResult = { + // Gets location from request, or from request conversation history, or use default value. + val locs = if (locToks.isEmpty) "entire house" else @@ -67,6 +82,6 @@ class LightSwitchModel extends NCModelFileAdapter("org/apache/nlpcraft/examples/ // Add HomeKit, Arduino or other integration here. // By default - just return a descriptive action string. - NCResult.text(s"Lights are [$status] in [${locations.toLowerCase}].") + NCResult.text(s"Lights are $act in [${locs.toLowerCase}].") } } diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/lightswitch_model.yaml b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/lightswitch_model.yaml index 94087f4..bb7683d 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/lightswitch_model.yaml +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/lightswitch_model.yaml @@ -36,20 +36,17 @@ elements: - "<ENTIRE_OPT> {house|home|building|{1st|first} floor|{2nd|second} floor}" - id: "ls:on" - groups: - - "act" description: "Light switch ON action." synonyms: - "<ACTION> <LIGHT>" - "<ACTION> on <LIGHT>" - id: "ls:off" - groups: - - "act" description: "Light switch OFF action." synonyms: - "<ACTION> <LIGHT> {off|out}" - "{<ACTION>|shut|kill|stop|eliminate} {off|out} <LIGHT>" - "no <LIGHT>" intents: - - "intent=ls conv=false term(act)={groups @@ 'act'} term(loc)={id == 'ls:loc'}*" \ No newline at end of file + - "intent=on conv=true term(act)={id == 'ls:on'} term(loc)={id == 'ls:loc'}*" + - "intent=off conv=true term(act)={id == 'ls:off'} term(loc)={id == 'ls:loc'}*" \ No newline at end of file
