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/10/14 03:25:09 UTC

[incubator-nlpcraft] branch master updated (788d1b6 -> 43ca004)

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

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


    from 788d1b6  Minor fixes.
     new d495873  WIP.
     new 56842f8  WIP.
     new 387f099  Update NCCli.scala
     new 8228110  Update NCCli.scala
     new a1aff98  Update NCCli.scala
     new 180fbf9  Merge branch 'master' into NLPCRAFT-108
     new 1ea1969  Update NCCli.scala
     new faaa36c  Update NCCli.scala
     new e8c26bc  Update NCCli.scala
     new e7f34f7  Update NCCli.scala
     new f968d83  Merge branch 'master' into NLPCRAFT-108
     new 5983b47  WIP.
     new 0da1751  WIP.
     new e472e9c  Update NCCli.scala
     new a72fc14  Update NCCli.scala
     new c25ab35  WIP.
     new 2406284  WIP.
     new d7b9604  Update NCBasicRestApi.scala
     new 815c99d  Update NCCli.scala
     new 6bcc6a2  Update NCCli.scala
     new ba21c9c  WIP.
     new cc09dc6  Update NCCli.scala
     new 43ca004  Update NCConversation.scala

The 23 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/common/util/NCUtils.scala  |  19 +
 .../examples/lightswitch/LightSwitchModel.scala    |   2 +-
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 991 ++++++++++++++++++---
 .../probe/mgrs/conversation/NCConversation.scala   |  15 +-
 .../nlpcraft/server/rest/NCBasicRestApi.scala      |  12 +-
 .../apache/nlpcraft/model/NCIntentSampleSpec.scala |   1 +
 openapi/nlpcraft_swagger.yml                       |  53 +-
 7 files changed, 920 insertions(+), 173 deletions(-)


[incubator-nlpcraft] 11/23: Merge branch 'master' into NLPCRAFT-108

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

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

commit f968d83b00befcd8967bc3ee02d066e7b31f8919
Merge: e7f34f7 788d1b6
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sun Oct 11 06:05:42 2020 -0700

    Merge branch 'master' into NLPCRAFT-108

 .../src/main/scala/org/apache/nlpcraft/common/NCService.scala |  4 ++--
 .../main/scala/org/apache/nlpcraft/probe/NCProbeBoot.scala    | 11 ++++++-----
 2 files changed, 8 insertions(+), 7 deletions(-)


[incubator-nlpcraft] 20/23: Update NCCli.scala

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

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

commit 6bcc6a2072a412ada0334107e16324a1cf6d632f
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 14:54:43 2020 -0700

    Update NCCli.scala
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 326 ++++++++++-----------
 1 file changed, 162 insertions(+), 164 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 cf7e262..3e5cdb8 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
@@ -162,11 +162,11 @@ object NCCli extends App {
     case class NotEnoughArguments(cmd: Command)
         extends IllegalArgumentException(s"Not enough arguments, type $C'help --cmd=${cmd.name}'$RST to get help.")
 
-    case class RestCall(
+    case class RestSpec(
         path: String,
         desc: String,
         group: String,
-        params: Seq[RestCallParameter]
+        params: Seq[RestSpecParameter]
     )
 
     sealed trait JsonType
@@ -176,7 +176,7 @@ object NCCli extends App {
     case object OBJECT extends JsonType
     case object ARRAY extends JsonType
 
-    case class RestCallParameter(
+    case class RestSpecParameter(
         name: String,
         kind: JsonType,
         optional: Boolean = false // Mandatory by default.
@@ -185,281 +185,281 @@ object NCCli extends App {
     //noinspection DuplicatedCode
     // TODO: this needs to be loaded dynamically from OpenAPI spec.
     private final val REST_SPEC = Seq(
-        RestCall(
+        RestSpec(
             path = "clear/conversation",
             desc = "Clears conversation STM",
             group = "Asking",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "mdlId", kind = STRING),
-                RestCallParameter(name = "usrId", kind = STRING, optional = true),
-                RestCallParameter(name = "usrExtId", kind = STRING, optional = true)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "mdlId", kind = STRING),
+                RestSpecParameter(name = "usrId", kind = STRING, optional = true),
+                RestSpecParameter(name = "usrExtId", kind = STRING, optional = true)
             )
         ),
-        RestCall(
+        RestSpec(
             "clear/dialog",
             "Clears dialog flow",
             "Asking",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "mdlId", kind = STRING),
-                RestCallParameter(name = "usrId", kind = STRING, optional = true),
-                RestCallParameter(name = "usrExtId", kind = STRING, optional = true)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "mdlId", kind = STRING),
+                RestSpecParameter(name = "usrId", kind = STRING, optional = true),
+                RestSpecParameter(name = "usrExtId", kind = STRING, optional = true)
             )
         ),
-        RestCall(
+        RestSpec(
             "model/sugsyn",
             "Runs model synonym suggestion tool",
             "Tools",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "mdlId", kind = STRING),
-                RestCallParameter(name = "minScore", kind = NUMERIC)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "mdlId", kind = STRING),
+                RestSpecParameter(name = "minScore", kind = NUMERIC)
             )
         ),
-        RestCall(
+        RestSpec(
             "check",
             "Gets status and result of submitted requests",
             "Asking",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "usrId", kind = STRING, optional = true),
-                RestCallParameter(name = "usrExtId", kind = STRING, optional = true),
-                RestCallParameter(name = "srvReqIds", kind = ARRAY, optional = true),
-                RestCallParameter(name = "maxRows", kind = NUMERIC, optional = true)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "usrId", kind = STRING, optional = true),
+                RestSpecParameter(name = "usrExtId", kind = STRING, optional = true),
+                RestSpecParameter(name = "srvReqIds", kind = ARRAY, optional = true),
+                RestSpecParameter(name = "maxRows", kind = NUMERIC, optional = true)
             )
         ),
-        RestCall(
+        RestSpec(
             "cancel",
             "Cancels a question",
             "Asking",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "usrId", kind = STRING, optional = true),
-                RestCallParameter(name = "usrExtId", kind = STRING, optional = true),
-                RestCallParameter(name = "srvReqIds", kind = ARRAY, optional = true),
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "usrId", kind = STRING, optional = true),
+                RestSpecParameter(name = "usrExtId", kind = STRING, optional = true),
+                RestSpecParameter(name = "srvReqIds", kind = ARRAY, optional = true),
             )
         ),
-        RestCall(
+        RestSpec(
             "ask",
             "Asks a question",
             "Asking",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "usrId", kind = STRING, optional = true),
-                RestCallParameter(name = "usrExtId", kind = STRING, optional = true),
-                RestCallParameter(name = "txt", kind = STRING),
-                RestCallParameter(name = "mdlId", kind = STRING),
-                RestCallParameter(name = "data", kind = OBJECT, optional = true),
-                RestCallParameter(name = "enableLog", kind = BOOLEAN, optional = true),
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "usrId", kind = STRING, optional = true),
+                RestSpecParameter(name = "usrExtId", kind = STRING, optional = true),
+                RestSpecParameter(name = "txt", kind = STRING),
+                RestSpecParameter(name = "mdlId", kind = STRING),
+                RestSpecParameter(name = "data", kind = OBJECT, optional = true),
+                RestSpecParameter(name = "enableLog", kind = BOOLEAN, optional = true),
             )
         ),
-        RestCall(
+        RestSpec(
             "ask/sync",
             "Asks a question in synchronous mode",
             "Asking",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "usrId", kind = STRING, optional = true),
-                RestCallParameter(name = "usrExtId", kind = STRING, optional = true),
-                RestCallParameter(name = "txt", kind = STRING),
-                RestCallParameter(name = "mdlId", kind = STRING),
-                RestCallParameter(name = "data", kind = OBJECT, optional = true),
-                RestCallParameter(name = "enableLog", kind = BOOLEAN, optional = true),
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "usrId", kind = STRING, optional = true),
+                RestSpecParameter(name = "usrExtId", kind = STRING, optional = true),
+                RestSpecParameter(name = "txt", kind = STRING),
+                RestSpecParameter(name = "mdlId", kind = STRING),
+                RestSpecParameter(name = "data", kind = OBJECT, optional = true),
+                RestSpecParameter(name = "enableLog", kind = BOOLEAN, optional = true),
             )
         ),
-        RestCall(
+        RestSpec(
             "user/get",
             "Gets current user information",
             "User",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "id", kind = STRING, optional = true),
-                RestCallParameter(name = "usrExtId", kind = STRING, optional = true)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "id", kind = STRING, optional = true),
+                RestSpecParameter(name = "usrExtId", kind = STRING, optional = true)
             )
         ),
-        RestCall(
+        RestSpec(
             "user/all",
             "Gets all users",
             "User",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "acsTok", kind = STRING),
             )
         ),
-        RestCall(
+        RestSpec(
             "user/update",
             "Updates regular user",
             "User",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "firstName", kind = STRING),
-                RestCallParameter(name = "lastName", kind = STRING),
-                RestCallParameter(name = "id", kind = STRING, optional = true),
-                RestCallParameter(name = "avatarUrl", kind = STRING, optional = true),
-                RestCallParameter(name = "properties", kind = OBJECT, optional = true)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "firstName", kind = STRING),
+                RestSpecParameter(name = "lastName", kind = STRING),
+                RestSpecParameter(name = "id", kind = STRING, optional = true),
+                RestSpecParameter(name = "avatarUrl", kind = STRING, optional = true),
+                RestSpecParameter(name = "properties", kind = OBJECT, optional = true)
             )
         ),
-        RestCall(
+        RestSpec(
             "user/delete",
             "Deletes user",
             "User",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "id", kind = STRING, optional = true),
-                RestCallParameter(name = "usrExtId", kind = STRING, optional = true)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "id", kind = STRING, optional = true),
+                RestSpecParameter(name = "usrExtId", kind = STRING, optional = true)
             )
         ),
-        RestCall(
+        RestSpec(
             "user/admin",
             "Updates user admin permissions",
             "User",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "id", kind = STRING, optional = true),
-                RestCallParameter(name = "isAdmin", kind = BOOLEAN)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "id", kind = STRING, optional = true),
+                RestSpecParameter(name = "isAdmin", kind = BOOLEAN)
             )
         ),
-        RestCall(
+        RestSpec(
             "user/passwd/reset",
             "Resets password for the user",
             "User",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "id", kind = STRING, optional = true),
-                RestCallParameter(name = "newPasswd", kind = STRING)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "id", kind = STRING, optional = true),
+                RestSpecParameter(name = "newPasswd", kind = STRING)
             )
         ),
-        RestCall(
+        RestSpec(
             "user/add",
             "Adds new user",
             "User",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "firstName", kind = STRING),
-                RestCallParameter(name = "lastName", kind = STRING),
-                RestCallParameter(name = "email", kind = STRING),
-                RestCallParameter(name = "passwd", kind = STRING),
-                RestCallParameter(name = "isAdmin", kind = BOOLEAN),
-                RestCallParameter(name = "usrExtId", kind = STRING, optional = true),
-                RestCallParameter(name = "avatarUrl", kind = STRING, optional = true),
-                RestCallParameter(name = "properties", kind = OBJECT, optional = true)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "firstName", kind = STRING),
+                RestSpecParameter(name = "lastName", kind = STRING),
+                RestSpecParameter(name = "email", kind = STRING),
+                RestSpecParameter(name = "passwd", kind = STRING),
+                RestSpecParameter(name = "isAdmin", kind = BOOLEAN),
+                RestSpecParameter(name = "usrExtId", kind = STRING, optional = true),
+                RestSpecParameter(name = "avatarUrl", kind = STRING, optional = true),
+                RestSpecParameter(name = "properties", kind = OBJECT, optional = true)
             )
         ),
-        RestCall(
+        RestSpec(
             "company/get",
             "Gets current user company information",
             "Company",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "acsTok", kind = STRING),
             )
         ),
-        RestCall(
+        RestSpec(
             "company/add",
             "Adds new company",
             "Company",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "name", kind = STRING),
-                RestCallParameter(name = "website", kind = STRING, optional = true),
-                RestCallParameter(name = "country", kind = STRING, optional = true),
-                RestCallParameter(name = "region", kind = STRING, optional = true),
-                RestCallParameter(name = "city", kind = STRING, optional = true),
-                RestCallParameter(name = "address", kind = STRING, optional = true),
-                RestCallParameter(name = "postalCode", kind = STRING, optional = true),
-                RestCallParameter(name = "adminEmail", kind = STRING),
-                RestCallParameter(name = "adminPasswd", kind = STRING),
-                RestCallParameter(name = "adminFirstName", kind = STRING),
-                RestCallParameter(name = "adminLastName", kind = STRING),
-                RestCallParameter(name = "adminAvatarUrl", kind = STRING, optional = true)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "name", kind = STRING),
+                RestSpecParameter(name = "website", kind = STRING, optional = true),
+                RestSpecParameter(name = "country", kind = STRING, optional = true),
+                RestSpecParameter(name = "region", kind = STRING, optional = true),
+                RestSpecParameter(name = "city", kind = STRING, optional = true),
+                RestSpecParameter(name = "address", kind = STRING, optional = true),
+                RestSpecParameter(name = "postalCode", kind = STRING, optional = true),
+                RestSpecParameter(name = "adminEmail", kind = STRING),
+                RestSpecParameter(name = "adminPasswd", kind = STRING),
+                RestSpecParameter(name = "adminFirstName", kind = STRING),
+                RestSpecParameter(name = "adminLastName", kind = STRING),
+                RestSpecParameter(name = "adminAvatarUrl", kind = STRING, optional = true)
             )
         ),
-        RestCall(
+        RestSpec(
             "company/update",
             "Updates company data",
             "Company",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "name", kind = STRING),
-                RestCallParameter(name = "website", kind = STRING, optional = true),
-                RestCallParameter(name = "country", kind = STRING, optional = true),
-                RestCallParameter(name = "region", kind = STRING, optional = true),
-                RestCallParameter(name = "city", kind = STRING, optional = true),
-                RestCallParameter(name = "address", kind = STRING, optional = true),
-                RestCallParameter(name = "postalCode", kind = STRING, optional = true)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "name", kind = STRING),
+                RestSpecParameter(name = "website", kind = STRING, optional = true),
+                RestSpecParameter(name = "country", kind = STRING, optional = true),
+                RestSpecParameter(name = "region", kind = STRING, optional = true),
+                RestSpecParameter(name = "city", kind = STRING, optional = true),
+                RestSpecParameter(name = "address", kind = STRING, optional = true),
+                RestSpecParameter(name = "postalCode", kind = STRING, optional = true)
             )
         ),
-        RestCall(
+        RestSpec(
             "company/delete",
             "Deletes company",
             "Company",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "acsTok", kind = STRING),
             )
         ),
-        RestCall(
+        RestSpec(
             "company/token/reset",
             "Resets company probe auth token",
             "Company",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "acsTok", kind = STRING),
             )
         ),
-        RestCall(
+        RestSpec(
             "feedback/add",
             "Adds feedback",
             "Asking",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "usrId", kind = STRING, optional = true),
-                RestCallParameter(name = "extUsrId", kind = STRING, optional = true),
-                RestCallParameter(name = "comment", kind = STRING, optional = true),
-                RestCallParameter(name = "srvReqId", kind = STRING),
-                RestCallParameter(name = "score", kind = STRING)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "usrId", kind = STRING, optional = true),
+                RestSpecParameter(name = "extUsrId", kind = STRING, optional = true),
+                RestSpecParameter(name = "comment", kind = STRING, optional = true),
+                RestSpecParameter(name = "srvReqId", kind = STRING),
+                RestSpecParameter(name = "score", kind = STRING)
             )
         ),
-        RestCall(
+        RestSpec(
             "feedback/delete",
             "Deletes feedback",
             "Asking",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "id", kind = NUMERIC)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "id", kind = NUMERIC)
             )
         ),
-        RestCall(
+        RestSpec(
             "feedback/all",
             "Gets all feedback",
             "Asking",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
-                RestCallParameter(name = "usrId", kind = STRING, optional = true),
-                RestCallParameter(name = "extUsrId", kind = STRING, optional = true),
-                RestCallParameter(name = "srvReqId", kind = STRING,  optional = true)
+                RestSpecParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "usrId", kind = STRING, optional = true),
+                RestSpecParameter(name = "extUsrId", kind = STRING, optional = true),
+                RestSpecParameter(name = "srvReqId", kind = STRING,  optional = true)
             )
         ),
-        RestCall(
+        RestSpec(
             "signin",
             "Signs in and obtains new access token",
             "Authentication",
             params = Seq(
-                RestCallParameter(name = "email", kind = STRING),
-                RestCallParameter(name = "passwd", kind = STRING)
+                RestSpecParameter(name = "email", kind = STRING),
+                RestSpecParameter(name = "passwd", kind = STRING)
             )
         ),
-        RestCall(
+        RestSpec(
             "signout",
             "Signs out and releases access token",
             "Authentication",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "acsTok", kind = STRING),
             )
         ),
-        RestCall(
+        RestSpec(
             "probe/all",
             "Gets all probes",
             "Probe",
             params = Seq(
-                RestCallParameter(name = "acsTok", kind = STRING),
+                RestSpecParameter(name = "acsTok", kind = STRING),
             )
         )
     )
@@ -605,7 +605,7 @@ object NCCli extends App {
                 ),
                 Parameter(
                     id = "xxx",
-                    names = Seq("-xxx"),
+                    names = Seq("--xxx"),
                     value = Some("value"),
                     optional = true,
                     synthetic = true,
@@ -613,7 +613,7 @@ object NCCli extends App {
                         s"${y("'xxx'")} name corresponds to the REST call parameter that can be found at https://nlpcraft.apache.org/using-rest.html " +
                         s"The value of this parameter should be a valid JSON value using valid JSON syntax. Note that strings " +
                         s"don't have to be in double quotes. JSON objects and arrays should be specified as a JSON string in single quotes. You can have " +
-                        s"as many ${y("'-xxx=value'")} parameters as requires by the ${y("'--path'")} parameter. " +
+                        s"as many ${y("'--xxx=value'")} parameters as requires by the ${y("'--path'")} parameter. " +
                         s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion for possible parameters and their values."
                 )
             ),
