This is an automated email from the ASF dual-hosted git repository. aradzinski pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit 1be41b43a913c1301eea99576d7ffc1d0f37df2b Author: Aaron Radzinzski <[email protected]> AuthorDate: Tue Apr 27 10:53:17 2021 +0300 WIP. --- ...hProcessor.kt => MinecraftFIllMatchProcessor.kt} | 21 ++++++++++++--------- .../nlpcraft/example/minecraft/MinecraftModel.kt | 18 ++++++++++++++++-- .../minecraft/{Utils.kt => MinecraftUtils.kt} | 9 +++++++++ ...craftValueLoaders.kt => MinecraftValueLoader.kt} | 0 .../minecraft/src/main/resources/minecraft.yaml | 6 +++--- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/FIllMatchProcessor.kt b/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftFIllMatchProcessor.kt similarity index 88% rename from nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/FIllMatchProcessor.kt rename to nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftFIllMatchProcessor.kt index 376d554..1890fea 100644 --- a/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/FIllMatchProcessor.kt +++ b/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftFIllMatchProcessor.kt @@ -22,10 +22,12 @@ import org.apache.nlpcraft.example.minecraft.MinecraftValueLoader.Companion.dump import org.apache.nlpcraft.model.* import java.util.* -class FIllMatchProcessor { +/** + * Utility fill processor. + */ +class MinecraftFIllMatchProcessor { companion object { fun process( - ctx: NCIntentMatch, @NCIntentTerm("shape") shape: NCToken, @NCIntentTerm("block") blockToken: NCToken, @NCIntentTerm("len") length: Optional<NCToken>, @@ -50,15 +52,15 @@ class FIllMatchProcessor { 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") + else -> throw NCRejection("Unsupported shape: $shape") } } - private fun positionCoordinate(position: NCToken): Coordinate { - return when (position.id) { + private fun positionCoordinate(pos: NCToken): Coordinate { + return when (pos.id) { "position:player" -> Coordinate() - "position:front" -> Coordinate(0, 0, transformLength(Optional.of(position), 10)) - else -> throw NCRejection("Unsupported position") + "position:front" -> Coordinate(0, 0, transformLength(Optional.of(pos), 10)) + else -> throw NCRejection("Unsupported position: ${pos.id}") } } @@ -68,14 +70,15 @@ class FIllMatchProcessor { .filter { it.id == "nlpcraft:num" } .findAny() .map { it.toInt() } - }.orElse(default) + } + .orElse(default) } private fun findPlayer(position: NCToken): String { return position.partTokens.stream() .filter { it.id == "mc:player" } .findAny() - .orElseThrow { AssertionError("Player wasn't found") } + .orElseThrow { AssertionError("Player wasn't found.") } .player() } } diff --git a/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftModel.kt b/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftModel.kt index fd1abe5..ae218fe 100644 --- a/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftModel.kt +++ b/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftModel.kt @@ -23,8 +23,14 @@ import org.apache.nlpcraft.example.minecraft.MinecraftValueLoader.Companion.dump import org.apache.nlpcraft.model.* import java.util.* +/** + * Minecraft example model. + */ @Suppress("unused") class MinecraftModel : NCModelFileAdapter("minecraft.yaml") { + /** + * Weather intent callback. + */ @NCIntentRef("weatherIntent") @NCIntentSample( "make it rain", @@ -40,6 +46,9 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") { return NCResult.text("weather ${tok.id}") } + /** + * Time intent callback. + */ @NCIntentRef("timeIntent") @NCIntentSample( "set time to evening", @@ -65,6 +74,9 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") { return NCResult.text("time set $time") } + /** + * Give intent callback. + */ @NCIntentRef("giveIntent") @NCIntentSample( "give me iron sword", @@ -90,12 +102,14 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") { return NCResult.text("give $player $itemRegistry $itemQuantity") } + /** + * Fill intent callback. + */ @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" ) @@ -106,6 +120,6 @@ class MinecraftModel : NCModelFileAdapter("minecraft.yaml") { @NCIntentTerm("len") length: Optional<NCToken>, @NCIntentTerm("position") position: NCToken, ): NCResult { - return FIllMatchProcessor.process(ctx, shape, block, length, position) + return MinecraftFIllMatchProcessor.process(shape, block, length, position) } } diff --git a/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/Utils.kt b/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftUtils.kt similarity index 97% rename from nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/Utils.kt rename to nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftUtils.kt index e469f74..8fab25e 100644 --- a/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/Utils.kt +++ b/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftUtils.kt @@ -22,14 +22,23 @@ import org.apache.nlpcraft.model.NCToken private var firstPersonWords = setOf("me", "my", "i") +/** + * + */ internal fun NCToken.toInt(): Int { return this.meta<Double>("nlpcraft:num:from").toInt() } +/** + * + */ internal fun NCToken.player(): String { return if (firstPersonWords.contains(this.normalizedText)) "@p" else this.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" diff --git a/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftValueLoaders.kt b/nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftValueLoader.kt similarity index 100% rename from nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftValueLoaders.kt rename to nlpcraft-examples/minecraft/src/main/kotlin/org/apache/nlpcraft/example/minecraft/MinecraftValueLoader.kt diff --git a/nlpcraft-examples/minecraft/src/main/resources/minecraft.yaml b/nlpcraft-examples/minecraft/src/main/resources/minecraft.yaml index 57eed4e..5d0a844 100644 --- a/nlpcraft-examples/minecraft/src/main/resources/minecraft.yaml +++ b/nlpcraft-examples/minecraft/src/main/resources/minecraft.yaml @@ -25,7 +25,7 @@ description: Minecraft Model. macros: - name: "<PLAYER_NICKNAME>" - macro: "//[a-zA-Z0-9]+//" + macro: "{//[a-zA-Z0-9]+//}" elements: # General synonyms @@ -35,11 +35,11 @@ elements: - id: mc:item metadata: mc:type: item - valueLoader: org.apache.nlpcraft.example.minecraft.MinecraftObjectValueLoader + valueLoader: org.apache.nlpcraft.example.minecraft.MinecraftValueLoader - id: mc:block metadata: mc:type: block - valueLoader: org.apache.nlpcraft.example.minecraft.MinecraftObjectValueLoader + valueLoader: org.apache.nlpcraft.example.minecraft.MinecraftValueLoader # Weather intent - id: weather:action
