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 2021/07/25 19:49:02 UTC

[incubator-nlpcraft] branch NLPCRAFT-379 updated: WIP on NLPCRAFT-379

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

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


The following commit(s) were added to refs/heads/NLPCRAFT-379 by this push:
     new e66facf  WIP on NLPCRAFT-379
e66facf is described below

commit e66facf2e63662b78c2b3289479389ef9212a616
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sun Jul 25 12:48:44 2021 -0700

    WIP on NLPCRAFT-379
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       |  1 +
 .../model/tools/cmdline/NCCliCommands.scala        |  7 +++++++
 .../nlpcraft/server/probe/NCProbeManager.scala     | 24 +++++++++++-----------
 3 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
index 55decb2..549372d 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala
@@ -1558,6 +1558,7 @@ object NCCli extends NCCliBase {
      */
     private [cmdline] def cmdInfo(cmd: Command, args: Seq[Argument], repl: Boolean): Unit = {
         cmdInfoServer(CMDS.find(_.name == "info-server").get, Seq.empty[Argument], repl)
+        logln()
         cmdInfoProbe(CMDS.find(_.name == "info-probe").get, Seq.empty[Argument], repl)
     }
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala
index 9ecf1b4..3b43ef0 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCliCommands.scala
@@ -95,6 +95,7 @@ private [cmdline] object NCCliCommands {
     private final lazy val SCRIPT_NAME = U.sysEnv("NLPCRAFT_CLI_SCRIPT").getOrElse(s"nlpcraft.${if (SystemUtils.IS_OS_UNIX) "sh" else "cmd"}")
     private final lazy val PROMPT = if (SCRIPT_NAME.endsWith("cmd")) ">" else "$"
     private final lazy val VER = NCVersion.getCurrent
+    private final lazy val REST_SPEC_URL = "https://nlpcraft.apache.org/using-rest.html"
 
     //noinspection DuplicatedCode
     // All supported commands.
@@ -158,6 +159,7 @@ private [cmdline] object NCCliCommands {
             group = "2. REST Commands",
             synopsis = s"Wrapper for ${y("'/signin'")} REST call.",
             desc = Some(
+                s"See ${REST_SPEC_URL} for REST call specification. " +
                 s"If no arguments provided, it signs in with the " +
                 s"default 'admin@admin.com' user account. NOTE: please make sure to remove this account when " +
                 s"running in production."
@@ -195,6 +197,7 @@ private [cmdline] object NCCliCommands {
             group = "2. REST Commands",
             synopsis = s"Wrapper for ${y("'/signout'")} REST call in REPL mode.",
             desc = Some(
+                s"See ${REST_SPEC_URL} for REST call specification. " +
                 s"Signs out currently signed in user. Note that this command makes sense only in REPL mode."
             ),
             body = NCCli.cmdSignOut,
@@ -274,6 +277,7 @@ private [cmdline] object NCCliCommands {
             group = "2. REST Commands",
             synopsis = s"Wrapper for ${y("'/ask/sync'")} REST call.",
             desc = Some(
+                s"See ${REST_SPEC_URL} for REST call specification. " +
                 s"Requires user to be already signed in. This command ${bo("only makes sense in the REPL mode")} as " +
                 s"it requires user to be signed in. REPL session keeps the currently active access " +
                 s"token after user signed in. For command line mode, use ${y("'rest'")} command with " +
@@ -546,6 +550,7 @@ private [cmdline] object NCCliCommands {
             group = "2. REST Commands",
             synopsis = s"Wrapper for ${y("'/model/info'")} REST call.",
             desc = Some(
+                s"See ${REST_SPEC_URL} for REST call specification. " +
                 s"Requires user to be already signed in. This command ${bo("only makes sense in the REPL mode")} as " +
                 s"it requires user to be signed in. REPL session keeps the currently active access " +
                 s"token after user signed in. For command line mode, use ${y("'rest'")} command with " +
@@ -581,6 +586,7 @@ private [cmdline] object NCCliCommands {
             group = "2. REST Commands",
             synopsis = s"Wrapper for ${y("'/model/syns'")} REST call.",
             desc = Some(
+                s"See ${REST_SPEC_URL} for REST call specification. " +
                 s"Requires user to be already signed in. This command ${bo("only makes sense in the REPL mode")} as " +
                 s"it requires user to be signed in. REPL session keeps the currently active access " +
                 s"token after user signed in. For command line mode, use ${y("'rest'")} command with " +
@@ -624,6 +630,7 @@ private [cmdline] object NCCliCommands {
             group = "2. REST Commands",
             synopsis = s"Wrapper for ${y("'/model/sugsyn'")} REST call.",
             desc = Some(
+                s"See ${REST_SPEC_URL} for REST call specification. " +
                 s"Requires user to be already signed in. This command ${bo("only makes sense in the REPL mode")} as " +
                 s"it requires user to be signed in. REPL session keeps the currently active access " +
                 s"token after user signed in. For command line mode, use ${y("'rest'")} command with " +
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 71bbf6f..feed48c 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
@@ -1122,22 +1122,22 @@ object NCProbeManager extends NCService {
                         res.containsKey("macros")
                     )
 
-                    val macros = res.remove("macros").asInstanceOf[java.util.Map[String, String]]
-                    val syns = res.get("synonyms").asInstanceOf[java.util.List[String]]
-                    val vals = res.get("values").asInstanceOf[java.util.Map[String, java.util.List[String]]]
+                    val macros = res.remove("macros").asInstanceOf[java.util.Map[String, String]].asScala
+                    val syns = res.get("synonyms").asInstanceOf[java.util.List[String]].asScala
+                    val vals = res.get("values").asInstanceOf[java.util.Map[String, java.util.List[String]]].asScala
 
-                    val parser = new NCMacroParser
+                    val parser = NCMacroParser(macros.toList)
 
-                    macros.asScala.foreach(t => parser.addMacro(t._1, t._2))
+                    val synsExp = syns.flatMap(s => parser.expand(s)).sorted
+                    val valsExp = vals.map(v => v._1 -> v._2.asScala.flatMap(s => parser.expand(s)).sorted.asJava).toMap
 
-                    val synsExp: java.util.List[String] =
-                        syns.asScala.flatMap(s => parser.expand(s)).sorted.asJava
+                    res.put("synonymsExp", synsExp.asJava)
+                    res.put("valuesExp", valsExp.asJava)
 
-                    val valsExp: java.util.Map[String, java.util.List[String]] =
-                        vals.asScala.map(v => v._1 -> v._2.asScala.flatMap(s => parser.expand(s)).sorted.asJava).toMap.asJava
-
-                    res.put("synonymsExp", synsExp)
-                    res.put("valuesExp", valsExp)
+                    // Add statistics.
+                    res.put("synonymsExpCnt", Integer.valueOf(synsExp.size))
+                    res.put("synonymsCnt", Integer.valueOf(syns.size))
+                    res.put("synonymsExpRatePct", java.lang.Long.valueOf(Math.round(synsExp.size.toDouble * 100 / syns.size.toDouble)))
 
                     res
                 }