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/02/27 05:04:00 UTC
[incubator-nlpcraft] 15/24: NLPCRAFT-91: "Give" supports player
target and quantity
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 5926e0383bbb3c388650aef4f39c7fc3785a4721
Author: Ifropc <if...@apache.org>
AuthorDate: Thu Feb 4 21:59:22 2021 -0800
NLPCRAFT-91: "Give" supports player target and quantity
---
.../org/apache/nlpcraft/example/MinecraftModel.kt | 17 ++++++++++++++---
.../minecraft-model/src/main/resources/minecraft.yaml | 7 +++++--
2 files changed, 19 insertions(+), 5 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 bf6ff5c..9e476d2 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
@@ -21,6 +21,7 @@ package org.apache.nlpcraft.example
import org.apache.nlpcraft.common.NCException
import org.apache.nlpcraft.example.MinecraftObjectValueLoader.Companion.dumps
import org.apache.nlpcraft.model.*
+import java.util.*
class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
@NCIntentRef("weatherIntent")
@@ -58,15 +59,25 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
fun onGiveMatch(
ctx: NCIntentMatch,
@NCIntentTerm("item") item: NCToken,
- @NCIntentTerm("target") target: NCToken
+ @NCIntentTerm("target") target: NCToken,
+ @NCIntentTerm("quantity") quantity: Optional<NCToken>
): NCResult {
if (ctx.isAmbiguous) {
throw NCRejection("Ambiguous request")
}
val itemRegistry = dumps["item"]!![item.value]!!
- val player = if (target.value == "me") "@p" else target.value?:"@p"
+ val player = if (target.normText() == "me") "@p" else target.originalText ?: "@p"
- return NCResult.text("give $player $itemRegistry")
+ val itemQuantity = quantity
+ .flatMap { x -> x.metaOpt<Double>("nlpcraft:num:from") }
+ .map { x -> x.toLong() }
+ .orElse(1)
+
+ return NCResult.text("give $player $itemRegistry $itemQuantity")
+ }
+
+ private fun NCToken.normText(): String {
+ return this.meta("nlpcraft:nlp:normtext")
}
}
diff --git a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
index 1696d20..d56e05a 100644
--- a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
+++ b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
@@ -79,7 +79,7 @@ elements:
- "{give}"
- id: give:target
synonyms:
- - "{me}" # TODO: also could be another player
+ - "{me|//[a-zA-Z0-9]+//}"
- id: give:item
metadata:
minecraft:type: item
@@ -90,4 +90,7 @@ elements:
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(item)={id == 'give:item'}
+ - intent=giveIntent term(action)={id == 'give:action'} term(target)={id == 'give:target'} term(quantity)={id == 'nlpcraft:num'}? term(item)={id == 'give:item'}
+
+# give me sand
+swearWordsAllowed: true