You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2020/09/13 07:12:19 UTC

[incubator-nlpcraft] branch NLPCRAFT-41 updated (53b0da8 -> 5edb8b5)

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

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


    from 53b0da8  Update TimeModel.java
     new 2e74f63  WIP.
     new 5edb8b5  WIP.

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:
 nlpcraft/src/main/resources/log4j2.xml             |  2 +-
 .../nlpcraft/common/makro/NCMacroParser.scala      |  2 +-
 .../org/apache/nlpcraft/common/util/NCUtils.scala  | 33 +++++++++++-
 .../apache/nlpcraft/examples/time/TimeModel.java   |  2 +-
 .../nlpcraft/examples/weather/WeatherModel.java    |  3 +-
 .../model/intent/impl/NCIntentDslCompiler.scala    | 10 ++--
 .../org/apache/nlpcraft/probe/NCProbeBoot.scala    |  2 +-
 .../probe/mgrs/conn/NCConnectionManager.scala      |  2 +-
 .../probe/mgrs/deploy/NCDeployManager.scala        | 60 ++++++++++++----------
 .../probe/mgrs/nlp/NCProbeEnrichmentManager.scala  |  2 +-
 .../org/apache/nlpcraft/server/NCServer.scala      |  9 ++--
 .../nlpcraft/server/probe/NCProbeManager.scala     | 24 +++++----
 .../nlpcraft/server/query/NCQueryManager.scala     |  2 +-
 .../server/sugsyn/NCSuggestSynonymManager.scala    |  2 +-
 .../nlpcraft/server/user/NCUserManager.scala       |  5 +-
 nlpcraft/src/test/resources/log4j2.xml             |  2 +-
 16 files changed, 99 insertions(+), 63 deletions(-)


[incubator-nlpcraft] 01/02: WIP.

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2e74f635c40a0d0eda35535751c850d7154814df
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sat Sep 12 17:46:59 2020 -0700

    WIP.
---
 nlpcraft/src/main/resources/log4j2.xml             |  2 +-
 .../nlpcraft/common/makro/NCMacroParser.scala      |  2 +-
 .../org/apache/nlpcraft/common/util/NCUtils.scala  | 27 ++++++++++++--
 .../apache/nlpcraft/examples/time/TimeModel.java   |  2 +-
 .../nlpcraft/examples/weather/weather_model.json   |  2 ++
 .../org/apache/nlpcraft/probe/NCProbeBoot.scala    |  2 +-
 .../probe/mgrs/conn/NCConnectionManager.scala      |  2 +-
 .../probe/mgrs/deploy/NCDeployManager.scala        | 42 +++++++++++-----------
 .../probe/mgrs/nlp/NCProbeEnrichmentManager.scala  |  2 +-
 .../org/apache/nlpcraft/server/NCServer.scala      |  9 ++---
 .../nlpcraft/server/probe/NCProbeManager.scala     | 24 ++++++++-----
 .../nlpcraft/server/query/NCQueryManager.scala     |  2 +-
 .../server/sugsyn/NCSuggestSynonymManager.scala    |  2 +-
 .../nlpcraft/server/user/NCUserManager.scala       |  5 +--
 nlpcraft/src/test/resources/log4j2.xml             |  2 +-
 15 files changed, 77 insertions(+), 50 deletions(-)

diff --git a/nlpcraft/src/main/resources/log4j2.xml b/nlpcraft/src/main/resources/log4j2.xml
index 1bdc05d..d9a627b 100644
--- a/nlpcraft/src/main/resources/log4j2.xml
+++ b/nlpcraft/src/main/resources/log4j2.xml
@@ -19,7 +19,7 @@
 
 <Configuration status="INFO">
     <Properties>
