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

[incubator-nlpcraft] branch NLPCRAFT-91 updated (f019be3 -> 6a20eb1)

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.


    from f019be3  NLPCRAFT-91: fill command draft
     new 240bfa6  Fix regex
     new 6a20eb1  NLPCRAFT-91: Replace usage of macros with stand-alone element

The 2 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:
 .../org/apache/nlpcraft/example/MinecraftModel.kt  | 11 ++++++---
 .../src/main/resources/minecraft.yaml              | 26 +++++++++++++---------
 .../probe/mgrs/deploy/NCDeployManager.scala        | 10 ++++-----
 3 files changed, 27 insertions(+), 20 deletions(-)


[incubator-nlpcraft] 01/02: 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 240bfa6af2e5ccbf02fa5c9ab44f2780a1896c6d
Author: Ifropc <if...@apache.org>
AuthorDate: Wed Feb 10 17:54:05 2021 -0800

    Fix regex
---
 .../apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala    | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

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 1119c27..d9e7842 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
@@ -17,14 +17,13 @@
 
 package org.apache.nlpcraft.probe.mgrs.deploy
 
+import io.opencensus.trace.Span
 import java.io._
 import java.lang.reflect.{InvocationTargetException, Method, ParameterizedType, Type}
 import java.util
 import java.util.function.Function
 import java.util.jar.JarInputStream
 import java.util.regex.{Pattern, PatternSyntaxException}
-
-import io.opencensus.trace.Span
 import org.apache.nlpcraft.common._
 import org.apache.nlpcraft.common.ascii.NCAsciiTable
 import org.apache.nlpcraft.common.config.NCConfigurable
@@ -36,14 +35,13 @@ import org.apache.nlpcraft.model.factories.basic.NCBasicModelFactory
 import org.apache.nlpcraft.model.intent.impl.{NCIntentDslCompiler, NCIntentSolver}
 import org.apache.nlpcraft.model.intent.utils.NCDslIntent
 import org.apache.nlpcraft.probe.mgrs.NCProbeSynonymChunkKind.{DSL, REGEX, TEXT}
-import org.apache.nlpcraft.probe.mgrs.{NCProbeModel, NCProbeSynonym, NCProbeSynonymChunk}
 import org.apache.nlpcraft.probe.mgrs.model.NCModelSynonymDslCompiler
+import org.apache.nlpcraft.probe.mgrs.{NCProbeModel, NCProbeSynonym, NCProbeSynonymChunk}
 import resource.managed
-
 import scala.collection.JavaConverters._
 import scala.collection.convert.DecorateAsScala
-import scala.collection.{Map, Seq, Set, mutable}
 import scala.collection.mutable.{ArrayBuffer, ListBuffer}
+import scala.collection.{Map, Seq, Set, mutable}
 import scala.util.control.Exception._
 
 /**
@@ -51,7 +49,7 @@ import scala.util.control.Exception._
   */
 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] 02/02: 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 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