You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by if...@apache.org on 2021/03/25 03:26:22 UTC

[incubator-nlpcraft] 12/29: NLPCRAFT-91: Add /time command support

This is an automated email from the ASF dual-hosted git repository.

ifropc pushed a commit to branch NLPCRAFT-91
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git

commit 5dd22724b12681a99230337af0258286d094eea6
Author: Ifropc <if...@apache.org>
AuthorDate: Sun Dec 27 19:07:31 2020 -0800

    NLPCRAFT-91: Add /time command support
---
 nlpcraft-examples/minecraft-model/README.md        |  3 +-
 .../org/apache/nlpcraft/example/MinecraftModel.kt  | 23 +++++++++++++++-
 .../src/main/resources/minecraft.yaml              | 32 ++++++++++++++++++++++
 3 files changed, 56 insertions(+), 2 deletions(-)

diff --git a/nlpcraft-examples/minecraft-model/README.md b/nlpcraft-examples/minecraft-model/README.md
index 6b504e3..67b5002 100644
--- a/nlpcraft-examples/minecraft-model/README.md
+++ b/nlpcraft-examples/minecraft-model/README.md
@@ -47,7 +47,8 @@ on client side, prefixed with slash (`/make it sunny`)
 ### Supported commands
 | Command | Example of usage |
 | :---: |:---:|
-`/weather` | All those moments will be lost in time, like tears in rain | 
+`/weather` | Make it rain | 
+`/time` | Set current time to evening | 
 
 ### Copyright
 Copyright (C) 2020 Apache Software Foundation
diff --git a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/MinecraftModel.kt b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/MinecraftModel.kt
index 76cedd9..676066a 100644
--- a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/MinecraftModel.kt
+++ b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/MinecraftModel.kt
@@ -18,16 +18,37 @@
 
 package org.apache.nlpcraft.example
 
+import org.apache.nlpcraft.common.NCException
 import org.apache.nlpcraft.model.*
 
 class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
     @NCIntentRef("weatherIntent")
     @Suppress("unused")
-    fun onMatch(ctx: NCIntentMatch, @NCIntentTerm("arg") tok: NCToken): NCResult {
+    fun onWeatherMatch(ctx: NCIntentMatch, @NCIntentTerm("arg") tok: NCToken): NCResult {
         if (ctx.isAmbiguous) {
             throw NCRejection("Ambiguous request")
         }
 
         return NCResult.text("weather ${tok.id}")
     }
+
+    @NCIntentRef("timeIntent")
+    @Suppress("unused")
+    fun onTimeMatch(ctx: NCIntentMatch, @NCIntentTerm("arg") tok: NCToken): NCResult {
+        if (ctx.isAmbiguous) {
+            throw NCRejection("Ambiguous request")
+        }
+
+        val time: Int = when (tok.id) {
+            "morning" -> 23000
+            "day" -> 1000
+            "afternoon" -> 6000
+            "evening" -> 12000
+            "night" -> 12000
+            "midnight" -> 18000
+            else -> null
+        } ?: throw NCException("Invalid token id")
+
+        return NCResult.text("time set $time")
+    }
 }
diff --git a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
index a679ddd..f6b37d5 100644
--- a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
+++ b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
@@ -40,6 +40,38 @@ elements:
     synonyms:
       - "{thunder|storm|stormy}"
 
+  - id: morning
+    groups:
+      - time
+    synonyms:
+      - "{morning}"
+  - id: day
+    groups:
+      - time
+    synonyms:
+      - "{day}"
+  - id: afternoon
+    groups:
+      - time
+    synonyms:
+      - "{afternoon|noon}"
+  - id: evening
+    groups:
+      - time
+    synonyms:
+      - "{evening}"
+  - id: night
+    groups:
+      - time
+    synonyms:
+      - "{night}"
+  - id: midnight
+    groups:
+      - time
+    synonyms:
+      - "{midnight}"
+
 # List of model intents.
 intents:
   - intent=weatherIntent term(arg)={groups @@ 'weather'}
+  - intent=timeIntent term(arg)={groups @@ 'time'}