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:15:22 UTC
[incubator-nlpcraft] branch NLPCRAFT-91 updated (cff3e87 -> 81d87fd)
This is an automated email from the ASF dual-hosted git repository.
ifropc pushed a change to branch NLPCRAFT-91
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git.
discard cff3e87 NLPCRAFT-91: Fixes for new syntax
discard 11592ba NLPCRAFT-91: Add examples to MinecraftModel
discard 680a658 NLPCRAFT-91: Finish fill command
discard 16fe93b NLPCRAFT-91: Small fixes for model
discard 82ae8da NLPCRAFT-91: Support basic /fill command (different shapes and static position)
discard 61628a8 Add copyright
discard 89fa81a NLPCRAFT-91: Replace usage of macros with stand-alone element
discard 88653a4 Fix regex
new f41b781 Fix regex
new cf37d1e NLPCRAFT-91: Replace usage of macros with stand-alone element
new fa190da Add copyright
new 36c4f49 NLPCRAFT-91: Support basic /fill command (different shapes and static position)
new 7a7765b NLPCRAFT-91: Small fixes for model
new 6460b74 NLPCRAFT-91: Finish fill command
new 877264a NLPCRAFT-91: Add examples to MinecraftModel
new 81d87fd NLPCRAFT-91: Fixes for new syntax
This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version. This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:
* -- * -- B -- O -- O -- O (cff3e87)
\
N -- N -- N refs/heads/NLPCRAFT-91 (81d87fd)
You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.
Any revisions marked "omit" are not gone; other references still
refer to them. Any revisions marked "discard" are gone forever.
The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
[incubator-nlpcraft] 03/08: Add copyright
Posted by if...@apache.org.
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 fa190daaf9bfc6ae087a1e76965e0257a1086652
Author: Ifropc <if...@apache.org>
AuthorDate: Thu Feb 11 00:24:19 2021 -0800
Add copyright
---
.../kotlin/org/apache/nlpcraft/example/ValueLoaders.kt | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
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 e664afb..c43951c 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
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
package org.apache.nlpcraft.example
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
[incubator-nlpcraft] 04/08: NLPCRAFT-91: Support basic /fill
command (different shapes and static position)
Posted by if...@apache.org.
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 36c4f49852a63e14e387bf06253cdb7fb26e577e
Author: Ifropc <if...@apache.org>
AuthorDate: Thu Feb 11 00:24:48 2021 -0800
NLPCRAFT-91: Support basic /fill command (different shapes and static position)
---
.../org/apache/nplcraft/example/ExampleMod.java | 5 ++-
.../apache/nlpcraft/example/FIllMatchProcessor.kt | 52 ++++++++++++++++++++++
.../org/apache/nlpcraft/example/MinecraftModel.kt | 17 +------
.../kotlin/org/apache/nlpcraft/example/Utils.kt | 49 ++++++++++++++++++++
.../src/main/resources/minecraft.yaml | 7 ++-
5 files changed, 109 insertions(+), 21 deletions(-)
diff --git a/nlpcraft-examples/minecraft-mod/src/main/java/org/apache/nplcraft/example/ExampleMod.java b/nlpcraft-examples/minecraft-mod/src/main/java/org/apache/nplcraft/example/ExampleMod.java
index c3c349f..f76ccd8 100644
--- a/nlpcraft-examples/minecraft-mod/src/main/java/org/apache/nplcraft/example/ExampleMod.java
+++ b/nlpcraft-examples/minecraft-mod/src/main/java/org/apache/nplcraft/example/ExampleMod.java
@@ -31,6 +31,7 @@ import java.util.Optional;
import java.util.stream.Collectors;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.FileUtil;
+import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.registry.DefaultedRegistry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.CommandEvent;
@@ -68,7 +69,7 @@ public class ExampleMod {
return;
}
String command = event.getParseResults().getReader().getString();
- LOGGER.debug("Processing command:" + command);
+ Vector2f rotation = event.getParseResults().getContext().getSource().getRotation();
askProbe(command).map(r -> r.state)
.filter(s -> s.errorCode == null)
.map(s -> s.resBody)
@@ -134,7 +135,7 @@ public class ExampleMod {
http.setRequestMethod("POST"); // PUT is another valid option
http.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
http.setConnectTimeout(1_000);
- http.setReadTimeout(1_000);
+ http.setReadTimeout(3_000);
http.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(http.getOutputStream());
diff --git a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt
new file mode 100644
index 0000000..b43694b
--- /dev/null
+++ b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.nlpcraft.example
+
+import org.apache.nlpcraft.example.MinecraftObjectValueLoader.Companion.dumps
+import org.apache.nlpcraft.model.*
+
+class FIllMatchProcessor {
+ companion object {
+ fun process(
+ ctx: NCIntentMatch,
+ @NCIntentTerm("shape") shape: NCToken,
+ @NCIntentTerm("block") blockToken: NCToken,
+ @NCIntentTerm("len") length: NCToken,
+ @NCIntentTerm("position") position: NCToken
+ ): NCResult {
+ val (from, to) = resultCoordinates(length = length.toInt(), shape.id)
+ val block = dumps["item"]!![blockToken.value]!!
+
+ // TODO: Use user rotation
+ // TODO: handle y coordinate for cube
+ return NCResult.text("execute at @p positioned ~ ~ ~*1 rotated 0 0 run fill ${from.relativeRotated()} ${to.relativeRotated()} $block")
+ }
+
+ private fun resultCoordinates(length: Int, shape: String): Pair<Coordinate, Coordinate> {
+ return when (shape) {
+ "line" -> Coordinate(-length / 2) to Coordinate((length - 1) / 2)
+ "square" -> Coordinate(-length / 2,0, -length / 2) to Coordinate((length - 1) / 2, 0,(length - 1) / 2)
+ "cube" -> Coordinate(-length / 2,-length / 2, -length / 2) to Coordinate((length - 1) / 2, (length - 1) / 2,(length - 1) / 2)
+ else -> {
+ throw NCRejection("Unsupported shape")
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
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 99a5ad2..d4ed279 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,8 +25,6 @@ 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) {
@@ -68,10 +66,7 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
val itemRegistry = dumps["item"]!![item.value]!!
val player = player(target.partTokens[1])
- val itemQuantity = quantity
- .flatMap { x -> x.metaOpt<Double>("nlpcraft:num:from") }
- .map { x -> x.toLong() }
- .orElse(1)
+ val itemQuantity = quantity.map(NCToken::toInt).orElse(1)
return NCResult.text("give $player $itemRegistry $itemQuantity")
}
@@ -84,14 +79,6 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
@NCIntentTerm("len") length: NCToken,
@NCIntentTerm("position") position: NCToken,
): NCResult {
- TODO()
- }
-
- 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"
+ return FIllMatchProcessor.process(ctx, shape, block, length, position)
}
}
diff --git a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/Utils.kt b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/Utils.kt
new file mode 100644
index 0000000..79fc784
--- /dev/null
+++ b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/Utils.kt
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.nlpcraft.example
+
+import org.apache.nlpcraft.model.NCToken
+
+private var firstPersonWords = setOf("me", "my", "i")
+
+internal fun NCToken.normText(): String {
+ return this.meta("nlpcraft:nlp:normtext")
+}
+
+internal fun NCToken.toInt(): Int {
+ return this.meta<Double>("nlpcraft:num:from").toInt()
+}
+
+internal fun player(target: NCToken): String {
+ return if (firstPersonWords.contains(target.normText())) "@p" else target.originalText ?: "@p"
+}
+
+internal data class Coordinate(val x: Int = 0, val y: Int = 0, val z: Int = 0) {
+ override fun toString(): String {
+ return "$x $y $z"
+ }
+
+ fun relative(): String {
+ return "~$x ~$y ~$z"
+ }
+
+ fun relativeRotated(): String {
+ return "^$x ^$y ^$z"
+ }
+}
\ No newline at end of file
diff --git a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
index 6d356bd..8ff6b5a 100644
--- a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
+++ b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
@@ -24,8 +24,10 @@ description: Minecraft Model.
]
macros:
+# - name: "<PLAYER_NAME>"
+# macro: "{me|I|my|//[a-zA-Z0-9]+//}"
- name: "<PLAYER_NAME>"
- macro: "{me|I|my|//[a-zA-Z0-9]+//}"
+ macro: "{me|I|my}"
elements:
# General synonyms
@@ -108,9 +110,6 @@ elements:
- id: cube
groups:
- fill:shape
- - id: sphere
- groups:
- - fill:shape
- id: square
groups:
- fill:shape
[incubator-nlpcraft] 06/08: NLPCRAFT-91: Finish fill command
Posted by if...@apache.org.
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 6460b74feb6db83df12db7cc12b4521dadf15147
Author: Ifropc <if...@apache.org>
AuthorDate: Thu Feb 18 19:41:36 2021 -0800
NLPCRAFT-91: Finish fill command
---
nlpcraft-examples/minecraft-model/README.md | 11 +++---
.../apache/nlpcraft/example/FIllMatchProcessor.kt | 39 ++++++++++++++++++++--
.../org/apache/nlpcraft/example/MinecraftModel.kt | 4 +--
.../kotlin/org/apache/nlpcraft/example/Utils.kt | 4 +--
.../src/main/resources/minecraft.yaml | 6 ++--
5 files changed, 49 insertions(+), 15 deletions(-)
diff --git a/nlpcraft-examples/minecraft-model/README.md b/nlpcraft-examples/minecraft-model/README.md
index 348cd79..63dd1fa 100644
--- a/nlpcraft-examples/minecraft-model/README.md
+++ b/nlpcraft-examples/minecraft-model/README.md
@@ -45,11 +45,12 @@ use modded client, so vanilla client could be used. Commands could be either inv
on client side, prefixed with slash (`/make it sunny`)
### Supported commands
-| Command | Example of usage |
-| :---: |:---:|
-`/weather` | Make it rain |
-`/time` | Set current time to evening |
-`/give` | Give me iron sword |
+| Command | Example of usage | Commentary
+| :---: |:---:|:---|
+`/weather` | Make it rain | |
+`/time` | Set current time to evening | |
+`/give` | Give me iron sword | You can specify quanity |
+`/fill` | Make a cube of gold near me | Can specify length (size of 10, length 10), position (10 meters in front of me/other player) |
### Copyright
Copyright (C) 2020 Apache Software Foundation
diff --git a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt
index 26d617e..06db335 100644
--- a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt
+++ b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt
@@ -20,6 +20,7 @@ package org.apache.nlpcraft.example
import org.apache.nlpcraft.example.MinecraftObjectValueLoader.Companion.dumps
import org.apache.nlpcraft.model.*
+import java.util.*
class FIllMatchProcessor {
companion object {
@@ -27,15 +28,20 @@ class FIllMatchProcessor {
ctx: NCIntentMatch,
@NCIntentTerm("shape") shape: NCToken,
@NCIntentTerm("block") blockToken: NCToken,
- @NCIntentTerm("len") length: NCToken,
+ @NCIntentTerm("len") length: Optional<NCToken>,
@NCIntentTerm("position") position: NCToken
): NCResult {
- val (from, to) = resultCoordinates(length = length.toInt(), shape.id)
+ val (from, to) = resultCoordinates(transformLength(length), shape.id)
val block = dumps["item"]!![blockToken.value]!!
+ val player = findPlayer(position)
+ val positionCoordinate = positionCoordinate(position)
// TODO: Use user rotation
// TODO: handle y coordinate for cube
- return NCResult.text("execute at @p positioned ~ ~ ~ rotated 0 0 run fill ${from.relativeRotated()} ${to.relativeRotated()} $block")
+ return NCResult.text(
+ "execute at $player positioned ${positionCoordinate.relative()} rotated 0 0 run " +
+ "fill ${from.relativeRotated()} ${to.relativeRotated()} $block"
+ )
}
private fun resultCoordinates(length: Int, shape: String): Pair<Coordinate, Coordinate> {
@@ -51,5 +57,32 @@ class FIllMatchProcessor {
}
}
}
+
+ private fun positionCoordinate(position: NCToken): Coordinate {
+ return when (position.id ) {
+ "position:player" -> Coordinate()
+ "position:front" -> Coordinate(0, 0, transformLength(Optional.of(position), 10))
+ else -> {
+ throw NCRejection("Unsupported position")
+ }
+ }
+ }
+
+ private fun transformLength(length: Optional<NCToken>, default: Int = 5): Int {
+ return length.flatMap { x ->
+ x.partTokens.stream()
+ .filter { it.id == "nlpcraft:num" }
+ .findAny()
+ .map { it.toInt() }
+ }.orElse(default)
+ }
+
+ private fun findPlayer(position: NCToken): String {
+ return position.partTokens.stream()
+ .filter { it.id == "mc:player" }
+ .findAny()
+ .orElseThrow { NCRejection("") }
+ .player()
+ }
}
}
\ No newline at end of file
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 b92c57c..2cc667c 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
@@ -65,7 +65,7 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
}
val itemRegistry = dumps["item"]!![item.value]!!
- val player = player(target.partTokens[1])
+ val player = target.partTokens[1].player()
val itemQuantity = quantity.map(NCToken::toInt).orElse(1)
return NCResult.text("give $player $itemRegistry $itemQuantity")
@@ -76,7 +76,7 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
ctx: NCIntentMatch,
@NCIntentTerm("shape") shape: NCToken,
@NCIntentTerm("block") block: NCToken,
- @NCIntentTerm("len") length: NCToken,
+ @NCIntentTerm("len") length: Optional<NCToken>,
@NCIntentTerm("position") position: NCToken,
): NCResult {
return FIllMatchProcessor.process(ctx, shape, block, length, position)
diff --git a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/Utils.kt b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/Utils.kt
index 79fc784..ae52a10 100644
--- a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/Utils.kt
+++ b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/Utils.kt
@@ -30,8 +30,8 @@ internal fun NCToken.toInt(): Int {
return this.meta<Double>("nlpcraft:num:from").toInt()
}
-internal fun player(target: NCToken): String {
- return if (firstPersonWords.contains(target.normText())) "@p" else target.originalText ?: "@p"
+internal fun NCToken.player(): String {
+ return if (firstPersonWords.contains(this.normText())) "@p" else this.originalText ?: "@p"
}
internal data class Coordinate(val x: Int = 0, val y: Int = 0, val z: Int = 0) {
diff --git a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
index 31762b1..99cee41 100644
--- a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
+++ b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
@@ -123,7 +123,7 @@ elements:
- "wall"
- id: fill:length
synonyms:
- - "{{size|length|diameter} {of|*}}"
+ - "{{size|length|diameter} {of|*} ^^[length](id == 'nlpcraft:num')^^}"
- id: position:player
groups:
- fill:position
@@ -135,7 +135,7 @@ elements:
groups:
- fill:position
synonyms:
- - "{{{^^[distance](id == 'nlpcraft:num')^^ m|meter|meters|ft|feet}|*} {in|*} front {of|*} ^^[player](id == 'mc:player')^^}"
+ - "{{^^[distance](id == 'nlpcraft:num')^^|*} {in|*} front {of|*} ^^[player](id == 'mc:player')^^}"
"permutateSynonyms": false
@@ -148,7 +148,7 @@ intents:
- "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'}"
+ term(len)={id == 'fill:length'}? term(position)={groups @@ 'fill:position'}"
# give me sand
swearWordsAllowed: true
[incubator-nlpcraft] 02/08: NLPCRAFT-91: Replace usage of macros
with stand-alone element
Posted by if...@apache.org.
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 cf37d1ef5be8e3ecd43495d6ac9a69bce27cf120
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
[incubator-nlpcraft] 05/08: NLPCRAFT-91: Small fixes for model
Posted by if...@apache.org.
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 7a7765b29069f6dcaa791e1054db49e86280257e
Author: Ifropc <if...@apache.org>
AuthorDate: Thu Feb 18 18:24:31 2021 -0800
NLPCRAFT-91: Small fixes for model
---
.../kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt | 11 +++++++----
.../main/kotlin/org/apache/nlpcraft/example/MinecraftModel.kt | 4 ++++
.../minecraft-model/src/main/resources/minecraft.yaml | 5 ++++-
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt
index b43694b..26d617e 100644
--- a/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt
+++ b/nlpcraft-examples/minecraft-model/src/main/kotlin/org/apache/nlpcraft/example/FIllMatchProcessor.kt
@@ -35,14 +35,17 @@ class FIllMatchProcessor {
// TODO: Use user rotation
// TODO: handle y coordinate for cube
- return NCResult.text("execute at @p positioned ~ ~ ~*1 rotated 0 0 run fill ${from.relativeRotated()} ${to.relativeRotated()} $block")
+ return NCResult.text("execute at @p positioned ~ ~ ~ rotated 0 0 run fill ${from.relativeRotated()} ${to.relativeRotated()} $block")
}
private fun resultCoordinates(length: Int, shape: String): Pair<Coordinate, Coordinate> {
return when (shape) {
- "line" -> Coordinate(-length / 2) to Coordinate((length - 1) / 2)
- "square" -> Coordinate(-length / 2,0, -length / 2) to Coordinate((length - 1) / 2, 0,(length - 1) / 2)
- "cube" -> Coordinate(-length / 2,-length / 2, -length / 2) to Coordinate((length - 1) / 2, (length - 1) / 2,(length - 1) / 2)
+ "line" -> Coordinate(-length / 2) to
+ Coordinate((length - 1) / 2)
+ "square" -> Coordinate(-length / 2, 0, -length / 2) to
+ Coordinate((length - 1) / 2, 0, (length - 1) / 2)
+ "cube" -> Coordinate(-length / 2, -length / 2, -length / 2) to
+ Coordinate((length - 1) / 2, (length - 1) / 2, (length - 1) / 2)
else -> {
throw NCRejection("Unsupported shape")
}
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 d4ed279..b92c57c 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
@@ -81,4 +81,8 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
): NCResult {
return FIllMatchProcessor.process(ctx, shape, block, length, position)
}
+
+ override fun getAbstractTokens(): MutableSet<String> {
+ return mutableSetOf("mc:player")
+ }
}
diff --git a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
index 8ff6b5a..31762b1 100644
--- a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
+++ b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
@@ -99,6 +99,7 @@ elements:
- id: give:action
synonyms:
- "{give ^^[target](id == 'mc:player')^^}"
+ "permutateSynonyms": false
- id: give:block-word
synonyms:
- "{block|blocks}"
@@ -128,12 +129,14 @@ elements:
- fill:position
synonyms:
- "{{at|near} ^^[player](id == 'mc:player')^^ {position|*}|where ^^[player](id == 'mc:player')^^}"
+ "permutateSynonyms": false
- id: position:front
groups:
- fill:position
synonyms:
- - "{{^^[distance](id == 'nlpcraft:num')^^ m|meter|meters|ft|feet}? {in|*} front {of|*} ^^[player](id == 'mc:player')^^}"
+ - "{{{^^[distance](id == 'nlpcraft:num')^^ m|meter|meters|ft|feet}|*} {in|*} front {of|*} ^^[player](id == 'mc:player')^^}"
+ "permutateSynonyms": false
[incubator-nlpcraft] 08/08: NLPCRAFT-91: Fixes for new syntax
Posted by if...@apache.org.
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 81d87fd0c2e97bdfe2f12b48e28f877aeb7fe021
Author: Ifropc <if...@apache.org>
AuthorDate: Fri Feb 26 21:05:44 2021 -0800
NLPCRAFT-91: Fixes for new syntax
---
nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
index 99cee41..9ad7c6a 100644
--- a/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
+++ b/nlpcraft-examples/minecraft-model/src/main/resources/minecraft.yaml
@@ -123,19 +123,19 @@ elements:
- "wall"
- id: fill:length
synonyms:
- - "{{size|length|diameter} {of|*} ^^[length](id == 'nlpcraft:num')^^}"
+ - "{{size|length|diameter} {of|_} ^^[length](id == 'nlpcraft:num')^^}"
- id: position:player
groups:
- fill:position
synonyms:
- - "{{at|near} ^^[player](id == 'mc:player')^^ {position|*}|where ^^[player](id == 'mc:player')^^}"
+ - "{{at|near} ^^[player](id == 'mc:player')^^ {position|_}|where ^^[player](id == 'mc:player')^^}"
"permutateSynonyms": false
- id: position:front
groups:
- fill:position
synonyms:
- - "{{^^[distance](id == 'nlpcraft:num')^^|*} {in|*} front {of|*} ^^[player](id == 'mc:player')^^}"
+ - "{{^^[distance](id == 'nlpcraft:num')^^|_} {in|_} front {of|_} ^^[player](id == 'mc:player')^^}"
"permutateSynonyms": false
[incubator-nlpcraft] 01/08: Fix regex
Posted by if...@apache.org.
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 f41b78183f65129e3f88ea6d5d01c5c1352a18a3
Author: Ifropc <if...@apache.org>
AuthorDate: Wed Feb 10 17:54:05 2021 -0800
Fix regex
---
.../scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
index a68e305..45cf1c5 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
@@ -47,12 +47,13 @@ import scala.collection.{Map, Seq, Set, mutable}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.control.Exception._
+
/**
* Model deployment manager.
*/
object NCDeployManager extends NCService with DecorateAsScala {
private final val TOKENS_PROVIDERS_PREFIXES = Set("nlpcraft:", "google:", "stanford:", "opennlp:", "spacy:")
- private final val ID_REGEX = "^[_a-zA-Z]+[a-zA-Z0-9:-_]*$"
+ private final val ID_REGEX = "^[_a-zA-Z]+[a-zA-Z0-9:\\-_]*$"
private final val CLS_INTENT = classOf[NCIntent]
private final val CLS_INTENT_REF = classOf[NCIntentRef]
[incubator-nlpcraft] 07/08: NLPCRAFT-91: Add examples to
MinecraftModel
Posted by if...@apache.org.
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 877264a24e608b365da87bf51166ae80685e030c
Author: Ifropc <if...@apache.org>
AuthorDate: Mon Feb 22 18:38:52 2021 -0800
NLPCRAFT-91: Add examples to MinecraftModel
---
.../kotlin/org/apache/nlpcraft/example/MinecraftModel.kt | 15 +++++++++++++++
1 file changed, 15 insertions(+)
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 2cc667c..68efd43 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
@@ -26,6 +26,7 @@ import java.util.*
@Suppress("unused")
class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
@NCIntentRef("weatherIntent")
+ @NCIntentSample("make it rain")
fun onWeatherMatch(ctx: NCIntentMatch, @NCIntentTerm("arg") tok: NCToken): NCResult {
if (ctx.isAmbiguous) {
throw NCRejection("Ambiguous request")
@@ -35,6 +36,7 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
}
@NCIntentRef("timeIntent")
+ @NCIntentSample("set time to evening")
fun onTimeMatch(ctx: NCIntentMatch, @NCIntentTerm("arg") tok: NCToken): NCResult {
if (ctx.isAmbiguous) {
throw NCRejection("Ambiguous request")
@@ -54,6 +56,11 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
}
@NCIntentRef("giveIntent")
+ @NCIntentSample(
+ "give me iron sword",
+ "give me 10 grass blocks",
+ "give PlayerName a jigsaw"
+ )
fun onGiveMatch(
ctx: NCIntentMatch,
@NCIntentTerm("item") item: NCToken,
@@ -72,6 +79,14 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") {
}
@NCIntentRef("fillIntent")
+ @NCIntentSample(
+ "make a box of sand in front of me",
+ "make a cube of gold near me",
+ "make a line of grass with length of 2 near me",
+
+ "create a rectangle of dirt in front of PlayerName",
+ "make a box of sand with the size of 2 10 meters in front of me"
+ )
fun onFillMatch(
ctx: NCIntentMatch,
@NCIntentTerm("shape") shape: NCToken,