-        <Property name="pattern">%d{MMM-dd|HH:mm:ss}|%-5p| %m%n</Property>
+        <Property name="pattern">%highlight{%d{MMM-dd|HH:mm:ss}|%level{WARN=WRN, DEBUG=DBG, ERROR=ERR, TRACE=TRC, INFO=INF}| %m%n}</Property>
     </Properties>
     <Appenders>
         <Console name="stdout" target="SYSTEM_OUT">
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/makro/NCMacroParser.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/makro/NCMacroParser.scala
index b1b4c31..5576856 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/makro/NCMacroParser.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/makro/NCMacroParser.scala
@@ -387,7 +387,7 @@ class NCMacroParser {
             val ms = m.get.toString()
             
             if (!macros.keySet.contains(ms))
-                throw new NCE(s"Unknown macro [match=$ms, txt=$txt]")
+                throw new NCE(s"Unknown macro [macro=$ms, txt=$txt]")
             
             // Expand all registered macros.
             for ((k, v) ← macros) s = s.replace(k, v)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index bd4e102..4c78322 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -162,7 +162,7 @@ object NCUtils extends LazyLogging {
     }
     catch {
         case _: InterruptedException ⇒ Thread.currentThread().interrupt()
-        case e: Throwable ⇒ logger.error("Unhandled exception caught.", e)
+        case e: Throwable ⇒ prettyError(logger, "Unhandled exception caught:", e)
     }
 
     /**
@@ -1131,7 +1131,7 @@ object NCUtils extends LazyLogging {
             Thread.sleep(delay)
         catch {
             case _: InterruptedException ⇒ Thread.currentThread().interrupt()
-            case e: Throwable ⇒ logger.error("Unhandled exception caught during sleep.", e)
+            case e: Throwable ⇒ prettyError(logger, "Unhandled exception caught during sleep:", e)
         }
 
     /**
@@ -1325,6 +1325,29 @@ object NCUtils extends LazyLogging {
     }
 
     /**
+     *
+     * @param logger
+     * @param title
+     * @param e
+     */
+    def prettyError(logger: Logger, title: String, e: Throwable): Unit = {
+        logger.error(title)
+
+        val INDENT = 2
+
+        var x = e
+        var indent = INDENT
+
+        while (x != null) {
+            logger.error(s"${" " * indent}+-${x.getLocalizedMessage}")
+
+            indent += INDENT
+
+            x = x.getCause
+        }
+    }
+
+    /**
       * Unzips file.
       *
       * @param zipFile Zip file.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java
index f09304c..696529e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java
@@ -112,7 +112,7 @@ public class TimeModel extends NCModelFileAdapter {
         // Instead of defaulting to a local time - we reject with a specific error message for cleaner UX.
         throw new NCRejection(String.format("No timezone mapping for %s, %s.", city, cntry));
     }
-    
+
     /**
      * Callback on local time intent match.
      *
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/weather_model.json b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/weather_model.json
index b5d6577..1a35666 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/weather_model.json
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/weather_model.json
@@ -38,6 +38,7 @@
         "indicator"
       ],
       "synonyms": [
+        "a",
         "{history|past|previous}"
       ]
     },
@@ -48,6 +49,7 @@
         "indicator"
       ],
       "synonyms": [
+        "a",
         "{future|forecast|prognosis|prediction}"
       ]
     }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
index 75ce4d4..02eadbe 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala
@@ -174,7 +174,7 @@ private [probe] object NCProbeBoot extends LazyLogging with NCOpenCensusTrace {
         
         catching(classOf[Throwable]) either startManagers(cfg) match {
             case Left(e) ⇒ // Exception.
-                logger.error("Failed to start probe.", e)
+                U.prettyError(logger, "Failed to start probe:", e)
 
                 stop0()
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
index b2f69dc..8fee8d6 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conn/NCConnectionManager.scala
@@ -449,7 +449,7 @@ object NCConnectionManager extends NCService {
                         closeAll()
                 
                         // Ack the error message.
-                        logger.error("Unexpected error establishing REST server connection (aborting).", e)
+                        U.prettyError(logger, "Unexpected error establishing REST server connection:", e)
                     
                         abort()
                 }
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 c8d2889..5e92015 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
@@ -26,6 +26,7 @@ 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
 import org.apache.nlpcraft.common.makro.NCMacroParser
 import org.apache.nlpcraft.common.nlp.core.{NCNlpCoreManager, NCNlpPorterStemmer}
@@ -386,8 +387,6 @@ object NCDeployManager extends NCService with DecorateAsScala {
         for (ldr ← valLdrs)
             ldr.onDiscard()
 
-        var foundDups = false
-
         val allAliases =
             syns
                 .flatMap(_.syn)
@@ -413,34 +412,33 @@ object NCDeployManager extends NCService with DecorateAsScala {
                 s"dups=${idAliasDups.mkString(", ")}" +
             "]")
 
+        val dupSyns = mutable.Buffer.empty[(String, Seq[String], String)]
+
         // Check for synonym dups across all elements.
         for (
             ((syn, isDirect), holders) ←
                 syns.groupBy(p ⇒ (p.syn.mkString(" "), p.syn.isDirect)) if holders.size > 1 && isDirect
         ) {
-            val msg = s"Duplicate synonym detected (ignoring) [" +
-                s"mdlId=$mdlId, " +
-                s"elm=${
-                    holders.map(
-                        p ⇒ s"id=${p.elmId}${if (p.syn.value == null) "" else s", value=${p.syn.value}"}"
-                    ).mkString("(", ",", ")")
-                }, " +
-                s"syn=$syn" +
-            s"]"
+            dupSyns.append((
+                mdlId,
+                holders.map(p ⇒ s"id=${p.elmId}${if (p.syn.value == null) "" else s", value=${p.syn.value}"}").toSeq,
+                syn
+            ))
+        }
 
-            if (mdl.isDupSynonymsAllowed)
-                logger.trace(msg)
-            else
-                logger.warn(msg)
+        if (dupSyns.nonEmpty) {
+            val tbl = NCAsciiTable("Model ID", "Elements", "Dup Synonym")
 
-            foundDups = true
-        }
+            dupSyns.sortBy(_._1).foreach(row ⇒ tbl += (
+                row._1,
+                row._2,
+                row._3
+            ))
 
-        if (foundDups) {
-            if (mdl.isDupSynonymsAllowed) {
-                logger.warn(s"Found duplicate synonyms - check trace message [mdlId=$mdlId]")
-                logger.warn(s"Duplicates synonyms are allowed by '$mdlId' model but the large number may degrade the performance.")
-            }
+            logger.warn(s"\nDup synonyms in '$mdlId' model:\n${tbl.toString}")
+
+            if (mdl.isDupSynonymsAllowed)
+                logger.warn(s"NOTE: '$mdlId' model allows dup synonyms but the large number may degrade the performance.")
             else
                 throw new NCE(s"Duplicated synonyms found and not allowed - check warning messages [mdlId=$mdlId]")
         }
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 0b52845..5db75e8 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
@@ -172,7 +172,7 @@ object NCProbeEnrichmentManager extends NCService with NCOpenCensusModelStats {
             case e: Throwable ⇒
                 span.setStatus(Status.INTERNAL.withDescription(e.getMessage))
                 
-                logger.error("Failed to process request.", e)
+                U.prettyError(logger,"Failed to process request:", e)
             
                 val msg = NCProbeMessage("P2S_ASK_RESULT",
                     "srvReqId" → srvReqId,
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
index 27e5714..17956bd 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/NCServer.scala
@@ -169,7 +169,7 @@ object NCServer extends App with NCIgniteInstance with LazyLogging with NCOpenCe
                 try
                     p.stop(span)
                 catch {
-                    case e: Exception ⇒ logger.warn("Error stopping manager.", e)
+                    case e: Exception ⇒ U.prettyError(logger, "Error stopping managers:", e)
                 }
             )
         }
@@ -235,11 +235,8 @@ object NCServer extends App with NCIgniteInstance with LazyLogging with NCOpenCe
     
         catching(classOf[Throwable]) either startManagers() match {
             case Left(e) ⇒ // Exception.
-                e match {
-                    case x: NCE ⇒ logger.error(s"Failed to start server.", x)
-                    case x: Throwable ⇒ logger.error("Failed to start server due to unexpected error.", x)
-                }
-            
+                U.prettyError(logger, "Failed to start server:", e)
+
                 System.exit(1)
         
             case _ ⇒ // Managers started OK.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
index 5caede3..abdd5b6 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/probe/NCProbeManager.scala
@@ -125,6 +125,8 @@ object NCProbeManager extends NCService {
             s"probeGuid=$probeGuid, " +
             s"probeToken=$probeToken" +
             s"]"
+
+        def short: String = s"$probeId (guid:$probeGuid, tok:$probeToken)"
     }
     
     // Immutable probe holder.
@@ -259,7 +261,7 @@ object NCProbeManager extends NCService {
                     case Some(holder) ⇒
                         holder.close()
             
-                        logger.info(s"Probe removed: $probeKey")
+                        logger.info(s"Probe removed: ${probeKey.short}")
 
                         // Clears unused models.
                         mdls --= mdls.keys.filter(id ⇒ !probes.exists { case (_, p) ⇒ p.probe.models.exists(_.id == id) })
@@ -268,7 +270,7 @@ object NCProbeManager extends NCService {
             case Some(hld) ⇒
                 hld.close()
                 
-                logger.info(s"Pending probe removed: $probeKey")
+                logger.info(s"Pending probe removed: ${probeKey.short}")
         }
 
     /**
@@ -292,14 +294,14 @@ object NCProbeManager extends NCService {
                     }
                     catch {
                         case _: EOFException ⇒
-                            logger.trace(s"Probe closed connection: $probeKey")
+                            logger.trace(s"Probe closed connection: ${probeKey.short}")
          
                             closeAndRemoveHolder(probeKey)
 
                         case e: Throwable ⇒
                             logger.error(s"Uplink socket error [" +
                                 s"sock=$sock, " +
-                                s"probeKey=$probeKey, " +
+                                s"probeKey=${probeKey.short}, " +
                                 s"probeMsg=$probeMsg" +
                                 s"error=${e.getLocalizedMessage}" +
                                 s"]")
@@ -309,7 +311,7 @@ object NCProbeManager extends NCService {
                 }
             else
                 logger.warn(s"Sending message to unknown probe (ignoring) [" +
-                    s"probeKey=$probeKey, " +
+                    s"probeKey=${probeKey.short}, " +
                     s"probeMsg=$probeMsg" +
                 s"]")
         }
@@ -466,12 +468,12 @@ object NCProbeManager extends NCService {
                         case _: SocketTimeoutException | _: InterruptedException | _: InterruptedIOException ⇒ ()
                     
                         case _: EOFException ⇒
-                            logger.error(s"Probe closed downlink connection: $probeKey")
+                            logger.error(s"Probe closed downlink connection: ${probeKey.short}")
                         
                             t.interrupt()
                     
                         case e: Throwable ⇒
-                            logger.error(s"Error reading probe downlink socket (${e.getMessage}): $probeKey")
+                            logger.error(s"Error reading probe downlink socket (${e.getMessage}): ${probeKey.short}")
 
                             t.interrupt()
                     }
@@ -700,7 +702,7 @@ object NCProbeManager extends NCService {
         }
         
         if (!knownProbe)
-            logger.error(s"Received message from unknown probe (ignoring): $probeKey]")
+            logger.error(s"Received message from unknown probe (ignoring): ${probeKey.short}]")
         else {
             val typ = probeMsg.getType
 
@@ -800,7 +802,11 @@ object NCProbeManager extends NCService {
         val probe = hol.probe
         
         tbl += (
-            probe.probeId,
+            Seq(
+                probe.probeId,
+                s"  uid: ${probe.probeGuid}",
+                s"  tok: ${probe.probeToken}"
+            ),
             s"${probe.osName} ver. ${probe.osVersion}",
             s"${probe.tmzAbbr}, ${probe.tmzId}",
             s"${probe.hostName} (${probe.hostAddr})",
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala
index a88ebf6..81c7376 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala
@@ -75,7 +75,7 @@ object NCQueryManager extends NCService with NCIgniteInstance with NCOpenCensusS
                         }
                     }
                     catch {
-                        case e: Throwable ⇒ logger.error("Error processing cache events.", e)
+                        case e: Throwable ⇒ U.prettyError(logger,"Error processing cache events:", e)
                     }
                 ,
                 EventType.EVT_CACHE_OBJECT_PUT
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
index fce10d9..1e6cb90 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/sugsyn/NCSuggestSynonymManager.scala
@@ -431,7 +431,7 @@ object NCSuggestSynonymManager extends NCService {
                     catch {
                         case e: NCE ⇒ promise.failure(e)
                         case e: Throwable ⇒
-                            logger.warn("Unexpected error.", e)
+                            U.prettyError(logger, "Unexpected error:", e)
 
                             promise.failure(e)
                     }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/user/NCUserManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/user/NCUserManager.scala
index 758efe8..7076caa 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/user/NCUserManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/user/NCUserManager.scala
@@ -154,9 +154,10 @@ object NCUserManager extends NCService with NCIgniteInstance {
                             case e: IllegalStateException ⇒
                                 // Attempt to hide possible race condition with Ignite on a shutdown.
                                 if (!e.getMessage.startsWith("Grid is in invalid state to perform this operation"))
-                                    logger.error("Error during timeout scanner process.", e)
+                                    U.prettyError(logger,"Error during timeout scanner process:", e)
 
-                            case e: Throwable ⇒ logger.error("Error during timeout scanner process.", e)
+                            case e: Throwable ⇒
+                                U.prettyError(logger,"Error during timeout scanner process:", e)
                         }
                 }
             },
diff --git a/nlpcraft/src/test/resources/log4j2.xml b/nlpcraft/src/test/resources/log4j2.xml
index a233dc6..e5ad404 100644
--- a/nlpcraft/src/test/resources/log4j2.xml
+++ b/nlpcraft/src/test/resources/log4j2.xml
@@ -19,7 +19,7 @@
 
 <Configuration status="INFO">
     <Properties>
-        <Property name="pattern">%d{MMM-dd|HH:mm:ss}|%-5p| %C{1} - (%F:%L) - %m%n</Property>
+        <Property name="pattern">%highlight{%d{MMM-dd|HH:mm:ss}|%level{WARN=WRN, DEBUG=DBG, ERROR=ERR, TRACE=TRC, INFO=INF}| %C{1} - (%F:%L) - %m%n}</Property>
     </Properties>
     <Appenders>
         <Console name="stdout" target="SYSTEM_OUT">


[incubator-nlpcraft] 02/02: WIP.

Posted by ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5edb8b5c355e80dff0c4581a3d2d547b8762e30b
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sat Sep 12 19:36:25 2020 -0700

    WIP.
---
 .../org/apache/nlpcraft/common/util/NCUtils.scala      |  8 +++++++-
 .../apache/nlpcraft/examples/weather/WeatherModel.java |  3 ++-
 .../nlpcraft/examples/weather/weather_model.json       |  2 --
 .../model/intent/impl/NCIntentDslCompiler.scala        | 10 ++++------
 .../nlpcraft/probe/mgrs/deploy/NCDeployManager.scala   | 18 ++++++++++++------
 5 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index 4c78322..8a30b2d 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -1339,7 +1339,13 @@ object NCUtils extends LazyLogging {
         var indent = INDENT
 
         while (x != null) {
-            logger.error(s"${" " * indent}+-${x.getLocalizedMessage}")
+            var first = true
+
+            x.getLocalizedMessage.split("\n").foreach(line ⇒ {
+                logger.error(s"${" " * indent}${if (first) "+-" else "  "}${line.trim}")
+
+                first = false
+            })
 
             indent += INDENT
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java
index f123d6a..5bc0734 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java
@@ -86,7 +86,7 @@ public class WeatherModel extends NCModelFileAdapter {
 
         Optional<GeoDataBean> geoOpt = geoMrg.get(ctx.getContext().getRequest());
 
-        if (!geoOpt.isPresent())
+        if (geoOpt.isEmpty())
             throw new NCRejection("City cannot be determined.");
 
         // Manually process request for local weather. We need to separate between 'local Moscow weather'
@@ -132,6 +132,7 @@ public class WeatherModel extends NCModelFileAdapter {
     )
     @NCIntentSample({
         "What's the local weather forecast?",
+        "What's the local weather forecast?",
         "What's the weather in Moscow?",
         "What is the weather like outside?",
         "How's the weather?",
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/weather_model.json b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/weather_model.json
index 1a35666..b5d6577 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/weather_model.json
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/weather_model.json
@@ -38,7 +38,6 @@
         "indicator"
       ],
       "synonyms": [
-        "a",
         "{history|past|previous}"
       ]
     },
@@ -49,7 +48,6 @@
         "indicator"
       ],
       "synonyms": [
-        "a",
         "{future|forecast|prognosis|prediction}"
       ]
     }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentDslCompiler.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentDslCompiler.scala
index 2261d1d..2b91361 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentDslCompiler.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/NCIntentDslCompiler.scala
@@ -328,12 +328,10 @@ object NCIntentDslCompiler extends LazyLogging {
             msg: String,
             e: RecognitionException): Unit = {
             
-            val errMsg = s"Intent DSL syntax error at line $line:$charPos - $msg"
-            
-            logger.error(errMsg)
-            logger.error(s"  |-- Model:  $mdlId")
-            logger.error(s"  |-- Intent: $dsl")
-            logger.error(s"  +-- Error:  ${makeCharPosPointer(dsl.length, charPos)}")
+            val errMsg = s"Intent DSL syntax error at line $line:$charPos - $msg\n" +
+                s"  |- Model:  $mdlId\n" +
+                s"  |- Intent: $dsl\n" +
+                s"  +- Error:  ${makeCharPosPointer(dsl.length, charPos)}"
             
             throw new NCE(errMsg)
         }
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 5e92015..fc760f2 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
@@ -143,7 +143,11 @@ object NCDeployManager extends NCService with DecorateAsScala {
 
         for (elm ← mdl.getElements.asScala)
             if (!elm.getId.matches(ID_REGEX))
-                throw new NCE(s"Model element ID '${elm.getId}' does not match '$ID_REGEX' regex in: $mdlId")
+                throw new NCE(s"Model element ID does not match regex [" +
+                    s"mdlId=$mdlId, " +
+                    s"elmId=${elm.getId}, " +
+                    s"regex=$ID_REGEX" +
+                s"]")
 
         checkMacros(mdl)
 
@@ -786,8 +790,8 @@ object NCDeployManager extends NCService with DecorateAsScala {
 
             if (elmId.toLowerCase.startsWith("nlpcraft:"))
                 throw new NCE(s"Model element ID type cannot start with 'nlpcraft:' [" +
-                    s"elmId=$elmId, " +
-                    s"mdlId=${mdl.getId}" +
+                    s"mdlId=${mdl.getId}, " +
+                    s"elmId=$elmId" +
                 s"]")
 
             if (hasWhitespace(elmId))
@@ -1078,12 +1082,14 @@ object NCDeployManager extends NCService with DecorateAsScala {
         val intentTermIds = terms.filter(_.getId != null).map(_.getId)
         val invalidIds = termIds.filter(id ⇒ !intentTermIds.contains(id))
 
-        if (invalidIds.nonEmpty)
-            throw new NCE(s"Unknown term IDs in @NCIntentTerm annotation [" +
+        if (invalidIds.nonEmpty) {
+            // Report only the first one for simplicity & clarity.
+            throw new NCE(s"Unknown term ID in @NCIntentTerm annotation [" +
                 s"mdlId=$mdlId, " +
-                s"ids='${invalidIds.mkString(", ")}', " +
+                s"id='${invalidIds.head}', " +
                 s"callback=${method2Str(mtd)}" +
             s"]")
+        }
 
         val paramGenTypes = getTokensSeq(mtd.getGenericParameterTypes)