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:27 UTC

[incubator-nlpcraft] 17/29: NLPCRAFT-91: fill command draft

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 b61e046d0bebcc8f5e0e6998a9c41e29783d5f1c
Author: Ifropc <if...@apache.org>
AuthorDate: Mon Feb 8 19:27:52 2021 -0800

    NLPCRAFT-91: fill command draft
---
 .../org/apache/nlpcraft/example/MinecraftModel.kt  | 15 ++++-
 .../org/apache/nlpcraft/example/ValueLoaders.kt    |  2 +-
 .../src/main/resources/{blocks.json => block.json} |  0
 .../src/main/resources/minecraft.yaml              | 66 +++++++++++++++++++---
 4 files changed, 72 insertions(+), 11 deletions(-)

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 9e476d2..73456f6 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
@@ -23,9 +23,9 @@ import org.apache.nlpcraft.example.MinecraftObjectValueLoader.Companion.dumps
 import org.apache.nlpcraft.model.*
 import java.util.*
 
+@Suppress("unused")
 class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
     @NCIntentRef("weatherIntent")
-    @Suppress("unused")
     fun onWeatherMatch(ctx: NCIntentMatch, @NCIntentTerm("arg") tok: NCToken): NCResult {
         if (ctx.isAmbiguous) {
             throw NCRejection("Ambiguous request")
@@ -35,7 +35,6 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
     }
 
     @NCIntentRef("timeIntent")
-    @Suppress("unused")
     fun onTimeMatch(ctx: NCIntentMatch, @NCIntentTerm("arg") tok: NCToken): NCResult {
         if (ctx.isAmbiguous) {
             throw NCRejection("Ambiguous request")
@@ -55,7 +54,6 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
     }
 
     @NCIntentRef("giveIntent")
-    @Suppress("unused")
     fun onGiveMatch(
         ctx: NCIntentMatch,
         @NCIntentTerm("item") item: NCToken,
@@ -77,6 +75,17 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
         return NCResult.text("give $player $itemRegistry $itemQuantity")
     }
 
+    @NCIntentRef("fillIntent")
+    fun onFillMatch(
+        ctx: NCIntentMatch,
+        @NCIntentTerm("shape") shape: NCToken,
+        @NCIntentTerm("block") block: NCToken,
+        @NCIntentTerm("len") length: NCToken,
+        @NCIntentTerm("position") position: NCToken,
+    ): NCResult {
+        TODO()
+    }
+
     private fun NCToken.normText(): String {
         return this.meta("nlpcraft:nlp:normtext")
     }
diff --git a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/ValueLoaders.kt b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/ValueLoaders.kt
index 989371e..e664afb 100644
--- a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/ValueLoaders.kt
+++ b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/ValueLoaders.kt
@@ -13,7 +13,7 @@ class MinecraftObjectValueLoader : NCValueLoader {
     }
 
     override fun load(owner: NCElement?): MutableSet<NCValue> {
-        val type = owner!!.metax<String>("minecraft:type")
+        val type = owner!!.metax<String>("mc:type")
 
         val inputStream = NCModelFileAdapter::class.java.classLoader.getResourceAsStream("${type}.json")
             ?: throw NCException("Minecraft object dump not found: ${type}.json")
diff --git a/nlpcraft-examples/minecraft-model/src/main/resources/blocks.json b/nlpcraft-examples/minecraft-model/src/main/resources/block.json
similarity index 100%
rename from nlpcraft-examples/minecraft-model/src/main/resources/blocks.json
rename to nlpcraft-examples/minecraft-model/src/main/resources/block.json
diff --git a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
index d56e05a..708f67d 100644
--- a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
+++ b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
@@ -20,7 +20,27 @@ name: Minecraft Model
 version: '1.0'
 description: Minecraft Model.
 
+macros:
+# Doesn't work with fill
+#  - name: "<PLAYER_NAME>"
+#    macro: "{me|I|my|//[a-zA-Z0-9]+//}"
+  - name: "<PLAYER_NAME>"
+    macro: "{me|I|my}"
+
 elements:
+  # General synonyms
+  - id: mc:player
+    synonyms:
+      - "<PLAYER_NAME>"
+  - id: mc:item
+    metadata:
+      mc:type: item
+    valueLoader: org.apache.nlpcraft.example.MinecraftObjectValueLoader
+  - id: mc:block
+    metadata:
+      mc:type: block
+    valueLoader: org.apache.nlpcraft.example.MinecraftObjectValueLoader
+
   # Weather intent
   - id: rain
     description: Set rain weather
@@ -77,20 +97,52 @@ elements:
   - id: give:action
     synonyms:
       - "{give}"
-  - id: give:target
+
+  # Fill intent
+  - id: fill:action
     synonyms:
-      - "{me|//[a-zA-Z0-9]+//}"
-  - id: give:item
-    metadata:
-      minecraft:type: item
-    valueLoader: org.apache.nlpcraft.example.MinecraftObjectValueLoader
+      - "{fill|make|create}"
+  - id: cube
+    groups:
+      - fill:shape
+  - id: sphere
+    groups:
+      - fill:shape
+  - id: square
+    groups:
+      - fill:shape
+    synonyms:
+      - "{box|rectangle}"
+  - id: line
+    groups:
+      - fill:shape
+    synonyms:
+      - "wall"
+  - id: fill:length
+    synonyms:
+      - "{size of?|length of?|diameter of?}"
+  - id: position:player
+    groups:
+      - fill:position
+    synonyms:
+      - "{{at|near} <PLAYER_NAME> position?|where <PLAYER_NAME>}"
+  - id: position:front
+    groups:
+      - fill:position
+    synonyms:
+      - "{{^^[distance](id == 'nlpcraft:num')^^ m|meter|meters|ft|feet}? in? front of? <PLAYER_NAME>}"
+
+
 
 
 # List of model intents.
 intents:
   - intent=weatherIntent term(arg)={groups @@ 'weather'}
   - intent=timeIntent term(arg)={groups @@ 'time'}
-  - intent=giveIntent term(action)={id == 'give:action'} term(target)={id == 'give:target'} term(quantity)={id == 'nlpcraft:num'}? term(item)={id == 'give:item'}
+  - "intent=giveIntent term(action)={id == 'give:action'} term(target)={id == 'mc:player'}
+  term(quantity)={id == 'nlpcraft:num'}? term(item)={id == 'mc:item'}"
+  - "intent=fillIntent term={id == 'fill:action'} term(shape)={groups @@ 'fill:shape'} term(block)={id == 'mc:block'}
+  term={id == 'fill:length'}? term(len)={id == 'nlpcraft:num'} term(position)={groups @@ 'fill:position'}"
 
 # give me sand
 swearWordsAllowed: true