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

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


The following commit(s) were added to refs/heads/NLPCRAFT-474 by this push:
     new 31f46a9  WIP
31f46a9 is described below

commit 31f46a993e574cdc2386aee7657517c36694e6cc
Author: Aaron Radzinski <[email protected]>
AuthorDate: Wed Jan 26 00:45:50 2022 -0800

    WIP
---
 .../nlpcraft/internal/intent/NCIDLIntent.scala     |  2 +-
 .../intent/compiler/NCIDLCodeGenerator.scala       |  2 +-
 .../internal/intent/compiler/NCIDLCompiler.scala   | 20 +++---
 .../apache/nlpcraft/internal/util/NCUtils.scala    | 84 +---------------------
 .../impl/NCSemanticSynonymsProcessor.scala         | 12 +---
 5 files changed, 18 insertions(+), 102 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/NCIDLIntent.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/NCIDLIntent.scala
index 09c2cf2..578f445 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/NCIDLIntent.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/NCIDLIntent.scala
@@ -49,7 +49,7 @@ case class NCIDLIntent(
     // Flow regex as a compiled pattern.
     // Regex validity check is already done during intent compilation.
     lazy val flowRegex: Option[Pattern] = flow match
-        case Some(r) => Some(Pattern.compile(r))
+        case Some(r) => Option(Pattern.compile(r))
         case None => None
 
     lazy val isFlowDefined: Boolean = flow.isDefined
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCodeGenerator.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCodeGenerator.scala
index f09bdf5..19fe67f 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCodeGenerator.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCodeGenerator.scala
@@ -406,7 +406,7 @@ trait NCIDLCodeGenerator:
             stack.push(() => {
                 val (v1, v2, n) = extract2(x1, x2)
 
-                if isStr(v1) && isStr(v2) then Z(asStr(v1) + asStr(v2), n)
+                if isStr(v1) && isStr(v2) then Z(s"${asStr(v1)}${asStr(v2)}", 
n)
                 else if isInt(v1) && isInt(v2) then Z(asInt(v1) + asInt(v2), n)
                 else if isInt(v1) && isReal(v2) then Z(asInt(v1) + asReal(v2), 
n)
                 else if isReal(v1) && isInt(v2) then Z(asReal(v1) + asInt(v2), 
n)
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompiler.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompiler.scala
index c23d176..e4e6c2c 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompiler.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLCompiler.scala
@@ -199,7 +199,7 @@ object NCIDLCompiler extends LazyLogging:
         override def exitFlowDecl(ctx: IDP.FlowDeclContext): Unit =
             val regex = NCUtils.trimQuotes(ctx.qstring().getText)
 
-            if regex != null && regex.length > 2 then flowRegex = if 
(regex.nonEmpty) Some(regex) else None
+            if regex != null && regex.length > 2 then flowRegex = if 
(regex.nonEmpty) Option(regex) else None
             if flowRegex.isDefined then // Pre-check.
                 try Pattern.compile(flowRegex.get)
                 catch case e: PatternSyntaxException => 
SE(s"${e.getDescription} in intent flow regex '${e.getPattern}' near index 
${e.getIndex}.")(ctx.qstring())
@@ -358,15 +358,15 @@ object NCIDLCompiler extends LazyLogging:
         val hold = NCCompilerUtils.mkErrorHolder(idlLine, charPos)
         val aMsg = NCUtils.decapitalize(msg) match
             case s: String if s.last == '.' => s
-            case s: String => s + '.'
-
-        s"IDL $kind error in '$srcName' at line $line - $aMsg\n" +
-            s"  |-- Model ID: ${mdlCfg.getId}\n" +
-            s"  |-- Model origin: ${mdlCfg.getOrigin}\n" +
-            s"  |-- Intent origin: $origin\n" +
-            s"  |--\n" +
-            s"  |-- Line:  ${hold.origStr}\n" +
-            s"  +-- Error: ${hold.ptrStr}"
+            case s: String => s"$s."
+
+        s"""IDL $kind error in '$srcName' at line $line - $aMsg
+          |-- Model ID: ${mdlCfg.getId}
+          |-- Model origin: ${mdlCfg.getOrigin}
+          |-- Intent origin: $origin
+          |--
+          |-- Line:  ${hold.origStr}
+          +-- Error: ${hold.ptrStr}"""
     }
 
     /**
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
index e3cf07e..73b898a 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/util/NCUtils.scala
@@ -314,7 +314,7 @@ object NCUtils extends LazyLogging:
                     case '\r' => sb ++= "\\r"
                     case _ =>
                         if ch < ' ' then
-                            val t = "000" + Integer.toHexString(ch)
+                            val t = s"000${Integer.toHexString(ch)}"
                             sb ++= "\\u" ++= t.substring(t.length - 4)
 
                         else
@@ -323,84 +323,6 @@ object NCUtils extends LazyLogging:
             sb.toString()
 
     /**
-      *
-      * @param logger
-      * @param title
-      * @param e
-      */
-    def prettyError(logger: Logger, title: String, e: Throwable): Unit =
-        // Keep the full trace in the 'trace' log level.
-        logger.trace(title, e)
-
-        prettyErrorImpl(new PrettyErrorLogger {
-            override def log(s: String): Unit = logger.error(s)
-        }, title, e)
-    
-    /**
-      *
-      * @param title
-      * @param e
-      */
-    def prettyError(title: String, e: Throwable): Unit = prettyErrorImpl(new 
PrettyErrorLogger(), title, e)
-
-    sealed class PrettyErrorLogger:
-        def log(s: String): Unit = System.err.println(s)
-
-    /**
-      *
-      * @param logger
-      * @param title
-      * @param e
-      */
-    private def prettyErrorImpl(logger: PrettyErrorLogger, title: String, e: 
Throwable): Unit =
-        logger.log(title)
-
-        val INDENT = 2
-        var x = e
-        var indent = INDENT
-        while (x != null)
-            var first = true
-            var errMsg = x.getLocalizedMessage
-            if errMsg == null then errMsg = "<null>"
-            val exClsName = if !x.isInstanceOf[NCException] then 
s"[${x.getClass.getCanonicalName}] " else ""
-            val trace = 
x.getStackTrace.find(!_.getClassName.startsWith("scala.")).getOrElse(x.getStackTrace.head)
-            val fileName = trace.getFileName
-            val lineNum = trace.getLineNumber
-            val msg =
-                if fileName == null || lineNum < 0 then
-                    s"$exClsName$errMsg"
-                else
-                    s"$exClsName$errMsg -> ($fileName:$lineNum)"
-
-            msg.split("\n").foreach(line => {
-                val s = s"${" " * indent}${if first then "+-+ " else "   
"}$line}"
-                logger.log(s)
-                first = false
-            })
-
-            val traces = x.getStackTrace.filter { t =>
-                val mtdName = t.getMethodName
-                val clsName = t.getClassName
-
-                // Clean up trace.
-                clsName.startsWith("org.apache.nlpcraft") &&
-                    
!clsName.startsWith("org.apache.nlpcraft.internal.opencensus") &&
-                    !mtdName.contains("startScopedSpan") &&
-                    !mtdName.contains('$')
-            }
-            for (trace <- traces)
-                val fileName = trace.getFileName
-                val lineNum = trace.getLineNumber
-                val mtdName = trace.getMethodName
-                val clsName = 
trace.getClassName.replace("org.apache.nlpcraft", "o.a.n")
-
-                logger.log(s"${" " * indent}  | ${clsName}.$mtdName -> 
($fileName:$lineNum)")
-
-            indent += INDENT
-
-            x = x.getCause
-
-    /**
       * Makes thread.
       *
       * @param name Name.
@@ -421,7 +343,7 @@ object NCUtils extends LazyLogging:
                     logger.trace(s"Thread exited: $name")
                 catch
                     case _: InterruptedException => logger.trace(s"Thread 
interrupted: $name")
-                    case e: Throwable => prettyError(logger, s"Unexpected 
error during '$name' thread execution:", e)
+                    case e: Throwable => logger.warn(s"Unexpected error during 
'$name' thread execution:", e)
                 finally
                     stopped = true
 
@@ -485,7 +407,7 @@ object NCUtils extends LazyLogging:
             Thread.sleep(delay)
         catch
             case _: InterruptedException => Thread.currentThread().interrupt()
-            case e: Throwable => prettyError(logger, "Unhandled exception 
caught during sleep:", e)
+            case e: Throwable => logger.warn("Unhandled exception caught 
during sleep:", e)
 
 
     /**
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticSynonymsProcessor.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticSynonymsProcessor.scala
index fcde40f..40d1c3b 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticSynonymsProcessor.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticSynonymsProcessor.scala
@@ -87,9 +87,7 @@ private[impl] object NCSemanticSynonymsProcessor extends 
LazyLogging:
 
             // Ignore suspicious chars if regex is used in macro...
             for ((name, value) <- macros if isSuspicious(name) || 
(isSuspicious(value) && !value.contains("//")))
-                logger.warn(s"Suspicious macro definition (use of 
${SUSP_SYNS_CHARS.map(s => s"'$s'").mkString(", ")} chars) [" +
-                    s"macro=$name" +
-                s"]")
+                logger.warn(s"Suspicious macro definition (use of 
${SUSP_SYNS_CHARS.map(s => s"'$s'").mkString(", ")} chars) [macro=$name]")
 
     /**
       *
@@ -198,7 +196,7 @@ private[impl] object NCSemanticSynonymsProcessor extends 
LazyLogging:
                             else
                                 regex.used = true
                                 Some(regex.mkChunk())
-                        case None => Some(NCSemanticSynonymChunk(TEXT, 
tok.getText, stemmer.stem(tok.getText)))
+                        case None => Option(NCSemanticSynonymChunk(TEXT, 
tok.getText, stemmer.stem(tok.getText)))
                 ).toSeq
             }).toSeq
 
@@ -259,11 +257,7 @@ private[impl] object NCSemanticSynonymsProcessor extends 
LazyLogging:
 
             if elemIds.size > 1 then
                 for (s <- hs.map(_.synonym).distinct)
-                    logger.warn(
-                        s"Synonym appears in multiple elements [" +
-                            s"synonym='${s.chunks.mkString(" ")}', " +
-                            s"elements=${elemIds.mkString("{", ",", "}")}" +
-                        s"]")
+                    logger.warn(s"Synonym appears in multiple elements 
[synonym='${s.chunks.mkString(" ")}', elements=${elemIds.mkString("{", ",", 
"}")}]")
         })
 
         val txtBuf = buf.filter(_.synonym.isText)

Reply via email to