@@ -621,26 +621,24 @@ object NCCli extends App {
                 Example(
                     usage = Seq(
                         s"$PROMPT $SCRIPT_NAME call -p=signin",
-                        "  -email=admin@admin.com",
-                        "  -passwd=admin"
+                        "  --email=admin@admin.com",
+                        "  --passwd=admin"
                     ),
                     desc =
                         s"Issues ${y("'signin'")} REST call with given JSON payload provided as a set of parameters. " +
-                        s"Note that ${y("'-email'")} and ${y("'-passwd'")} parameters correspond to the REST call " +
+                        s"Note that ${y("'--email'")} and ${y("'--passwd'")} parameters correspond to the REST call " +
                         s"specification for ${y("'/signin'")} path."
-
                 ),
                 Example(
                     usage = Seq(
                         s"$PROMPT $SCRIPT_NAME call --path=ask/sync",
-                        "  -acsTok=qwerty123456",
-                        "  -mdlId=my.model.id",
-                        "  -data='{\"data1\": true, \"data2\": 123, \"data3\": \"some text\"}'",
-                        "  -enableLog=false"
+                        "  --acsTok=qwerty123456",
+                        "  --mdlId=my.model.id",
+                        "  --data='{\"data1\": true, \"data2\": 123, \"data3\": \"some text\"}'",
+                        "  --enableLog=false"
                     ),
                     desc =
                         s"Issues ${y("'ask/sync'")} REST call with given JSON payload provided as a set of parameters."
-
                 )
             )
         ),
@@ -1838,25 +1836,27 @@ object NCCli extends App {
             val jsName = arg.parameter.id
 
             REST_SPEC.find(_.path == path) match {
-                case Some(call) ⇒ call.params.find(_.name == jsName) match {
-                    case Some(param) ⇒
-                        if (!first)
-                            buf ++= ","
+                case Some(spec) ⇒
+                    spec.params.find(_.name == jsName) match {
+                        case Some(param) ⇒
+                            if (!first)
+                                buf ++= ","
 
-                        first = false
+                            first = false
 
-                        buf ++= "\"" + jsName +"\":"
+                            buf ++= "\"" + jsName +"\":"
 
-                        val value = arg.value.getOrElse(throw InvalidJsonParameter(cmd, arg.parameter.names.head))
+                            val value = arg.value.getOrElse(throw InvalidJsonParameter(cmd, arg.parameter.names.head))
 
-                        param.kind match {
-                            case STRING ⇒ buf ++= "\"" + U.escapeJson(stripQuotes(value)) + "\""
-                            case OBJECT | ARRAY ⇒ buf ++= stripQuotes(value)
-                            case BOOLEAN | NUMERIC ⇒ buf ++= value
-                        }
+                            param.kind match {
+                                case STRING ⇒ buf ++= "\"" + U.escapeJson(stripQuotes(value)) + "\""
+                                case OBJECT | ARRAY ⇒ buf ++= stripQuotes(value)
+                                case BOOLEAN | NUMERIC ⇒ buf ++= value
+                            }
+
+                        case None ⇒ throw InvalidJsonParameter(cmd, jsName)
+                    }
 
-                    case None ⇒ throw InvalidJsonParameter(cmd, jsName)
-                }
                 case None ⇒ throw InvalidParameter(cmd, "path")
             }
         }
