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 93e4c6c WIP.
93e4c6c is described below
commit 93e4c6cd6aa9d5e8bf8c965dfb6b3dc9e4cdd140
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Oct 7 18:01:45 2021 +0300
WIP.
---
.../{NCCustomParser.java => NCAddElement.java} | 33 +++++-
.../{NCStart.scala => model/NCContext.java} | 22 +++-
.../{NCCustomParser.java => NCConversation.java} | 13 ++-
.../org/apache/nlpcraft/model/NCCustomParser.java | 2 +-
.../{NCCustomParser.java => NCDialogFlowItem.java} | 28 ++++-
.../{NCCustomParser.java => NCIntentMatch.java} | 15 ++-
.../apache/nlpcraft/model/NCIntentSampleRef.java | 1 +
.../scala/org/apache/nlpcraft/model/NCModel.java | 24 ++--
.../apache/nlpcraft/model/NCModelAddClasses.java | 1 +
.../apache/nlpcraft/model/NCModelAddPackage.java | 1 +
.../{NCCustomParser.java => NCModelBehaviour.java} | 35 +++++-
.../org/apache/nlpcraft/model/NCModelConfig.java | 76 +++++++------
.../model/{NCCustomParser.java => NCVariant.java} | 15 ++-
.../nlpcraft/model/builders/NCElementBuilder.java | 39 +++++++
.../model/builders/NCModelBehaviourBuilder.java | 55 +++++++++
.../nlpcraft/model/builders/NCModelBuilder.java | 24 ++++
.../model/builders/NCModelConfigBuilder.java | 123 +++++++++++++++++++++
.../nlpcraft/model/impl/NCElementsProvider.java | 43 +++++++
.../nlpcraft/model/impl/NCIntentsProvider.java | 47 ++++++++
.../java/org/apache/nlpcraft/model/NCSpec.java | 119 ++++++++++++++++++++
pom.xml | 13 +++
21 files changed, 663 insertions(+), 66 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCAddElement.java
similarity index 52%
copy from nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
copy to nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCAddElement.java
index 3193fb5..b6aadfd 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCAddElement.java
@@ -17,8 +17,35 @@
package org.apache.nlpcraft.model;
-import java.util.*;
+import java.lang.annotation.Documented;
+import java.lang.annotation.Repeatable;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
-public interface NCCustomParser extends NCLifecycle {
- List<NCCustomElement> parse(NCRequest req, NCModelConfig mdl,
List<NCCustomWord> words, List<NCCustomElement> elements);
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+// TODO: json or yaml
+@Documented
+@Retention(value=RUNTIME)
+@Target(value=METHOD)
+@Repeatable(NCAddElement.NCAddElementList.class)
+public @interface NCAddElement {
+ /**
+ * ID of the intent term.
+ *
+ * @return ID of the intent term.
+ */
+ String value();
+
+ /**
+ *
+ */
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target(value=METHOD)
+ @Documented
+ @interface NCAddElementList {
+ NCAddElement[] value();
+ }
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCStart.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java
similarity index 67%
rename from nlpcraft/src/main/scala/org/apache/nlpcraft/NCStart.scala
rename to nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java
index 7fb367c..a5250b2 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCStart.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCContext.java
@@ -6,7 +6,7 @@
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
- * https://www.apache.org/licenses/LICENSE-2.0
+ * 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,
@@ -15,9 +15,19 @@
* limitations under the License.
*/
-package org.apache.nlpcraft
+package org.apache.nlpcraft.model;
-/**
- *
- */
-object NCStart extends App
+import java.io.*;
+import java.util.*;
+
+public interface NCContext extends NCMetadata, Serializable {
+ boolean isOwnerOf(NCToken tok);
+
+ Collection<? extends NCVariant> getVariants();
+
+ NCModel getModel();
+
+ NCRequest getRequest();
+
+ NCConversation getConversation();
+}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCConversation.java
similarity index 73%
copy from nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
copy to nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCConversation.java
index 3193fb5..2425019 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCConversation.java
@@ -17,8 +17,15 @@
package org.apache.nlpcraft.model;
-import java.util.*;
+import java.util.List;
+import java.util.function.Predicate;
-public interface NCCustomParser extends NCLifecycle {
- List<NCCustomElement> parse(NCRequest req, NCModelConfig mdl,
List<NCCustomWord> words, List<NCCustomElement> elements);
+public interface NCConversation extends NCMetadata {
+ List<NCToken> getTokens();
+
+ List<NCDialogFlowItem> getDialogFlow();
+
+ void clearStm(Predicate<NCToken> filter);
+
+ void clearDialog(Predicate<String/* Intent ID. */> filter);
}
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 3193fb5..846282d 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
@@ -19,6 +19,6 @@ package org.apache.nlpcraft.model;
import java.util.*;
-public interface NCCustomParser extends NCLifecycle {
+public interface NCCustomParser {
List<NCCustomElement> parse(NCRequest req, NCModelConfig mdl,
List<NCCustomWord> words, List<NCCustomElement> elements);
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
similarity index 61%
copy from nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
copy to nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
index 3193fb5..ae89fda 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
@@ -19,6 +19,30 @@ package org.apache.nlpcraft.model;
import java.util.*;
-public interface NCCustomParser extends NCLifecycle {
- List<NCCustomElement> parse(NCRequest req, NCModelConfig mdl,
List<NCCustomWord> words, List<NCCustomElement> elements);
+public interface NCDialogFlowItem extends NCMetadata {
+ String getIntentId();
+
+ NCResult getResult();
+
+ List<List<NCToken>> getIntentTokens();
+
+ List<NCToken> getTermTokens(int idx);
+
+ List<NCToken> getTermTokens(String termId);
+
+ NCVariant getVariant();
+
+ String getUserId();
+
+ String getServerRequestId();
+
+ String getNormalizedText();
+
+ long getReceiveTimestamp();
+//
+// Optional<String> getRemoteAddress();
+//
+// Optional<String> getClientAgent();
+
+ Map<String, Object> getRequestData();
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java
similarity index 73%
copy from nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
copy to nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java
index 3193fb5..330d884 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentMatch.java
@@ -17,8 +17,19 @@
package org.apache.nlpcraft.model;
+import java.io.*;
import java.util.*;
-public interface NCCustomParser extends NCLifecycle {
- List<NCCustomElement> parse(NCRequest req, NCModelConfig mdl,
List<NCCustomWord> words, List<NCCustomElement> elements);
+public interface NCIntentMatch extends NCMetadata, Serializable {
+ String getIntentId();
+
+ NCContext getContext();
+
+ List<List<NCToken>> getIntentTokens();
+
+ List<NCToken> getTermTokens(int idx);
+
+ List<NCToken> getTermTokens(String termId);
+
+ NCVariant getVariant();
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentSampleRef.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentSampleRef.java
index 7df7228..84dad3f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentSampleRef.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentSampleRef.java
@@ -64,6 +64,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Target(value=METHOD)
@Repeatable(NCIntentSampleRef.NCIntentSampleList.class)
public @interface NCIntentSampleRef {
+ // TODO: can be deleted,
/**
* Local file path, classpath resource path or URL supported by {@link
java.net.URL} class. The content of the source
* should be a new-line separated list of string. Empty strings and
strings starting with '#" (hash) symbol will
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 c10db04..24a855e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModel.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModel.java
@@ -17,19 +17,25 @@
package org.apache.nlpcraft.model;
-/**
- *
- */
+import java.util.Set;
+import java.util.Map;
+import java.util.List;
+
public interface NCModel {
- String ask(String mdlId, String txt, Map<String, Object> data, boolean
enableLog, String userId);
+ void start();
+ void stop();
+
+ String ask(String txt, Map<String, Object> data, boolean enableLog, String
userId);
- NCResult askSync(String mdlId, String txt, Map<String, Object> data,
boolean enableLog, String userId);
+ NCResult askSync(String txt, Map<String, Object> data, boolean enableLog,
String userId);
- void cancel(Set<String> srvReqIds, Long usrId, String usrExtId);
+ void cancel(Set<String> srvReqIds, String userId);
- List<NCResult> check(Set<String> srvReqIds, Integer maxRows, String usrId);
+ List<NCResult> check(Set<String> srvReqIds, Integer maxRows, String
userId);
- void clearConversation(String mdlId, String String);
+ void clearConversation(String userId);
+ void clearDialog(String userId);
- void clearDialog(String mdlId, String String);
+ NCModelConfig getModelConfig();
+ NCModelBehaviour getModelBehaviour();
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelAddClasses.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelAddClasses.java
index d8241d4..8dd5c38 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelAddClasses.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelAddClasses.java
@@ -46,6 +46,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(value=RUNTIME)
@Target(value=TYPE)
public @interface NCModelAddClasses {
+ // TODO: drop it,
/**
* Array of class instances to additionally scan for intent callbacks.
*
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelAddPackage.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelAddPackage.java
index 41ca9dc..584ac62 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelAddPackage.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelAddPackage.java
@@ -46,6 +46,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Retention(value=RUNTIME)
@Target(value=TYPE)
public @interface NCModelAddPackage {
+ // TODO: drop it,
/**
* Array of JVM package names to recursively scan for intent callbacks.
*
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelBehaviour.java
similarity index 52%
copy from nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
copy to nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelBehaviour.java
index 3193fb5..0eff5d0 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelBehaviour.java
@@ -17,8 +17,37 @@
package org.apache.nlpcraft.model;
-import java.util.*;
+import java.time.Duration;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
-public interface NCCustomParser extends NCLifecycle {
- List<NCCustomElement> parse(NCRequest req, NCModelConfig mdl,
List<NCCustomWord> words, List<NCCustomElement> elements);
+public interface NCModelBehaviour {
+ List<String> getIntentsDsl();
+
+ 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/NCModelConfig.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelConfig.java
index ca91c22..5bdae6c 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelConfig.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCModelConfig.java
@@ -17,10 +17,13 @@
package org.apache.nlpcraft.model;
+import org.apache.nlpcraft.model.builders.NCModelBuilder;
+
import java.time.Duration;
import java.util.*;
public interface NCModelConfig extends NCMetadata {
+ // TODO: move all defaults into builder?
long CONV_TIMEOUT_MIN = 0L;
long CONV_TIMEOUT_MAX = Long.MAX_VALUE;
@@ -101,18 +104,14 @@ public interface NCModelConfig extends NCMetadata {
int DFLT_MIN_NON_STOPWORDS = 0;
- boolean DFLT_IS_NON_ENGLISH_ALLOWED = true;
+ //boolean DFLT_IS_NON_ENGLISH_ALLOWED = true;
- boolean DFLT_IS_NOT_LATIN_CHARSET_ALLOWED = false;
+ //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_PERMUTATE_SYNONYMS = false;
-
- boolean DFLT_IS_DUP_SYNONYMS_ALLOWED = true;
-
boolean DFLT_IS_NO_USER_TOKENS_ALLOWED = true;
// TODO: add javadoc
@@ -164,13 +163,13 @@ public interface NCModelConfig extends NCMetadata {
return DFLT_MIN_NON_STOPWORDS;
}
- default boolean isNonEnglishAllowed() {
- return DFLT_IS_NON_ENGLISH_ALLOWED;
- }
+ //default boolean isNonEnglishAllowed() {
+ // return DFLT_IS_NON_ENGLISH_ALLOWED;
+ //}
- default boolean isNotLatinCharsetAllowed() {
- return DFLT_IS_NOT_LATIN_CHARSET_ALLOWED;
- }
+// default boolean isNotLatinCharsetAllowed() {
+// return DFLT_IS_NOT_LATIN_CHARSET_ALLOWED;
+// }
default boolean isSwearWordsAllowed() {
return DFLT_IS_SWEAR_WORDS_ALLOWED;
@@ -180,13 +179,6 @@ public interface NCModelConfig extends NCMetadata {
return DFLT_IS_NO_NOUNS_ALLOWED;
}
- default boolean isPermutateSynonyms() {
- return DFLT_IS_PERMUTATE_SYNONYMS;
- }
-
- default boolean isDupSynonymsAllowed() {
- return DFLT_IS_DUP_SYNONYMS_ALLOWED;
- }
default int getMaxTotalSynonyms() {
return DFLT_MAX_TOTAL_SYNONYMS;
@@ -196,14 +188,6 @@ public interface NCModelConfig extends NCMetadata {
return DFLT_IS_NO_USER_TOKENS_ALLOWED;
}
- default boolean isSparse() {
- return DFLT_IS_SPARSE;
- }
-
- default boolean isGreedy() {
- return DFLT_IS_GREEDY;
- }
-
default Map<String, Object> getMetadata() {
return DFLT_METADATA;
}
@@ -220,18 +204,10 @@ public interface NCModelConfig extends NCMetadata {
return Collections.emptySet();
}
- default Map<String, String> getMacros() {
- return Collections.emptyMap();
- }
-
default List<NCCustomParser> getParsers() {
return Collections.emptyList();
}
- default Set<NCElement> getElements() {
- return Collections.emptySet();
- }
-
default int getMaxElementSynonyms() { return DFLT_MAX_ELEMENT_SYNONYMS; }
default boolean isMaxSynonymsThresholdError() { return
DFLT_MAX_SYNONYMS_THRESHOLD_ERROR; }
@@ -243,4 +219,34 @@ public interface NCModelConfig extends NCMetadata {
default boolean isStopWordsAllowed() {
return DFLT_IS_STOPWORDS_ALLOWED;
}
+
+ List<NCElement> getElements();
+ List<String> getIntentsDsl();
+
+///
+
+ 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/NCCustomParser.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCVariant.java
similarity index 62%
copy from nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
copy to nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCVariant.java
index 3193fb5..0e81211 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCCustomParser.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCVariant.java
@@ -18,7 +18,18 @@
package org.apache.nlpcraft.model;
import java.util.*;
+import java.util.stream.*;
-public interface NCCustomParser extends NCLifecycle {
- List<NCCustomElement> parse(NCRequest req, NCModelConfig mdl,
List<NCCustomWord> words, List<NCCustomElement> elements);
+public interface NCVariant extends List<NCToken>, NCMetadata {
+ default List<NCToken> getMatchedTokens() {
+ return stream().filter(tok -> !tok.isFreeWord() &&
!tok.isStopWord()).collect(Collectors.toList());
+ }
+
+ default List<NCToken> getFreeTokens() {
+ return
stream().filter(NCToken::isFreeWord).collect(Collectors.toList());
+ }
+
+ default List<NCToken> getStopWordTokens() {
+ return
stream().filter(NCToken::isStopWord).collect(Collectors.toList());
+ }
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCElementBuilder.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCElementBuilder.java
new file mode 100644
index 0000000..c5f43bd
--- /dev/null
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCElementBuilder.java
@@ -0,0 +1,39 @@
+package org.apache.nlpcraft.model.builders;
+
+import org.apache.nlpcraft.model.NCElement;
+import org.apache.nlpcraft.model.NCValue;
+import org.apache.nlpcraft.model.NCValueLoader;
+
+import java.util.List;
+import java.util.Map;
+
+public class NCElementBuilder {
+ public NCElementBuilder withId(String id) {
+ return null;
+ }
+ public NCElementBuilder withParentId(String id) {
+ return null;
+ }
+ public NCElementBuilder withGroups(List<String> groups) {
+ return null;
+ }
+ public NCElementBuilder withMetadata(Map<String, Object> meta) {
+ return null;
+ }
+ public NCElementBuilder withDescrition(String desc) {
+ return null;
+ }
+ public NCElementBuilder withValues(List<NCValue> values) {
+ return null;
+ }
+ public NCElementBuilder withValueLoader(NCValueLoader loader) {
+ return null;
+ }
+ public NCElementBuilder withSynonyms(List<String> syns) {
+ return null;
+ }
+
+ public NCElement make() {
+ return null;
+ }
+}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelBehaviourBuilder.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelBehaviourBuilder.java
new file mode 100644
index 0000000..74655c7
--- /dev/null
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelBehaviourBuilder.java
@@ -0,0 +1,55 @@
+package org.apache.nlpcraft.model.builders;
+
+import org.apache.nlpcraft.model.NCContext;
+import org.apache.nlpcraft.model.NCIntentMatch;
+import org.apache.nlpcraft.model.NCRejection;
+import org.apache.nlpcraft.model.NCResult;
+import org.apache.nlpcraft.model.NCVariant;
+import org.apache.nlpcraft.model.NCModelBehaviour;
+
+import java.util.List;
+import java.util.Map;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+
+public class NCModelBehaviourBuilder {
+ public NCModelBehaviourBuilder withIntentsDsl(List<String> intentsDsl) {
+ return null;
+ }
+
+ // IntentID - sample.
+ public NCModelBehaviourBuilder withIntentsDslSamples(Map<String,
List<List<String>>> samples) {
+ return null;
+ }
+
+ public NCModelBehaviourBuilder withOnParsedVariant(Predicate<NCVariant>
predicate) {
+ return null;
+ }
+
+ public NCModelBehaviourBuilder
withOnMatchedIntent(Predicate<NCIntentMatch> predicate) throws NCRejection {
+ return null;
+ }
+
+ public NCModelBehaviourBuilder withOnContext(Function<NCContext, NCResult>
resultMaker) throws NCRejection {
+ return null;
+ }
+
+
+ public NCModelBehaviourBuilder withOnResult(BiFunction<NCIntentMatch,
NCResult, NCResult> resultMaker) {
+ return null;
+ }
+
+ public NCModelBehaviourBuilder withOnRejection(BiFunction<NCIntentMatch,
NCRejection, NCResult> resultMaker) {
+ return null;
+ }
+
+ public NCModelBehaviourBuilder withOnError(BiFunction<NCContext,
Throwable, NCResult> resultMaker) {
+ return null;
+ }
+
+ public NCModelBehaviour make() {
+ 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
new file mode 100644
index 0000000..c0c8058
--- /dev/null
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelBuilder.java
@@ -0,0 +1,24 @@
+package org.apache.nlpcraft.model.builders;
+
+import org.apache.nlpcraft.model.NCElement;
+import org.apache.nlpcraft.model.NCModel;
+import org.apache.nlpcraft.model.NCModelBehaviour;
+import org.apache.nlpcraft.model.NCModelConfig;
+import org.apache.nlpcraft.model.NCValue;
+import org.apache.nlpcraft.model.NCValueLoader;
+
+import java.util.List;
+import java.util.Map;
+
+public class NCModelBuilder {
+ public NCModelBuilder withConfig(NCModelConfig cfg) {
+ return null;
+ }
+ public NCModelBuilder withModelBehaviour(NCModelBehaviour b) {
+ return null;
+ }
+
+ public NCModel make() {
+ 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
new file mode 100644
index 0000000..28b016e
--- /dev/null
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/builders/NCModelConfigBuilder.java
@@ -0,0 +1,123 @@
+package org.apache.nlpcraft.model.builders;
+
+import org.apache.nlpcraft.model.NCCustomParser;
+import org.apache.nlpcraft.model.NCElement;
+import org.apache.nlpcraft.model.NCValue;
+import org.apache.nlpcraft.model.NCValueLoader;
+import org.apache.nlpcraft.model.NCModelConfig;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+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;
+ }
+
+ //NCModelConfigBuilder withNonEnglishAllowed() {
+// return null;
+// }
+
+// NCModelConfigBuilder withNotLatinCharsetAllowed() {
+// 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;
+ }
+
+ public NCModelConfig make() {
+ return null;
+ }
+}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCElementsProvider.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCElementsProvider.java
new file mode 100644
index 0000000..0684672
--- /dev/null
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCElementsProvider.java
@@ -0,0 +1,43 @@
+package org.apache.nlpcraft.model.impl;
+
+import org.apache.nlpcraft.model.NCElement;
+import org.apache.nlpcraft.model.NCValueLoader;
+
+import java.util.List;
+import java.util.Map;
+import java.io.File;
+
+public class NCElementsProvider {
+ private Map<String, NCValueLoader> loaders;
+ private List<File> files;
+ private List<Class<?>> classes;
+
+ public Map<String, NCValueLoader> getLoaders() {
+ return loaders;
+ }
+
+ public void setLoaders(Map<String, NCValueLoader> loaders) {
+ this.loaders = loaders;
+ }
+
+ public List<File> getFiles() {
+ return files;
+ }
+
+ public void setFiles(List<File> files) {
+ this.files = files;
+ }
+
+ public List<Class<?>> getClasses() {
+ return classes;
+ }
+
+ public void setClasses(List<Class<?>> classes) {
+ this.classes = classes;
+ }
+
+ public List<NCElement> getElements() {
+ // TODO: implement.
+ return null;
+ }
+}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCIntentsProvider.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCIntentsProvider.java
new file mode 100644
index 0000000..bbc89d6
--- /dev/null
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/impl/NCIntentsProvider.java
@@ -0,0 +1,47 @@
+package org.apache.nlpcraft.model.impl;
+
+import java.io.File;
+import java.util.List;
+import java.util.Map;
+
+public class NCIntentsProvider {
+ private List<File> intentsFiles;
+ // Intent ID - samples
+ private Map<String, File> samplesFiles;
+ private List<Class<?>> classes;
+
+ public List<File> getIntentsFiles() {
+ return intentsFiles;
+ }
+
+ public void setIntentsFiles(List<File> intentsFiles) {
+ this.intentsFiles = intentsFiles;
+ }
+
+ public Map<String, File> getSamplesFiles() {
+ return samplesFiles;
+ }
+
+ public void setSamplesFiles(Map<String, File> samplesFiles) {
+ this.samplesFiles = samplesFiles;
+ }
+
+ public List<Class<?>> getClasses() {
+ return classes;
+ }
+
+ public void setClasses(List<Class<?>> classes) {
+ this.classes = classes;
+ }
+
+ public List<String> getIntentsDls() {
+ // TODO: implement.
+ return null;
+ }
+
+ public Map<String, List<List<String>>> getIntentsSamples() {
+ // TODO: implement.
+ return null;
+ }
+
+}
diff --git a/nlpcraft/src/test/java/org/apache/nlpcraft/model/NCSpec.java
b/nlpcraft/src/test/java/org/apache/nlpcraft/model/NCSpec.java
new file mode 100644
index 0000000..4d9af99
--- /dev/null
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/model/NCSpec.java
@@ -0,0 +1,119 @@
+package org.apache.nlpcraft.model;
+
+import org.apache.nlpcraft.model.NCModelConfig;
+import org.apache.nlpcraft.model.NCValueLoader;
+import org.apache.nlpcraft.model.builders.NCElementBuilder;
+import org.apache.nlpcraft.model.builders.NCModelBehaviourBuilder;
+import org.apache.nlpcraft.model.builders.NCModelConfigBuilder;
+import org.apache.nlpcraft.model.builders.NCModelBuilder;
+import org.apache.nlpcraft.model.impl.NCElementsProvider;
+import org.apache.nlpcraft.model.impl.NCIntentsProvider;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.BiFunction;
+
+public class NCSpec {
+ private static<T> Set<T> asSet(T s) {
+ return Collections.singleton(s);
+ }
+
+ private static<T> List<T> asList(T s) {
+ return Collections.singletonList(s);
+ }
+
+ private NCModelConfig getModelConfig() {
+ Map<String, NCValueLoader> loaders = new HashMap<>();
+
+ loaders.put(
+ "elemetId",
+ new NCValueLoader() {
+ public Set<NCValue> load(NCElement owner) {
+ return null;
+ }
+ }
+ );
+
+ NCElementsProvider elemsProvider = new NCElementsProvider();
+
+ elemsProvider.setFiles(asList(new java.io.File("path.yaml")));
+ elemsProvider.setLoaders(loaders);
+
+ List<NCElement> elements = elemsProvider.getElements();
+
+ elements.add(new
NCElementBuilder().withId("additionalElementId").make());
+
+ return
+ new NCModelConfigBuilder().
+ withDescription("test model").
+ withElements(elements).
+ make();
+ }
+
+ private NCModelBehaviour getModelBehaviour() {
+ NCIntentsProvider intentsProvider = new NCIntentsProvider();
+
+ class SomeClassWithIntents {
+ @NCIntentRef("remove:waypoint")
+ public void x() {
+
+ }
+ }
+
+ intentsProvider.setClasses(asList(SomeClassWithIntents.class));
+
+ List<String> intents = intentsProvider.getIntentsDls();
+
+ return
+ new NCModelBehaviourBuilder().
+ withIntentsDsl(intentsProvider.getIntentsDls()).
+ withIntentsDslSamples(intentsProvider.getIntentsSamples()).
+ withOnRejection(new BiFunction<NCIntentMatch, NCRejection,
NCResult>() {
+ @Override
+ public NCResult apply(NCIntentMatch math, NCRejection rej)
{
+ return NCResult.text("OK");
+ }
+ }).
+ make();
+ }
+
+ private NCModel getModel() {
+ return
+ new NCModelBuilder().
+ withConfig(getModelConfig()).
+ withModelBehaviour(getModelBehaviour()).
+ make();
+ }
+
+ @Test
+ public void test1() {
+ NCModel mdl = getModel();
+
+ mdl.start();
+
+ String reqId = mdl.ask("weather today", null, true, null);
+
+ mdl.cancel(asSet(reqId), null);
+
+ mdl.stop();
+ }
+
+ @Test
+ public void test2() {
+ NCModel mdl =
+ new NCModelBuilder().
+ withConfig(new NCModelConfigBuilder().withElements(asList(new
NCElementBuilder().withId("elemeId").withSynonyms(asList("element")).make())).make()).
+ withModelBehaviour(new
NCModelBehaviourBuilder().withIntentsDsl(asList("intent=req term(date)~{# ==
'opennlp:date'}?")).make()).
+ make();
+
+ mdl.start();
+
+ NCResult res = mdl.askSync("weather today", null, true, null);
+
+ mdl.stop();
+ }
+}
diff --git a/pom.xml b/pom.xml
index 6210045..307d751 100644
--- a/pom.xml
+++ b/pom.xml
@@ -244,6 +244,19 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>${maven.jar.plugin.ver}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.ver}</version>
<configuration>