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

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


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

commit 4ac834d97c258625ae5a51e9afcddca6de5ec2d2
Author: Sergey Kamov <[email protected]>
AuthorDate: Tue Oct 12 09:32:30 2021 +0300

    WIP.
---
 .../main/scala/org/apache/nlpcraft/NCNlpcraft.java |  9 ++-
 .../scala/org/apache/nlpcraft/model/NCContext.java |  4 +-
 .../apache/nlpcraft/model/NCDialogFlowItem.java    |  2 +-
 .../org/apache/nlpcraft/model/NCIntentMatch.java   |  2 +-
 .../apache/nlpcraft/model/NCModelBehaviour.java    |  4 +-
 .../scala/org/apache/nlpcraft/model/NCRequest.java |  2 +-
 .../scala/org/apache/nlpcraft/model/NCToken.java   |  3 +
 .../scala/org/apache/nlpcraft/model/NCVariant.java | 88 ----------------------
 .../nlpcraft/model/builders/NCModelBuilder.java    | 23 ++++--
 .../model/builders/NCModelConfigBuilder.java       |  6 +-
 .../src/test/java/org/apache/nlpcraft/NCSpec.java  |  2 +-
 11 files changed, 34 insertions(+), 111 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCNlpcraft.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCNlpcraft.java
index e069613..2da6a1e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCNlpcraft.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCNlpcraft.java
@@ -19,6 +19,7 @@ package org.apache.nlpcraft;
 
 import org.apache.nlpcraft.model.NCResult;
 
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -33,12 +34,12 @@ public interface NCNlpcraft {
     NCResult askSync(String txt, String userId);
     NCResult askSync(String txt);
 
-    List<NCResult> check(Set<String> srvReqIds, int maxRows);
+    List<NCResult> check(Collection<String> reqIds, int maxRows);
     List<NCResult> check(String userId, int maxRows);
-    NCResult check(String srvReqId);
+    NCResult check(String reqId);
 
-    void cancel(Set<String> srvReqIds);
-    void cancel(String srvReqId);
+    void cancel(Collection<String> reqIds);
+    void cancel(String reqId);
     void cancelAll(String userId);
     void cancelAll();
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java
index e8df68f..6209256 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java
@@ -17,7 +17,7 @@
 
 package org.apache.nlpcraft.model;
 
-import java.util.Collection;
+import java.util.*;
 
 /**
  * Data model query context. This context defines fully processed user input 
and its associated data that
@@ -40,7 +40,7 @@ public interface NCContext {
      *
      * @return All parsing variants of this query. Always contains at least 
one variant.
      */
-    Collection<? extends NCVariant> getVariants();
+    Collection<List<NCToken>> getVariants();
 
     /**
      * Gets model instance for this query.
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
index 6ed3c2f..6a75c66 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
@@ -88,7 +88,7 @@ public interface NCDialogFlowItem {
      * @return Sentence parsing variant that produced the matching for the 
winning intent.
      * @see #getIntentTokens()
      */
-    NCVariant getVariant();
+    List<NCToken> getVariant();
 
     /**
      * Gets descriptor of the user on behalf of which the input request was 
submitted.
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java
index d208eb1..1a14f9f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java
@@ -103,5 +103,5 @@ public interface NCIntentMatch  {
      * @return Sentence parsing variant that produced the matching for this 
intent.
      * @see #getIntentTokens() 
      */
-    NCVariant getVariant();
+    List<NCToken> getVariant();
 }
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelBehaviour.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelBehaviour.java
index 5a65448..83ea472 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelBehaviour.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelBehaviour.java
@@ -16,6 +16,8 @@
  */
 
 package org.apache.nlpcraft.model;
+
+import java.util.List;
 /**
  *
  */
