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/11 01:56:08 UTC
[incubator-nlpcraft] 02/02: NLPCRAFT-91: Replace usage of macros
with stand-alone element
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 6a20eb1cf79b7c4e8f0b9a523433a3457f2a2714
Author: Ifropc <if...@apache.org>
AuthorDate: Wed Feb 10 17:55:49 2021 -0800
NLPCRAFT-91: Replace usage of macros with stand-alone element
---
.../org/apache/nlpcraft/example/MinecraftModel.kt | 11 ++++++---
.../src/main/resources/minecraft.yaml | 26 +++++++++++++---------
2 files changed, 23 insertions(+), 14 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 73456f6..99a5ad2 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
@@ -25,6 +25,8 @@ import java.util.*
@Suppress("unused")
class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
+ private var firstPersonWords = setOf("me", "my", "i")
+
@NCIntentRef("weatherIntent")
fun onWeatherMatch(ctx: NCIntentMatch, @NCIntentTerm("arg") tok: NCToken): NCResult {
if (ctx.isAmbiguous) {
@@ -57,7 +59,7 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
fun onGiveMatch(
ctx: NCIntentMatch,
@NCIntentTerm("item") item: NCToken,
- @NCIntentTerm("target") target: NCToken,
+ @NCIntentTerm("action") target: NCToken,
@NCIntentTerm("quantity") quantity: Optional<NCToken>
): NCResult {
if (ctx.isAmbiguous) {
@@ -65,8 +67,7 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
}
val itemRegistry = dumps["item"]!![item.value]!!
- val player = if (target.normText() == "me") "@p" else target.originalText ?: "@p"
-
+ val player = player(target.partTokens[1])
val itemQuantity = quantity
.flatMap { x -> x.metaOpt<Double>("nlpcraft:num:from") }
.map { x -> x.toLong() }
@@ -89,4 +90,8 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
private fun NCToken.normText(): String {
return this.meta("nlpcraft:nlp:normtext")
}
+
+ private fun player(target: NCToken): String {
+ return if (firstPersonWords.contains(target.normText())) "@p" else target.originalText ?: "@p"
+ }
}
diff --git a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
index 708f67d..6d356bd 100644
--- a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
+++ b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
@@ -19,13 +19,13 @@ id: nlpcraft.minecraft.ex
name: Minecraft Model
version: '1.0'
description: Minecraft Model.
+"enabledBuiltInTokens": [
+ "nlpcraft:num"
+]
macros:
-# Doesn't work with fill
-# - name: "<PLAYER_NAME>"
-# macro: "{me|I|my|//[a-zA-Z0-9]+//}"
- name: "<PLAYER_NAME>"
- macro: "{me|I|my}"
+ macro: "{me|I|my|//[a-zA-Z0-9]+//}"
elements:
# General synonyms
@@ -96,7 +96,10 @@ elements:
# Give intent
- id: give:action
synonyms:
- - "{give}"
+ - "{give ^^[target](id == 'mc:player')^^}"
+ - id: give:block-word
+ synonyms:
+ - "{block|blocks}"
# Fill intent
- id: fill:action
@@ -120,17 +123,18 @@ elements:
- "wall"
- id: fill:length
synonyms:
- - "{size of?|length of?|diameter of?}"
+ - "{{size|length|diameter} {of|*}}"
- id: position:player
groups:
- fill:position
synonyms:
- - "{{at|near} <PLAYER_NAME> position?|where <PLAYER_NAME>}"
+ - "{{at|near} ^^[player](id == 'mc:player')^^ {position|*}|where ^^[player](id == 'mc:player')^^}"
+
- id: position:front
groups:
- fill:position
synonyms:
- - "{{^^[distance](id == 'nlpcraft:num')^^ m|meter|meters|ft|feet}? in? front of? <PLAYER_NAME>}"
+ - "{{^^[distance](id == 'nlpcraft:num')^^ m|meter|meters|ft|feet}? {in|*} front {of|*} ^^[player](id == 'mc:player')^^}"
@@ -139,9 +143,9 @@ elements:
intents:
- intent=weatherIntent term(arg)={groups @@ 'weather'}
- intent=timeIntent term(arg)={groups @@ 'time'}
- - "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'}
+ - "intent=giveIntent term(action)={id == 'give:action'} term(quantity)={id == 'nlpcraft:num'}?
+ term(item)={id == 'mc:item'} term={id == 'give:block-word'}?"
+ - "intent=fillIntent term={id == 'fill:action'} term(shape)={groups @@ 'fill:shape'} term(block)={id == 'mc:item'}
term={id == 'fill:length'}? term(len)={id == 'nlpcraft:num'} term(position)={groups @@ 'fill:position'}"
# give me sand