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

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


The following commit(s) were added to refs/heads/NLPCRAFT-319 by this push:
     new 4c113d4  WIP.
4c113d4 is described below

commit 4c113d4e268a0f8246a09a82da7167497416e029
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon May 17 22:42:56 2021 +0300

    WIP.
---
 .../nlpcraft/model/meta/NCMetaResultSpec.scala     | 20 ++++++-----
 .../nlpcraft/server/rest/NCRestAskSpec.scala       | 16 +++++++++
 .../nlpcraft/server/rest/RestTestModel.scala       | 39 +++++++++++++++++++---
 openapi/nlpcraft_swagger.yml                       |  8 +++++
 4 files changed, 71 insertions(+), 12 deletions(-)

diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/meta/NCMetaResultSpec.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/meta/NCMetaResultSpec.scala
index 9e2fe6e..8aec5cb 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/meta/NCMetaResultSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/meta/NCMetaResultSpec.scala
@@ -28,12 +28,16 @@ import java.util
   * Test model.
   */
 object NCMetaResultSpecModel {
+    final val K1 = "k1"
+    final val K2 = "k2"
+    final val K3 = "k3"
+
     final val V1 = "v1"
     final val V2 = 2.2.asInstanceOf[AnyRef]
     final val V3 = new util.HashMap[String, AnyRef]()
 
-    V3.put("k1", V1)
-    V3.put("k2", V2)
+    V3.put(K1, V1)
+    V3.put(K2, V2)
 }
 
 import org.apache.nlpcraft.model.meta.NCMetaResultSpecModel._
@@ -45,9 +49,9 @@ class NCMetaResultSpecModel extends NCAbstractTokensModel {
     def onIntent(): NCResult = {
         val res = NCResult.text("OK")
 
-        res.getMetadata.put("k1", V1)
-        res.getMetadata.put("k2", V2)
-        res.getMetadata.put("k3", V3)
+        res.getMetadata.put(K1, V1)
+        res.getMetadata.put(K2, V2)
+        res.getMetadata.put(K3, V3)
 
         res
     }
@@ -66,8 +70,8 @@ class NCMetaResultSpec extends NCMetaSpecAdapter {
 
         println(s"Meta received: $meta")
 
-        require(meta.get("k1") == V1)
-        require(meta.get("k2") == V2)
-        require(meta.get("k3") == V3)
+        require(meta.get(K1) == V1)
+        require(meta.get(K2) == V2)
+        require(meta.get(K3) == V3)
     }
 }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestAskSpec.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestAskSpec.scala
index 56fc5ba..8013c0a 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestAskSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/NCRestAskSpec.scala
@@ -152,4 +152,20 @@ class NCRestAskSpec extends NCRestSpec {
 
         post("cancel")()
     }
+
+    @Test
+    def testSyncMeta(): Unit = {
+        post(
+            "ask/sync",
+            "txt" → "meta",
+            "mdlId" → "rest.test.model"
+        )(
+            ("$.state.status", (status: String) ⇒ assertEquals("QRY_READY", 
status)),
+            ("$.state.resMeta", (meta: java.util.Map[String, Object]) ⇒ {
+                import RestTestModel._
+
+                assertEquals(Map(K1 → V1, K2 → V2, K3 → V3).asJava, meta)
+            })
+        )
+    }
 }
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/RestTestModel.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/RestTestModel.scala
index 115caa5..621be18 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/RestTestModel.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/server/rest/RestTestModel.scala
@@ -18,11 +18,29 @@
 package org.apache.nlpcraft.server.rest
 
 import org.apache.nlpcraft.NCTestElement
-import org.apache.nlpcraft.model.{NCElement, NCIntent, NCIntentMatch, 
NCIntentRef, NCIntentSample, NCModelAdapter, NCResult}
+import org.apache.nlpcraft.model.{NCElement, NCIntent, NCIntentSample, 
NCModelAdapter, NCResult}
 
 import java.util
 
 /**
+  * REST test model helper.
+  */
+object RestTestModel {
+    final val K1 = "k1"
+    final val K2 = "k2"
+    final val K3 = "k3"
+
+    final val V1 = "v1"
+    final val V2 = 2.2.asInstanceOf[AnyRef]
+    final val V3 = new util.HashMap[String, AnyRef]()
+
+    V3.put(K1, V1)
+    V3.put(K2, V2)
+}
+
+import RestTestModel._
+
+/**
   * REST test model.
   */
 class RestTestModel extends NCModelAdapter("rest.test.model", "REST test 
model", "1.0.0") {
@@ -30,14 +48,27 @@ class RestTestModel extends 
NCModelAdapter("rest.test.model", "REST test model",
         Set(
             NCTestElement("a"),
             NCTestElement("b"),
-            NCTestElement("x", "cat")
+            NCTestElement("x", "cat"),
+            NCTestElement("meta")
         )
 
     @NCIntent("intent=onA term(t)={tok_id() == 'a'}")
     @NCIntentSample(Array("My A"))
-    private def a(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+    private def a(): NCResult = NCResult.text("OK")
 
     @NCIntent("intent=onB term(t)={tok_id() == 'b'}")
     @NCIntentSample(Array("My B"))
-    private def b(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
+    private def b(): NCResult = NCResult.text("OK")
+
+    @NCIntent("intent=onMeta term(t)={tok_id() == 'meta'}")
+    @NCIntentSample(Array("meta"))
+    private def meta(): NCResult = {
+        val res = NCResult.text("OK")
+
+        res.getMetadata.put(K1, V1)
+        res.getMetadata.put(K2, V2)
+        res.getMetadata.put(K3, V3)
+
+        res
+    }
 }
diff --git a/openapi/nlpcraft_swagger.yml b/openapi/nlpcraft_swagger.yml
index fbf0f1c..c33996e 100644
--- a/openapi/nlpcraft_swagger.yml
+++ b/openapi/nlpcraft_swagger.yml
@@ -352,6 +352,10 @@ paths:
                         Optional body (string or JSON object) of the result if 
returned by model
                         (provided only if status is <code>QRY_READY</code> and 
processing was
                         not rejected or terminated due to an exception).
+                    resMeta:
+                      type: object
+                      description: >-
+                        Optional meta JSON object. TODO:
                     error:
                       type: string
                       description: >-
@@ -650,6 +654,10 @@ paths:
                       Optional body (string or JSON object) of the result if 
returned by model
                       (provided only if status is <code>QRY_READY</code> and 
processing was
                       not rejected or terminated due to an exception).
+                  resMeta:
+                    type: object
+                    description: >-
+                      Optional meta JSON object. TODO:
                   error:
                     type: string
                     description: >-

Reply via email to