This is an automated email from the ASF dual-hosted git repository.

aradzinski pushed a commit to branch NLPCRAFT-203
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-203 by this push:
     new 76fdd63  Test fixes.
76fdd63 is described below

commit 76fdd630dd9dc4382e96293a3833193c01ab2982
Author: Aaron Radzinski <[email protected]>
AuthorDate: Tue Dec 29 16:41:02 2020 -0800

    Test fixes.
---
 .../model/intent/impl/NCIntentSolverEngine.scala   | 65 ++++++++++--------
 .../probe/mgrs/nlp/NCProbeEnrichmentManager.scala  | 17 +++--
 .../apache/nlpcraft/model/NCIntentDslSpec2.scala   | 80 +++-------------------
 3 files changed, 56 insertions(+), 106 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngine.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngine.scala
index 16105fe..a1c832b 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngine.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentSolverEngine.scala
@@ -447,36 +447,43 @@ object NCIntentSolverEngine extends LazyLogging with 
NCOpenCensusTrace {
 
             if (abort)
                 None
-            else if (senToks.exists(tok ⇒ !tok.used && 
tok.token.isUserDefined)) {
-                logger.info(s"Intent '$intentId' ${r("did not")} match because 
of remaining unused user tokens $varStr.")
-
-                NCTokenLogger.prepareTable(senToks.filter(tok ⇒ !tok.used && 
tok.token.isUserDefined).map(_.token)).
-                    info(
-                        logger,
-                        Some(s"Unused user tokens for intent '$intentId' 
$varStr:")
-                    )
-
-                None
-            }
-            else if (!senToks.exists(tok ⇒ tok.used && !tok.conv)) {
-                logger.info(s"Intent '$intentId' ${r("did not")} match because 
all its matched tokens came from STM $varStr.")
-
-                None
-            }
             else {
-                // Number of remaining (unused) non-free words in the sentence 
is a measure of exactness of the match.
-                // The match is exact when all non-free words are used in that 
match.
-                // Negate to make sure the bigger (smaller negative number) is 
better.
-                val nonFreeWordNum = -senToks.count(t ⇒ !t.used && 
!t.token.isFreeWord)
-
-                intentW.prepend(nonFreeWordNum)
-                
-                Some(IntentMatch(
-                    tokenGroups = intentGrps.toList,
-                    weight = intentW,
-                    intent = intent,
-                    exactMatch = nonFreeWordNum == 0
-                ))
+                val usedSenToks = senToks.filter(_.used)
+                val unusedSenToks = senToks.filter(!_.used)
+                val usedConvToks = convToks.filter(_.used)
+
+                var res: Option[IntentMatch] = None
+
+                if (usedSenToks.isEmpty && usedConvToks.isEmpty)
+                    logger.info(s"Intent '$intentId' ${r("did not")} match 
because no tokens were matched $varStr.")
+                else if (usedSenToks.isEmpty && usedConvToks.nonEmpty)
+                    logger.info(s"Intent '$intentId' ${r("did not")} match 
because all its matched tokens came from STM $varStr.")
+                else if (unusedSenToks.exists(_.token.isUserDefined))
+                    
NCTokenLogger.prepareTable(unusedSenToks.filter(_.token.isUserDefined).map(_.token)).
+                        info(
+                            logger,
+                            Some(
+                                s"Intent '$intentId' ${r("did not")} match 
because of remaining unused user tokens $varStr." +
+                                s"\nUnused user tokens for intent '$intentId' 
$varStr:"
+                            )
+                        )
+                else {
+                    // Number of remaining (unused) non-free words in the 
sentence is a measure of exactness of the match.
+                    // The match is exact when all non-free words are used in 
that match.
+                    // Negate to make sure the bigger (smaller negative 
number) is better.
+                    val nonFreeWordNum = -senToks.count(t ⇒ !t.used && 
!t.token.isFreeWord)
+
+                    intentW.prepend(nonFreeWordNum)
+
+                    res = Some(IntentMatch(
+                        tokenGroups = intentGrps.toList,
+                        weight = intentW,
+                        intent = intent,
+                        exactMatch = nonFreeWordNum == 0
+                    ))
+                }
+
+                res
             }
         }
     }
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
index fcdbb09..2b774c5 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
@@ -335,9 +335,15 @@ object NCProbeEnrichmentManager extends NCService with 
NCOpenCensusModelStats {
             NCConnectionManager.send(msg, span)
             
             if (errMsg.isEmpty)
-                logger.info(s"OK result sent back to server 
[srvReqId=${rv(g(srvReqId))}, type=${resType.getOrElse("")}]")
+                logger.info(s"OK result sent back to server [" +
+                    s"srvReqId=${rv(g(srvReqId))}, " +
+                    s"type=${resType.getOrElse("")}" +
+                s"]")
             else
-                logger.info(s"REJECT response sent back to server 
[srvReqId=${rv(g(srvReqId))}, response=${errMsg.get}]")
+                logger.info(s"REJECT response sent back to server [" +
+                    s"srvReqId=${rv(g(srvReqId))}, " +
+                    s"response=${errMsg.get}" +
+                s"]")
         }
 
         val mdl = NCModelManager.getModel(mdlId, span)
@@ -653,11 +659,8 @@ object NCProbeEnrichmentManager extends NCService with 
NCOpenCensusModelStats {
                             "errMsg" → e.getMessage
                         )
     
-                        logger.info(s"Rejection [srvReqId=${rv(g(srvReqId))}, 
msg=${e.getMessage}]")
-    
-                        if (e.getCause != null)
-                            logger.info(s"Rejection cause:", e.getCause)
-    
+                        U.prettyError(logger,s"Rejection for server request 
ID: $srvReqId", e)
+
                         val res = mdl.model.onRejection(solverIn.intentMatch, 
e)
     
                         if (res != null)
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec2.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec2.scala
index 0c52761..bd6dc99 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec2.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec2.scala
@@ -18,7 +18,7 @@
 package org.apache.nlpcraft.model
 
 import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
-import org.junit.jupiter.api.Assertions.{assertEquals, assertFalse, assertTrue}
+import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
 import org.junit.jupiter.api.Test
 
 import java.util
@@ -37,54 +37,20 @@ class NCIntentDslSpecModel2 extends NCModelAdapter(
         Set("a", "b", "c", "d", "e").map(id ⇒ new NCElement { override def 
getId: String = id }).asJava
 
     // a. Mandatory, List, +, *, ?
-    @NCIntent("intent=aMandatory term(a)={id == 'a' }")
+    @NCIntent("intent=a_11 term(a)={id == 'a' }")
     private def aMandatory(ctx: NCIntentMatch): NCResult = "OK"
 
-    @NCIntent("intent=aList term(a)={id == 'a' }[1,3]")
+    @NCIntent("intent=a_13 term(a)={id == 'a' }[1,3]")
     private def aList(ctx: NCIntentMatch): NCResult = "OK"
 
-    @NCIntent("intent=aPlus term(a)={id == 'a' }+")
+    @NCIntent("intent=a_plus term(a)={id == 'a' }+")
     private def aPlus(ctx: NCIntentMatch): NCResult = "OK"
 
-    @NCIntent("intent=aAsterisk term(a)={id == 'a' }*")
+    @NCIntent("intent=a_star term(a)={id == 'a' }*")
     private def aAsterisk(ctx: NCIntentMatch): NCResult = "OK"
 
-    @NCIntent("intent=aOptional term(a)={id == 'a' }?")
+    @NCIntent("intent=a_01 term(a)~{id == 'a' }?")
     private def aOptional(ctx: NCIntentMatch): NCResult = "OK"
-
-    // b. List, +, *, ?
-    @NCIntent("intent=bList term(b)={id == 'b' }[1,3]")
-    private def bList(ctx: NCIntentMatch): NCResult = "OK"
-
-    @NCIntent("intent=bPlus term(b)={id == 'b' }+")
-    private def bPlus(ctx: NCIntentMatch): NCResult = "OK"
-
-    @NCIntent("intent=bAsterisk term(b)={id == 'b' }*")
-    private def bAsterisk(ctx: NCIntentMatch): NCResult = "OK"
-
-    @NCIntent("intent=bOptional term(b)={id == 'b' }?")
-    private def bOptional(ctx: NCIntentMatch): NCResult = "OK"
-
-    // c. +, *, ?
-    @NCIntent("intent=cPlus term(c)={id == 'c' }+")
-    private def cPlus(ctx: NCIntentMatch): NCResult = "OK"
-
-    @NCIntent("intent=cAsterisk term(c)={id == 'c' }*")
-    private def cAsterisk(ctx: NCIntentMatch): NCResult = "OK"
-
-    @NCIntent("intent=cOptional term(c)={id == 'c' }?")
-    private def cOptional(ctx: NCIntentMatch): NCResult = "OK"
-
-    // d. *, ?
-    @NCIntent("intent=dAsterisk term(d)={id == 'd' }*")
-    private def dAsterisk(ctx: NCIntentMatch): NCResult = "OK"
-
-    @NCIntent("intent=dOptional term(d)={id == 'd' }?")
-    private def dOptional(ctx: NCIntentMatch): NCResult = "OK"
-
-    // e. ?
-    @NCIntent("intent=eOptional term(e)={id == 'e' }?")
-    private def eOptional(ctx: NCIntentMatch): NCResult = "OK"
 }
 
 /**
@@ -100,38 +66,12 @@ class NCIntentDslSpec2 extends NCTestContext {
         assertEquals(intent, res.getIntentId, s"Checked: $txt")
     }
 
-    private def checkError(txt: String): Unit = {
-        val res = getClient.ask(txt)
-
-        assertFalse(res.isOk)
-    }
-
     @Test
     def test(): Unit = {
-        check("a", "aMandatory")
-        check("a a", "aList")
-        check("a a a", "aList")
-        check("a a a a", "aPlus")
-
-        check("b", "bList")
-        check("b b", "bList")
-        check("b b b", "bList")
-        check("b b b b", "bPlus")
-
-        check("c", "cPlus")
-        check("c c", "cPlus")
-        check("c c c", "cPlus")
-        check("c c c c", "cPlus")
-
-        check("d", "dAsterisk")
-        check("d d", "dAsterisk")
-        check("d d d", "dAsterisk")
-        check("d d d d", "dAsterisk")
-
-        check("Moscow", "eOptional")
-        check("e Moscow", "eOptional")
-        checkError("e e")
-        checkError("e e e")
+        check("a", "a_13")
+        check("a a", "a_13")
+        check("a a a", "a_13")
+        check("a a a a", "a_plus")
     }
 }
 

Reply via email to