You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2021/05/10 19:49:01 UTC

[incubator-nlpcraft-java-client] 01/01: WIP.

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

sergeykamov pushed a commit to branch develop-0.7.5
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft-java-client.git

commit e3491d1bf429220052964571f22454e8429dc93f
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Mon May 10 22:48:49 2021 +0300

    WIP.
---
 pom.xml                                            |  2 +-
 .../java/org/apache/nlpcraft/client/NCClient.java  | 28 +++------
 .../java/org/apache/nlpcraft/client/NCCompany.java | 10 ++++
 .../apache/nlpcraft/client/impl/NCClientImpl.java  | 67 +++++++++++-----------
 .../nlpcraft/client/impl/beans/NCCompanyBean.java  |  6 ++
 .../org/apache/nlpcraft/client/NCAskSyncTest.java  | 20 +++++--
 .../apache/nlpcraft/client/NCClearDialogTest.java  |  3 +-
 .../org/apache/nlpcraft/client/NCCompanyTest.java  | 35 +++++++----
 .../org/apache/nlpcraft/client/NCTestAdapter.java  |  3 +-
 .../org/apache/nlpcraft/client/NCUserTest.java     | 14 +++--
 .../nlpcraft/client/models/NCCommonSpecModel.java  |  2 +-
 .../client/models/NCConversationSpecModel.java     |  2 +-
 .../nlpcraft/client/models/NCDialogSpecModel.java  |  5 +-
 .../client/models/NCSuggestionSpecModel.java       |  2 +-
 14 files changed, 117 insertions(+), 82 deletions(-)

diff --git a/pom.xml b/pom.xml
index 30ac327..9b886e9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -29,7 +29,7 @@
         <commons.validator.ver>1.7</commons.validator.ver>
         <gson.ver>2.8.6</gson.ver>
         <log4j.ver>2.14.0</log4j.ver>
-        <nlpcraft.ver>0.7.2</nlpcraft.ver>
+        <nlpcraft.ver>0.7.5</nlpcraft.ver>
         <junit.ver>5.7.0</junit.ver>
         <maven.compiler.version>3.8.0</maven.compiler.version>
         <maven.shade.plugin.ver>3.2.4</maven.shade.plugin.ver>
