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

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


The following commit(s) were added to refs/heads/master-0.7.2 by this push:
     new 8c5921b  WIP.
8c5921b is described below

commit 8c5921baf8d0c2dd77ecc0fd910a04f47032cb08
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Nov 23 17:27:06 2020 +0300

    WIP.
---
 .../java/org/apache/nlpcraft/client/NCClient.java  |  3 +
 .../nlpcraft/client/NCSuggestionSynonym.java       | 31 ++++++++++
 .../apache/nlpcraft/client/impl/NCClientImpl.java  | 23 ++++++-
 .../client/impl/beans/NCSuggestionSynonymBean.java | 71 ++++++++++++++++++++++
 .../impl/beans/NCSuggestionSynonymResultBean.java  | 32 ++++++++++
 .../{NCConversationTest.java => NCClearTest.java}  | 17 ++++--
 .../{NCConversationTest.java => NCModelTest.java}  | 55 +++++++----------
 7 files changed, 192 insertions(+), 40 deletions(-)

diff --git a/src/main/java/org/apache/nlpcraft/client/NCClient.java 
b/src/main/java/org/apache/nlpcraft/client/NCClient.java
index 79c7432..01dea5a 100644
--- a/src/main/java/org/apache/nlpcraft/client/NCClient.java
+++ b/src/main/java/org/apache/nlpcraft/client/NCClient.java
@@ -542,6 +542,9 @@ public interface NCClient {
      * @throws IOException Thrown in case of generic I/O errors.
      */
     void deleteCompany() throws NCClientException, IOException;
+
+    // TODO:
+    NCSuggestionSynonym suggestSynonyms(String mdlId, Double minScore)  throws 
NCClientException, IOException;
     
     /**
      * Closes the client and signs out from the REST server. Any further calls 
to this client will result in
diff --git a/src/main/java/org/apache/nlpcraft/client/NCSuggestionSynonym.java 
b/src/main/java/org/apache/nlpcraft/client/NCSuggestionSynonym.java
new file mode 100644
index 0000000..fd53743
--- /dev/null
+++ b/src/main/java/org/apache/nlpcraft/client/NCSuggestionSynonym.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.client;
+
+import java.util.List;
+
+// TODO:
+public interface NCSuggestionSynonym {
+    String getModelId();
+    double getMinScore();
+    long getDurationMs();
+    long getTimestamp();
+    String getError();
+    List<Object> getSuggestions(); // TODO:  ?
+    List<String> getWarnings();
+}
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 f8fec25..e3ef957 100644
--- a/src/main/java/org/apache/nlpcraft/client/impl/NCClientImpl.java
+++ b/src/main/java/org/apache/nlpcraft/client/impl/NCClientImpl.java
@@ -39,6 +39,7 @@ import org.apache.nlpcraft.client.NCFeedback;
 import org.apache.nlpcraft.client.NCNewCompany;
 import org.apache.nlpcraft.client.NCProbe;
 import org.apache.nlpcraft.client.NCResult;
+import org.apache.nlpcraft.client.NCSuggestionSynonym;
 import org.apache.nlpcraft.client.NCUser;
 import org.apache.nlpcraft.client.impl.beans.NCAskBean;
 import org.apache.nlpcraft.client.impl.beans.NCAskSyncBean;
@@ -52,6 +53,7 @@ import org.apache.nlpcraft.client.impl.beans.NCProbesAllBean;
 import org.apache.nlpcraft.client.impl.beans.NCRequestStateBean;
 import org.apache.nlpcraft.client.impl.beans.NCSigninBean;
 import org.apache.nlpcraft.client.impl.beans.NCStatusResponseBean;
+import org.apache.nlpcraft.client.impl.beans.NCSuggestionSynonymResultBean;
 import org.apache.nlpcraft.client.impl.beans.NCTokenCreationBean;
 import org.apache.nlpcraft.client.impl.beans.NCUserAddBean;
 import org.apache.nlpcraft.client.impl.beans.NCUserBean;
@@ -324,7 +326,7 @@ public class NCClientImpl implements NCClient {
      */
     private <T extends NCStatusResponseBean> T checkAndExtract(String js, Type 
type) throws NCClientException {
         T t = gson.fromJson(js, type);
-        
+
         checkStatus(t.getStatus());
         
         return t;
@@ -340,7 +342,7 @@ public class NCClientImpl implements NCClient {
      * @throws IllegalStateException
      */
     @SafeVarargs
-    private final String post(String url, Pair<String, Object>... ps) throws 
NCClientException, IOException {
+    private String post(String url, Pair<String, Object>... ps) throws 
NCClientException, IOException {
         if (!started)
             throw new IllegalStateException("Client is not initialized.");
         
@@ -403,7 +405,7 @@ public class NCClientImpl implements NCClient {
     
                 if (js == null)
                     throw new NCClientException(String.format("Unexpected 
empty response [code=%d]", code));
-    
+
                 if (code == 200)
                     return js;
     
@@ -990,4 +992,19 @@ public class NCClientImpl implements NCClient {
             )
         );
     }
+
+    @Override
+    public NCSuggestionSynonym suggestSynonyms(String mdlId, Double minScore) 
throws NCClientException, IOException {
+        NCSuggestionSynonymResultBean res = checkAndExtract(
+            post(
+                "model/sugsyn",
+                Pair.of("acsTok", acsTok),
+                Pair.of("mdlId", mdlId),
+                Pair.of("minScore", minScore)
+            ),
+            NCSuggestionSynonymResultBean.class
+        );
+
+        return res.getResult();
+    }
 }
diff --git 
a/src/main/java/org/apache/nlpcraft/client/impl/beans/NCSuggestionSynonymBean.java
 
b/src/main/java/org/apache/nlpcraft/client/impl/beans/NCSuggestionSynonymBean.java
new file mode 100644
index 0000000..85a9fef
--- /dev/null
+++ 
b/src/main/java/org/apache/nlpcraft/client/impl/beans/NCSuggestionSynonymBean.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.client.impl.beans;
+
+import com.google.gson.annotations.SerializedName;
+import org.apache.nlpcraft.client.NCSuggestionSynonym;
+
+import java.util.List;
+
+/**
+ * REST bean.
+ */
+public class NCSuggestionSynonymBean implements NCSuggestionSynonym {
+    @SerializedName("modelId") private String modelId;
+    @SerializedName("minScore") private double minScore;
+    @SerializedName("durationMs") private long durationMs;
+    @SerializedName("timestamp") private long timestamp;
+    @SerializedName("error") private String error;
+    @SerializedName("suggestions") private List<Object> suggestions;
+    @SerializedName("warnings") private java.util.List<String> warnings;
+
+    @Override
+    public String getModelId() {
+        return modelId;
+    }
+
+    @Override
+    public double getMinScore() {
+        return minScore;
+    }
+
+    @Override
+    public long getDurationMs() {
+        return durationMs;
+    }
+
+    @Override
+    public long getTimestamp() {
+        return timestamp;
+    }
+
+    @Override
+    public String getError() {
+        return error;
+    }
+
+    @Override
+    public List<Object> getSuggestions() {
+        return suggestions;
+    }
+
+    @Override
+    public List<String> getWarnings() {
+        return warnings;
+    }
+}
diff --git 
a/src/main/java/org/apache/nlpcraft/client/impl/beans/NCSuggestionSynonymResultBean.java
 
b/src/main/java/org/apache/nlpcraft/client/impl/beans/NCSuggestionSynonymResultBean.java
new file mode 100644
index 0000000..6851382
--- /dev/null
+++ 
b/src/main/java/org/apache/nlpcraft/client/impl/beans/NCSuggestionSynonymResultBean.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.client.impl.beans;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * REST bean.
+ */
+public class NCSuggestionSynonymResultBean extends NCStatusResponseBean  {
+    @SerializedName("result") private NCSuggestionSynonymBean result;
+
+    // TODO:
+    public NCSuggestionSynonymBean getResult() {
+        return result;
+    }
+}
diff --git a/src/test/java/org/apache/nlpcraft/client/NCConversationTest.java 
b/src/test/java/org/apache/nlpcraft/client/NCClearTest.java
similarity index 86%
copy from src/test/java/org/apache/nlpcraft/client/NCConversationTest.java
copy to src/test/java/org/apache/nlpcraft/client/NCClearTest.java
index 42e0942..96d2c13 100644
--- a/src/test/java/org/apache/nlpcraft/client/NCConversationTest.java
+++ b/src/test/java/org/apache/nlpcraft/client/NCClearTest.java
@@ -25,9 +25,9 @@ import java.util.Optional;
 import java.util.function.Consumer;
 
 /**
- * REST client test. Methods `clear/conversation`.
+ * REST client test. Methods `clear/conversation` and `clear/dialog`.
  */
-class NCConversationTest extends NCTestAdapter {
+class NCClearTest extends NCTestAdapter {
     /**
      *
      */
@@ -51,7 +51,7 @@ class NCConversationTest extends NCTestAdapter {
      * @throws Exception
      */
     @Test
-    void test1() throws Exception {
+    void testClearConversation1() throws Exception {
         check("Ping me in 3 minutes", this::checkOk);
 
         // Should be answered with conversation.
@@ -67,7 +67,7 @@ class NCConversationTest extends NCTestAdapter {
      * @throws Exception
      */
     @Test
-    void test2() throws Exception {
+    void testClearConversation2() throws Exception {
         check("Ping me in 3 minutes", this::checkOk);
 
         // Should be answered with conversation.
@@ -80,4 +80,13 @@ class NCConversationTest extends NCTestAdapter {
         // Cannot be answered without conversation.
         check("3 minutes", this::checkError);
     }
+
+    /**
+     *
+     * @throws Exception
+     */
+    @Test
+    void testClearDialog() throws Exception {
+        admCli.clearDialog(MDL_ID, null, null);
+    }
 }
diff --git a/src/test/java/org/apache/nlpcraft/client/NCConversationTest.java 
b/src/test/java/org/apache/nlpcraft/client/NCModelTest.java
similarity index 52%
rename from src/test/java/org/apache/nlpcraft/client/NCConversationTest.java
rename to src/test/java/org/apache/nlpcraft/client/NCModelTest.java
index 42e0942..d1e2aa9 100644
--- a/src/test/java/org/apache/nlpcraft/client/NCConversationTest.java
+++ b/src/test/java/org/apache/nlpcraft/client/NCModelTest.java
@@ -22,12 +22,16 @@ import org.apache.nlpcraft.model.NCModel;
 import org.junit.jupiter.api.Test;
 
 import java.util.Optional;
-import java.util.function.Consumer;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
- * REST client test. Methods `clear/conversation`.
+ * REST client test. Methods `model/sugsyn`.
  */
-class NCConversationTest extends NCTestAdapter {
+class NCModelTest extends NCTestAdapter {
     /**
      *
      */
@@ -39,45 +43,30 @@ class NCConversationTest extends NCTestAdapter {
     }
 
     /**
-     * @param txt
-     * @param resConsumer
-     * @throws Exception
-     */
-    private void check(String txt, Consumer<NCResult> resConsumer) throws 
Exception {
-        resConsumer.accept(admCli.askSync(MDL_ID, txt, null, true, null, 
null));
-    }
-
-    /**
+     *
+     * @param s
+     * @param minScore
      * @throws Exception
      */
-    @Test
-    void test1() throws Exception {
-        check("Ping me in 3 minutes", this::checkOk);
-
-        // Should be answered with conversation.
-        check("3 minutes", this::checkOk);
+    private static void check(NCSuggestionSynonym s, double minScore) {
+        System.out.println(s);
 
-        admCli.clearConversation(MDL_ID, null, null);
+        assertNotNull(s);
 
-        // Cannot be answered without conversation.
-        check("3 minutes", this::checkError);
+        assertNull(s.getError());
+        assertNotNull(s.getModelId());
+        assertNotNull(s.getSuggestions());
+        assertFalse(s.getSuggestions().isEmpty());
+        assertFalse(s.getSuggestions().isEmpty());
+        assertTrue(s.getMinScore() >= minScore);
     }
 
     /**
      * @throws Exception
      */
     @Test
-    void test2() throws Exception {
-        check("Ping me in 3 minutes", this::checkOk);
-
-        // Should be answered with conversation.
-        check("3 minutes", this::checkOk);
-
-        admCli.clearConversation(MDL_ID,
-            // Finds its own ID.
-            get(admCli.getAllUsers(), (u) -> 
NCClientBuilder.DFLT_EMAIL.equals(u.getEmail())).getId(), null);
-
-        // Cannot be answered without conversation.
-        check("3 minutes", this::checkError);
+    void testSuggestionSynonym() throws Exception {
+        check(admCli.suggestSynonyms(MDL_ID, null), 0);
+        check(admCli.suggestSynonyms(MDL_ID, 0.5), 0.5);
     }
 }

Reply via email to