This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch master-model
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/master-model by this push:
new aaeff61 WIP.
aaeff61 is described below
commit aaeff61075526c1d6d9423575366bc54502f33d8
Author: Sergey Kamov <[email protected]>
AuthorDate: Fri Oct 8 08:22:50 2021 +0300
WIP.
---
.../org/apache/nlpcraft/model/NCCustomParser.java | 2 +-
.../org/apache/nlpcraft/model/NCCustomWord.java | 18 +-
.../scala/org/apache/nlpcraft/model/NCModel.java | 217 ++++++++++++++++--
.../org/apache/nlpcraft/model/NCModelConfig.java | 253 ---------------------
.../org/apache/nlpcraft/model/NCNlpcraft.java | 30 +++
.../nlpcraft/model/builders/NCModelBuilder.java | 177 +++++++++++++-
.../model/builders/NCModelConfigBuilder.java | 171 --------------
.../nlpcraft/model/builders/NCNlpcraftBuilder.java | 18 ++
.../org/apache/nlpcraft/model/nlp/NCNlpParser.java | 7 +
.../org/apache/nlpcraft/model/nlp/NCNlpWord.java | 12 +
.../java/org/apache/nlpcraft/model/NCSpec.java | 49 ++--
11 files changed, 461 insertions(+), 493 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
index 846282d..91601f5 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
@@ -20,5 +20,5 @@ package org.apache.nlpcraft.model;
import java.util.*;
public interface NCCustomParser {
- List<NCCustomElement> parse(NCRequest req, NCModelConfig mdl,
List<NCCustomWord> words, List<NCCustomElement> elements);
+ List<NCCustomElement> parse(NCRequest req, NCModel mdl, List<NCCustomWord>
words, List<NCCustomElement> elements);
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomWord.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomWord.java
index 8806f98..51b2e0f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomWord.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomWord.java
@@ -17,23 +17,9 @@
package org.apache.nlpcraft.model;
-public interface NCCustomWord {
- String getNormalizedText();
-
- String getOriginalText();
-
- int getStartCharIndex();
-
- int getEndCharIndex();
-
- String getPos();
-
- String getPosDescription();
-
- String getLemma();
-
- String getStem();
+import org.apache.nlpcraft.model.nlp.NCNlpWord;
+public interface NCCustomWord extends NCNlpWord {
boolean isStopWord();
boolean isBracketed();
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModel.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModel.java
index 224da14..603ad6b 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModel.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModel.java
@@ -17,38 +17,211 @@
package org.apache.nlpcraft.model;
+import org.apache.nlpcraft.model.nlp.NCNlpParser;
+import org.apache.nlpcraft.model.nlp.NCNlpWord;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Set;
import java.util.Map;
import java.util.List;
+import java.util.function.Function;
public interface NCModel {
- NCModelConfig getModelConfig();
+ long CONV_TIMEOUT_MIN = 0L;
+ long CONV_TIMEOUT_MAX = Long.MAX_VALUE;
+ long MAX_UNKNOWN_WORDS_MIN = 0L;
+ long MAX_UNKNOWN_WORDS_MAX = Long.MAX_VALUE;
+ long MAX_FREE_WORDS_MIN = 0L;
+ long MAX_FREE_WORDS_MAX = Long.MAX_VALUE;
+ long MAX_SUSPICIOUS_WORDS_MIN = 0L;
+ long MAX_SUSPICIOUS_WORDS_MAX = Long.MAX_VALUE;
+ long MIN_WORDS_MIN = 1L;
+ long MIN_WORDS_MAX = Long.MAX_VALUE;
+ long MIN_NON_STOPWORDS_MIN = 0L;
+ long MIN_NON_STOPWORDS_MAX = Long.MAX_VALUE;
+ long MIN_TOKENS_MIN = 0L;
+ long MIN_TOKENS_MAX = Long.MAX_VALUE;
+ long MAX_TOKENS_MIN = 0L;
+ long MAX_TOKENS_MAX = 100L;
+ long MAX_WORDS_MIN = 1L;
+ long MAX_WORDS_MAX = 100L;
+ long MAX_SYN_MIN = 1L;
+ long MAX_SYN_MAX = Long.MAX_VALUE;
+ long CONV_DEPTH_MIN = 1L;
+ long CONV_DEPTH_MAX = Long.MAX_VALUE;
+ int MODEL_ID_MAXLEN = 32;
+ int MODEL_NAME_MAXLEN = 64;
+ int MODEL_VERSION_MAXLEN = 16;
+ int MODEL_ELEMENT_ID_MAXLEN = 64;
+ int DFLT_MAX_ELEMENT_SYNONYMS = 1000;
+ int DFLT_MAX_TOTAL_SYNONYMS = Integer.MAX_VALUE;
+ boolean DFLT_MAX_SYNONYMS_THRESHOLD_ERROR = false;
+ long DFLT_CONV_TIMEOUT_MS = Duration.ofMinutes(60).toMillis();
+ int DFLT_CONV_DEPTH = 3;
+ Map<String, Object> DFLT_METADATA = new HashMap<>();
+ int DFLT_MAX_UNKNOWN_WORDS = Integer.MAX_VALUE;
+ int DFLT_MAX_FREE_WORDS = Integer.MAX_VALUE;
+ int DFLT_MAX_SUSPICIOUS_WORDS = 0;
+ int DFLT_MIN_WORDS = 1;
+ int DFLT_MAX_WORDS = 50;
+ int DFLT_MIN_TOKENS = 0;
+ int DFLT_MAX_TOKENS = 50;
+ int DFLT_MIN_NON_STOPWORDS = 0;
+ boolean DFLT_IS_SWEAR_WORDS_ALLOWED = false;
+ boolean DFLT_IS_NO_NOUNS_ALLOWED = true;
+ boolean DFLT_IS_NO_USER_TOKENS_ALLOWED = true;
+ boolean DFLT_IS_STOPWORDS_ALLOWED = true;
- // Lifecycle. TODO: I am not sure that we need them. Look at it after
Server API development.
- void start();
- void stop();
+ // Common.
+ String getId();
+ String getName();
+ String getVersion();
+ default String getDescription() {
+ return null;
+ }
+ default String getOrigin() {
+ return getClass().getCanonicalName();
+ }
+
+ // Propeties.
+ default int getMaxUnknownWords() {
+ return DFLT_MAX_UNKNOWN_WORDS;
+ }
+
+ default int getMaxFreeWords() {
+ return DFLT_MAX_FREE_WORDS;
+ }
+
+ default int getMaxSuspiciousWords() {
+ return DFLT_MAX_SUSPICIOUS_WORDS;
+ }
+
+ default int getMinWords() {
+ return DFLT_MIN_WORDS;
+ }
+
+ default int getMaxWords() {
+ return DFLT_MAX_WORDS;
+ }
+
+ default int getMinTokens() {
+ return DFLT_MIN_TOKENS;
+ }
+
+ default int getMaxTokens() {
+ return DFLT_MAX_TOKENS;
+ }
+
+ default int getMinNonStopwords() {
+ return DFLT_MIN_NON_STOPWORDS;
+ }
+
+ default boolean isSwearWordsAllowed() {
+ return DFLT_IS_SWEAR_WORDS_ALLOWED;
+ }
+
+ default boolean isNoNounsAllowed() {
+ return DFLT_IS_NO_NOUNS_ALLOWED;
+ }
+
+ default int getMaxTotalSynonyms() {
+ return DFLT_MAX_TOTAL_SYNONYMS;
+ }
+
+ default boolean isNoUserTokensAllowed() {
+ return DFLT_IS_NO_USER_TOKENS_ALLOWED;
+ }
+
+ default Map<String, Object> getMetadata() {
+ return DFLT_METADATA;
+ }
+
+ default Set<String> getAdditionalStopWords() {
+ return Collections.emptySet();
+ }
- // NLP API.
- String ask(String txt, Map<String, Object> data, boolean enableLog, String
userId);
- String ask(String txt, String userId);
- String ask(String txt);
+ default Set<String> getExcludedStopWords() {
+ return Collections.emptySet();
+ }
- NCResult askSync(String txt, Map<String, Object> data, boolean enableLog,
String userId);
- NCResult askSync(String txt, String userId);
- NCResult askSync(String txt);
+ default Set<String> getSuspiciousWords() {
+ return Collections.emptySet();
+ }
- List<NCResult> check(Set<String> srvReqIds, int maxRows);
- List<NCResult> check(String userId, int maxRows);
- NCResult check(String srvReqId);
+ default List<NCCustomParser> getParsers() {
+ return Collections.emptyList();
+ }
- void cancel(Set<String> srvReqIds);
- void cancel(String srvReqId);
- void cancelAll(String userId);
- void cancelAll();
+ default int getMaxElementSynonyms() { return DFLT_MAX_ELEMENT_SYNONYMS; }
- void clearConversation(String userId);
- void clearConversation();
+ default boolean isMaxSynonymsThresholdError() { return
DFLT_MAX_SYNONYMS_THRESHOLD_ERROR; }
- void clearDialog(String userId);
- void clearDialog();
+ default long getConversationTimeout() { return DFLT_CONV_TIMEOUT_MS; }
+
+ default int getConversationDepth() { return DFLT_CONV_DEPTH; }
+
+ default boolean isStopWordsAllowed() {
+ return DFLT_IS_STOPWORDS_ALLOWED;
+ }
+
+ // User elements.
+ List<NCElement> getElements();
+
+ // Nlp.
+ NCNlpParser getNlpParser();
+ Function<List<NCNlpWord>, List<NCNlpWord>> getStopWordsFilter();
+ Function<List<NCNlpWord>, List<NCNlpWord>> getSwearWordsFilter();
+ Function<List<NCNlpWord>, List<NCNlpWord>> getSuspiciousWordsFilter();
+
+ // Intents data.
+ // model class by default + for methods of given instances.
+ // Scanned for NCIntent, NCIntentRef, NCIntentSample, NCIntentSampleRef
+ default List<Object> getIntentsObjects() {
+ return null;
+ }
+
+ // model class by default + for static methods of given classes.
+ // Scanned for NCIntent, NCIntentRef, NCIntentSample, NCIntentSampleRef
+ default List<Class<?>> getIntentsClasses() {
+ return null;
+ }
+
+ default List<String> getIntents() {
+ return null;
+ }
+ default Map<String, List<List<String>>> getSamples() {
+ return null;
+ }
+
+ // Behaviuor.
+ default boolean onParsedVariant(NCVariant var) {
+ return true;
+ }
+
+ default NCResult onContext(NCContext ctx) throws NCRejection {
+ return null;
+ }
+
+ default boolean onMatchedIntent(NCIntentMatch ctx) throws NCRejection {
+ return true;
+ }
+
+ default NCResult onResult(NCIntentMatch ctx, NCResult res) {
+ return null;
+ }
+
+ default NCResult onRejection(NCIntentMatch ctx, NCRejection e) {
+ return null;
+ }
+
+ default NCResult onError(NCContext ctx, Throwable e) {
+ return null;
+ }
+
+
+ // Lifecycle. TODO: I am not sure that we need them. Look at it after
Server API development.
+ void start();
+ void stop();
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelConfig.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelConfig.java
deleted file mode 100644
index 667b7fc..0000000
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelConfig.java
+++ /dev/null
@@ -1,253 +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 org.apache.nlpcraft.model.builders.NCModelBuilder;
-
-import java.lang.reflect.Method;
-import java.time.Duration;
-import java.util.*;
-
-public interface NCModelConfig extends NCMetadata {
- // TODO: move all defaults into NCModelConfigBuilder?
- long CONV_TIMEOUT_MIN = 0L;
-
- long CONV_TIMEOUT_MAX = Long.MAX_VALUE;
-
- long MAX_UNKNOWN_WORDS_MIN = 0L;
-
- long MAX_UNKNOWN_WORDS_MAX = Long.MAX_VALUE;
-
- long MAX_FREE_WORDS_MIN = 0L;
-
- long MAX_FREE_WORDS_MAX = Long.MAX_VALUE;
-
- long MAX_SUSPICIOUS_WORDS_MIN = 0L;
-
- long MAX_SUSPICIOUS_WORDS_MAX = Long.MAX_VALUE;
-
- long MIN_WORDS_MIN = 1L;
-
- long MIN_WORDS_MAX = Long.MAX_VALUE;
-
- long MIN_NON_STOPWORDS_MIN = 0L;
-
- long MIN_NON_STOPWORDS_MAX = Long.MAX_VALUE;
-
- long MIN_TOKENS_MIN = 0L;
-
- long MIN_TOKENS_MAX = Long.MAX_VALUE;
-
- long MAX_TOKENS_MIN = 0L;
-
- long MAX_TOKENS_MAX = 100L;
-
- long MAX_WORDS_MIN = 1L;
-
- long MAX_WORDS_MAX = 100L;
-
- long MAX_SYN_MIN = 1L;
-
- long MAX_SYN_MAX = Long.MAX_VALUE;
-
- long CONV_DEPTH_MIN = 1L;
-
- long CONV_DEPTH_MAX = Long.MAX_VALUE;
-
- int MODEL_ID_MAXLEN = 32;
-
- int MODEL_NAME_MAXLEN = 64;
-
- int MODEL_VERSION_MAXLEN = 16;
-
- int MODEL_ELEMENT_ID_MAXLEN = 64;
-
- int DFLT_MAX_ELEMENT_SYNONYMS = 1000;
-
- int DFLT_MAX_TOTAL_SYNONYMS = Integer.MAX_VALUE;
-
- boolean DFLT_MAX_SYNONYMS_THRESHOLD_ERROR = false;
-
- long DFLT_CONV_TIMEOUT_MS = Duration.ofMinutes(60).toMillis();
-
- int DFLT_CONV_DEPTH = 3;
-
- Map<String, Object> DFLT_METADATA = new HashMap<>();
-
- int DFLT_MAX_UNKNOWN_WORDS = Integer.MAX_VALUE;
-
- int DFLT_MAX_FREE_WORDS = Integer.MAX_VALUE;
-
- int DFLT_MAX_SUSPICIOUS_WORDS = 0;
-
- int DFLT_MIN_WORDS = 1;
-
- int DFLT_MAX_WORDS = 50;
-
- int DFLT_MIN_TOKENS = 0;
-
- int DFLT_MAX_TOKENS = 50;
-
- int DFLT_MIN_NON_STOPWORDS = 0;
-
- //boolean DFLT_IS_NON_ENGLISH_ALLOWED = true;
-
- //boolean DFLT_IS_NOT_LATIN_CHARSET_ALLOWED = false;
-
- boolean DFLT_IS_SWEAR_WORDS_ALLOWED = false;
-
- boolean DFLT_IS_NO_NOUNS_ALLOWED = true;
-
- boolean DFLT_IS_NO_USER_TOKENS_ALLOWED = true;
-
- // TODO: add javadoc
- boolean DFLT_IS_STOPWORDS_ALLOWED = true;
-
- String getId();
-
- String getName();
-
- String getVersion();
-
- default String getDescription() {
- return null;
- }
-
- default String getOrigin() {
- return getClass().getCanonicalName();
- }
-
- default int getMaxUnknownWords() {
- return DFLT_MAX_UNKNOWN_WORDS;
- }
-
- default int getMaxFreeWords() {
- return DFLT_MAX_FREE_WORDS;
- }
-
- default int getMaxSuspiciousWords() {
- return DFLT_MAX_SUSPICIOUS_WORDS;
- }
-
- default int getMinWords() {
- return DFLT_MIN_WORDS;
- }
-
- default int getMaxWords() {
- return DFLT_MAX_WORDS;
- }
-
- default int getMinTokens() {
- return DFLT_MIN_TOKENS;
- }
-
- default int getMaxTokens() {
- return DFLT_MAX_TOKENS;
- }
-
- default int getMinNonStopwords() {
- return DFLT_MIN_NON_STOPWORDS;
- }
-
- default boolean isSwearWordsAllowed() {
- return DFLT_IS_SWEAR_WORDS_ALLOWED;
- }
-
- default boolean isNoNounsAllowed() {
- return DFLT_IS_NO_NOUNS_ALLOWED;
- }
-
-
- default int getMaxTotalSynonyms() {
- return DFLT_MAX_TOTAL_SYNONYMS;
- }
-
- default boolean isNoUserTokensAllowed() {
- return DFLT_IS_NO_USER_TOKENS_ALLOWED;
- }
-
- default Map<String, Object> getMetadata() {
- return DFLT_METADATA;
- }
-
- default Set<String> getAdditionalStopWords() {
- return Collections.emptySet();
- }
-
- default Set<String> getExcludedStopWords() {
- return Collections.emptySet();
- }
-
- default Set<String> getSuspiciousWords() {
- return Collections.emptySet();
- }
-
- default List<NCCustomParser> getParsers() {
- return Collections.emptyList();
- }
-
- default int getMaxElementSynonyms() { return DFLT_MAX_ELEMENT_SYNONYMS; }
-
- default boolean isMaxSynonymsThresholdError() { return
DFLT_MAX_SYNONYMS_THRESHOLD_ERROR; }
-
- default long getConversationTimeout() { return DFLT_CONV_TIMEOUT_MS; }
-
- default int getConversationDepth() { return DFLT_CONV_DEPTH; }
-
- default boolean isStopWordsAllowed() {
- return DFLT_IS_STOPWORDS_ALLOWED;
- }
-
- List<NCElement> getElements();
-
- // model class by default + for methods of given instances.
- // Scanned for NCIntent, NCIntentRef, NCIntentSample, NCIntentSampleRef
- default List<Object> getIntentsObjects() {
- return null;
- }
-
- // model class by default + for static methods of given classes.
- // Scanned for NCIntent, NCIntentRef, NCIntentSample, NCIntentSampleRef
- default List<Class<?>> getIntentsClasses() {
- return null;
- }
-
- default boolean onParsedVariant(NCVariant var) {
- return true;
- }
-
- default NCResult onContext(NCContext ctx) throws NCRejection {
- return null;
- }
-
- default boolean onMatchedIntent(NCIntentMatch ctx) throws NCRejection {
- return true;
- }
-
- default NCResult onResult(NCIntentMatch ctx, NCResult res) {
- return null;
- }
-
- default NCResult onRejection(NCIntentMatch ctx, NCRejection e) {
- return null;
- }
-
- default NCResult onError(NCContext ctx, Throwable e) {
- return null;
- }
-}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCNlpcraft.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCNlpcraft.java
new file mode 100644
index 0000000..ae230d5
--- /dev/null
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCNlpcraft.java
@@ -0,0 +1,30 @@
+package org.apache.nlpcraft.model;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public interface NCNlpcraft {
+ String ask(String txt, Map<String, Object> data, boolean enableLog, String
userId);
+ String ask(String txt, String userId);
+ String ask(String txt);
+
+ NCResult askSync(String txt, Map<String, Object> data, boolean enableLog,
String userId);
+ NCResult askSync(String txt, String userId);
+ NCResult askSync(String txt);
+
+ List<NCResult> check(Set<String> srvReqIds, int maxRows);
+ List<NCResult> check(String userId, int maxRows);
+ NCResult check(String srvReqId);
+
+ void cancel(Set<String> srvReqIds);
+ void cancel(String srvReqId);
+ void cancelAll(String userId);
+ void cancelAll();
+
+ void clearConversation(String userId);
+ void clearConversation();
+
+ void clearDialog(String userId);
+ void clearDialog();
+}
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 395f864..0dcbed2 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
@@ -1,10 +1,183 @@
package org.apache.nlpcraft.model.builders;
+import org.apache.nlpcraft.model.NCContext;
+import org.apache.nlpcraft.model.NCCustomParser;
+import org.apache.nlpcraft.model.NCElement;
+import org.apache.nlpcraft.model.NCIntentMatch;
import org.apache.nlpcraft.model.NCModel;
-import org.apache.nlpcraft.model.NCModelConfig;
+import org.apache.nlpcraft.model.NCRejection;
+import org.apache.nlpcraft.model.NCResult;
+import org.apache.nlpcraft.model.NCVariant;
+import org.apache.nlpcraft.model.nlp.NCNlpParser;
+import org.apache.nlpcraft.model.nlp.NCNlpWord;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Predicate;
public class NCModelBuilder {
- public NCModelBuilder withConfig(NCModelConfig cfg) {
+ public NCModelBuilder withDescription(String description) {
+ return null;
+ }
+
+ public NCModelBuilder withOrigin(String origin) {
+ return null;
+ }
+
+ public NCModelBuilder withMaxUnknownWords(int maxUnknownWords) {
+ return null;
+ }
+
+ public NCModelBuilder withMaxFreeWords(int maxFreeWords) {
+ return null;
+ }
+
+ public NCModelBuilder withMaxSuspiciousWords(int maxSuspiciousWords) {
+ return null;
+ }
+
+ public NCModelBuilder withMinWords(int minWords) {
+ return null;
+ }
+
+ public NCModelBuilder withMaxWords(int maxWords) {
+ return null;
+ }
+
+ public NCModelBuilder withMinTokens(int minTokens) {
+ return null;
+ }
+
+ public NCModelBuilder withMaxTokens(int maxTokens) {
+ return null;
+ }
+
+ public NCModelBuilder withMinNonStopwords(int minNonStopwords) {
+ return null;
+ }
+
+ public NCModelBuilder withSwearWordsAllowed(boolean swearWordsAllowed) {
+ return null;
+ }
+
+ public NCModelBuilder withNoNounsAllowed(boolean noNounsAllowed) {
+ return null;
+ }
+
+ public NCModelBuilder withDupSynonymsAllowed(boolean dupSynonymsAllowed) {
+ return null;
+ }
+
+ public NCModelBuilder withMaxTotalSynonyms(int maxTotalSynonyms) {
+ return null;
+ }
+
+ public NCModelBuilder withNoUserTokensAllowed(boolean noUserTokensAllowed)
{
+ return null;
+ }
+
+ public NCModelBuilder withMetadata(Map<String, Object> meta) {
+ return null;
+ }
+
+ public NCModelBuilder withAdditionalStopWords(Set<String>
additionalStopWords) {
+ return null;
+ }
+
+ public NCModelBuilder withExcludedStopWords(Set<String> excludedStopWords)
{
+ return null;
+ }
+
+ public NCModelBuilder withSuspiciousWords(Set<String> suspiciousWords) {
+ return null;
+ }
+
+ public NCModelBuilder withParsers(List<NCCustomParser> parsers) {
+ return null;
+ }
+
+ public NCModelBuilder withMaxElementSynonyms(int maxElementSynonyms) {
return null; }
+
+ public NCModelBuilder withMaxSynonymsThresholdError(boolean
maxSynonymsThresholdError) { return null; }
+
+ public NCModelBuilder withConversationTimeout(long conversationTimeout) {
return null; }
+
+ public NCModelBuilder withConversationDepth(int conversationDepth) {
return null; }
+
+ public NCModelBuilder withStopWordsAllowed(boolean stopWordsAllowed) {
+ return null;
+ }
+
+ public NCModelBuilder withElements(List<NCElement> elements) {
+ return null;
+ }
+
+ public NCModelBuilder withNlpParser(NCNlpParser parser) {
+ return null;
+ }
+ public NCModelBuilder withStopWordsFilter(Function<List<NCNlpWord>,
List<NCNlpWord>> filter) {
+ return null;
+ }
+ public NCModelBuilder withSwearWordsFilter(Function<List<NCNlpWord>,
List<NCNlpWord>> filter) {
+ return null;
+ }
+ public NCModelBuilder withSuspiciousWordsFilter(Function<List<NCNlpWord>,
List<NCNlpWord>> filter) {
+ return null;
+ }
+
+
+ // model class by default + for 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.
+ // Scanned for NCIntent, NCIntentRef, NCIntentSample, NCIntentSampleRef
+ public NCModelBuilder withIntentsObjects(List<Object> objs) {
+ return null;
+ }
+
+ // Manually defined intents.
+ public NCModelBuilder withIntents(List<String> objs) {
+ return null;
+ }
+ public NCModelBuilder withIntentsFromFiles(List<File> objs) {
+ return null;
+ }
+ public NCModelBuilder withIntentsFromUrls(List<File> objs) {
+ return null;
+ }
+ public NCModelBuilder withIntentsSamplesMap(Map<String,
List<List<String>>> map) {
+ return null;
+ }
+
+
+ public NCModelBuilder withOnParsedVariant(Predicate<NCVariant> predicate) {
+ return null;
+ }
+
+ public NCModelBuilder withOnMatchedIntent(Predicate<NCIntentMatch>
predicate) throws NCRejection {
+ return null;
+ }
+
+ public NCModelBuilder withOnContext(Function<NCContext, NCResult>
resultMaker) throws NCRejection {
+ return null;
+ }
+
+ public NCModelBuilder withOnResult(BiFunction<NCIntentMatch, NCResult,
NCResult> resultMaker) {
+ return null;
+ }
+
+ public NCModelBuilder withOnRejection(BiFunction<NCIntentMatch,
NCRejection, NCResult> resultMaker) {
+ return null;
+ }
+
+ public NCModelBuilder withOnError(BiFunction<NCContext, Throwable,
NCResult> resultMaker) {
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
deleted file mode 100644
index 51b9e45..0000000
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelConfigBuilder.java
+++ /dev/null
@@ -1,171 +0,0 @@
-package org.apache.nlpcraft.model.builders;
-
-import org.apache.nlpcraft.model.NCContext;
-import org.apache.nlpcraft.model.NCCustomParser;
-import org.apache.nlpcraft.model.NCElement;
-import org.apache.nlpcraft.model.NCIntentMatch;
-import org.apache.nlpcraft.model.NCRejection;
-import org.apache.nlpcraft.model.NCResult;
-import org.apache.nlpcraft.model.NCValue;
-import org.apache.nlpcraft.model.NCValueLoader;
-import org.apache.nlpcraft.model.NCModelConfig;
-import org.apache.nlpcraft.model.NCVariant;
-
-import java.io.File;
-import java.lang.reflect.Method;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.function.BiFunction;
-import java.util.function.Function;
-import java.util.function.Predicate;
-
-public class NCModelConfigBuilder {
- public NCModelConfigBuilder withDescription(String description) {
- return null;
- }
-
- public NCModelConfigBuilder withOrigin(String origin) {
- return null;
- }
-
- public NCModelConfigBuilder withMaxUnknownWords(int maxUnknownWords) {
- return null;
- }
-
- public NCModelConfigBuilder withMaxFreeWords(int maxFreeWords) {
- return null;
- }
-
- public NCModelConfigBuilder withMaxSuspiciousWords(int maxSuspiciousWords)
{
- return null;
- }
-
- public NCModelConfigBuilder withMinWords(int minWords) {
- return null;
- }
-
- public NCModelConfigBuilder withMaxWords(int maxWords) {
- return null;
- }
-
- public NCModelConfigBuilder withMinTokens(int minTokens) {
- return null;
- }
-
- public NCModelConfigBuilder withMaxTokens(int maxTokens) {
- return null;
- }
-
- public NCModelConfigBuilder withMinNonStopwords(int minNonStopwords) {
- return null;
- }
-
- public NCModelConfigBuilder withSwearWordsAllowed(boolean
swearWordsAllowed) {
- return null;
- }
-
- public NCModelConfigBuilder withNoNounsAllowed(boolean noNounsAllowed) {
- return null;
- }
-
- public NCModelConfigBuilder withDupSynonymsAllowed(boolean
dupSynonymsAllowed) {
- return null;
- }
-
- public NCModelConfigBuilder withMaxTotalSynonyms(int maxTotalSynonyms) {
- return null;
- }
-
- public NCModelConfigBuilder withNoUserTokensAllowed(boolean
noUserTokensAllowed) {
- return null;
- }
-
- public NCModelConfigBuilder withMetadata(Map<String, Object> meta) {
- return null;
- }
-
- public NCModelConfigBuilder withAdditionalStopWords(Set<String>
additionalStopWords) {
- return null;
- }
-
- public NCModelConfigBuilder withExcludedStopWords(Set<String>
excludedStopWords) {
- return null;
- }
-
- public NCModelConfigBuilder withSuspiciousWords(Set<String>
suspiciousWords) {
- return null;
- }
-
- public NCModelConfigBuilder withParsers(List<NCCustomParser> parsers) {
- return null;
- }
-
- public NCModelConfigBuilder withMaxElementSynonyms(int maxElementSynonyms)
{ return null; }
-
- public NCModelConfigBuilder withMaxSynonymsThresholdError(boolean
maxSynonymsThresholdError) { return null; }
-
- public NCModelConfigBuilder withConversationTimeout(long
conversationTimeout) { return null; }
-
- public NCModelConfigBuilder withConversationDepth(int conversationDepth) {
return null; }
-
- public NCModelConfigBuilder withStopWordsAllowed(boolean stopWordsAllowed)
{
- return null;
- }
-
- public NCModelConfigBuilder withElements(List<NCElement> elements) {
- return null;
- }
-
- // model class by default + for static methods of given classes.
- // Scanned for NCIntent, NCIntentRef, NCIntentSample, NCIntentSampleRef
- public NCModelConfigBuilder withIntentsClasses(List<Class<?>> classes) {
- return null;
- }
-
- // model class by default + for methods of given instances.
- // Scanned for NCIntent, NCIntentRef, NCIntentSample, NCIntentSampleRef
- public NCModelConfigBuilder withIntentsObjects(List<Object> objs) {
- return null;
- }
-
- // Manually defined intents.
- public NCModelConfigBuilder withIntents(List<String> objs) {
- return null;
- }
- public NCModelConfigBuilder withIntentsFromFiles(List<File> objs) {
- return null;
- }
- public NCModelConfigBuilder withIntentsFromUrls(List<File> objs) {
- return null;
- }
-
- public NCModelConfigBuilder withOnParsedVariant(Predicate<NCVariant>
predicate) {
- return null;
- }
-
- public NCModelConfigBuilder withOnMatchedIntent(Predicate<NCIntentMatch>
predicate) throws NCRejection {
- return null;
- }
-
- public NCModelConfigBuilder withOnContext(Function<NCContext, NCResult>
resultMaker) throws NCRejection {
- return null;
- }
-
- public NCModelConfigBuilder withOnResult(BiFunction<NCIntentMatch,
NCResult, NCResult> resultMaker) {
- return null;
- }
-
- public NCModelConfigBuilder withOnRejection(BiFunction<NCIntentMatch,
NCRejection, NCResult> resultMaker) {
- return null;
- }
-
- public NCModelConfigBuilder withOnError(BiFunction<NCContext, Throwable,
NCResult> resultMaker) {
- return null;
- }
-
- public NCModelConfig getModelConfig() {
- return null;
- }
-}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCNlpcraftBuilder.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCNlpcraftBuilder.java
new file mode 100644
index 0000000..6c8589b
--- /dev/null
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCNlpcraftBuilder.java
@@ -0,0 +1,18 @@
+package org.apache.nlpcraft.model.builders;
+
+import org.apache.nlpcraft.model.NCModel;
+import org.apache.nlpcraft.model.NCNlpcraft;
+
+public class NCNlpcraftBuilder {
+ public NCNlpcraftBuilder withModel(NCModel mdl) {
+ return null;
+ }
+
+ public NCNlpcraftBuilder withUrl(String url) {
+ return null;
+ }
+
+ public NCNlpcraft getNCNlpcraft() {
+ return null;
+ }
+}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpParser.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpParser.java
new file mode 100644
index 0000000..11400b8
--- /dev/null
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpParser.java
@@ -0,0 +1,7 @@
+package org.apache.nlpcraft.model.nlp;
+
+import java.util.List;
+
+public interface NCNlpParser {
+ List<NCNlpWord> parse(String normTxt);
+}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpWord.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpWord.java
new file mode 100644
index 0000000..73418ac
--- /dev/null
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/nlp/NCNlpWord.java
@@ -0,0 +1,12 @@
+package org.apache.nlpcraft.model.nlp;
+
+public interface NCNlpWord {
+ String getWord();
+ String getNormalWord();
+ String getLemma();
+ String getStem();
+ String getPos();
+ int getStart();
+ int getEnd();
+ int getLength();
+}
diff --git a/nlpcraft/src/test/java/org/apache/nlpcraft/model/NCSpec.java
b/nlpcraft/src/test/java/org/apache/nlpcraft/model/NCSpec.java
index e8d99f6..dc501be 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/model/NCSpec.java
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/model/NCSpec.java
@@ -1,8 +1,8 @@
package org.apache.nlpcraft.model;
import org.apache.nlpcraft.model.annotations.NCIntentRef;
+import org.apache.nlpcraft.model.builders.NCNlpcraftBuilder;
import org.apache.nlpcraft.model.builders.NCSingleElementBuilder;
-import org.apache.nlpcraft.model.builders.NCModelConfigBuilder;
import org.apache.nlpcraft.model.builders.NCModelBuilder;
import org.apache.nlpcraft.model.builders.NCMultiElementsBuilder;
import org.junit.jupiter.api.Test;
@@ -38,7 +38,7 @@ public class NCSpec {
}
- private NCModelConfig getModelConfig() {
+ private NCModel getModel() {
Map<String, NCValueLoader> loaders = new HashMap<>();
loaders.put(
@@ -60,10 +60,8 @@ public class NCSpec {
elements.add(new
NCSingleElementBuilder().withId("additionalElementId").getElement());
-
-
return
- new NCModelConfigBuilder().
+ new NCModelBuilder().
withDescription("test model").
withElements(elements).
withIntentsClasses(
@@ -75,25 +73,21 @@ public class NCSpec {
return NCResult.text("OK");
}
}).
- getModelConfig();
- }
-
- private NCModel getModel() {
- return
- new NCModelBuilder().
- withConfig(getModelConfig()).
getModel();
}
+
@Test
public void test1() {
NCModel mdl = getModel();
mdl.start();
- String reqId = mdl.ask("weather today");
+ NCNlpcraft nlp = new
NCNlpcraftBuilder().withModel(mdl).getNCNlpcraft();
+
+ String reqId = nlp.ask("weather today");
- mdl.cancel(reqId);
+ nlp.cancel(reqId);
mdl.stop();
}
@@ -102,23 +96,22 @@ public class NCSpec {
public void test2() {
NCModel mdl =
new NCModelBuilder().
- withConfig(
- new NCModelConfigBuilder().
- withElements(
- asList(
- new NCSingleElementBuilder().
- withId("elemeId").
- withSynonyms(asList("element")).
- getElement()
- )
- ).
- withIntentsObjects(asList(new SomeClassWithIntents())).
- getModelConfig()
- ).getModel();
+ withElements(
+ asList(
+ new NCSingleElementBuilder().
+ withId("elemeId").
+ withSynonyms(asList("element")).
+ getElement()
+ )
+ ).
+ withIntentsObjects(asList(new SomeClassWithIntents())).
+ getModel();
mdl.start();
- NCResult res = mdl.askSync("weather today", "some user id");
+ NCNlpcraft nlp = new
NCNlpcraftBuilder().withModel(mdl).getNCNlpcraft();
+
+ NCResult res = nlp.askSync("weather today", "some user id");
mdl.stop();
}