@@ -34,7 +36,7 @@ public interface NCModelBehaviour {
      * @param var A variant (list of tokens) to accept or reject.
      * @return {@code True} to accept variant for further processing, {@code 
false} otherwise.
      */
-    default boolean onParsedVariant(NCVariant var) {
+    default boolean onParsedVariant(List<NCToken> var) {
         return true;
     }
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCRequest.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCRequest.java
index b266922..d8db100 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCRequest.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCRequest.java
@@ -45,7 +45,7 @@ public interface NCRequest {
      *
      * @return Server request ID.
      */
-    String getServerRequestId();
+    String getRequestId();
 
     /**
      * Gets normalized text of the user input.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
index a643b40..ae1c246 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCToken.java
@@ -272,4 +272,7 @@ public interface NCToken {
      * @return Internal globally unique system ID of the token.
      */
     String getUnid();
+
+    // TODO: maybe add it?
+    List<Integer> getWordsIndexes();
 }
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCVariant.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCVariant.java
deleted file mode 100644
index 8e83463..0000000
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCVariant.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.model;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * TODO: Let's drop list extending.
- *
- * A parsing variant is a list of tokens representing one possible parsing 
variant of the user input.
- * <p>
- * Note that a given user input can have one or more possible different 
parsing variants. Depending on model
- * configuration a user input can produce hundreds or even thousands of 
parsing variants.
- *
- * @see NCModel#onParsedVariant(NCVariant)
- * @see NCContext#getVariants()
- */
-public interface NCVariant extends List<NCToken> {
-    /**
-     * Utility method that returns all non-freeword tokens. It's equivalent to:
-     * <pre class="brush: java">
-     *     return stream().filter(tok -&gt; !tok.isFreeWord() &amp;&amp; 
!tok.isStopWord()).collect(Collectors.toList());
-     * </pre>
-     *
-     * @return All non-freeword tokens.
-     * @see NCToken#isFreeWord()
-     */
-    default List<NCToken> getMatchedTokens() {
-        return stream().filter(tok -> !tok.isFreeWord() && 
!tok.isStopWord()).collect(Collectors.toList());
-    }
-
-    /**
-     * Utility method that returns all freeword tokens. It's equivalent to:
-     * <pre class="brush: java">
-     *     return 
stream().filter(NCToken::isFreeWord).collect(Collectors.toList());
-     * </pre>
-     *
-     * @return All freeword tokens.
-     * @see NCToken#isFreeWord()
-     */
-    default List<NCToken> getFreeTokens() {
-        return 
stream().filter(NCToken::isFreeWord).collect(Collectors.toList());
-    }
-
-    /**
-     * Utility method that returns all stop word tokens. It's equivalent to:
-     * <pre class="brush: java">
-     *     return 
stream().filter(NCToken::isStopWord).collect(Collectors.toList());
-     * </pre>
-     *
-     * @return All stop word tokens.
-     * @see NCToken#isAbstract()
-     */
-    default List<NCToken> getStopWordTokens() {
-        return 
stream().filter(NCToken::isStopWord).collect(Collectors.toList());
-    }
-
-    /**
-     * Utility method that returns all user-defined tokens. It's equivalent to:
-     * <pre class="brush: java">
-     *     return 
stream().filter(NCToken::isUserDefined).collect(Collectors.toList());
-     * </pre>
-     *
-     * @return All user-defined tokens.
-     * @see NCToken#isUserDefined()
-     */
-    default List<NCToken> getUserDefinedTokens() {
-        // TODO: Why is it dropped?
-        //return 
stream().filter(NCToken::isUserDefined).collect(Collectors.toList());
-        return null;
-    }
-}
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelBuilder.java
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelBuilder.java
index d905deb..7f72fba 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelBuilder.java
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelBuilder.java
@@ -27,42 +27,49 @@ import java.util.List;
 import java.util.Map;
 
 public class NCModelBuilder {
+    // Intents or Behaviour - mandatory.
+
+    // Config.
     public NCModelBuilder withConfig(NCModelConfig cfg) {
         return null;
     }
+
+    // Behaviour.
     public NCModelBuilder withBehaviour(NCModelBehaviour behaviour) {
         return null;
     }
 
-    // Intents or Behaviour - mandatory.
-
-    // 5. Intents related methods:
-    // model class by default + for static methods of given classes.
+    // Intents related methods:
+    // Static methods of given classes.
     // Scanned for NCIntent, NCIntentRef, NCIntentSample, NCIntentSampleRef
     public NCModelBuilder withIntentsClasses(List<Class<?>> classes) {
         return null;
     }
 
-    // model class by default + for methods of given instances.
+    // Methods of given instances.
     // Scanned for NCIntent, NCIntentRef, NCIntentSample, NCIntentSampleRef
     public NCModelBuilder withIntentsObjects(List<Object> objs) {
         return null;
     }
 
     // Manually defined intents.
+    // Code in classes and objects can have references on defined below 
intents and samples and via NCIntentRef and NCIntentSampleRef.
     public NCModelBuilder withIntents(List<String> objs) {
         return null;
     }
-    public NCModelBuilder withIntentsFromFiles(List<File> objs) {
+    public NCModelBuilder withIntentsSamples(Map<String, List<List<String>>> 
map) {
         return null;
     }
-    public NCModelBuilder withIntentsFromUrls(List<URL> objs) {
+
+    // Files only for intents, not for samples ?
+    public NCModelBuilder withIntentsFromFiles(List<File> objs) {
         return null;
     }
-    public NCModelBuilder withIntentsSamplesMap(Map<String, 
List<List<String>>> map) {
+    public NCModelBuilder withIntentsFromUrls(List<URL> objs) {
         return null;
     }
 
+
     public NCModel getModel() {
         return null;
     }
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelConfigBuilder.java
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelConfigBuilder.java
index a77cd81..9c30373 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelConfigBuilder.java
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelConfigBuilder.java
@@ -31,10 +31,9 @@ import java.util.function.Function;
 // All other - optional.
 public class NCModelConfigBuilder {
     // 1. Common  properties.
-    // Mandatory.
     public NCModelConfigBuilder withId(String description) {
         return null;
-    }
+    } // Mandatory.
     public NCModelConfigBuilder withName(String description) {
         return null;
     }
@@ -84,7 +83,7 @@ public class NCModelConfigBuilder {
         return null;
     }
 
-    // 2. Words - for built stop/swear EN detection. (Suspicious vai 
dictioanry)
+    // 2. Words - for built stop/swear EN detection. (Suspicious via 
dictionary)
     public NCModelConfigBuilder withAdditionalStopWords(Set<String> 
additionalStopWords) {
         return null;
     }
@@ -118,7 +117,6 @@ public class NCModelConfigBuilder {
     public NCModelConfigBuilder withNerParsers(List<NCNlpNerParser> parsers) {
         return null;
     }
-    // Intents or Behaviour - mandatory.
 
     public NCModelConfig getConfig() {
         return null;
diff --git a/nlpcraft/src/test/java/org/apache/nlpcraft/NCSpec.java 
b/nlpcraft/src/test/java/org/apache/nlpcraft/NCSpec.java
index b01ca24..69e2f75 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/NCSpec.java
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/NCSpec.java
@@ -104,7 +104,7 @@ public class NCSpec {
                 
withIntentsClasses(Collections.singletonList(SomeClassWithIntents.class)).
                 // You can set link on this if prepare model without builder.
                 withIntentsObjects(Collections.singletonList(new 
SomeClassWithIntents())).
-                withIntentsSamplesMap(
+                withIntentsSamples(
                     new HashMap<>() { { put("intent1", 
Arrays.asList(Arrays.asList("sample1", "sample2"))); } }
                 ).
                 // Model behaviour.

Reply via email to