diff --git a/src/main/java/org/apache/nlpcraft/client/NCClient.java b/src/main/java/org/apache/nlpcraft/client/NCClient.java
index 283d913..b27be7d 100644
--- a/src/main/java/org/apache/nlpcraft/client/NCClient.java
+++ b/src/main/java/org/apache/nlpcraft/client/NCClient.java
@@ -334,18 +334,18 @@ public interface NCClient {
      *
      * @param mdlId ID of the model to submit the request to.
      * @param txt Text to process.
-     * @param data Optional JSON data payload.
+     * @param data Optional JSON data payload. TODO:
      * @param enableLog Whether or not to enable processing log collection.
      * @param usrId Optional user ID.
      * @param usrExtId Optional external "on-behalf-of" user ID.
      * @return Server request ID of the submitted request.
      * @throws NCClientException Thrown in case of client-specific errors.
      * @throws IOException Thrown in case of generic I/O errors.
-     * @see #askSync(String, String, String, boolean, Long, String) 
+     * @see #askSync(String, String, Map, boolean, Long, String)
      * @see #askSync(String, String) 
      * @see #ask(String, String) 
      */
-    String ask(String mdlId, String txt, String data, boolean enableLog, Long usrId, String usrExtId) throws NCClientException, IOException;
+    String ask(String mdlId, String txt, Map<String, Object> data, boolean enableLog, Long usrId, String usrExtId) throws NCClientException, IOException;
 
     /**
      * Submits request for asynchronous processing. This is a shortcut call that is equivalent to:
@@ -386,22 +386,10 @@ public interface NCClient {
      * @throws IOException Thrown in case of generic I/O errors.
      * @see #askSync(String, String)
      * @see #ask(String, String)
-     * @see #ask(String, String, String, boolean, Long, String) 
+     * @see #ask(String, String, Map, boolean, Long, String)
      */
-    NCResult askSync(String mdlId, String txt, String data, boolean enableLog, Long usrId, String usrExtId) throws NCClientException, IOException;
+    NCResult askSync(String mdlId, String txt, Map<String, Object> data, boolean enableLog, Long usrId, String usrExtId) throws NCClientException, IOException;
 
-    /**
-     * Submits request for synchronous processing. This is a shortcut call that is equivalent to:
-     * <pre class="brush: java">
-     *     askSync(mdlId, txt, null, false, null, null);
-     * </pre>
-     *
-     * @param mdlId ID of the model to submit the request to.
-     * @param txt Text to process.
-     * @return Query processing result.
-     * @throws NCClientException Thrown in case of client-specific errors.
-     * @throws IOException Thrown in case of generic I/O errors.
-     */
     default NCResult askSync(String mdlId, String txt) throws NCClientException, IOException {
         return askSync(mdlId, txt, null, false, null, null);
     }
@@ -488,7 +476,8 @@ public interface NCClient {
         String adminPasswd,
         String adminFirstName,
         String adminLastName,
-        String adminAvatarUrl
+        String adminAvatarUrl,
+        Map<String, String> props // TODO:
     ) throws NCClientException, IOException;
 
     /**
@@ -522,7 +511,8 @@ public interface NCClient {
         String region,
         String city,
         String address,
-        String postalCode
+        String postalCode,
+        Map<String, String> props // TODO:
     ) throws NCClientException, IOException;
 
     /**
diff --git a/src/main/java/org/apache/nlpcraft/client/NCCompany.java b/src/main/java/org/apache/nlpcraft/client/NCCompany.java
index 8202cba..0a02c34 100644
--- a/src/main/java/org/apache/nlpcraft/client/NCCompany.java
+++ b/src/main/java/org/apache/nlpcraft/client/NCCompany.java
@@ -17,6 +17,8 @@
 
 package org.apache.nlpcraft.client;
 
+import java.util.Map;
+
 /**
  * Company descriptor.
  *
@@ -78,4 +80,12 @@ public interface NCCompany {
      * @return Optional postal code of the company.
      */
     String getPostalCode();
+
+    /**
+     * TODO:
+     * Gets properties.
+     *
+     * @return Optional properties.
+     */
+    Map<String, String> getProperties();
 }
diff --git a/src/main/java/org/apache/nlpcraft/client/impl/NCClientImpl.java b/src/main/java/org/apache/nlpcraft/client/impl/NCClientImpl.java
index e2957c9..1d7055b 100644
--- a/src/main/java/org/apache/nlpcraft/client/impl/NCClientImpl.java
+++ b/src/main/java/org/apache/nlpcraft/client/impl/NCClientImpl.java
@@ -662,13 +662,12 @@ public class NCClientImpl implements NCClient {
     
         started = false;
     }
-    
+
     @Override