@@ -1973,7 +1973,7 @@ object NCCli extends App {
 
                     candidates.addAll(CMDS.find(_.name == cmd) match {
                         case Some(c) ⇒
-                            c.params.flatMap(param ⇒ {
+                            c.params.filter(!_.synthetic).flatMap(param ⇒ {
                                 val hasVal = param.value.isDefined
                                 val names = param.names.filter(_.startsWith("--")) // Skip shorthands from auto-completion.
 
@@ -2035,7 +2035,7 @@ object NCCli extends App {
                                         candidates.addAll(
                                             spec.params.map(param ⇒ {
                                                 mkCandidate(
-                                                    disp = s"-${param.name}",
+                                                    disp = s"--${param.name}",
                                                     grp = if (param.optional) OPTIONAL_GRP else MANDATORY_GRP,
                                                     desc = null,
                                                     completed = false
@@ -2048,7 +2048,7 @@ object NCCli extends App {
                                         if (spec.params.exists(_.name == "acsTok") && state.accessToken.isDefined)
                                             candidates.add(
                                                 mkCandidate(
-                                                    disp = s"-acsTok=${state.accessToken.get}",
+                                                    disp = s"--acsTok=${state.accessToken.get}",
                                                     grp = MANDATORY_GRP,
                                                     desc = null,
                                                     completed = true
@@ -2060,7 +2060,7 @@ object NCCli extends App {
                                             candidates.addAll(
                                                 state.probes.flatMap(_.models.toList).map(mdl ⇒ {
                                                     mkCandidate(
-                                                        disp = s"-mdlId=${mdl.id}",
+                                                        disp = s"--mdlId=${mdl.id}",
                                                         grp = MANDATORY_GRP,
                                                         desc = null,
                                                         completed = true
@@ -2073,7 +2073,7 @@ object NCCli extends App {
                                         if (path == "signin") {
                                             candidates.add(
                                                 mkCandidate(
-                                                    disp = "-email=admin@admin.com",
+                                                    disp = "--email=admin@admin.com",
                                                     grp = DFTL_USER_GRP,
                                                     desc = null,
                                                     completed = true
@@ -2081,7 +2081,7 @@ object NCCli extends App {
                                             )
                                             candidates.add(
                                                 mkCandidate(
-                                                    disp = "-passwd=admin",
+                                                    disp = "--passwd=admin",
                                                     grp = DFTL_USER_GRP,
                                                     desc = null,
                                                     completed = true
@@ -2100,8 +2100,6 @@ object NCCli extends App {
         }
 
         class ReplHistory extends DefaultHistory {
-            private var lastLine: String = _
-
             /**
              *
              * @param time
@@ -2481,7 +2479,7 @@ object NCCli extends App {
                 case None ⇒
                     if (hasSynth)
                         Argument(Parameter(
-                            id = name.substring(1), // Remove single '-' from the beginning.
+                            id = name.substring(2), // Remove single '--' from the beginning.
                             names = Seq(name),
                             value = value,
                             synthetic = true,


[incubator-nlpcraft] 04/23: Update NCCli.scala

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

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

commit 8228110ce021917e34cfc8170aac7c832e473210
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Oct 9 19:01:21 2020 -0700

    Update NCCli.scala
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 78 ++++++++++++++--------
 1 file changed, 51 insertions(+), 27 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 2840ac6..b3d9769 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
@@ -75,7 +75,7 @@ object NCCli extends App {
     )
 
     // TODO: this needs to be loaded dynamically from OpenAPI spec.
-    private final val REST_PATHS = Seq(
+    private final val REST_CMDS = Seq(
         RestCall("clear/conversation", "Clears conversation STM", "Asking"),
         RestCall("clear/dialog", "Clears dialog flow", "Asking"),
         RestCall("model/sugsyn", "Runs model synonym suggestion tool", "Tools"),
@@ -177,7 +177,7 @@ object NCCli extends App {
          * @param name
          * @return
          */
-        def findParameterByName(name: String): Option[Parameter] =
+        def findParameterByNameOpt(name: String): Option[Parameter] =
             params.find(_.names.contains(name))
 
         /**
@@ -185,8 +185,16 @@ object NCCli extends App {
          * @param id
          * @return
          */
-        def findParameterById(id: String): Option[Parameter] =
+        def findParameterByIdOpt(id: String): Option[Parameter] =
             params.find(_.id == id)
+
+        /**
+         *
+         * @param id
+         * @return
+         */
+        def findParameterById(id: String): Parameter =
+            findParameterByIdOpt(id).get
     }
     // Single command's example.
     case class Example(
@@ -213,7 +221,7 @@ object NCCli extends App {
     private final val CMDS = Seq(
         Command(
             name = "rest",
-            group = "Rest API",
+            group = "Rest Commands",
             synopsis = s"Issues REST call to local REST server.",
             desc = Some(
                 s"All NLPCraft REST API uses HTTP POST and JSON parameters ('Content-Type: application/json' header). " +
@@ -256,7 +264,7 @@ object NCCli extends App {
         ),
         Command(
             name = "tail-server",
-            group = "Server Ops",
+            group = "Server Commands",
             synopsis = s"Shows last N lines from the local REST server log.",
             desc = Some(
                 s"Only works for the server started via this script."
@@ -280,7 +288,7 @@ object NCCli extends App {
         ),
         Command(
             name = "start-server",
-            group = "Server Ops",
+            group = "Server Commands",
             synopsis = s"Starts local REST server.",
             desc = Some(
                 s"REST server is started in the external JVM process with both stdout and stderr piped out into log file. " +
@@ -332,7 +340,7 @@ object NCCli extends App {
         ),
         Command(
             name = "restart-server",
-            group = "Server Ops",
+            group = "Server Commands",
             synopsis = s"Restarts local REST server.",
             desc = Some(
                 s"This command is equivalent to executing  ${y("'stop-server'")} and then ${y("'start-server'")} commands with " +
@@ -384,19 +392,19 @@ object NCCli extends App {
         ),
         Command(
             name = "info-server",
-            group = "Server Ops",
+            group = "Server Commands",
             synopsis = s"Info about local REST server.",
             body = cmdInfoServer
         ),
         Command(
             name = "cls",
-            group = "REPL",
+            group = "REPL Commands",
             synopsis = s"Clears terminal screen.",
             body = cmdCls
         ),
         Command(
             name = "nano",
-            group = "REPL",
+            group = "REPL Commands",
             synopsis = s"Runs built-in ${y("'nano'")} editor.",
             body = cmdNano,
             desc = Some(
@@ -428,7 +436,7 @@ object NCCli extends App {
         ),
         Command(
             name = "less",
-            group = "REPL",
+            group = "REPL Commands",
             synopsis = s"Runs built-in ${y("'less'")} command.",
             body = cmdLess,
             desc = Some(
@@ -459,7 +467,7 @@ object NCCli extends App {
         ),
         Command(
             name = "no-ansi",
-            group = "REPL",
+            group = "REPL Commands",
             synopsis = s"Disables ANSI escape codes for terminal colors & controls.",
             desc = Some(
                 s"This is a special command that can be combined with any other commands."
@@ -474,7 +482,7 @@ object NCCli extends App {
         ),
         Command(
             name = "ansi",
-            group = "REPL",
+            group = "REPL Commands",
             synopsis = s"Enables ANSI escape codes for terminal colors & controls.",
             desc = Some(
                 s"This is a special command that can be combined with any other commands."
@@ -489,7 +497,7 @@ object NCCli extends App {
         ),
         Command(
             name = "ping-server",
-            group = "Server Ops",
+            group = "Server Commands",
             synopsis = s"Pings local REST server.",
             desc = Some(
                 s"REST server is pinged using ${y("'/health'")} REST call to check its online status."
@@ -516,7 +524,7 @@ object NCCli extends App {
         ),
         Command(
             name = "stop-server",
-            group = "Server Ops",
+            group = "Server Commands",
             synopsis = s"Stops local REST server.",
             desc = Some(
                 s"Local REST server must be started via ${y(s"'$SCRIPT_NAME''")} or other compatible way."
@@ -525,13 +533,13 @@ object NCCli extends App {
         ),
         Command(
             name = "quit",
-            group = "REPL",
-            synopsis = s"Quits REPL when in REPL mode.",
+            group = "REPL Commands",
+            synopsis = s"Quits REPL mode.",
             body = cmdQuit
         ),
         Command(
             name = "help",
-            group = "REPL",
+            group = "REPL Commands",
             synopsis = s"Displays help for ${y(s"'$SCRIPT_NAME'")}.",
             desc = Some(
                 s"By default, without ${y("'--all'")} or ${y("'--cmd'")} parameters, displays the abbreviated form of manual " +
@@ -566,7 +574,7 @@ object NCCli extends App {
         ),
         Command(
             name = "version",
-            group = "REPL",
+            group = "REPL Commands",
             synopsis = s"Displays full version of ${y(s"'$SCRIPT_NAME'")} script.",
             desc = Some(
                 "Depending on the additional parameters can display only the semantic version or the release date."
@@ -1176,7 +1184,7 @@ object NCCli extends App {
                     "align:left, maxWidth:85" → cmd.synopsis
                 ))
 
-                logln(s"\n$grp:\n${tbl.toString}")
+                logln(s"\n$B$grp:$RST\n${tbl.toString}")
             })
         }
         else if (args.size == 1 && args.head.parameter.id == "all") { // Show a full format help for all commands.
@@ -1382,7 +1390,7 @@ object NCCli extends App {
         if (!U.isValidJson(rawJson))
             throw MalformedJson()
 
-        if (!REST_PATHS.exists(_.path == path))
+        if (!REST_CMDS.exists(_.path == path))
             throw new IllegalArgumentException(s"Unknown REST path $C'$path'$RST, type ${c("'help --cmd=rest'")} to get help.")
 
         val endpoint = getRestEndpointFromBeacon
@@ -1455,7 +1463,7 @@ object NCCli extends App {
                     candidates.addAll(cmds.map(n ⇒ {
                         val name = n._1
                         val desc = n._2.substring(0, n._2.length - 1) // Remove last '.'.
-                        val grp = n._3
+                        val grp = s"${n._3}:"
 
                         mkCandidate(
                             id = name,
@@ -1477,7 +1485,7 @@ object NCCli extends App {
                                 names.map(name ⇒ mkCandidate(
                                     id = if (hasVal) name + "=" else name,
                                     disp = name,
-                                    grp = null,
+                                    grp = "Parameters:",
                                     desc = null,
                                     completed = !hasVal)
                                 )
@@ -1499,10 +1507,26 @@ object NCCli extends App {
                             ))
                             .asJava
                         )
-
                     // For 'rest' - add additional auto-completion candidates.
-                    if (cmd == REST_CMD.name) {
-
+                    else if (cmd == REST_CMD.name) {
+                        val pathParam = REST_CMD.findParameterById("path")
+                        val hasPathAlready = words.exists(w ⇒ pathParam.names.exists(x ⇒ w.startsWith(x)))
+
+                        if (!hasPathAlready)
+                            candidates.addAll(
+                                REST_CMDS.map(cmd ⇒ {
+                                    val name = s"--path=${cmd.path}"
+
+                                    mkCandidate(
+                                        id = name,
+                                        disp = name,
+                                        grp = s"REST ${cmd.group}:",
+                                        desc = cmd.desc,
+                                        completed = true
+                                    )
+                                })
+                                .asJava
+                            )
                     }
                 }
             }
@@ -1815,7 +1839,7 @@ object NCCli extends App {
             val name = if (parts.size == 1) arg else parts(0)
             val value = if (parts.size == 1) None else Some(parts(1))
 
-            cmd.findParameterByName(name) match {
+            cmd.findParameterByNameOpt(name) match {
                 case None ⇒ throw mkError()
                 case Some(param) ⇒
                     if ((param.value.isDefined && value.isEmpty) || (param.value.isEmpty && value.isDefined))


[incubator-nlpcraft] 13/23: WIP.

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

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

commit 0da1751eeef5f4b103d99268dccde6ca9716876d
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 00:18:32 2020 -0700

    WIP.
---
 .../org/apache/nlpcraft/common/util/NCUtils.scala  |  19 ++
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 266 ++++++++++++++++-----
 2 files changed, 226 insertions(+), 59 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 50f444a..266b880 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
@@ -18,6 +18,7 @@
 package org.apache.nlpcraft.common.util
 
 import java.io._
+import java.lang.reflect.Type
 import java.math.RoundingMode
 import java.net._
 import java.nio.charset.Charset
@@ -1463,6 +1464,24 @@ object NCUtils extends LazyLogging {
     /**
      *
      * @param json
+     * @tparam T
+     * @return
+     */
+    def jsonToObject[T](json: String, typ: Type): T =
+        GSON.fromJson(json, typ)
+
+    /**
+     *
+     * @param json
+     * @tparam T
+     * @return
+     */
+    def jsonToObject[T](json: String, cls: Class[T]): T =
+        GSON.fromJson(json, cls)
+
+    /**
+     *
+     * @param json
      * @param field
      * @return
      */
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 79d6f22..fda5951 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
@@ -41,6 +41,7 @@ import java.nio.file.Paths
 import java.util.regex.Pattern
 
 import org.apache.commons.io.input.{ReversedLinesFileReader, Tailer, TailerListenerAdapter}
+import org.apache.commons.lang3.time.DurationFormatUtils
 import org.apache.http.util.EntityUtils
 import org.jline.builtins.Commands
 import org.jline.reader.Completer
@@ -96,6 +97,42 @@ object NCCli extends App {
 
     private var term: Terminal = _
 
+    // See NCProbeMdo.
+    case class Probe(
+        probeToken: String,
+        probeId: String,
+        probeGuid: String,
+        probeApiVersion: String,
+        probeApiDate: String,
+        osVersion: String,
+        osName: String,
+        osArch: String,
+        startTstamp: Long,
+        tmzId: String,
+        tmzAbbr: String,
+        tmzName: String,
+        userName: String,
+        javaVersion: String,
+        javaVendor: String,
+        hostName: String,
+        hostAddr: String,
+        macAddr: String,
+        models: Array[ProbeModel]
+    )
+
+    // See NCProbeModelMdo.
+    case class ProbeModel(
+        id: String,
+        name: String,
+        version: String,
+        enabledBuiltInTokens: Array[String]
+    )
+
+    case class ProbeAllResponse(
+        probes: Array[Probe],
+        status: String
+    )
+
     case class SplitError(index: Int)
         extends Exception
     case class NoLocalServer()
@@ -434,10 +471,11 @@ object NCCli extends App {
     case class ReplState(
         var isServerOnline: Boolean = false,
         var accessToken: Option[String] = None,
-        var serverOutput: Option[File] = None
+        var serverLog: Option[File] = None,
+        var probes: List[Probe] = Nil // List of connected probes.
     )
 
-    private val replState = ReplState()
+    @volatile private var state = ReplState()
 
     // Single CLI command.
     case class Command(
@@ -499,7 +537,7 @@ object NCCli extends App {
     private final val CMDS = Seq(
         Command(
             name = "rest",
-            group = "REST Commands",
+            group = "2. REST Commands",
             synopsis = s"REST call in a convenient way for command line mode.",
             desc = Some(
                 s"When using this command you supply all call parameters as a single ${y("'--json'")} parameter with a JSON string. " +
@@ -543,11 +581,11 @@ object NCCli extends App {
         ),
         Command(
             name = "call",
-            group = "REST Commands",
+            group = "2. REST Commands",
             synopsis = s"REST call in a convenient way for REPL mode.",
             desc = Some(
                 s"When using this command you supply all call parameters separately through their own parameters named " +
-                s"after their counterparts in REST specification. " +
+                s"after their corresponding parameters in REST specification. " +
                 s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion and " +
                 s"auto-completion candidates for commonly used paths and call parameters."
             ),
@@ -571,7 +609,8 @@ object NCCli extends App {
                     synthetic = true,
                     desc =
                         s"${y("'xxx'")} name corresponds to the REST call parameter that can be found at https://nlpcraft.apache.org/using-rest.html " +
-                        s"The value of this parameter should be a valid JSON value using valid JSON syntax. You can have " +
+                        s"The value of this parameter should be a valid JSON value using valid JSON syntax. Note that strings " +
+                        s"don't have to be in double quotes. JSON objects and arrays should be specified as a JSON string in single quotes. You can have " +
                         s"as many ${y("'-xxx=value'")} parameters as requires by the ${y("'--path'")} parameter. " +
                         s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion for possible parameters and their values."
                 )
@@ -579,22 +618,33 @@ object NCCli extends App {
             examples = Seq(
                 Example(
                     usage = Seq(
-                        s"$PROMPT $SCRIPT_NAME call ",
-                        "  -p=signin",
+                        s"$PROMPT $SCRIPT_NAME call -p=signin",
                         "  -email=admin@admin.com",
                         "  -passwd=admin"
                     ),
                     desc =
                         s"Issues ${y("'signin'")} REST call with given JSON payload provided as a set of parameters. " +
                         s"Note that ${y("'-email'")} and ${y("'-passwd'")} parameters correspond to the REST call " +
-                        s"specification for  ${y("'/signin'")} path."
+                        s"specification for ${y("'/signin'")} path."
+
+                ),
+                Example(
+                    usage = Seq(
+                        s"$PROMPT $SCRIPT_NAME call --path=ask/sync",
+                        "  -acsTok=qwerty123456",
+                        "  -mdlId=my.model.id",
+                        "  -data='{\"data1\": true, \"data2\": 123, \"data3\": \"some text\"}'",
+                        "  -enableLog=false"
+                    ),
+                    desc =
+                        s"Issues ${y("'ask/sync'")} REST call with given JSON payload provided as a set of parameters."
 
                 )
             )
         ),
         Command(
             name = "tail-server",
-            group = "Server Commands",
+            group = "1. Server Commands",
             synopsis = s"Shows last N lines from the local REST server log.",
             desc = Some(
                 s"Only works for the server started via this script."
@@ -618,7 +668,7 @@ object NCCli extends App {
         ),
         Command(
             name = "start-server",
-            group = "Server Commands",
+            group = "1. Server Commands",
             synopsis = s"Starts local REST server.",
             desc = Some(
                 s"REST server is started in the external JVM process with both stdout and stderr piped out into log file. " +
@@ -670,7 +720,7 @@ object NCCli extends App {
         ),
         Command(
             name = "restart-server",
-            group = "Server Commands",
+            group = "1. Server Commands",
             synopsis = s"Restarts local REST server.",
             desc = Some(
                 s"This command is equivalent to executing  ${y("'stop-server'")} and then ${y("'start-server'")} commands with " +
@@ -722,19 +772,19 @@ object NCCli extends App {
         ),
         Command(
             name = "info-server",
-            group = "Server Commands",
+            group = "1. Server Commands",
             synopsis = s"Info about local REST server.",
             body = cmdInfoServer
         ),
         Command(
             name = "cls",
-            group = "REPL Commands",
+            group = "3. REPL Commands",
             synopsis = s"Clears terminal screen.",
             body = cmdCls
         ),
         Command(
             name = "nano",
-            group = "REPL Commands",
+            group = "3. REPL Commands",
             synopsis = s"Runs built-in ${y("'nano'")} editor.",
             body = cmdNano,
             desc = Some(
@@ -766,7 +816,7 @@ object NCCli extends App {
         ),
         Command(
             name = "less",
-            group = "REPL Commands",
+            group = "3. REPL Commands",
             synopsis = s"Runs built-in ${y("'less'")} command.",
             body = cmdLess,
             desc = Some(
@@ -797,7 +847,7 @@ object NCCli extends App {
         ),
         Command(
             name = "no-ansi",
-            group = "REPL Commands",
+            group = "3. REPL Commands",
             synopsis = s"Disables ANSI escape codes for terminal colors & controls.",
             desc = Some(
                 s"This is a special command that can be combined with any other commands."
@@ -812,7 +862,7 @@ object NCCli extends App {
         ),
         Command(
             name = "ansi",
-            group = "REPL Commands",
+            group = "3. REPL Commands",
             synopsis = s"Enables ANSI escape codes for terminal colors & controls.",
             desc = Some(
                 s"This is a special command that can be combined with any other commands."
@@ -827,7 +877,7 @@ object NCCli extends App {
         ),
         Command(
             name = "ping-server",
-            group = "Server Commands",
+            group = "1. Server Commands",
             synopsis = s"Pings local REST server.",
             desc = Some(
                 s"REST server is pinged using ${y("'/health'")} REST call to check its online status."
@@ -854,7 +904,7 @@ object NCCli extends App {
         ),
         Command(
             name = "stop-server",
-            group = "Server Commands",
+            group = "1. Server Commands",
             synopsis = s"Stops local REST server.",
             desc = Some(
                 s"Local REST server must be started via ${y(s"'$SCRIPT_NAME''")} or other compatible way."
@@ -863,13 +913,13 @@ object NCCli extends App {
         ),
         Command(
             name = "quit",
-            group = "REPL Commands",
+            group = "3. REPL Commands",
             synopsis = s"Quits REPL mode.",
             body = cmdQuit
         ),
         Command(
             name = "help",
-            group = "REPL Commands",
+            group = "3. REPL Commands",
             synopsis = s"Displays help for ${y(s"'$SCRIPT_NAME'")}.",
             desc = Some(
                 s"By default, without ${y("'--all'")} or ${y("'--cmd'")} parameters, displays the abbreviated form of manual " +
@@ -904,7 +954,7 @@ object NCCli extends App {
         ),
         Command(
             name = "version",
-            group = "REPL Commands",
+            group = "3. REPL Commands",
             synopsis = s"Displays full version of ${y(s"'$SCRIPT_NAME'")} script.",
             desc = Some(
                 "Depending on the additional parameters can display only the semantic version or the release date."
@@ -1030,7 +1080,7 @@ object NCCli extends App {
         val output = new File(SystemUtils.getUserHome, s".nlpcraft/server_log_$logTstamp.txt")
 
         // Store in REPL state right away.
-        replState.serverOutput = Some(output)
+        state.serverLog = Some(output)
 
         val srvPb = new ProcessBuilder(
             JAVA,
@@ -1133,7 +1183,7 @@ object NCCli extends App {
                 .start()
 
                 val tailer = Tailer.create(
-                    replState.serverOutput.get,
+                    state.serverLog.get,
                     new TailerListenerAdapter {
                         override def handle(line: String): Unit = {
                             if (TAILER_PTRN.matcher(line).matches())
@@ -1151,7 +1201,7 @@ object NCCli extends App {
                     if (progressBar.completed) {
                         // First, load the beacon, if any.
                         if (beacon == null)
-                            beacon = loadServerBeacon().orNull
+                            beacon = loadServerBeacon(autoSignIn = true).orNull
 
                         // Once beacon is loaded, ensure that REST endpoint is live.
                         if (beacon != null)
@@ -1172,7 +1222,7 @@ object NCCli extends App {
                 }
                 else {
                     logln(g(" [OK]"))
-                    logln(mkServerBeaconTable(beacon).toString)
+                    logServerInfo(beacon)
 
                     showTip()
                 }
@@ -1310,10 +1360,11 @@ object NCCli extends App {
     /**
      * Loads and returns server beacon file.
      *
+     * @param autoSignIn
      * @return
      */
-    private def loadServerBeacon(): Option[NCCliServerBeacon] = {
-        val beacon = try {
+    private def loadServerBeacon(autoSignIn: Boolean = false): Option[NCCliServerBeacon] = {
+        val beaconOpt = try {
             val beacon = (
                 managed(
                     new ObjectInputStream(
@@ -1331,6 +1382,7 @@ object NCCli extends App {
                 case Some(ph) ⇒
                     beacon.ph = ph
 
+                    // See if we can detect server log if server was started by this script.
                     val files = new File(SystemUtils.getUserHome, ".nlpcraft").listFiles(new FilenameFilter {
                         override def accept(dir: File, name: String): Boolean =
                             name.startsWith(s".pid_$ph")
@@ -1359,9 +1411,45 @@ object NCCli extends App {
             case _: Exception ⇒ None
         }
 
-        replState.isServerOnline = beacon.isDefined
+        beaconOpt match {
+            case Some(beacon) ⇒
+                state.isServerOnline = true
+
+                val baseUrl = "http://" + beacon.restEndpoint
+
+                // Attempt to signin with the default account.
+                if (autoSignIn && state.accessToken.isEmpty) {
+                    httpPostResponseJson(
+                        baseUrl,
+                        "signin",
+                        "{\"email\": \"admin@admin.com\", \"passwd\": \"admin\"}") match {
+                        case Some(json) ⇒ state.accessToken = Option(Try(U.getJsonStringField(json, "acsTok")).getOrElse(null))
+                        case None ⇒ ()
+                    }
 
-        beacon
+                    if (state.accessToken.isDefined)
+                        logln(s"REST server signed in with default '${c("admin@admin.com")}' user.")
+                }
+
+                // Attempt to get all connected probes if successfully signed in prior.
+                if (state.accessToken.isDefined)
+                    httpPostResponseJson(
+                        baseUrl,
+                        "probe/all",
+                        "{\"acsTok\": \"" + state.accessToken.get + "\"}") match {
+                        case Some(json) ⇒ state.probes =
+                            Try(
+                                U.jsonToObject[ProbeAllResponse](json, classOf[ProbeAllResponse]).probes.toList
+                            ).getOrElse(Nil)
+                        case None ⇒ ()
+                    }
+
+            case None ⇒
+                // Reset REPL state.
+                state = ReplState()
+        }
+
+        beaconOpt
     }
 
     /**
@@ -1395,14 +1483,16 @@ object NCCli extends App {
             case Some(beacon) ⇒
                 val pid = beacon.pid
 
+                // TODO: signout if previously signed in.
+
                 if (beacon.ph.destroy()) {
                     logln(s"Server (pid ${c(pid)}) has been stopped.")
 
                     // Attempt to delete beacon file right away.
                     new File(beacon.beaconPath).delete()
 
-                    // Update state right away.
-                    replState.isServerOnline = false
+                    // Reset REPL state right away.
+                    state = ReplState()
                 } else
                     error(s"Failed to stop the local REST server (pid ${c(pid)}).")
 
@@ -1573,8 +1663,8 @@ object NCCli extends App {
      * @param beacon
      * @return
      */
-    private def mkServerBeaconTable(beacon: NCCliServerBeacon): NCAsciiTable = {
-        val tbl = new NCAsciiTable
+    private def logServerInfo(beacon: NCCliServerBeacon): Unit = {
+        var tbl = new NCAsciiTable
 
         val logPath = if (beacon.logPath != null) g(beacon.logPath) else y("<not available>")
 
@@ -1604,7 +1694,39 @@ object NCCli extends App {
         tbl += ("Log file", logPath)
         tbl += ("Started on", s"${g(DateFormat.getDateTimeInstance.format(new Date(beacon.startMs)))}")
 
-        tbl
+        logln(s"Local REST server:\n${tbl.toString}")
+
+        if (state.probes.nonEmpty) {
+            tbl = new NCAsciiTable
+
+            def addProbeToTable(tbl: NCAsciiTable, probe: Probe): NCAsciiTable = {
+                tbl += (
+                    Seq(
+                        probe.probeId,
+                        s"  ${c("guid")}: ${probe.probeGuid}",
+                        s"  ${c("tok")}: ${probe.probeToken}"
+                    ),
+                    DurationFormatUtils.formatDurationHMS(currentTime - probe.startTstamp),
+                    s"${probe.osName} ver. ${probe.osVersion}",
+                    s"${probe.hostName} (${probe.hostAddr})",
+                    probe.models.toList.map(m ⇒ s"${b(m.id)}, v${m.version}")
+                )
+
+                tbl
+            }
+
+            tbl #= (
+                "Probe ID",
+                "Uptime",
+                "OS",
+                "Host",
+                "Models Deployed"
+            )
+
+            state.probes.foreach(addProbeToTable(tbl, _))
+
+            logln(s"Connected probes:\n${tbl.toString}")
+        }
     }
 
     /**
@@ -1615,7 +1737,7 @@ object NCCli extends App {
      */
     private def cmdInfoServer(cmd: Command, args: Seq[Argument], repl: Boolean): Unit = {
         loadServerBeacon() match {
-            case Some(beacon) ⇒ logln(s"Local REST server:\n${mkServerBeaconTable(beacon).toString}")
+            case Some(beacon) ⇒ logServerInfo(beacon)
             case None ⇒ throw NoLocalServer()
         }
     }
@@ -1781,18 +1903,8 @@ object NCCli extends App {
         if (!REST_SPEC.exists(_.path == path))
             throw InvalidParameter(cmd, "path")
 
-        val endpoint = getRestEndpointFromBeacon
-
-        val resp = httpPost(endpoint, path, mkHttpHandler(resp ⇒ {
-            val status = resp.getStatusLine
-
-            HttpRestResponse(
-                status.getStatusCode,
-                Option(EntityUtils.toString(resp.getEntity)).getOrElse(
-                    throw new IllegalStateException(s"Unexpected REST error: ${status.getReasonPhrase}")
-                )
-            )
-        }), json)
+        // Make the REST call.
+        val resp = httpPostResponse(getRestEndpointFromBeacon, path, json)
 
         // Ack HTTP response code.
         logln(s"HTTP ${if (resp.code == 200) g("200") else r(resp.code)}")
@@ -1808,9 +1920,9 @@ object NCCli extends App {
 
         if (resp.code == 200) {
             if (path == "signin")
-                replState.accessToken = Some(U.getJsonStringField(resp.data, "acsTok"))
+                state.accessToken = Some(U.getJsonStringField(resp.data, "acsTok"))
             else if (path == "signout")
-                replState.accessToken = None
+                state.accessToken = None
         }
     }
 
@@ -1818,8 +1930,8 @@ object NCCli extends App {
      *
      */
     private def readEvalPrintLoop(): Unit = {
-        loadServerBeacon() match {
-            case Some(beacon) ⇒ logln(s"Server detected:\n${mkServerBeaconTable(beacon).toString}")
+        loadServerBeacon(autoSignIn = true) match {
+            case Some(beacon) ⇒ logServerInfo(beacon)
             case None ⇒ ()
         }
 
@@ -1956,8 +2068,8 @@ object NCCli extends App {
 
         while (!exit) {
             val rawLine = try {
-                val srvStr = bo(s"${if (replState.isServerOnline) s"ON " else s"OFF "}")
-                val acsTokStr = bo(s"${replState.accessToken.getOrElse("<signed out>")} ")
+                val srvStr = bo(s"${if (state.isServerOnline) s"ON " else s"OFF "}")
+                val acsTokStr = bo(s"${state.accessToken.getOrElse("<signed out>")} ")
 
                 reader.printAbove("\n" + rb(w(s" server: $srvStr")) + wb(k(s" acsTok: $acsTokStr")))
                 reader.readLine(s"${g(">")} ")
@@ -2112,17 +2224,53 @@ object NCCli extends App {
     }
 
     /**
+     *
+     * @param endpoint
+     * @param path
+     * @param json
+     * @return
+     */
+    private def httpPostResponse(endpoint: String, path: String, json: String): HttpRestResponse =
+        httpPost(endpoint, path, mkHttpHandler(resp ⇒ {
+            val status = resp.getStatusLine
+
+            HttpRestResponse(
+                status.getStatusCode,
+                Option(EntityUtils.toString(resp.getEntity)).getOrElse(
+                    throw new IllegalStateException(s"Unexpected REST error: ${status.getReasonPhrase}")
+                )
+            )
+        }), json)
+
+    /**
+     *
+     * @param endpoint
+     * @param path
+     * @param json
+     * @return
+     */
+    private def httpPostResponseJson(endpoint: String, path: String, json: String): Option[String] =
+        httpPost(endpoint, path, mkHttpHandler(resp ⇒ {
+            val status = resp.getStatusLine
+
+            if (status.getStatusCode == 200)
+                Option(EntityUtils.toString(resp.getEntity))
+            else
+                None
+        }), json)
+
+    /**
      * Posts HTTP GET request.
      *
-     * @param baseUrl Base endpoint URL.
-     * @param cmd REST call command.
+     * @param endpoint Base endpoint URL.
+     * @param path REST call command.
      * @param resp
      * @param jsParams
      * @return
      * @throws IOException
      */
-    private def httpGet[T](baseUrl: String, cmd: String, resp: ResponseHandler[T], jsParams: (String, AnyRef)*): T = {
-        val bldr = new URIBuilder(prepRestUrl(baseUrl, cmd))
+    private def httpGet[T](endpoint: String, path: String, resp: ResponseHandler[T], jsParams: (String, AnyRef)*): T = {
+        val bldr = new URIBuilder(prepRestUrl(endpoint, path))
 
         jsParams.foreach(p ⇒ bldr.setParameter(p._1, p._2.toString))
 


[incubator-nlpcraft] 05/23: Update NCCli.scala

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

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

commit a1aff98f890f024fad565a7945d5e3489a3dc741
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Oct 9 19:03:39 2020 -0700

    Update NCCli.scala
---
 .../src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 b3d9769..d4f4eda 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
@@ -221,7 +221,7 @@ object NCCli extends App {
     private final val CMDS = Seq(
         Command(
             name = "rest",
-            group = "Rest Commands",
+            group = "REST Commands",
             synopsis = s"Issues REST call to local REST server.",
             desc = Some(
                 s"All NLPCraft REST API uses HTTP POST and JSON parameters ('Content-Type: application/json' header). " +


[incubator-nlpcraft] 07/23: Update NCCli.scala

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

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

commit 1ea1969274968ab56659e131c4db7da4e3b346c7
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sat Oct 10 00:24:43 2020 -0700

    Update NCCli.scala
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 75 +++++++++++++++++++---
 1 file changed, 66 insertions(+), 9 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 d4f4eda..2af3e69 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
@@ -207,6 +207,7 @@ object NCCli extends App {
         names: Seq[String],
         value: Option[String] = None,
         optional: Boolean = false, // Mandatory by default.
+        synthetic: Boolean = false,
         desc: String
     )
 
@@ -222,11 +223,12 @@ object NCCli extends App {
         Command(
             name = "rest",
             group = "REST Commands",
-            synopsis = s"Issues REST call to local REST server.",
+            synopsis = s"REST call in a convenient way for command line mode.",
             desc = Some(
-                s"All NLPCraft REST API uses HTTP POST and JSON parameters ('Content-Type: application/json' header). " +
-                s"To issue the REST call you need to supply path and parameters. In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion and " +
-                s"auto-completion candidates for commonly used paths and JSON payload components."
+                s"When using this command you supply all call parameters as a single ${y("'--json'")} parameter with a JSON string. " +
+                s"In REPL mode, you can hit ${rv(" Tab ")} to see auto-suggestion and auto-completion candidates for " +
+                s"commonly used paths. However, ${y("'call'")} command provides more convenient way to issue REST " +
+                s"calls when in REPL mode."
             ),
             body = cmdRest,
             params = Seq(
@@ -263,6 +265,57 @@ object NCCli extends App {
             )
         ),
         Command(
+            name = "call",
+            group = "REST Commands",
+            synopsis = s"REST call in a convenient way for REPL mode.",
+            desc = Some(
+                s"When using this command you supply all call parameters separately through their own parameters named " +
+                s"after their counterparts in REST specification. " +
+                s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion and " +
+                s"auto-completion candidates for commonly used paths and call parameters."
+            ),
+            body = cmdRest,
+            params = Seq(
+                Parameter(
+                    id = "path",
+                    names = Seq("--path", "-p"),
+                    value = Some("path"),
+                    desc =
+                        s"REST path, e.g. ${y("'signin'")} or ${y("'ask/sync'")}. " +
+                        s"Note that you don't need supply '/' at the beginning. " +
+                        s"See more details at https://nlpcraft.apache.org/using-rest.html " +
+                        s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion for possible REST paths."
+                ),
+                Parameter(
+                    id = "xxx",
+                    names = Seq("-xxx"),
+                    value = Some("value"),
+                    optional = true,
+                    synthetic = true,
+                    desc =
+                        s"${y("'xxx'")} name corresponds to the REST call parameter that can be found at https://nlpcraft.apache.org/using-rest.html " +
+                        s"The value of this parameter should be a valid JSON value using valid JSON syntax. You can have " +
+                        s"as many ${y("'-xxx=value'")} parameters as requires by the ${y("'--path'")} parameter. " +
+                        s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion for possible parameters and their values."
+                )
+            ),
+            examples = Seq(
+                Example(
+                    usage = Seq(
+                        s"$PROMPT $SCRIPT_NAME call ",
+                        "  -p=signin",
+                        "  -email=admin@admin.com",
+                        "  -passwd=admin"
+                    ),
+                    desc =
+                        s"Issues ${y("'signin'")} REST call with given JSON payload provided as a set of parameters. " +
+                        s"Note that ${y("'-email'")} and ${y("'-passwd'")} parameters correspond to the REST call " +
+                        s"specification for  ${y("'/signin'")} path."
+
+                )
+            )
+        ),
+        Command(
             name = "tail-server",
             group = "Server Commands",
             synopsis = s"Shows last N lines from the local REST server log.",
@@ -1211,7 +1264,7 @@ object NCCli extends App {
             for (arg ← args) {
                 val cmdName = arg.value.get
 
-                CMDS.find(_.name.contains(cmdName)) match {
+                CMDS.find(_.name == cmdName) match {
                     case Some(c) ⇒
                         if (!seen.contains(c.name)) {
                             tbl +/ (
@@ -1583,7 +1636,11 @@ object NCCli extends App {
             if (rawLine == null || QUIT_CMD.name == rawLine.trim)
                 exit = true
             else {
-                val line = rawLine.trim().replace("\n", "").replace("\t", "")
+                val line = rawLine
+                    .trim()
+                    .replace("\n", "")
+                    .replace("\t", " ")
+                    .trim()
 
                 if (line.nonEmpty)
                     try {
@@ -1855,11 +1912,11 @@ object NCCli extends App {
      * @param repl
      */
     private def processAnsi(args: Seq[String], repl: Boolean): Unit = {
-        args.find(arg ⇒ NO_ANSI_CMD.name.contains(arg)) match {
+        args.find(_ == NO_ANSI_CMD.name) match {
             case Some(_) ⇒ NO_ANSI_CMD.body(NO_ANSI_CMD, Seq.empty, repl)
             case None ⇒ ()
         }
-        args.find(arg ⇒ ANSI_CMD.name.contains(arg)) match {
+        args.find(_ == ANSI_CMD.name) match {
             case Some(_) ⇒ ANSI_CMD.body(ANSI_CMD, Seq.empty, repl)
             case None ⇒ ()
         }
@@ -1876,7 +1933,7 @@ object NCCli extends App {
         processAnsi(args, repl)
 
         // Remove 'no-ansi' and 'ansi' commands from the argument list, if any.
-        val xargs = args.filter(arg ⇒ !NO_ANSI_CMD.name.contains(arg) && !ANSI_CMD.name.contains(arg))
+        val xargs = args.filter(arg ⇒ arg != NO_ANSI_CMD.name && arg != ANSI_CMD.name)
 
         if (xargs.nonEmpty) {
             val cmd = xargs.head


[incubator-nlpcraft] 22/23: Update NCCli.scala

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

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

commit cc09dc6f03c67dc8aa1b5495a6fa3efcab212a81
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 20:11:07 2020 -0700

    Update NCCli.scala
---
 .../main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala  | 6 +++---
 1 file changed, 3 insertions(+), 3 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 f8efcb2..1959aa9 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
@@ -69,7 +69,7 @@ object NCCli extends App {
     //noinspection RegExpRedundantEscape
     private final val TAILER_PTRN = Pattern.compile("^.*NC[a-zA-Z0-9]+ started \\[[\\d]+ms\\]$")
     private final val CMD_NAME = Pattern.compile("(^\\s*[\\w-]+)(\\s)")
-    private final val CMD_PARAM = Pattern.compile("(\\s--?[\\w-]+)([= ]?)")
+    private final val CMD_PARAM = Pattern.compile("(\\s)(--?[\\w-]+)")
 
     // Number of server services that need to be started + 1 progress start.
     // Used for progress bar functionality.
@@ -2112,7 +2112,7 @@ object NCCli extends App {
                         CMD_PARAM.matcher(
                             buffer
                         )
-                        .replaceAll(c("$1") + "$2")
+                        .replaceAll("$1" + c("$2"))
                     )
                     .replaceAll(bo(g("$1")) + "$2")
                 )
@@ -2180,7 +2180,7 @@ object NCCli extends App {
                     .trim()
 
                 if (line.nonEmpty)
-                    try 
+                    try
                         doCommand(splitBySpace(line), repl = true)
                     catch {
                         case e: SplitError ⇒


[incubator-nlpcraft] 09/23: Update NCCli.scala

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

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

commit e8c26bcd6270a1b9d98f308c3f7136bfbd83900b
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sat Oct 10 11:22:12 2020 -0700

    Update NCCli.scala
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 92 +++++++++++-----------
 1 file changed, 46 insertions(+), 46 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 e592258..d78062d 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
@@ -68,6 +68,52 @@ object NCCli extends App {
     //noinspection RegExpRedundantEscape
     private final val TAILER_PTRN = Pattern.compile("^.*NC[a-zA-Z0-9]+ started \\[[\\d]+ms\\]$")
 
+    // Number of server services that need to be started + 1 progress start.
+    // Used for progress bar functionality.
+    // +==================================================================+
+    // | MAKE SURE TO UPDATE THIS VAR WHEN NUMBER OF SERVICES IS CHANGED. |
+    // +==================================================================+
+    private final val NUM_SRV_SERVICES = 30/*services*/ + 1/*progress start*/
+
+    private final val SRV_BEACON_PATH = ".nlpcraft/server_beacon"
+    private final val HIST_PATH = ".nlpcraft/.cli_history"
+
+    private final lazy val VER = NCVersion.getCurrent
+    private final lazy val JAVA = U.sysEnv("NLPCRAFT_CLI_JAVA").getOrElse(new File(SystemUtils.getJavaHome,s"bin/java${if (SystemUtils.IS_OS_UNIX) "" else ".exe"}").getAbsolutePath)
+    private final lazy val INSTALL_HOME = U.sysEnv("NLPCRAFT_CLI_INSTALL_HOME").getOrElse(SystemUtils.USER_DIR)
+    private final lazy val JAVA_CP = U.sysEnv("NLPCRAFT_CLI_JAVA_CP").getOrElse(ManagementFactory.getRuntimeMXBean.getClassPath)
+    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 IS_SCRIPT = U.sysEnv("NLPCRAFT_CLI").isDefined
+
+    private final val T___ = "    "
+    private val OPEN_BRK = Seq('[', '{', '(', '<')
+    private val CLOSE_BRK = Seq(']', '}', ')', '>')
+    // Pair for each open or close bracket.
+    private val BRK_PAIR = OPEN_BRK.zip(CLOSE_BRK).toMap ++ CLOSE_BRK.zip(OPEN_BRK).toMap
+
+    private var exitStatus = 0
+
+    private var term: Terminal = _
+
+    case class SplitError(index: Int)
+        extends Exception
+    case class NoLocalServer()
+        extends IllegalStateException(s"Local REST server not found.")
+    case class MissingParameter(cmd: Command, paramId: String)
+        extends IllegalArgumentException(
+            s"Missing mandatory parameter: $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, " +
+            s"type $C'help --cmd=${cmd.name}'$RST to get help."
+        )
+    case class HttpError(httpCode: Int)
+        extends IllegalStateException(s"REST error (HTTP ${c(httpCode)}).")
+    case class MalformedJson()
+        extends IllegalStateException("Malformed JSON.")
+    case class TooManyArguments(cmd: Command)
+        extends IllegalArgumentException(s"Too many arguments, type $C'help --cmd=${cmd.name}'$RST to get help.")
+    case class NotEnoughArguments(cmd: Command)
+        extends IllegalArgumentException(s"Not enough arguments, type $C'help --cmd=${cmd.name}'$RST to get help.")
+
     case class RestCall(
         path: String,
         desc: String,
@@ -370,52 +416,6 @@ object NCCli extends App {
         )
     )
 
-    // Number of server services that need to be started + 1 progress start.
-    // Used for progress bar functionality.
-    // +==================================================================+
-    // | MAKE SURE TO UPDATE THIS VAR WHEN NUMBER OF SERVICES IS CHANGED. |
-    // +==================================================================+
-    private final val NUM_SRV_SERVICES = 30/*services*/ + 1/*progress start*/
-
-    private final val SRV_BEACON_PATH = ".nlpcraft/server_beacon"
-    private final val HIST_PATH = ".nlpcraft/.cli_history"
-
-    private final lazy val VER = NCVersion.getCurrent
-    private final lazy val JAVA = U.sysEnv("NLPCRAFT_CLI_JAVA").getOrElse(new File(SystemUtils.getJavaHome,s"bin/java${if (SystemUtils.IS_OS_UNIX) "" else ".exe"}").getAbsolutePath)
-    private final lazy val INSTALL_HOME = U.sysEnv("NLPCRAFT_CLI_INSTALL_HOME").getOrElse(SystemUtils.USER_DIR)
-    private final lazy val JAVA_CP = U.sysEnv("NLPCRAFT_CLI_JAVA_CP").getOrElse(ManagementFactory.getRuntimeMXBean.getClassPath)
-    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 IS_SCRIPT = U.sysEnv("NLPCRAFT_CLI").isDefined
-
-    private final val T___ = "    "
-    private val OPEN_BRK = Seq('[', '{', '(', '<')
-    private val CLOSE_BRK = Seq(']', '}', ')', '>')
-    // Pair for each open or close bracket.
-    private val BRK_PAIR = OPEN_BRK.zip(CLOSE_BRK).toMap ++ CLOSE_BRK.zip(OPEN_BRK).toMap
-
-    private var exitStatus = 0
-
-    private var term: Terminal = _
-
-    case class SplitError(index: Int)
-        extends Exception
-    case class NoLocalServer()
-        extends IllegalStateException(s"Local REST server not found.")
-    case class MissingParameter(cmd: Command, paramId: String)
-        extends IllegalArgumentException(
-            s"Missing mandatory parameter: $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, " +
-            s"type $C'help --cmd=${cmd.name}'$RST to get help."
-        )
-    case class HttpError(httpCode: Int)
-        extends IllegalStateException(s"REST error (HTTP ${c(httpCode)}).")
-    case class MalformedJson()
-        extends IllegalStateException("Malformed JSON.")
-    case class TooManyArguments(cmd: Command)
-        extends IllegalArgumentException(s"Too many arguments, type $C'help --cmd=${cmd.name}'$RST to get help.")
-    case class NotEnoughArguments(cmd: Command)
-        extends IllegalArgumentException(s"Not enough arguments, type $C'help --cmd=${cmd.name}'$RST to get help.")
-
     case class HttpRestResponse(
         code: Int,
         data: String


[incubator-nlpcraft] 14/23: Update NCCli.scala

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

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

commit e472e9c46672e0aa60b5ad4a50e087f5b9ec385f
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 02:01:45 2020 -0700

    Update NCCli.scala
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 116 ++++++++++++++++++---
 1 file changed, 102 insertions(+), 14 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 fda5951..166b5d1 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
@@ -1224,6 +1224,9 @@ object NCCli extends App {
                     logln(g(" [OK]"))
                     logServerInfo(beacon)
 
+                    if (state.accessToken.isDefined)
+                        logln(s"Signed in with default '${c("admin@admin.com")}' user.")
+
                     showTip()
                 }
             }
@@ -1418,7 +1421,7 @@ object NCCli extends App {
                 val baseUrl = "http://" + beacon.restEndpoint
 
                 // Attempt to signin with the default account.
-                if (autoSignIn && state.accessToken.isEmpty) {
+                if (autoSignIn && state.accessToken.isEmpty)
                     httpPostResponseJson(
                         baseUrl,
                         "signin",
@@ -1427,10 +1430,6 @@ object NCCli extends App {
                         case None ⇒ ()
                     }
 
-                    if (state.accessToken.isDefined)
-                        logln(s"REST server signed in with default '${c("admin@admin.com")}' user.")
-                }
-
                 // Attempt to get all connected probes if successfully signed in prior.
                 if (state.accessToken.isDefined)
                     httpPostResponseJson(
@@ -1707,8 +1706,10 @@ object NCCli extends App {
                         s"  ${c("tok")}: ${probe.probeToken}"
                     ),
                     DurationFormatUtils.formatDurationHMS(currentTime - probe.startTstamp),
-                    s"${probe.osName} ver. ${probe.osVersion}",
-                    s"${probe.hostName} (${probe.hostAddr})",
+                    Seq(
+                        s"${probe.hostName} (${probe.hostAddr})",
+                        s"${probe.osName} ver. ${probe.osVersion}"
+                    ),
                     probe.models.toList.map(m ⇒ s"${b(m.id)}, v${m.version}")
                 )
 
@@ -1718,8 +1719,7 @@ object NCCli extends App {
             tbl #= (
                 "Probe ID",
                 "Uptime",
-                "OS",
-                "Host",
+                "Host / OS",
                 "Models Deployed"
             )
 
@@ -1935,6 +1935,9 @@ object NCCli extends App {
             case None ⇒ ()
         }
 
+        if (state.accessToken.isDefined)
+            logln(s"REST server signed in with default '${c("admin@admin.com")}' user.")
+
         val parser = new DefaultParser()
 
         parser.setEofOnUnclosedBracket(Bracket.CURLY, Bracket.ROUND, Bracket.SQUARE)
@@ -1976,6 +1979,11 @@ object NCCli extends App {
                 else {
                     val cmd = words.head
 
+                    val OPTIONAL_GRP = "Optional:"
+                    val MANDATORY_GRP = "Mandatory:"
+                    val DFTL_USER_GRP = "Default user:"
+                    val CMDS_GRP = "Commands:"
+
                     candidates.addAll(CMDS.find(_.name == cmd) match {
                         case Some(c) ⇒
                             c.params.flatMap(param ⇒ {
@@ -1985,7 +1993,7 @@ object NCCli extends App {
                                 names.map(name ⇒ mkCandidate(
                                     id = if (hasVal) name + "=" else name,
                                     disp = name,
-                                    grp = "Parameters:",
+                                    grp = if (param.optional) OPTIONAL_GRP else MANDATORY_GRP,
                                     desc = null,
                                     completed = !hasVal)
                                 )
@@ -1995,20 +2003,21 @@ object NCCli extends App {
                         case None ⇒ Seq.empty[Candidate].asJava
                     })
 
-                    // For 'help' - add additional auto-completion candidates.
+                    // For 'help' - add additional auto-completion/suggestion candidates.
                     if (cmd == HELP_CMD.name)
                         candidates.addAll(CMDS.map(c ⇒ s"--cmd=${c.name}").map(s ⇒
                             mkCandidate(
                                 id = s,
                                 disp = s,
-                                grp = null,
+                                grp = CMDS_GRP,
                                 desc = null,
                                 completed = true
                             ))
                             .asJava
                         )
-                    // For 'rest' - add additional auto-completion candidates.
-                    else if (cmd == REST_CMD.name) {
+
+                    // For 'rest' or 'call' - add '--path' auto-completion/suggestion candidates.
+                    if (cmd == REST_CMD.name || cmd == CALL_CMD.name) {
                         val pathParam = REST_CMD.findParameterById("path")
                         val hasPathAlready = words.exists(w ⇒ pathParam.names.exists(x ⇒ w.startsWith(x)))
 
@@ -2028,6 +2037,85 @@ object NCCli extends App {
                                 .asJava
                             )
                     }
+
+                    // For 'call' - add additional auto-completion/suggestion candidates.
+                    if (cmd == CALL_CMD.name) {
+                        val pathParam = CALL_CMD.findParameterById("path")
+
+                        words.find(w ⇒ pathParam.names.exists(x ⇒ w.startsWith(x))) match {
+                            case Some(p) ⇒
+                                val path = p.substring(p.indexOf('=') + 1)
+
+                                REST_SPEC.find(_.path == path) match {
+                                    case Some(spec) ⇒
+                                        candidates.addAll(
+                                            spec.params.map(param ⇒ {
+                                                mkCandidate(
+                                                    id = s"-${param.name}=",
+                                                    disp = s"-${param.name}",
+                                                    grp = if (param.optional) OPTIONAL_GRP else MANDATORY_GRP,
+                                                    desc = null,
+                                                    completed = false
+                                                )
+                                            })
+                                            .asJava
+                                        )
+
+                                        // Add 'acsTok' auto-suggestion.
+                                        if (spec.params.exists(_.name == "acsTok") && state.accessToken.isDefined)
+                                            candidates.add(
+                                                mkCandidate(
+                                                    id = s"-acsTok=${state.accessToken.get}",
+                                                    disp = s"-acsTok=${state.accessToken.get}",
+                                                    grp = MANDATORY_GRP,
+                                                    desc = null,
+                                                    completed = true
+                                                )
+                                            )
+
+                                        // Add 'mdlId' auto-suggestion.
+                                        if (spec.params.exists(_.name == "mdlId") && state.probes.nonEmpty)
+                                            candidates.addAll(
+                                                state.probes.flatMap(_.models.toList).map(mdl ⇒ {
+                                                    mkCandidate(
+                                                        id = s"-mdlId=${mdl.name}",
+                                                        disp = s"-mdlId=${mdl.name}",
+                                                        grp = MANDATORY_GRP,
+                                                        desc = null,
+                                                        completed = true
+                                                    )
+                                                })
+                                                .asJava
+                                            )
+
+                                        // Add default 'email' and 'passwd' auto-suggestion for 'signin' path.
+                                        if (path == "signin") {
+                                            candidates.add(
+                                                mkCandidate(
+                                                    id = "-email=admin@admin.com",
+                                                    disp = "-email=admin@admin.com",
+                                                    grp = DFTL_USER_GRP,
+                                                    desc = null,
+                                                    completed = true
+                                                )
+                                            )
+                                            candidates.add(
+                                                mkCandidate(
+                                                    id = "-passwd=admin",
+                                                    disp = "-passwd=admin",
+                                                    grp = DFTL_USER_GRP,
+                                                    desc = null,
+                                                    completed = true
+                                                )
+                                            )
+                                        }
+
+                                    case None ⇒ ()
+                                }
+
+                            case None ⇒ ()
+                        }
+                    }
                 }
             }
         }


[incubator-nlpcraft] 10/23: Update NCCli.scala

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

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

commit e7f34f7ffaa3842f3d01ca782a4698dae82535b7
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sun Oct 11 06:04:44 2020 -0700

    Update NCCli.scala
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 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 d78062d..d88bb73 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
@@ -105,6 +105,16 @@ object NCCli extends App {
             s"Missing mandatory parameter: $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, " +
             s"type $C'help --cmd=${cmd.name}'$RST to get help."
         )
+    case class InvalidParameter(cmd: Command, paramId: String)
+        extends IllegalArgumentException(
+            s"Invalid parameter: $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, " +
+            s"type $C'help --cmd=${cmd.name}'$RST to get help."
+        )
+    case class InvalidJsonParameter(cmd: Command, param: String)
+        extends IllegalArgumentException(
+            s"Invalid JSON parameter: $C${"'$param'"}$RST, " +
+                s"type $C'help --cmd=${cmd.name}'$RST to get help."
+        )
     case class HttpError(httpCode: Int)
         extends IllegalStateException(s"REST error (HTTP ${c(httpCode)}).")
     case class MalformedJson()
@@ -1204,7 +1214,7 @@ object NCCli extends App {
                 try
                     Integer.parseInt(arg.value.get)
                 catch {
-                    case _ :Exception ⇒ throw new IllegalArgumentException(s"Invalid number of lines: ${arg.value.get}")
+                    case _ :Exception ⇒ throw InvalidParameter(cmd, lines)
                 }
 
             case None ⇒ 20 // Default.
@@ -1244,7 +1254,7 @@ object NCCli extends App {
                 try
                     Integer.parseInt(arg.value.get)
                 catch {
-                    case _ :Exception ⇒ throw new IllegalArgumentException(s"Invalid number of pings: ${arg.value.get}")
+                    case _ :Exception ⇒ throw InvalidParameter(cmd, "number")
                 }
 
             case None ⇒ 1 // Default.
@@ -1719,6 +1729,14 @@ object NCCli extends App {
         val path = normArgs.find(_.parameter.id == "path").getOrElse(throw MissingParameter(cmd, "path")).value.get
 
         checkRestPath(path)
+
+        val first = true
+
+        for (arg ← synthArgs) {
+            val jsName = arg.value.getOrElse(throw InvalidJsonParameter(cmd, ""))
+        }
+
+
     }
 
     /**


[incubator-nlpcraft] 19/23: Update NCCli.scala

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

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

commit 815c99d0f67ba25338b1644ecb7098795e28e995
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 13:53:31 2020 -0700

    Update NCCli.scala
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 44 ++++++++++++++++++++--
 1 file changed, 40 insertions(+), 4 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 c794464..cf7e262 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
@@ -38,6 +38,7 @@ import java.util.Date
 import java.io._
 import java.nio.charset.StandardCharsets
 import java.nio.file.Paths
+import java.time.Instant
 import java.util.regex.Pattern
 
 import org.apache.commons.io.input.{ReversedLinesFileReader, Tailer, TailerListenerAdapter}
@@ -472,6 +473,7 @@ object NCCli extends App {
         var isServerOnline: Boolean = false,
         var accessToken: Option[String] = None,
         var serverLog: Option[File] = None,
+        var lastOkInput: Option[String] = None,
         var probes: List[Probe] = Nil // List of connected probes.
     )
 
@@ -828,12 +830,14 @@ object NCCli extends App {
                     id = "file",
                     names = Seq("--file", "-f"),
                     value = Some("path"),
+                    optional = true,
                     desc =
                         s"File to open with built-in ${y("'less'")} commands. Relative paths will based off the current directory."
                 ),
                 Parameter(
                     id = "server-log",
                     names = Seq("--server-log", "-s"),
+                    optional = true,
                     desc =
                         s"Opens up built-in ${y("'less'")} command for currently running local REST server log."
                 )
@@ -1631,7 +1635,7 @@ object NCCli extends App {
                     case None ⇒
                         err = true
 
-                        unknownCommand(cmdName)
+                        errorUnknownCommand(cmdName)
                 }
             }
 
@@ -2095,13 +2099,37 @@ object NCCli extends App {
             }
         }
 
+        class ReplHistory extends DefaultHistory {
+            private var lastLine: String = _
+
+            /**
+             *
+             * @param time
+             * @param line
+             */
+            override def add(time: Instant, line: String): Unit = {
+                // No-op.
+            }
+
+            /**
+             *
+             */
+            def submitLastLine(): Unit =
+                state.lastOkInput match {
+                    case Some(line) ⇒ super.add(Instant.now(), line)
+                    case None ⇒ ()
+                }
+        }
+
+        val hist = new ReplHistory()
+
         val reader = LineReaderBuilder
             .builder
             .appName("NLPCraft")
             .terminal(term)
             .completer(completer)
             .parser(parser)
-            .history(new DefaultHistory())
+            .history(hist)
             .variable(LineReader.SECONDARY_PROMPT_PATTERN, s"${g("...>")} ")
             .variable(LineReader.INDENTATION, 2)
             .build
@@ -2155,9 +2183,13 @@ object NCCli extends App {
                 if (line.nonEmpty)
                     try {
                         doCommand(splitBySpace(line), repl = true)
+
+                        state.lastOkInput = if (exitStatus == 0) Some(line) else None
                     }
                     catch {
                         case e: SplitError ⇒
+                            state.lastOkInput = None
+
                             val idx = e.index
                             val lineX = line.substring(0, idx) + r(line.substring(idx, idx + 1) ) + line.substring(idx + 1)
                             val dashX = c("-" * idx) + r("^") + c("-" * (line.length - idx - 1))
@@ -2167,6 +2199,8 @@ object NCCli extends App {
                             error(s"  ${r("+-")} $dashX")
                     }
             }
+
+            hist.submitLastLine()
         }
 
         U.stopThread(pinger)
@@ -2239,7 +2273,7 @@ object NCCli extends App {
     /**
      *
      */
-    private def unknownCommand(cmd: String): Unit = {
+    private def errorUnknownCommand(cmd: String): Unit = {
         val c2 = c(s"'$cmd'")
         val h2 = c(s"'help'")
 
@@ -2486,6 +2520,7 @@ object NCCli extends App {
      * @param args
      * @param repl Whether or not called from 'repl' mode.
      */
+    @throws[Exception]
     private def doCommand(args: Seq[String], repl: Boolean): Unit = {
         // Process 'no-ansi' and 'ansi' commands first.
         processAnsi(args, repl)
@@ -2498,6 +2533,7 @@ object NCCli extends App {
 
             CMDS.find(_.name == cmd) match {
                 case Some(cmd) ⇒
+                    // Reset error code.
                     exitStatus = 0
 
                     try
@@ -2506,7 +2542,7 @@ object NCCli extends App {
                         case e: Exception ⇒ error(e.getLocalizedMessage)
                     }
 
-                case None ⇒ unknownCommand(cmd)
+                case None ⇒ errorUnknownCommand(cmd)
             }
         }
     }


[incubator-nlpcraft] 23/23: Update NCConversation.scala

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

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

commit 43ca004f5135f16e86fcc8d976e3b5d6b537a2e1
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 20:15:46 2020 -0700

    Update NCConversation.scala
---
 .../nlpcraft/probe/mgrs/conversation/NCConversation.scala | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversation.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversation.scala
index 365f4b4..e68f2bb 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversation.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/conversation/NCConversation.scala
@@ -152,7 +152,10 @@ case class NCConversation(
             ctx = ctx.asScala.filter(tok ⇒ !p.test(tok)).asJava
         }
 
-        logger.info(s"Conversation is cleared using token predicate.")
+        logger.info(s"Conversation is cleared using token predicate [" +
+            s"usrId=$usrId, " +
+            s"mdlId=$mdlId" +
+        s"]")
     }
 
     /**
@@ -252,7 +255,10 @@ case class NCConversation(
         require(Thread.holdsLock(stm))
 
         if (ctx.isEmpty)
-            logger.info(s"Conversation context is empty for [mdlId=$mdlId, usrId=$usrId]")
+            logger.info(s"Conversation context is empty for [" +
+                s"mdlId=$mdlId, " +
+                s"usrId=$usrId" +
+            s"]")
         else {
             val tbl = NCAsciiTable("Token ID", "Groups", "Text", "Value", "From request")
 
@@ -264,7 +270,10 @@ case class NCConversation(
                 tok.getServerRequestId
             ))
 
-            logger.info(s"Conversation tokens [mdlId=$mdlId, usrId=$usrId]:\n${tbl.toString()}")
+            logger.info(s"Conversation tokens [" +
+                s"mdlId=$mdlId, " +
+                s"usrId=$usrId" +
+            s"]:\n${tbl.toString()}")
         }
     }
 


[incubator-nlpcraft] 17/23: WIP.

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

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

commit 24062840ccbe533cd783630b65dda1ccfed45247
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 02:49:26 2020 -0700

    WIP.
---
 .../main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala  | 2 +-
 .../main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala | 6 +++---
 2 files changed, 4 insertions(+), 4 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 ce1f318..c794464 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
@@ -1711,7 +1711,7 @@ object NCCli extends App {
 
         state.probes.foreach(addProbeToTable(tbl, _))
 
-        logln(s"Connected probes:\n${tbl.toString}")
+        logln(s"Connected probes (${state.probes.size}):\n${tbl.toString}")
     }
 
     /**
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
index 33b8c2e..d57acd7 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
@@ -1838,7 +1838,7 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
 
         // General exception.
         case e: NCException ⇒
-            val errMsg = e.getLocalizedMessage
+            val errMsg = "Unexpected system error."
             val code = "NC_ERROR"
 
             // We have to log error reason because even general exceptions are not expected here.
@@ -1848,7 +1848,7 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
 
         // Unexpected errors.
         case e: Throwable ⇒
-            val errMsg = e.getLocalizedMessage
+            val errMsg = "Unexpected system error."
             val code = "NC_ERROR"
 
             U.prettyError(logger,s"Unexpected system error: $errMsg", e)
@@ -1886,7 +1886,7 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
                 case _: InvalidOriginRejection ⇒ complete(s"Invalid origin.")
 
                 // Common case.
-                case err: Rejection ⇒ complete(s"Bad request.")
+                case _: Rejection ⇒ complete(s"Bad request.")
             }.result
     }
 


[incubator-nlpcraft] 08/23: Update NCCli.scala

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

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

commit faaa36cb826aec8dc49cf546cc3e002dfe1f0895
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sat Oct 10 11:14:36 2020 -0700

    Update NCCli.scala
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 360 +++++++++++++++++++--
 1 file changed, 328 insertions(+), 32 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 2af3e69..e592258 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
@@ -71,36 +71,303 @@ object NCCli extends App {
     case class RestCall(
         path: String,
         desc: String,
-        group: String
+        group: String,
+        params: Seq[RestCallParameter]
     )
 
+    sealed trait JsonType
+    case object STRING extends JsonType
+    case object BOOLEAN extends JsonType
+    case object NUMERIC extends JsonType
+    case object OBJECT extends JsonType
+    case object ARRAY extends JsonType
+
+    case class RestCallParameter(
+        name: String,
+        kind: JsonType,
+        optional: Boolean = false // Mandatory by default.
+    )
+
+    //noinspection DuplicatedCode
     // TODO: this needs to be loaded dynamically from OpenAPI spec.
-    private final val REST_CMDS = Seq(
-        RestCall("clear/conversation", "Clears conversation STM", "Asking"),
-        RestCall("clear/dialog", "Clears dialog flow", "Asking"),
-        RestCall("model/sugsyn", "Runs model synonym suggestion tool", "Tools"),
-        RestCall("check", "Gets status and result of submitted requests", "Asking"),
-        RestCall("cancel", "Cancels a question", "Asking"),
-        RestCall("ask", "Asks a question", "Asking"),
-        RestCall("ask/sync", "Asks a question in synchronous mode", "Asking"),
-        RestCall("user/get", "Gets current user information", "User"),
-        RestCall("user/all", "Gets all users", "User"),
-        RestCall("user/update", "Updates regular user", "User"),
-        RestCall("user/delete", "Deletes user", "User"),
-        RestCall("user/admin", "Updates user admin permissions", "User"),
-        RestCall("user/passwd/reset", "Resets password for the user", "User"),
-        RestCall("user/add", "Adds new user", "User"),
-        RestCall("company/get", "Gets current user company information", "Company"),
-        RestCall("company/add", "Adds new company", "Company"),
-        RestCall("company/update", "Updates company data", "Company"),
-        RestCall("company/delete", "Deletes company", "Company"),
-        RestCall("company/token/reset", "Resets company probe auth token", "Company"),
-        RestCall("feedback/add", "Adds feedback", "Asking"),
-        RestCall("feedback/delete", "Deletes feedback", "Asking"),
-        RestCall("feedback/all", "Gets all feedback", "Asking"),
-        RestCall("signin", "Signs in and obtains new access token", "Authentication"),
-        RestCall("signout", "Signs out and releases access token", "Authentication"),
-        RestCall("probe/all", "Gets all probes", "Probe")
+    private final val REST_SPEC = Seq(
+        RestCall(
+            path = "clear/conversation",
+            desc = "Clears conversation STM",
+            group = "Asking",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "mdlId", kind = STRING),
+                RestCallParameter(name = "usrId", kind = STRING, optional = true),
+                RestCallParameter(name = "usrExtId", kind = STRING, optional = true)
+            )
+        ),
+        RestCall(
+            "clear/dialog",
+            "Clears dialog flow",
+            "Asking",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "mdlId", kind = STRING),
+                RestCallParameter(name = "usrId", kind = STRING, optional = true),
+                RestCallParameter(name = "usrExtId", kind = STRING, optional = true)
+            )
+        ),
+        RestCall(
+            "model/sugsyn",
+            "Runs model synonym suggestion tool",
+            "Tools",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "mdlId", kind = STRING),
+                RestCallParameter(name = "minScore", kind = NUMERIC)
+            )
+        ),
+        RestCall(
+            "check",
+            "Gets status and result of submitted requests",
+            "Asking",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "usrId", kind = STRING, optional = true),
+                RestCallParameter(name = "usrExtId", kind = STRING, optional = true),
+                RestCallParameter(name = "srvReqIds", kind = ARRAY, optional = true),
+                RestCallParameter(name = "maxRows", kind = NUMERIC, optional = true)
+            )
+        ),
+        RestCall(
+            "cancel",
+            "Cancels a question",
+            "Asking",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "usrId", kind = STRING, optional = true),
+                RestCallParameter(name = "usrExtId", kind = STRING, optional = true),
+                RestCallParameter(name = "srvReqIds", kind = ARRAY, optional = true),
+            )
+        ),
+        RestCall(
+            "ask",
+            "Asks a question",
+            "Asking",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "usrId", kind = STRING, optional = true),
+                RestCallParameter(name = "usrExtId", kind = STRING, optional = true),
+                RestCallParameter(name = "txt", kind = STRING),
+                RestCallParameter(name = "mdlId", kind = STRING),
+                RestCallParameter(name = "data", kind = OBJECT, optional = true),
+                RestCallParameter(name = "enableLog", kind = BOOLEAN, optional = true),
+            )
+        ),
+        RestCall(
+            "ask/sync",
+            "Asks a question in synchronous mode",
+            "Asking",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "usrId", kind = STRING, optional = true),
+                RestCallParameter(name = "usrExtId", kind = STRING, optional = true),
+                RestCallParameter(name = "txt", kind = STRING),
+                RestCallParameter(name = "mdlId", kind = STRING),
+                RestCallParameter(name = "data", kind = OBJECT, optional = true),
+                RestCallParameter(name = "enableLog", kind = BOOLEAN, optional = true),
+            )
+        ),
+        RestCall(
+            "user/get",
+            "Gets current user information",
+            "User",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "id", kind = STRING, optional = true),
+                RestCallParameter(name = "usrExtId", kind = STRING, optional = true)
+            )
+        ),
+        RestCall(
+            "user/all",
+            "Gets all users",
+            "User",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+            )
+        ),
+        RestCall(
+            "user/update",
+            "Updates regular user",
+            "User",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "firstName", kind = STRING),
+                RestCallParameter(name = "lastName", kind = STRING),
+                RestCallParameter(name = "id", kind = STRING, optional = true),
+                RestCallParameter(name = "avatarUrl", kind = STRING, optional = true),
+                RestCallParameter(name = "properties", kind = OBJECT, optional = true)
+            )
+        ),
+        RestCall(
+            "user/delete",
+            "Deletes user",
+            "User",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "id", kind = STRING, optional = true),
+                RestCallParameter(name = "usrExtId", kind = STRING, optional = true)
+            )
+        ),
+        RestCall(
+            "user/admin",
+            "Updates user admin permissions",
+            "User",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "id", kind = STRING, optional = true),
+                RestCallParameter(name = "isAdmin", kind = BOOLEAN)
+            )
+        ),
+        RestCall(
+            "user/passwd/reset",
+            "Resets password for the user",
+            "User",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "id", kind = STRING, optional = true),
+                RestCallParameter(name = "newPasswd", kind = STRING)
+            )
+        ),
+        RestCall(
+            "user/add",
+            "Adds new user",
+            "User",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "firstName", kind = STRING),
+                RestCallParameter(name = "lastName", kind = STRING),
+                RestCallParameter(name = "email", kind = STRING),
+                RestCallParameter(name = "passwd", kind = STRING),
+                RestCallParameter(name = "isAdmin", kind = BOOLEAN),
+                RestCallParameter(name = "usrExtId", kind = STRING, optional = true),
+                RestCallParameter(name = "avatarUrl", kind = STRING, optional = true),
+                RestCallParameter(name = "properties", kind = OBJECT, optional = true)
+            )
+        ),
+        RestCall(
+            "company/get",
+            "Gets current user company information",
+            "Company",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+            )
+        ),
+        RestCall(
+            "company/add",
+            "Adds new company",
+            "Company",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "name", kind = STRING),
+                RestCallParameter(name = "website", kind = STRING, optional = true),
+                RestCallParameter(name = "country", kind = STRING, optional = true),
+                RestCallParameter(name = "region", kind = STRING, optional = true),
+                RestCallParameter(name = "city", kind = STRING, optional = true),
+                RestCallParameter(name = "address", kind = STRING, optional = true),
+                RestCallParameter(name = "postalCode", kind = STRING, optional = true),
+                RestCallParameter(name = "adminEmail", kind = STRING),
+                RestCallParameter(name = "adminPasswd", kind = STRING),
+                RestCallParameter(name = "adminFirstName", kind = STRING),
+                RestCallParameter(name = "adminLastName", kind = STRING),
+                RestCallParameter(name = "adminAvatarUrl", kind = STRING, optional = true)
+            )
+        ),
+        RestCall(
+            "company/update",
+            "Updates company data",
+            "Company",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "name", kind = STRING),
+                RestCallParameter(name = "website", kind = STRING, optional = true),
+                RestCallParameter(name = "country", kind = STRING, optional = true),
+                RestCallParameter(name = "region", kind = STRING, optional = true),
+                RestCallParameter(name = "city", kind = STRING, optional = true),
+                RestCallParameter(name = "address", kind = STRING, optional = true),
+                RestCallParameter(name = "postalCode", kind = STRING, optional = true)
+            )
+        ),
+        RestCall(
+            "company/delete",
+            "Deletes company",
+            "Company",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+            )
+        ),
+        RestCall(
+            "company/token/reset",
+            "Resets company probe auth token",
+            "Company",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+            )
+        ),
+        RestCall(
+            "feedback/add",
+            "Adds feedback",
+            "Asking",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "usrId", kind = STRING, optional = true),
+                RestCallParameter(name = "extUsrId", kind = STRING, optional = true),
+                RestCallParameter(name = "comment", kind = STRING, optional = true),
+                RestCallParameter(name = "srvReqId", kind = STRING),
+                RestCallParameter(name = "score", kind = STRING)
+            )
+        ),
+        RestCall(
+            "feedback/delete",
+            "Deletes feedback",
+            "Asking",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "id", kind = NUMERIC)
+            )
+        ),
+        RestCall(
+            "feedback/all",
+            "Gets all feedback",
+            "Asking",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+                RestCallParameter(name = "usrId", kind = STRING, optional = true),
+                RestCallParameter(name = "extUsrId", kind = STRING, optional = true),
+                RestCallParameter(name = "srvReqId", kind = STRING,  optional = true)
+            )
+        ),
+        RestCall(
+            "signin",
+            "Signs in and obtains new access token",
+            "Authentication",
+            params = Seq(
+                RestCallParameter(name = "email", kind = STRING),
+                RestCallParameter(name = "passwd", kind = STRING)
+            )
+        ),
+        RestCall(
+            "signout",
+            "Signs out and releases access token",
+            "Authentication",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+            )
+        ),
+        RestCall(
+            "probe/all",
+            "Gets all probes",
+            "Probe",
+            params = Seq(
+                RestCallParameter(name = "acsTok", kind = STRING),
+            )
+        )
     )
 
     // Number of server services that need to be started + 1 progress start.
@@ -274,7 +541,7 @@ object NCCli extends App {
                 s"In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion and " +
                 s"auto-completion candidates for commonly used paths and call parameters."
             ),
-            body = cmdRest,
+            body = cmdCall,
             params = Seq(
                 Parameter(
                     id = "path",
@@ -662,6 +929,7 @@ object NCCli extends App {
     private final val QUIT_CMD = CMDS.find(_.name ==  "quit").get
     private final val HELP_CMD = CMDS.find(_.name ==  "help").get
     private final val REST_CMD = CMDS.find(_.name ==  "rest").get
+    private final val CALL_CMD = CMDS.find(_.name ==  "call").get
     private final val STOP_SRV_CMD = CMDS.find(_.name ==  "stop-server").get
     private final val START_SRV_CMD = CMDS.find(_.name ==  "start-server").get
 
@@ -1432,6 +1700,29 @@ object NCCli extends App {
 
     /**
      *
+     * @param path
+     */
+    private def checkRestPath(path: String): Unit =
+        if (!REST_SPEC.exists(_.path == path))
+            throw new IllegalArgumentException(s"Unknown REST path $C'$path'$RST, type ${c("'help --cmd=rest'")} to get help.")
+
+    /**
+     *
+     * @param cmd Command descriptor.
+     * @param args Arguments, if any, for this command.
+     * @param repl Whether or not executing from REPL.
+     */
+    private def cmdCall(cmd: Command, args: Seq[Argument], repl: Boolean): Unit = {
+        val normArgs = args.filter(_.parameter != null)
+        val synthArgs = args.filter(_.parameter == null)
+
+        val path = normArgs.find(_.parameter.id == "path").getOrElse(throw MissingParameter(cmd, "path")).value.get
+
+        checkRestPath(path)
+    }
+
+    /**
+     *
      * @param cmd Command descriptor.
      * @param args Arguments, if any, for this command.
      * @param repl Whether or not executing from REPL.
@@ -1443,8 +1734,7 @@ object NCCli extends App {
         if (!U.isValidJson(rawJson))
             throw MalformedJson()
 
-        if (!REST_CMDS.exists(_.path == path))
-            throw new IllegalArgumentException(s"Unknown REST path $C'$path'$RST, type ${c("'help --cmd=rest'")} to get help.")
+        checkRestPath(path)
 
         val endpoint = getRestEndpointFromBeacon
 
@@ -1567,7 +1857,7 @@ object NCCli extends App {
 
                         if (!hasPathAlready)
                             candidates.addAll(
-                                REST_CMDS.map(cmd ⇒ {
+                                REST_SPEC.map(cmd ⇒ {
                                     val name = s"--path=${cmd.path}"
 
                                     mkCandidate(
@@ -1895,9 +2185,15 @@ object NCCli extends App {
 
             val name = if (parts.size == 1) arg else parts(0)
             val value = if (parts.size == 1) None else Some(parts(1))
+            val hasSynth = cmd.params.exists(_.synthetic)
 
             cmd.findParameterByNameOpt(name) match {
-                case None ⇒ throw mkError()
+                case None ⇒
+                    if (hasSynth)
+                        Argument(null, value) // Synthetic argument (name is unspecified).
+                    else
+                        throw mkError()
+
                 case Some(param) ⇒
                     if ((param.value.isDefined && value.isEmpty) || (param.value.isEmpty && value.isDefined))
                         throw mkError()


[incubator-nlpcraft] 06/23: Merge branch 'master' into NLPCRAFT-108

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

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

commit 180fbf9569bafd1abcf39eb5f2d7d21185309ac4
Merge: a1aff98 49b8e26
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Oct 9 23:48:17 2020 -0700

    Merge branch 'master' into NLPCRAFT-108

 nlpcraft/pom.xml                                   |  15 ++
 .../org/apache/nlpcraft/model/NCIntentSample.java  |  17 +-
 .../test/impl/NCTestAutoModelValidatorImpl.scala   |  53 +++---
 .../apache/nlpcraft/probe/mgrs/NCProbeModel.scala  |   2 +-
 .../probe/mgrs/deploy/NCDeployManager.scala        |  42 +++--
 .../nlpcraft/server/rest/NCBasicRestApi.scala      | 201 ++++++++++++---------
 .../apache/nlpcraft/model/NCIntentSampleSpec.scala |  49 +++++
 pom.xml                                            |   1 +
 8 files changed, 246 insertions(+), 134 deletions(-)


[incubator-nlpcraft] 03/23: Update NCCli.scala

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

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

commit 387f0997e1fbf2aff126ac26616d3ad6fb576fd5
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Oct 9 18:12:33 2020 -0700

    Update NCCli.scala
---
 .../src/main/scala/org/apache/nlpcraft/model/tools/cmdline/NCCli.scala  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 7e514c2..2840ac6 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
@@ -1382,7 +1382,7 @@ object NCCli extends App {
         if (!U.isValidJson(rawJson))
             throw MalformedJson()
 
-        if (!REST_PATHS.exists(_._1 == path))
+        if (!REST_PATHS.exists(_.path == path))
             throw new IllegalArgumentException(s"Unknown REST path $C'$path'$RST, type ${c("'help --cmd=rest'")} to get help.")
 
         val endpoint = getRestEndpointFromBeacon


[incubator-nlpcraft] 18/23: Update NCBasicRestApi.scala

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

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

commit d7b960409a63784d9c4d4134578c7dc3c0a976aa
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 02:57:38 2020 -0700

    Update NCBasicRestApi.scala
---
 .../src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
index d57acd7..126b25a 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
@@ -324,7 +324,7 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
     @throws[InvalidField]
     protected def checkModelId(mdlId: String, compId: Long): Unit =
         if (!NCProbeManager.existsForModel(compId, mdlId))
-            throw InvalidModelId("mdlId")
+            throw InvalidModelId(mdlId)
 
     /**
       * Checks length of field value.


[incubator-nlpcraft] 02/23: WIP.

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

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

commit 56842f8dda4ad2048ed7f44e72014842f9f6382c
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Oct 9 18:12:09 2020 -0700

    WIP.
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 61 ++++++++++++----------
 openapi/nlpcraft_swagger.yml                       | 53 ++++++++++++-------
 2 files changed, 68 insertions(+), 46 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 bfa5c0c..7e514c2 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
@@ -68,35 +68,40 @@ object NCCli extends App {
     //noinspection RegExpRedundantEscape
     private final val TAILER_PTRN = Pattern.compile("^.*NC[a-zA-Z0-9]+ started \\[[\\d]+ms\\]$")
 
+    case class RestCall(
+        path: String,
+        desc: String,
+        group: String
+    )
+
     // TODO: this needs to be loaded dynamically from OpenAPI spec.
     private final val REST_PATHS = Seq(
-        "clear/conversation" -> "Clears conversation STM",
-        "clear/dialog" -> "Clears dialog flow",
-        "model/sugsyn" -> "Runs model synonym suggestion tool",
-        "check" -> "Gets status and result of submitted requests",
-        "cancel" -> "Cancels a question",
-        "ask" -> "Asks a question",
-        "ask/sync" -> "Asks a question in synchronous mode",
-        "user/get" -> "Gets current user information",
-        "user/all" -> "Gets all users",
-        "user/update" -> "Updates regular user",
-        "user/delete" -> "Deletes user",
-        "user/admin" -> "Updates user admin permissions",
-        "user/passwd/reset" -> "Resets password for the user",
-        "user/add" -> "Adds new user",
-        "company/get" -> "Gets current user company information",
-        "company/add" -> "Adds new company",
-        "company/update" -> "Updates company data",
-        "company/delete" -> "Deletes company",
-        "company/token/reset" -> "Resets company probe auth token",
-        "feedback/add" -> "Adds feedback",
-        "feedback/delete" -> "Deletes feedback",
-        "feedback/all" -> "Gets all feedback",
-        "signin" -> "Signs in and obtains new access token",
-        "signout" -> "Signs out and releases access token",
-        "probe/all" -> "Gets all probes"
+        RestCall("clear/conversation", "Clears conversation STM", "Asking"),
+        RestCall("clear/dialog", "Clears dialog flow", "Asking"),
+        RestCall("model/sugsyn", "Runs model synonym suggestion tool", "Tools"),
+        RestCall("check", "Gets status and result of submitted requests", "Asking"),
+        RestCall("cancel", "Cancels a question", "Asking"),
+        RestCall("ask", "Asks a question", "Asking"),
+        RestCall("ask/sync", "Asks a question in synchronous mode", "Asking"),
+        RestCall("user/get", "Gets current user information", "User"),
+        RestCall("user/all", "Gets all users", "User"),
+        RestCall("user/update", "Updates regular user", "User"),
+        RestCall("user/delete", "Deletes user", "User"),
+        RestCall("user/admin", "Updates user admin permissions", "User"),
+        RestCall("user/passwd/reset", "Resets password for the user", "User"),
+        RestCall("user/add", "Adds new user", "User"),
+        RestCall("company/get", "Gets current user company information", "Company"),
+        RestCall("company/add", "Adds new company", "Company"),
+        RestCall("company/update", "Updates company data", "Company"),
+        RestCall("company/delete", "Deletes company", "Company"),
+        RestCall("company/token/reset", "Resets company probe auth token", "Company"),
+        RestCall("feedback/add", "Adds feedback", "Asking"),
+        RestCall("feedback/delete", "Deletes feedback", "Asking"),
+        RestCall("feedback/all", "Gets all feedback", "Asking"),
+        RestCall("signin", "Signs in and obtains new access token", "Authentication"),
+        RestCall("signout", "Signs out and releases access token", "Authentication"),
+        RestCall("probe/all", "Gets all probes", "Probe")
     )
-    .sortBy(_._1)
 
     // Number of server services that need to be started + 1 progress start.
     // Used for progress bar functionality.
@@ -1160,13 +1165,13 @@ object NCCli extends App {
             if (!repl)
                 header()
 
-            CMDS.groupBy(_.group).foreach(entry ⇒ {
+            CMDS.groupBy(_.group).toSeq.sortBy(_._1).foreach(entry ⇒ {
                 val grp = entry._1
                 val grpCmds = entry._2
 
                 val tbl = NCAsciiTable().margin(left = if (repl) 0 else 4)
 
-                grpCmds.foreach(cmd ⇒ tbl +/ (
+                grpCmds.sortBy(_.name).foreach(cmd ⇒ tbl +/ (
                     "" → s"${g(cmd.name)}",
                     "align:left, maxWidth:85" → cmd.synopsis
                 ))
diff --git a/openapi/nlpcraft_swagger.yml b/openapi/nlpcraft_swagger.yml
index 32d0f8d..0a3b885 100644
--- a/openapi/nlpcraft_swagger.yml
+++ b/openapi/nlpcraft_swagger.yml
@@ -158,10 +158,27 @@ paths:
           description: Failed operation.
           schema:
             $ref: '#/definitions/Error'
+  /health:
+    get:
+      tags:
+        - Tools
+      summary: Health ping.
+      description: >-
+        Pings server for HTTP 200 code.
+      operationId: health
+      responses:
+        '200':
+          description: Successful operation.
+          schema:
+            $ref: '#/definitions/Ok'
+        '400':
+          description: Failed operation.
+          schema:
+            $ref: '#/definitions/Error'
   /model/sugsyn:
     post:
       tags:
-        - Model
+        - Tools
       summary: Runs model synonym suggestion tool.
       description: >-
         Runs model synonym suggestion tool that is based on BERT models and uses @NCIntentSample annotation.
@@ -648,7 +665,7 @@ paths:
   /user/get:
     post:
       tags:
-        - Users
+        - User
       summary: Gets current user information.
       description: Gets current user information.
       operationId: getUser
@@ -731,7 +748,7 @@ paths:
   /user/all:
     post:
       tags:
-        - Users
+        - User
       summary: Gets all users.
       description: Gets all users for the current user company. Administrative privileges required.
       operationId: getAllUsers
@@ -756,7 +773,7 @@ paths:
             type: object
             required:
               - status
-              - users
+              - User
             properties:
               status:
                 type: string
@@ -805,7 +822,7 @@ paths:
   /user/update:
     post:
       tags:
-        - Users
+        - User
       summary: Updates regular user.
       description: >-
         Updates user with given ID or the current user with given parameters.
@@ -862,7 +879,7 @@ paths:
   /user/delete:
     post:
       tags:
-        - Users
+        - User
       summary: Deletes user.
       description: >-
         Deletes user with given ID or the current user.
@@ -909,7 +926,7 @@ paths:
   /user/admin:
     post:
       tags:
-        - Users
+        - User
       summary: Updates user admin permissions.
       description: >-
         Updates user's permissions with given ID or the current user.
@@ -950,7 +967,7 @@ paths:
   /user/passwd/reset:
     post:
       tags:
-        - Users
+        - User
       summary: Resets password for the user.
       description: >-
         Resets the password for the user. Note that NLPCraft doesn't store password in reversible way
@@ -993,7 +1010,7 @@ paths:
   /user/add:
     post:
       tags:
-        - Users
+        - User
       summary: Adds new user.
       description: Adds new user with given parameters to the company of the admin caller. Administrative privileges required.
       operationId: addUser
@@ -1072,7 +1089,7 @@ paths:
   /company/get:
     post:
       tags:
-        - Companies
+        - Company
       summary: Gets current user company information.
       description: Gets current user company information.
       operationId: getCompany
@@ -1137,7 +1154,7 @@ paths:
   /company/add:
     post:
       tags:
-        - Companies
+        - Company
       summary: Adds new company.
       description: >-
         Adds new company with given parameters.
@@ -1238,7 +1255,7 @@ paths:
   /company/update:
     post:
       tags:
-        - Companies
+        - Company
       summary: Updates company data.
       description: >-
         Updates company data with given parameters.
@@ -1299,7 +1316,7 @@ paths:
   /company/delete:
     post:
       tags:
-        - Companies
+        - Company
       summary: Deletes company.
       description: >-
         Deletes company.
@@ -1331,7 +1348,7 @@ paths:
   /company/token/reset:
     post:
       tags:
-        - Companies
+        - Company
       summary: Resets company probe authentication token.
       description: >-
         Sets and returns new company probe authentication token.
@@ -1375,7 +1392,7 @@ paths:
   /feedback/add:
     post:
       tags:
-        - Feedbacks
+        - Asking
       summary: Adds feedback.
       description: Adds feedback for processed user request.
       operationId: addFeedback
@@ -1440,7 +1457,7 @@ paths:
   /feedback/delete:
     post:
       tags:
-        - Feedbacks
+        - Asking
       summary: Deletes feedback.
       description: >-
         Deletes feedback for given record ID.
@@ -1477,7 +1494,7 @@ paths:
   /feedback/all:
     post:
       tags:
-        - Feedbacks
+        - Asking
       summary: Gets feedback.
       description:  >-
         Gets all request feedback records.
@@ -1657,7 +1674,7 @@ paths:
   /probe/all:
     post:
       tags:
-        - Data Probes
+        - Probe
       summary: Gets all probes.
       description: >-
         Gets metadata for all active (currently connected) probes. Administrative privileges required.


[incubator-nlpcraft] 16/23: WIP.

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

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

commit c25ab35e6518317686b0d181e53b27952d23a27e
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 02:20:56 2020 -0700

    WIP.
---
 .../examples/lightswitch/LightSwitchModel.scala    |  2 +-
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 69 +++++++++-------------
 2 files changed, 28 insertions(+), 43 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
index c9c0479..261b239 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
@@ -67,6 +67,6 @@ class LightSwitchModel extends NCModelFileAdapter("org/apache/nlpcraft/examples/
         // Add HomeKit, Arduino or other integration here.
 
         // By default - just return a descriptive action string.
-        NCResult.text(s"Lights '$status' in '${locations.toLowerCase}'.")
+        NCResult.text(s"Lights are [$status] in [${locations.toLowerCase}].")
     }
 }
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 f147382..ce1f318 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
@@ -1043,19 +1043,6 @@ object NCCli extends App {
     }
 
     /**
-     *
-     * @param pathOpt
-     */
-    private def checkDirPath(pathOpt: Option[Argument]): Unit = {
-        if (pathOpt.isDefined) {
-            val file = new File(stripQuotes(pathOpt.get.value.get))
-
-            if (!file.exists() || !file.isDirectory)
-                throw new IllegalArgumentException(s"Directory not found: ${c(file.getAbsolutePath)}")
-        }
-    }
-
-    /**
      * @param cmd Command descriptor.
      * @param args Arguments, if any, for this command.
      * @param repl Whether or not running from REPL.
@@ -1224,10 +1211,10 @@ object NCCli extends App {
                     logln(g(" [OK]"))
                     logServerInfo(beacon)
 
+                    showTip()
+
                     if (state.accessToken.isDefined)
                         logln(s"Signed in with default '${c("admin@admin.com")}' user.")
-
-                    showTip()
                 }
             }
         }
@@ -1695,38 +1682,36 @@ object NCCli extends App {
 
         logln(s"Local REST server:\n${tbl.toString}")
 
-        if (state.probes.nonEmpty) {
-            tbl = new NCAsciiTable
+        tbl = new NCAsciiTable
 
-            def addProbeToTable(tbl: NCAsciiTable, probe: Probe): NCAsciiTable = {
-                tbl += (
-                    Seq(
-                        probe.probeId,
-                        s"  ${c("guid")}: ${probe.probeGuid}",
-                        s"  ${c("tok")}: ${probe.probeToken}"
-                    ),
-                    DurationFormatUtils.formatDurationHMS(currentTime - probe.startTstamp),
-                    Seq(
-                        s"${probe.hostName} (${probe.hostAddr})",
-                        s"${probe.osName} ver. ${probe.osVersion}"
-                    ),
-                    probe.models.toList.map(m ⇒ s"${b(m.id)}, v${m.version}")
-                )
+        def addProbeToTable(tbl: NCAsciiTable, probe: Probe): NCAsciiTable = {
+            tbl += (
+                Seq(
+                    probe.probeId,
+                    s"  ${c("guid")}: ${probe.probeGuid}",
+                    s"  ${c("tok")}: ${probe.probeToken}"
+                ),
+                DurationFormatUtils.formatDurationHMS(currentTime - probe.startTstamp),
+                Seq(
+                    s"${probe.hostName} (${probe.hostAddr})",
+                    s"${probe.osName} ver. ${probe.osVersion}"
+                ),
+                probe.models.toList.map(m ⇒ s"${b(m.id)}, v${m.version}")
+            )
 
-                tbl
-            }
+            tbl
+        }
 
-            tbl #= (
-                "Probe ID",
-                "Uptime",
-                "Host / OS",
-                "Models Deployed"
-            )
+        tbl #= (
+            "Probe ID",
+            "Uptime",
+            "Host / OS",
+            "Models Deployed"
+        )
 
-            state.probes.foreach(addProbeToTable(tbl, _))
+        state.probes.foreach(addProbeToTable(tbl, _))
 
-            logln(s"Connected probes:\n${tbl.toString}")
-        }
+        logln(s"Connected probes:\n${tbl.toString}")
     }
 
     /**


[incubator-nlpcraft] 21/23: WIP.

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

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

commit ba21c9caf07b7c5323ec8c94875dbe14340039db
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 19:58:19 2020 -0700

    WIP.
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 97 +++++++++++-----------
 .../apache/nlpcraft/model/NCIntentSampleSpec.scala |  1 +
 2 files changed, 48 insertions(+), 50 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 3e5cdb8..f8efcb2 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
@@ -38,19 +38,18 @@ import java.util.Date
 import java.io._
 import java.nio.charset.StandardCharsets
 import java.nio.file.Paths
-import java.time.Instant
 import java.util.regex.Pattern
 
 import org.apache.commons.io.input.{ReversedLinesFileReader, Tailer, TailerListenerAdapter}
 import org.apache.commons.lang3.time.DurationFormatUtils
 import org.apache.http.util.EntityUtils
 import org.jline.builtins.Commands
-import org.jline.reader.Completer
+import org.jline.reader.{Candidate, Completer, EndOfFileException, Highlighter, LineReader, LineReaderBuilder, ParsedLine, UserInterruptException}
 import org.jline.reader.impl.DefaultParser
 import org.jline.terminal.{Terminal, TerminalBuilder}
-import org.jline.reader.{Candidate, EndOfFileException, LineReader, LineReaderBuilder, ParsedLine, UserInterruptException}
 import org.jline.reader.impl.DefaultParser.Bracket
 import org.jline.reader.impl.history.DefaultHistory
+import org.jline.utils.AttributedString
 import org.jline.utils.InfoCmp.Capability
 import resource.managed
 
@@ -69,6 +68,8 @@ object NCCli extends App {
 
     //noinspection RegExpRedundantEscape
     private final val TAILER_PTRN = Pattern.compile("^.*NC[a-zA-Z0-9]+ started \\[[\\d]+ms\\]$")
+    private final val CMD_NAME = Pattern.compile("(^\\s*[\\w-]+)(\\s)")
+    private final val CMD_PARAM = Pattern.compile("(\\s--?[\\w-]+)([= ]?)")
 
     // Number of server services that need to be started + 1 progress start.
     // Used for progress bar functionality.
@@ -143,6 +144,10 @@ object NCCli extends App {
             s"Missing mandatory parameter $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, " +
             s"type $C'help --cmd=${cmd.name}'$RST to get help."
         )
+    case class MissingMandatoryJsonParameters(cmd: Command, path: String)
+        extends IllegalArgumentException(
+            s"Missing mandatory JSON parameter for $C${"'" + cmd.name + s" --path=$path'"}$RST, type $C'help --cmd=${cmd.name}'$RST to get help."
+        )
     case class InvalidParameter(cmd: Command, paramId: String)
         extends IllegalArgumentException(
             s"Invalid parameter $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, " +
@@ -473,7 +478,6 @@ object NCCli extends App {
         var isServerOnline: Boolean = false,
         var accessToken: Option[String] = None,
         var serverLog: Option[File] = None,
-        var lastOkInput: Option[String] = None,
         var probes: List[Probe] = Nil // List of connected probes.
     )
 
@@ -1832,38 +1836,40 @@ object NCCli extends App {
         var first = true
         val buf = new StringBuilder()
 
+        val spec = REST_SPEC.find(_.path == path).getOrElse(throw InvalidParameter(cmd, "path"))
+
+        var mandatoryParams = spec.params.filter(!_.optional)
+
         for (arg ← synthArgs) {
             val jsName = arg.parameter.id
 
-            REST_SPEC.find(_.path == path) match {
-                case Some(spec) ⇒
-                    spec.params.find(_.name == jsName) match {
-                        case Some(param) ⇒
-                            if (!first)
-                                buf ++= ","
+            spec.params.find(_.name == jsName) match {
+                case Some(param) ⇒
+                    mandatoryParams = mandatoryParams.filter(_.name != jsName)
 
-                            first = false
+                    if (!first)
+                        buf ++= ","
 
-                            buf ++= "\"" + jsName +"\":"
+                    first = false
 
-                            val value = arg.value.getOrElse(throw InvalidJsonParameter(cmd, arg.parameter.names.head))
+                    buf ++= "\"" + jsName + "\":"
 
-                            param.kind match {
-                                case STRING ⇒ buf ++= "\"" + U.escapeJson(stripQuotes(value)) + "\""
-                                case OBJECT | ARRAY ⇒ buf ++= stripQuotes(value)
-                                case BOOLEAN | NUMERIC ⇒ buf ++= value
-                            }
+                    val value = arg.value.getOrElse(throw InvalidJsonParameter(cmd, arg.parameter.names.head))
 
-                        case None ⇒ throw InvalidJsonParameter(cmd, jsName)
+                    param.kind match {
+                        case STRING ⇒ buf ++= "\"" + U.escapeJson(stripQuotes(value)) + "\""
+                        case OBJECT | ARRAY ⇒ buf ++= stripQuotes(value)
+                        case BOOLEAN | NUMERIC ⇒ buf ++= value
                     }
 
-                case None ⇒ throw InvalidParameter(cmd, "path")
+                case None ⇒ throw InvalidJsonParameter(cmd, jsName)
             }
         }
 
-        val json = s"{${buf.toString()}}"
+        if (mandatoryParams.nonEmpty)
+            throw MissingMandatoryJsonParameters(cmd, path)
 
-        httpRest(cmd, path, json)
+        httpRest(cmd, path, s"{${buf.toString()}}")
     }
 
     /**
@@ -2099,35 +2105,30 @@ object NCCli extends App {
             }
         }
 
-        class ReplHistory extends DefaultHistory {
-            /**
-             *
-             * @param time
-             * @param line
-             */
-            override def add(time: Instant, line: String): Unit = {
-                // No-op.
-            }
+        class ReplHighlighter extends Highlighter {
+            override def highlight(reader: LineReader, buffer: String): AttributedString =
+                AttributedString.fromAnsi(
+                    CMD_NAME.matcher(
+                        CMD_PARAM.matcher(
+                            buffer
+                        )
+                        .replaceAll(c("$1") + "$2")
+                    )
+                    .replaceAll(bo(g("$1")) + "$2")
+                )
 
-            /**
-             *
-             */
-            def submitLastLine(): Unit =
-                state.lastOkInput match {
-                    case Some(line) ⇒ super.add(Instant.now(), line)
-                    case None ⇒ ()
-                }
+            override def setErrorPattern(errorPattern: Pattern): Unit = ()
+            override def setErrorIndex(errorIndex: Int): Unit = ()
         }
 
-        val hist = new ReplHistory()
-
         val reader = LineReaderBuilder
             .builder
             .appName("NLPCraft")
             .terminal(term)
             .completer(completer)
             .parser(parser)
-            .history(hist)
+            .highlighter(new ReplHighlighter())
+            .history(new DefaultHistory())
             .variable(LineReader.SECONDARY_PROMPT_PATTERN, s"${g("...>")} ")
             .variable(LineReader.INDENTATION, 2)
             .build
@@ -2179,15 +2180,10 @@ object NCCli extends App {
                     .trim()
 
                 if (line.nonEmpty)
-                    try {
+                    try 
                         doCommand(splitBySpace(line), repl = true)
-
-                        state.lastOkInput = if (exitStatus == 0) Some(line) else None
-                    }
                     catch {
                         case e: SplitError ⇒
-                            state.lastOkInput = None
-
                             val idx = e.index
                             val lineX = line.substring(0, idx) + r(line.substring(idx, idx + 1) ) + line.substring(idx + 1)
                             val dashX = c("-" * idx) + r("^") + c("-" * (line.length - idx - 1))
@@ -2197,8 +2193,6 @@ object NCCli extends App {
                             error(s"  ${r("+-")} $dashX")
                     }
             }
-
-            hist.submitLastLine()
         }
 
         U.stopThread(pinger)
@@ -2475,6 +2469,9 @@ object NCCli extends App {
             val value = if (parts.size == 1) None else Some(parts(1).trim)
             val hasSynth = cmd.params.exists(_.synthetic)
 
+            if (name.endsWith("=")) // Missing value or extra '='.
+                throw mkError()
+
             cmd.findParameterByNameOpt(name) match {
                 case None ⇒
                     if (hasSynth)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentSampleSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentSampleSpec.scala
index d9872af..5b3804a 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentSampleSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentSampleSpec.scala
@@ -6,6 +6,7 @@ import org.apache.nlpcraft.model.tools.test.NCTestAutoModelValidator
 import org.junit.jupiter.api.Test
 
 import scala.collection.JavaConverters._
+import scala.language.implicitConversions
 
 /**
   * Sample annotation test model.


[incubator-nlpcraft] 12/23: WIP.

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

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

commit 5983b47785d5e5288670e3c016dc5235161468f7
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Sun Oct 11 11:36:03 2020 -0700

    WIP.
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 83 +++++++++++++++-------
 .../nlpcraft/server/rest/NCBasicRestApi.scala      |  4 +-
 2 files changed, 60 insertions(+), 27 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 d88bb73..79d6f22 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
@@ -102,17 +102,17 @@ object NCCli extends App {
         extends IllegalStateException(s"Local REST server not found.")
     case class MissingParameter(cmd: Command, paramId: String)
         extends IllegalArgumentException(
-            s"Missing mandatory parameter: $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, " +
+            s"Missing mandatory parameter $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, " +
             s"type $C'help --cmd=${cmd.name}'$RST to get help."
         )
     case class InvalidParameter(cmd: Command, paramId: String)
         extends IllegalArgumentException(
-            s"Invalid parameter: $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, " +
+            s"Invalid parameter $C${"'" + cmd.params.find(_.id == paramId).get.names.head + "'"}$RST, " +
             s"type $C'help --cmd=${cmd.name}'$RST to get help."
         )
     case class InvalidJsonParameter(cmd: Command, param: String)
         extends IllegalArgumentException(
-            s"Invalid JSON parameter: $C${"'$param'"}$RST, " +
+            s"Invalid JSON parameter $C${"'" + param + "'"}$RST, " +
                 s"type $C'help --cmd=${cmd.name}'$RST to get help."
         )
     case class HttpError(httpCode: Int)
@@ -1214,7 +1214,7 @@ object NCCli extends App {
                 try
                     Integer.parseInt(arg.value.get)
                 catch {
-                    case _ :Exception ⇒ throw InvalidParameter(cmd, lines)
+                    case _ :Exception ⇒ throw InvalidParameter(cmd, "lines")
                 }
 
             case None ⇒ 20 // Default.
@@ -1710,33 +1710,49 @@ object NCCli extends App {
 
     /**
      *
-     * @param path
-     */
-    private def checkRestPath(path: String): Unit =
-        if (!REST_SPEC.exists(_.path == path))
-            throw new IllegalArgumentException(s"Unknown REST path $C'$path'$RST, type ${c("'help --cmd=rest'")} to get help.")
-
-    /**
-     *
      * @param cmd Command descriptor.
      * @param args Arguments, if any, for this command.
      * @param repl Whether or not executing from REPL.
      */
     private def cmdCall(cmd: Command, args: Seq[Argument], repl: Boolean): Unit = {
-        val normArgs = args.filter(_.parameter != null)
-        val synthArgs = args.filter(_.parameter == null)
+        val normArgs = args.filter(!_.parameter.synthetic)
+        val synthArgs = args.filter(_.parameter.synthetic)
 
         val path = normArgs.find(_.parameter.id == "path").getOrElse(throw MissingParameter(cmd, "path")).value.get
 
-        checkRestPath(path)
-
-        val first = true
+        var first = true
+        val buf = new StringBuilder()
 
         for (arg ← synthArgs) {
-            val jsName = arg.value.getOrElse(throw InvalidJsonParameter(cmd, ""))
+            val jsName = arg.parameter.id
+
+            REST_SPEC.find(_.path == path) match {
+                case Some(call) ⇒ call.params.find(_.name == jsName) match {
+                    case Some(param) ⇒
+                        if (!first)
+                            buf ++= ","
+
+                        first = false
+
+                        buf ++= "\"" + jsName +"\":"
+
+                        val value = arg.value.getOrElse(throw InvalidJsonParameter(cmd, arg.parameter.names.head))
+
+                        param.kind match {
+                            case STRING ⇒ buf ++= "\"" + U.escapeJson(stripQuotes(value)) + "\""
+                            case OBJECT | ARRAY ⇒ buf ++= stripQuotes(value)
+                            case BOOLEAN | NUMERIC ⇒ buf ++= value
+                        }
+
+                    case None ⇒ throw InvalidJsonParameter(cmd, jsName)
+                }
+                case None ⇒ throw InvalidParameter(cmd, "path")
+            }
         }
 
+        val json = s"{${buf.toString()}}"
 
+        httpRest(cmd, path, json)
     }
 
     /**
@@ -1747,12 +1763,23 @@ object NCCli extends App {
      */
     private def cmdRest(cmd: Command, args: Seq[Argument], repl: Boolean): Unit = {
         val path = args.find(_.parameter.id == "path").getOrElse(throw MissingParameter(cmd, "path")).value.get
-        val rawJson = stripQuotes(args.find(_.parameter.id == "json").getOrElse(throw MissingParameter(cmd, "json")).value.get)
+        val json = stripQuotes(args.find(_.parameter.id == "json").getOrElse(throw MissingParameter(cmd, "json")).value.get)
+
+        httpRest(cmd, path, json)
+    }
 
-        if (!U.isValidJson(rawJson))
+    /**
+     *
+     * @param cmd
+     * @param path
+     * @param json
+     */
+    private def httpRest(cmd: Command, path: String, json: String): Unit = {
+        if (!U.isValidJson(json))
             throw MalformedJson()
 
-        checkRestPath(path)
+        if (!REST_SPEC.exists(_.path == path))
+            throw InvalidParameter(cmd, "path")
 
         val endpoint = getRestEndpointFromBeacon
 
@@ -1765,7 +1792,7 @@ object NCCli extends App {
                     throw new IllegalStateException(s"Unexpected REST error: ${status.getReasonPhrase}")
                 )
             )
-        }), stripQuotes(rawJson))
+        }), json)
 
         // Ack HTTP response code.
         logln(s"HTTP ${if (resp.code == 200) g("200") else r(resp.code)}")
@@ -2201,14 +2228,20 @@ object NCCli extends App {
             if (parts.size > 2)
                 throw mkError()
 
-            val name = if (parts.size == 1) arg else parts(0)
-            val value = if (parts.size == 1) None else Some(parts(1))
+            val name = if (parts.size == 1) arg.trim else parts(0).trim
+            val value = if (parts.size == 1) None else Some(parts(1).trim)
             val hasSynth = cmd.params.exists(_.synthetic)
 
             cmd.findParameterByNameOpt(name) match {
                 case None ⇒
                     if (hasSynth)
-                        Argument(null, value) // Synthetic argument (name is unspecified).
+                        Argument(Parameter(
+                            id = name.substring(1), // Remove single '-' from the beginning.
+                            names = Seq(name),
+                            value = value,
+                            synthetic = true,
+                            desc = null
+                        ), value) // Synthetic argument.
                     else
                         throw mkError()
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
index abed728..33b8c2e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
@@ -77,7 +77,7 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
     class InvalidArguments(msg: String) extends NCE(msg)
     case class OutOfRangeField(fn: String, from: Number, to: Number) extends InvalidArguments(s"API field ($fn) value is out of range ($from, $to).")
     case class TooLargeField(fn: String, max: Int) extends InvalidArguments(s"API field ($fn) value exceeded max length of $max.")
-    case class InvalidField(fn: String) extends InvalidArguments(s"API invalid field: $fn")
+    case class InvalidField(fn: String) extends InvalidArguments(s"API field invalid: $fn")
     case class EmptyField(fn: String) extends InvalidArguments(s"API field cannot be empty: $fn")
     case class InvalidExternalUserId(usrExtId: String) extends InvalidArguments(s"External user ID is invalid or unknown: $usrExtId")
     case class InvalidUserId(id: Long) extends InvalidArguments(s"User ID is invalid or unknown: $id")
@@ -1869,7 +1869,7 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
                 case _: SchemeRejection ⇒ complete("Unsupported scheme.")
                 case _: UnsatisfiableRangeRejection ⇒ complete("Invalid range.")
                 case _: TransformationRejection ⇒ complete("Transformation error.")
-                case _: MalformedRequestContentRejection ⇒ complete("Malformed content or missing data.")
+                case _: MalformedRequestContentRejection ⇒ complete("Malformed or missing content.")
                 case _: AuthenticationFailedRejection ⇒ complete("Authentication error.")
                 case _: TooManyRangesRejection ⇒ complete("Too many ranges.")
                 case err: MissingFormFieldRejection ⇒ complete(s"Missing form field: ${err.fieldName}")


[incubator-nlpcraft] 15/23: Update NCCli.scala

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

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

commit a72fc145487921d2beafa9c88bd76033f6cd5257
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Oct 13 02:12:38 2020 -0700

    Update NCCli.scala
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 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 166b5d1..f147382 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
@@ -1950,14 +1950,13 @@ object NCCli extends App {
 
             /**
              *
-             * @param id
              * @param disp
              * @param desc
              * @param completed
              * @return
              */
-            private def mkCandidate(id: String, disp: String, grp: String, desc: String, completed: Boolean): Candidate =
-                new Candidate(id, disp, grp, desc, null, null, completed)
+            private def mkCandidate(disp: String, grp: String, desc: String, completed: Boolean): Candidate =
+                new Candidate(disp, disp, grp, desc, null, null, completed)
 
             override def complete(reader: LineReader, line: ParsedLine, candidates: util.List[Candidate]): Unit = {
                 val words = line.words().asScala
@@ -1969,7 +1968,6 @@ object NCCli extends App {
                         val grp = s"${n._3}:"
 
                         mkCandidate(
-                            id = name,
                             disp = name,
                             grp = grp,
                             desc = desc,
@@ -1991,12 +1989,11 @@ object NCCli extends App {
                                 val names = param.names.filter(_.startsWith("--")) // Skip shorthands from auto-completion.
 
                                 names.map(name ⇒ mkCandidate(
-                                    id = if (hasVal) name + "=" else name,
-                                    disp = name,
+                                    disp = if (hasVal) name + "=" else name,
                                     grp = if (param.optional) OPTIONAL_GRP else MANDATORY_GRP,
                                     desc = null,
-                                    completed = !hasVal)
-                                )
+                                    completed = !hasVal
+                                ))
                             })
                             .asJava
 
@@ -2007,7 +2004,6 @@ object NCCli extends App {
                     if (cmd == HELP_CMD.name)
                         candidates.addAll(CMDS.map(c ⇒ s"--cmd=${c.name}").map(s ⇒
                             mkCandidate(
-                                id = s,
                                 disp = s,
                                 grp = CMDS_GRP,
                                 desc = null,
@@ -2027,7 +2023,6 @@ object NCCli extends App {
                                     val name = s"--path=${cmd.path}"
 
                                     mkCandidate(
-                                        id = name,
                                         disp = name,
                                         grp = s"REST ${cmd.group}:",
                                         desc = cmd.desc,
@@ -2051,7 +2046,6 @@ object NCCli extends App {
                                         candidates.addAll(
                                             spec.params.map(param ⇒ {
                                                 mkCandidate(
-                                                    id = s"-${param.name}=",
                                                     disp = s"-${param.name}",
                                                     grp = if (param.optional) OPTIONAL_GRP else MANDATORY_GRP,
                                                     desc = null,
@@ -2065,7 +2059,6 @@ object NCCli extends App {
                                         if (spec.params.exists(_.name == "acsTok") && state.accessToken.isDefined)
                                             candidates.add(
                                                 mkCandidate(
-                                                    id = s"-acsTok=${state.accessToken.get}",
                                                     disp = s"-acsTok=${state.accessToken.get}",
                                                     grp = MANDATORY_GRP,
                                                     desc = null,
@@ -2078,8 +2071,7 @@ object NCCli extends App {
                                             candidates.addAll(
                                                 state.probes.flatMap(_.models.toList).map(mdl ⇒ {
                                                     mkCandidate(
-                                                        id = s"-mdlId=${mdl.name}",
-                                                        disp = s"-mdlId=${mdl.name}",
+                                                        disp = s"-mdlId=${mdl.id}",
                                                         grp = MANDATORY_GRP,
                                                         desc = null,
                                                         completed = true
@@ -2092,7 +2084,6 @@ object NCCli extends App {
                                         if (path == "signin") {
                                             candidates.add(
                                                 mkCandidate(
-                                                    id = "-email=admin@admin.com",
                                                     disp = "-email=admin@admin.com",
                                                     grp = DFTL_USER_GRP,
                                                     desc = null,
@@ -2101,7 +2092,6 @@ object NCCli extends App {
                                             )
                                             candidates.add(
                                                 mkCandidate(
-                                                    id = "-passwd=admin",
                                                     disp = "-passwd=admin",
                                                     grp = DFTL_USER_GRP,
                                                     desc = null,


[incubator-nlpcraft] 01/23: WIP.

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

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

commit d495873971116c58db66ada9850ca4ae76cc145f
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Fri Oct 9 17:50:52 2020 -0700

    WIP.
---
 .../nlpcraft/model/tools/cmdline/NCCli.scala       | 66 +++++++++++++++-------
 .../nlpcraft/server/rest/NCBasicRestApi.scala      |  2 +-
 2 files changed, 47 insertions(+), 21 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 f4de0a9..bfa5c0c 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
@@ -160,6 +160,7 @@ object NCCli extends App {
     // Single CLI command.
     case class Command(
         name: String,
+        group: String,
         synopsis: String,
         desc: Option[String] = None,
         params: Seq[Parameter] = Seq.empty,
@@ -207,7 +208,8 @@ object NCCli extends App {
     private final val CMDS = Seq(
         Command(
             name = "rest",
-            synopsis = s"Issues REST call to locally running REST server.",
+            group = "Rest API",
+            synopsis = s"Issues REST call to local REST server.",
             desc = Some(
                 s"All NLPCraft REST API uses HTTP POST and JSON parameters ('Content-Type: application/json' header). " +
                 s"To issue the REST call you need to supply path and parameters. In REPL mode, hit ${rv(" Tab ")} to see auto-suggestion and " +
@@ -249,7 +251,8 @@ object NCCli extends App {
         ),
         Command(
             name = "tail-server",
-            synopsis = s"Shows last N lines for the local REST server log.",
+            group = "Server Ops",
+            synopsis = s"Shows last N lines from the local REST server log.",
             desc = Some(
                 s"Only works for the server started via this script."
             ),
@@ -272,6 +275,7 @@ object NCCli extends App {
         ),
         Command(
             name = "start-server",
+            group = "Server Ops",
             synopsis = s"Starts local REST server.",
             desc = Some(
                 s"REST server is started in the external JVM process with both stdout and stderr piped out into log file. " +
@@ -323,10 +327,11 @@ object NCCli extends App {
         ),
         Command(
             name = "restart-server",
+            group = "Server Ops",
             synopsis = s"Restarts local REST server.",
             desc = Some(
                 s"This command is equivalent to executing  ${y("'stop-server'")} and then ${y("'start-server'")} commands with " +
-                s"corresponding parameters. If there is no locally running REST server the ${y("'stop-server'")} command is ignored."
+                s"corresponding parameters. If there is no local REST server the ${y("'stop-server'")} command is ignored."
             ),
             body = cmdRestartServer,
             params = Seq(
@@ -374,16 +379,19 @@ object NCCli extends App {
         ),
         Command(
             name = "info-server",
-            synopsis = s"Basic information about locally running REST server.",
+            group = "Server Ops",
+            synopsis = s"Info about local REST server.",
             body = cmdInfoServer
         ),
         Command(
             name = "cls",
+            group = "REPL",
             synopsis = s"Clears terminal screen.",
             body = cmdCls
         ),
         Command(
             name = "nano",
+            group = "REPL",
             synopsis = s"Runs built-in ${y("'nano'")} editor.",
             body = cmdNano,
             desc = Some(
@@ -415,6 +423,7 @@ object NCCli extends App {
         ),
         Command(
             name = "less",
+            group = "REPL",
             synopsis = s"Runs built-in ${y("'less'")} command.",
             body = cmdLess,
             desc = Some(
@@ -445,7 +454,8 @@ object NCCli extends App {
         ),
         Command(
             name = "no-ansi",
-            synopsis = s"Disables usage of ANSI escape codes for colors & terminal controls.",
+            group = "REPL",
+            synopsis = s"Disables ANSI escape codes for terminal colors & controls.",
             desc = Some(
                 s"This is a special command that can be combined with any other commands."
             ),
@@ -459,7 +469,8 @@ object NCCli extends App {
         ),
         Command(
             name = "ansi",
-            synopsis = s"Enables usage of ANSI escape codes for colors & terminal controls.",
+            group = "REPL",
+            synopsis = s"Enables ANSI escape codes for terminal colors & controls.",
             desc = Some(
                 s"This is a special command that can be combined with any other commands."
             ),
@@ -473,6 +484,7 @@ object NCCli extends App {
         ),
         Command(
             name = "ping-server",
+            group = "Server Ops",
             synopsis = s"Pings local REST server.",
             desc = Some(
                 s"REST server is pinged using ${y("'/health'")} REST call to check its online status."
@@ -499,6 +511,7 @@ object NCCli extends App {
         ),
         Command(
             name = "stop-server",
+            group = "Server Ops",
             synopsis = s"Stops local REST server.",
             desc = Some(
                 s"Local REST server must be started via ${y(s"'$SCRIPT_NAME''")} or other compatible way."
@@ -507,12 +520,14 @@ object NCCli extends App {
         ),
         Command(
             name = "quit",
+            group = "REPL",
             synopsis = s"Quits REPL when in REPL mode.",
             body = cmdQuit
         ),
         Command(
             name = "help",
-            synopsis = s"Displays manual page for ${y(s"'$SCRIPT_NAME'")}.",
+            group = "REPL",
+            synopsis = s"Displays help for ${y(s"'$SCRIPT_NAME'")}.",
             desc = Some(
                 s"By default, without ${y("'--all'")} or ${y("'--cmd'")} parameters, displays the abbreviated form of manual " +
                 s"only listing the commands without parameters or examples."
@@ -546,6 +561,7 @@ object NCCli extends App {
         ),
         Command(
             name = "version",
+            group = "REPL",
             synopsis = s"Displays full version of ${y(s"'$SCRIPT_NAME'")} script.",
             desc = Some(
                 "Depending on the additional parameters can display only the semantic version or the release date."
@@ -1140,23 +1156,30 @@ object NCCli extends App {
             lines
         }
 
-        val tbl = NCAsciiTable().margin(left = if (repl) 0 else 4)
-
         if (args.isEmpty) { // Default - show abbreviated help.
             if (!repl)
                 header()
 
-            CMDS.foreach(cmd ⇒ tbl +/ (
-                "" → s"${g(cmd.name)}",
-                "align:left, maxWidth:85" → cmd.synopsis
-            ))
+            CMDS.groupBy(_.group).foreach(entry ⇒ {
+                val grp = entry._1
+                val grpCmds = entry._2
 
-            logln(tbl.toString)
+                val tbl = NCAsciiTable().margin(left = if (repl) 0 else 4)
+
+                grpCmds.foreach(cmd ⇒ tbl +/ (
+                    "" → s"${g(cmd.name)}",
+                    "align:left, maxWidth:85" → cmd.synopsis
+                ))
+
+                logln(s"\n$grp:\n${tbl.toString}")
+            })
         }
         else if (args.size == 1 && args.head.parameter.id == "all") { // Show a full format help for all commands.
             if (!repl)
                 header()
 
+            val tbl = NCAsciiTable().margin(left = if (repl) 0 else 4)
+
             CMDS.foreach(cmd ⇒
                 tbl +/ (
                     "" → s"${g(cmd.name)}",
@@ -1170,6 +1193,8 @@ object NCCli extends App {
             var err = false
             val seen = mutable.Buffer.empty[String]
 
+            val tbl = NCAsciiTable().margin(left = if (repl) 0 else 4)
+
             for (arg ← args) {
                 val cmdName = arg.value.get
 
@@ -1227,11 +1252,11 @@ object NCCli extends App {
         tbl += ("Token providers", s"${g(beacon.tokenProviders)}")
         tbl += ("NLP engine", s"${g(beacon.nlpEngine)}")
         tbl += ("Access tokens:", "")
-        tbl += ("  Scan frequency", s"${beacon.acsToksScanMins} mins")
-        tbl += ("  Expiration timeout", s"${beacon.acsToksExpireMins} mins")
+        tbl += ("  Scan frequency", s"$G${beacon.acsToksScanMins} mins$RST")
+        tbl += ("  Expiration timeout", s"$G${beacon.acsToksExpireMins} mins$RST")
         tbl += ("External config:", "")
-        tbl += ("  URL", s"${beacon.extConfigUrl}")
-        tbl += ("  Check MD5",s"${beacon.extConfigCheckMd5}")
+        tbl += ("  URL", s"${g(beacon.extConfigUrl)}")
+        tbl += ("  Check MD5",s"${g(beacon.extConfigCheckMd5)}")
         tbl += ("Log file", logPath)
         tbl += ("Started on", s"${g(DateFormat.getDateTimeInstance.format(new Date(beacon.startMs)))}")
 
@@ -1405,7 +1430,7 @@ object NCCli extends App {
         parser.regexVariable("")
 
         val completer = new Completer {
-            private val cmds = CMDS.map(c ⇒ c.name → c.synopsis)
+            private val cmds = CMDS.map(c ⇒ (c.name, c.synopsis, c.group))
 
             /**
              *
@@ -1425,11 +1450,12 @@ object NCCli extends App {
                     candidates.addAll(cmds.map(n ⇒ {
                         val name = n._1
                         val desc = n._2.substring(0, n._2.length - 1) // Remove last '.'.
+                        val grp = n._3
 
                         mkCandidate(
                             id = name,
                             disp = name,
-                            grp = null,
+                            grp = grp,
                             desc = desc,
                             completed = true
                         )
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
index 60b6569..5555b47 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/rest/NCBasicRestApi.scala
@@ -68,7 +68,7 @@ class NCBasicRestApi extends NCRestApi with LazyLogging with NCOpenCensusTrace w
      * General control exception.
      * Note that these classes must be public because scala 2.11 internal errors (compilations problems).
      */
-    case class AccessTokenFailure(acsTkn: String) extends NCE(s"Unknown access token: $acsTkn")
+    case class AccessTokenFailure(acsTkn: String) extends NCE(s"Unknown access token.")
     case class SignInFailure(email: String) extends NCE(s"Invalid or unknown user credentials for user with: $email")
     case class AdminRequired(email: String) extends NCE(s"Admin privileges required for user with: $email")
     case class InvalidOperation(email: String) extends NCE(s"Invalid operation.")