-    public String ask(String mdlId, String txt, String data, boolean enableLog, Long usrId, String usrExtId)
-        throws NCClientException, IOException {
+    public String ask(String mdlId, String txt, Map<String, Object> data, boolean enableLog, Long usrId, String usrExtId) throws NCClientException, IOException {
         notNull(mdlId, "mdlId");
         notNull(txt, "txt");
-        
+
         NCAskBean b =
             checkAndExtract(
                 post(
@@ -683,88 +682,86 @@ public class NCClientImpl implements NCClient {
                 ),
                 NCAskBean.class
             );
-        
+
         return b.getServerRequestId();
     }
-    
+
     @Override
-    public NCResult askSync(
-        String mdlId, String txt, String data, boolean enableLog, Long usrId, String usrExtId
-    ) throws NCClientException, IOException {
+    public NCResult askSync(String mdlId, String txt, Map<String, Object> data, boolean enableLog, Long usrId, String usrExtId) throws NCClientException, IOException {
         notNull(mdlId, "mdlId");
         notNull(txt, "txt");
-        
+
         if (embeddedProbe) {
             String srvReqId = ask(mdlId, txt, data, enableLog, usrId, usrExtId);
             int timeout = reqCfg.getSocketTimeout();
             long maxTime = System.currentTimeMillis() + timeout;
-    
+
             while (true) {
                 NCEmbeddedResult res = embeddedResMap.get(srvReqId);
-        
+
                 if (res != null)
                     return new NCResult() {
                         @Override
                         public String getServerRequestId() {
                             return res.getServerRequestId();
                         }
-    
+
                         @Override
                         public String getText() {
                             return res.getOriginalText();
                         }
-    
+
                         @Override
                         public long getUserId() {
                             return res.getUserId();
                         }
-    
+
                         @Override
                         public String getModelId() {
                             return res.getModelId();
                         }
-    
+
                         @Override
                         public String getProbeId() {
                             return res.getProbeId();
                         }
-    
+
                         @Override
                         public boolean isReady() {
                             return true;
                         }
-    
+
                         @Override
                         public String getResultType() {
                             return res.getType();
                         }
-    
+
                         @Override
                         public String getResultBody() {
                             return res.getBody();
                         }
-    
+
                         @Override
                         public Integer getErrorCode() {
                             return res.getErrorCode() ==  0 ? null : res.getErrorCode();
                         }
-    
+
                         @Override
                         public String getErrorMessage() {
                             return res.getErrorMessage();
                         }
-    
+
                         @Override
                         public String getLogHolder() {
-                            return res.getLogHolder();
+                            return res.getLogHolderJson();
                         }
                     };
-        
+
                 long sleepTime = maxTime - System.currentTimeMillis();
-        
+
                 if (sleepTime <= 0)
                     throw new NCClientException(String.format("Request timeout: %d", timeout));
-        
+
                 synchronized (mux) {
                     try {
                         mux.wait(sleepTime);
@@ -775,7 +772,7 @@ public class NCClientImpl implements NCClient {
                 }
             }
         }
-        
+
         NCAskSyncBean b =
             checkAndExtract(
                 post(
@@ -790,10 +787,11 @@ public class NCClientImpl implements NCClient {
                 ),
                 NCAskSyncBean.class
             );
-        
+
         return b.getState();
+
     }
-    
+
     @Override
     public long addFeedback(String srvReqId, double score, String comment, Long usrId, String usrExtId)
         throws NCClientException, IOException {
@@ -884,7 +882,7 @@ public class NCClientImpl implements NCClient {
     @Override
     public NCNewCompany addCompany(String name, String website, String country, String region, String city,
         String address, String postalCode, String adminEmail, String adminPasswd, String adminFirstName,
-        String adminLastName, String adminAvatarUrl) throws IOException, NCClientException {
+        String adminLastName, String adminAvatarUrl, Map<String, String> props) throws IOException, NCClientException {
         notNull(name, "name");
         notNull(adminEmail, "adminEmail");
         notNull(adminPasswd, "adminPasswd");
@@ -908,7 +906,8 @@ public class NCClientImpl implements NCClient {
                     Pair.of("adminPasswd", adminPasswd),
                     Pair.of("adminFirstName", adminFirstName),
                     Pair.of("adminLastName", adminLastName),
-                    Pair.of("postalCode", adminAvatarUrl)
+                    Pair.of("postalCode", adminAvatarUrl),
+                    Pair.of("properties", props)
                 ),
                 NCTokenCreationBean.class
             );
@@ -934,7 +933,8 @@ public class NCClientImpl implements NCClient {
         String region,
         String city,
         String address,
-        String postalCode
+        String postalCode,
+        Map<String, String> props
     ) throws IOException, NCClientException {
         notNull(name, "name");
     
@@ -949,7 +949,8 @@ public class NCClientImpl implements NCClient {
                     Pair.of("region", region),
                     Pair.of("city", city),
                     Pair.of("address", address),
-                    Pair.of("postalCode", postalCode)
+                    Pair.of("postalCode", postalCode),
+                    Pair.of("properties", props)
                 ),
                 NCStatusResponseBean.class
             )
diff --git a/src/main/java/org/apache/nlpcraft/client/impl/beans/NCCompanyBean.java b/src/main/java/org/apache/nlpcraft/client/impl/beans/NCCompanyBean.java
index 5b522f8..9d3157e 100644
--- a/src/main/java/org/apache/nlpcraft/client/impl/beans/NCCompanyBean.java
+++ b/src/main/java/org/apache/nlpcraft/client/impl/beans/NCCompanyBean.java
@@ -20,6 +20,8 @@ package org.apache.nlpcraft.client.impl.beans;
 import com.google.gson.annotations.SerializedName;
 import org.apache.nlpcraft.client.NCCompany;
 
+import java.util.Map;
+
 /**
  * REST bean.
  */
@@ -32,6 +34,7 @@ public class NCCompanyBean extends NCStatusResponseBean implements NCCompany {
     @SerializedName("city") private String city;
     @SerializedName("address") private String address;
     @SerializedName("postalCode") private String postalCode;
+    @SerializedName("properties") private Map<String, String> properties;
     
     @Override public long getId() {
         return id;
@@ -57,4 +60,7 @@ public class NCCompanyBean extends NCStatusResponseBean implements NCCompany {
     @Override public String getPostalCode() {
         return postalCode;
     }
+    @Override public Map<String, String> getProperties() {
+        return properties;
+    }
 }
diff --git a/src/test/java/org/apache/nlpcraft/client/NCAskSyncTest.java b/src/test/java/org/apache/nlpcraft/client/NCAskSyncTest.java
index 4a0c80a..8bef883 100644
--- a/src/test/java/org/apache/nlpcraft/client/NCAskSyncTest.java
+++ b/src/test/java/org/apache/nlpcraft/client/NCAskSyncTest.java
@@ -21,6 +21,8 @@ import org.apache.nlpcraft.client.models.NCCommonSpecModel;
 import org.apache.nlpcraft.model.NCModel;
 import org.junit.jupiter.api.Test;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Optional;
 import java.util.function.Consumer;
 
@@ -43,17 +45,23 @@ class NCAskSyncTest extends NCTestAdapter {
     private void check(String txt, Consumer<NCResult> resConsumer) throws Exception {
         // Different combinations of input parameters.
         resConsumer.accept(admCli.askSync(MDL_ID, txt, null, true, null, null));
-        resConsumer.accept(admCli.askSync(MDL_ID, txt, "{\"a\": 1}", true, null, null));
-        resConsumer.accept(admCli.askSync(MDL_ID, txt, "data", false, null, null));
-        resConsumer.accept(admCli.askSync(MDL_ID, txt, "data", false, admUsrId, null));
+
+        Map<String, Object> data = new HashMap<>();
+
+        data.put("a", 1);
+        data.put("b", "b1");
+
+        resConsumer.accept(admCli.askSync(MDL_ID, txt, data, true, null, null));
+        resConsumer.accept(admCli.askSync(MDL_ID, txt, data, false, null, null));
+        resConsumer.accept(admCli.askSync(MDL_ID, txt, data, false, admUsrId, null));
         
         String extId = "extId";
     
-        resConsumer.accept(admCli.askSync(MDL_ID, txt, "data", false, null, extId));
+        resConsumer.accept(admCli.askSync(MDL_ID, txt, data, false, null, extId));
     
         long id = get(admCli.getAllUsers(), (u) -> extId.equals(u.getExternalId())).getId();
     
-        resConsumer.accept(admCli.askSync(MDL_ID, txt, "data", false, id, extId));
+        resConsumer.accept(admCli.askSync(MDL_ID, txt, data, false, id, extId));
     }
     
     /**
@@ -64,7 +72,7 @@ class NCAskSyncTest extends NCTestAdapter {
     void test() throws Exception {
         // Only latin charset is supported.
         check("El tiempo en EspaƱa", this::checkError);
-    
+
         check("test", this::checkOk);
     }
 }
diff --git a/src/test/java/org/apache/nlpcraft/client/NCClearDialogTest.java b/src/test/java/org/apache/nlpcraft/client/NCClearDialogTest.java
index 92a871d..ec8d55f 100644
--- a/src/test/java/org/apache/nlpcraft/client/NCClearDialogTest.java
+++ b/src/test/java/org/apache/nlpcraft/client/NCClearDialogTest.java
@@ -61,8 +61,7 @@ class NCClearDialogTest extends NCTestAdapter {
         check("test1", this::checkOk);
 
         // There are too much `test1` before.
-        // TODO:
-        //check("test2", this::checkError);
+        check("test2", this::checkError);
     }
 
     /**
diff --git a/src/test/java/org/apache/nlpcraft/client/NCCompanyTest.java b/src/test/java/org/apache/nlpcraft/client/NCCompanyTest.java
index bdb16a3..0225602 100644
--- a/src/test/java/org/apache/nlpcraft/client/NCCompanyTest.java
+++ b/src/test/java/org/apache/nlpcraft/client/NCCompanyTest.java
@@ -19,6 +19,8 @@ package org.apache.nlpcraft.client;
 
 import org.junit.jupiter.api.Test;
 
+import java.util.HashMap;
+import java.util.Map;
 import java.util.UUID;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -37,6 +39,7 @@ class NCCompanyTest extends NCTestAdapter {
      * @param city
      * @param address
      * @param postalCode
+     * @param props
      */
     private static void check(
         NCCompany comp,
@@ -46,7 +49,8 @@ class NCCompanyTest extends NCTestAdapter {
         String region,
         String city,
         String address,
-        String postalCode
+        String postalCode,
+        Map<String, String> props
     ) {
         assertEquals(comp.getName(), name);
         assertEquals(comp.getWebsite(), website);
@@ -55,15 +59,17 @@ class NCCompanyTest extends NCTestAdapter {
         assertEquals(comp.getCity(), city);
         assertEquals(comp.getAddress(), address);
         assertEquals(comp.getPostalCode(), postalCode);
+        assertEquals(comp.getProperties(), props);
     }
     
     /**
      *
      * @param name
+     * @param props
      * @param other
      * @throws Exception
      */
-    private void test0(String name, String other) throws Exception {
+    private void test0(String name, Map<String, String> props, String other) throws Exception {
         String adminEmail = "test@" + UUID.randomUUID() + ".com";
         String adminPwd = "test";
     
@@ -79,7 +85,8 @@ class NCCompanyTest extends NCTestAdapter {
                 other, adminEmail, adminPwd,
                 "test",
                 "test",
-                null
+                null,
+                props
             );
     
         // Prepares client for this company.
@@ -90,25 +97,29 @@ class NCCompanyTest extends NCTestAdapter {
             get(newCompClient.getAllUsers(), (u) -> data.getAdminUserId() == u.getId());
     
             // Checks created company fields.
-            check(newCompClient.getCompany(), name, other, other, other, other, other, other);
+            check(newCompClient.getCompany(), name, other, other, other, other, other, other, props);
     
             name = "new " + name;
             other = "new " + other;
+
+            if (props != null) {
+                props.put("new", "new");
+            }
     
             // Updates fields.
-            newCompClient.updateCompany(name, other, other, other, other, other, other);
+            newCompClient.updateCompany(name, other, other, other, other, other, other, props);
     
             // Checks updates company fields.
-            check(newCompClient.getCompany(), name, other, other, other, other, other, other);
+            check(newCompClient.getCompany(), name, other, other, other, other, other, other, props);
     
             // Updates fields.
             newCompClient.updateCompany(
-                name, null, null, null, null, null, null
+                name, null, null, null, null, null, null, null
             );
     
             // Checks updates company fields.
             check(
-                newCompClient.getCompany(), name, null, null, null, null, null, null
+                newCompClient.getCompany(), name, null, null, null, null, null, null, null
             );
     
             // Checks method.
@@ -126,7 +137,11 @@ class NCCompanyTest extends NCTestAdapter {
      */
     @Test
     void test() throws Exception {
-        test0("company", "company");
-        test0("company", null);
+        Map<String, String> props = new HashMap<>();
+
+        props.put("k1", "v1");
+
+        test0("company", props, "company");
+        test0("company", null, null);
     }
 }
diff --git a/src/test/java/org/apache/nlpcraft/client/NCTestAdapter.java b/src/test/java/org/apache/nlpcraft/client/NCTestAdapter.java
index bdd7a9c..d78205a 100644
--- a/src/test/java/org/apache/nlpcraft/client/NCTestAdapter.java
+++ b/src/test/java/org/apache/nlpcraft/client/NCTestAdapter.java
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 
 import java.io.IOException;
+import java.util.Collections;
 import java.util.List;
 import java.util.Optional;
 import java.util.function.Predicate;
@@ -73,7 +74,7 @@ abstract class NCTestAdapter {
         mdlClass = getModelClass().orElse(null);
 
         if (mdlClass != null)
-            NCEmbeddedProbe.start(mdlClass);
+            NCEmbeddedProbe.start("nlpcraft.conf", Collections.singleton(mdlClass.getName()));
 
         admCli = new NCClientBuilder().build();
         
diff --git a/src/test/java/org/apache/nlpcraft/client/NCUserTest.java b/src/test/java/org/apache/nlpcraft/client/NCUserTest.java
index 61151de..7b7d994 100644
--- a/src/test/java/org/apache/nlpcraft/client/NCUserTest.java
+++ b/src/test/java/org/apache/nlpcraft/client/NCUserTest.java
@@ -22,6 +22,7 @@ import org.apache.nlpcraft.model.NCModel;
 import org.junit.jupiter.api.Test;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 
 import static org.apache.nlpcraft.client.models.NCCommonSpecModel.MDL_ID;
@@ -46,6 +47,7 @@ class NCUserTest extends NCTestAdapter {
      * @param avatar
      * @param isAdmin
      * @param extId
+     * @param props
      */
     private static void check(
         NCUser u,
@@ -54,7 +56,8 @@ class NCUserTest extends NCTestAdapter {
         String lastName,
         String avatar,
         boolean isAdmin,
-        String extId
+        String extId,
+        Map<String, String> props
     ) {
         assertEquals(u.getEmail(), email);
         assertEquals(u.getFirstName(), firstName);
@@ -62,6 +65,7 @@ class NCUserTest extends NCTestAdapter {
         assertEquals(u.getAvatarUrl(), avatar);
         assertEquals(u.isAdmin(), isAdmin);
         assertEquals(u.getExternalId(), extId);
+        assertEquals(u.getProperties(), props);
     }
     
     /**
@@ -72,7 +76,7 @@ class NCUserTest extends NCTestAdapter {
     private static void check(NCUser u1, NCUser u2) {
         assertEquals(u1.getId(), u2.getId());
         
-        check(u1, u2.getEmail(), u2.getFirstName(), u2.getLastName(), u2.getAvatarUrl(), u2.isAdmin(), u2.getExternalId());
+        check(u1, u2.getEmail(), u2.getFirstName(), u2.getLastName(), u2.getAvatarUrl(), u2.isAdmin(), u2.getExternalId(), u2.getProperties());
     }
     
     /**
@@ -90,7 +94,7 @@ class NCUserTest extends NCTestAdapter {
         
         NCUser user = get(users, (u) -> usrId1 == u.getId());
         
-        check(user, "email1@test.com", "first1", "last1", null, true, null);
+        check(user, "email1@test.com", "first1", "last1", null, true, null, null);
         
         admCli.resetUserPassword(usrId1, "pswd2");
         admCli.updateUserAdmin(usrId1, false);
@@ -100,7 +104,7 @@ class NCUserTest extends NCTestAdapter {
     
         user = get(users, (u) -> usrId1 == u.getId());
         
-        check(user, "email1@test.com", "first2", "last2", "av2", false, null);
+        check(user, "email1@test.com", "first2", "last2", "av2", false, null, null);
     
         admCli.deleteUser(usrId1, null);
     
@@ -117,7 +121,7 @@ class NCUserTest extends NCTestAdapter {
     
         user = get(users, (u) -> usrId2 == u.getId());
     
-        check(user, "email1@test.com", "first1", "last1", "av1", false, null);
+        check(user, "email1@test.com", "first1", "last1", "av1", false, null, null);
     
         admCli.deleteUser(usrId2, null);
     
diff --git a/src/test/java/org/apache/nlpcraft/client/models/NCCommonSpecModel.java b/src/test/java/org/apache/nlpcraft/client/models/NCCommonSpecModel.java
index 03b20af..aaac1b3 100644
--- a/src/test/java/org/apache/nlpcraft/client/models/NCCommonSpecModel.java
+++ b/src/test/java/org/apache/nlpcraft/client/models/NCCommonSpecModel.java
@@ -39,7 +39,7 @@ public class NCCommonSpecModel extends NCSpecModelAdapter {
         return Collections.singleton(mkElement("test"));
     }
 
-    @NCIntent("intent=intentId term~{id == 'test'}")
+    @NCIntent("intent=intentId term~{tok_id() == 'test'}")
     public org.apache.nlpcraft.model.NCResult onTest() {
         return org.apache.nlpcraft.model.NCResult.text("OK");
     }
diff --git a/src/test/java/org/apache/nlpcraft/client/models/NCConversationSpecModel.java b/src/test/java/org/apache/nlpcraft/client/models/NCConversationSpecModel.java
index 2050631..a71baab 100644
--- a/src/test/java/org/apache/nlpcraft/client/models/NCConversationSpecModel.java
+++ b/src/test/java/org/apache/nlpcraft/client/models/NCConversationSpecModel.java
@@ -41,7 +41,7 @@ public class NCConversationSpecModel extends NCSpecModelAdapter {
     }
 
     // 'test1' is mandatory, 'test2' is optional.
-    @NCIntent("intent=intentId term~{id == 'test1'} term~{id == 'test2'}?")
+    @NCIntent("intent=intentId term~{tok_id() == 'test1'} term~{tok_id() == 'test2'}?")
     public org.apache.nlpcraft.model.NCResult onTest() {
         return org.apache.nlpcraft.model.NCResult.text("OK");
     }
diff --git a/src/test/java/org/apache/nlpcraft/client/models/NCDialogSpecModel.java b/src/test/java/org/apache/nlpcraft/client/models/NCDialogSpecModel.java
index 1176259..e4e2003 100644
--- a/src/test/java/org/apache/nlpcraft/client/models/NCDialogSpecModel.java
+++ b/src/test/java/org/apache/nlpcraft/client/models/NCDialogSpecModel.java
@@ -41,12 +41,13 @@ public class NCDialogSpecModel extends NCSpecModelAdapter {
         return Stream.of(mkElement("test1"), mkElement("test2")).collect(Collectors.toCollection(HashSet::new));
     }
 
-    @NCIntent("intent=intentId1 term~{id == 'test1'}")
+    @NCIntent("intent=intentId1 term~{tok_id() == 'test1'}")
     public org.apache.nlpcraft.model.NCResult onTest1() {
         return org.apache.nlpcraft.model.NCResult.text("OK");
     }
 
-    @NCIntent("intent=intentId2 flow='intentId1[1,1]' term~{id == 'test2'}")
+    // Flow - `intentId1` must be one time.
+    @NCIntent("intent=intentId2 flow='^(?:intentId1)(^:intentId1)*$' term~{tok_id() == 'test2'}")
     public org.apache.nlpcraft.model.NCResult onTest2() {
         return org.apache.nlpcraft.model.NCResult.text("OK");
     }
diff --git a/src/test/java/org/apache/nlpcraft/client/models/NCSuggestionSpecModel.java b/src/test/java/org/apache/nlpcraft/client/models/NCSuggestionSpecModel.java
index c4875f9..c757ca1 100644
--- a/src/test/java/org/apache/nlpcraft/client/models/NCSuggestionSpecModel.java
+++ b/src/test/java/org/apache/nlpcraft/client/models/NCSuggestionSpecModel.java
@@ -41,7 +41,7 @@ public class NCSuggestionSpecModel extends NCSpecModelAdapter {
     }
 
     @NCIntentSample({"Tests passed well"})
-    @NCIntent("intent=intentId term~{id == 'test'}")
+    @NCIntent("intent=intentId term~{tok_id() == 'test'}")
     public org.apache.nlpcraft.model.NCResult onTest() {
         return org.apache.nlpcraft.model.NCResult.text("OK");
     }