This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-472
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-472 by this push:
new 27c9df4 WIP
27c9df4 is described below
commit 27c9df4cccb34d4077bd05e64c0ca5115f4cbb9c
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sun Jan 2 12:46:34 2022 -0800
WIP
---
.../main/scala/org/apache/nlpcraft/NCContext.java | 8 +++---
.../scala/org/apache/nlpcraft/NCConversation.java | 22 +++------------
.../main/scala/org/apache/nlpcraft/NCEntity.java | 7 -----
.../org/apache/nlpcraft/NCEntityValidator.java | 7 +++--
.../main/scala/org/apache/nlpcraft/NCIntent.java | 29 ++-----------------
.../scala/org/apache/nlpcraft/NCIntentRef.java | 21 ++------------
.../scala/org/apache/nlpcraft/NCIntentSample.java | 26 -----------------
.../org/apache/nlpcraft/NCIntentSampleRef.java | 20 -------------
.../scala/org/apache/nlpcraft/NCIntentTerm.java | 33 ++--------------------
.../scala/org/apache/nlpcraft/NCModelConfig.java | 2 +-
.../org/apache/nlpcraft/NCModelConfigAdapter.java | 8 +++---
.../main/scala/org/apache/nlpcraft/NCRequest.java | 7 -----
.../org/apache/nlpcraft/NCTokenValidator.java | 2 +-
...iantsValidator.java => NCVariantValidator.java} | 2 +-
.../apache/nlpcraft/nlp/util/NCTestConfig.scala | 2 +-
.../apache/nlpcraft/nlp/util/NCTestRequest.scala | 4 ---
16 files changed, 26 insertions(+), 174 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCContext.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCContext.java
index 39f4004..6887690 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCContext.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCContext.java
@@ -24,12 +24,12 @@ import java.util.*;
*/
public interface NCContext {
/**
- * Tests if given token is part of the query this context is associated
with.
+ * Tests if given entity is part of the query this context is associated
with.
*
- * @param tok Token to check.
- * @return {@code true} if given token is associated with this context,
{@code false} otherwise.
+ * @param ent Entity to check.
+ * @return {@code true} if given entity is associated with this context,
{@code false} otherwise.
*/
- boolean isOwnerOf(NCEntity tok);
+ boolean isOwnerOf(NCEntity ent);
/**
* Gets model configuration for this query.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCConversation.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCConversation.java
index 7f96285..6cfc375 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCConversation.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCConversation.java
@@ -25,17 +25,9 @@ import java.util.function.Predicate;
*/
public interface NCConversation {
/**
- * Gets an ordered list of tokens stored in the conversation's STM
(short-term memory) for the current
- * user. Tokens in the returned list are ordered by their conversational
depth, i.e.
- * the tokens from more recent requests appear before tokens from older
requests.
- * <p>
- * Note also that rules by which STM operates are undefined for the
purpose of this function (i.e. callers
- * should not rely on any observed behavior of how STM stores and evicts
its content).
- *
- * @return List of tokens for this conversation's STM. The list can be
empty which indicates that
- * conversation is brand new (or timed out).
+ *
*/
- List<NCEntity> getTokens();
+ List<NCEntity> getEntities();
/**
* Gets the chronologically ordered list of previously matched intents
sorted from oldest to newest
@@ -46,14 +38,8 @@ public interface NCConversation {
List<NCDialogFlowItem> getDialogFlow();
/**
- * Removes all tokens satisfying given token predicate from the
conversation's STM.
- * <p>
- * This is particularly useful when the logic processing the user input
makes an implicit
- * assumption not present in the user input itself. Such assumption may
alter the conversation (without
- * having an explicit token responsible for it) and therefore this method
can be used to remove "stale" tokens
- * from conversation's STM.
- *
- * @param filter Token remove filter.
+ *
+ * @param filter Entity remove filter.
*/
void clearStm(Predicate<NCEntity> filter);
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCEntity.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCEntity.java
index 57aa4e4..0b2bd14 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCEntity.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCEntity.java
@@ -43,11 +43,4 @@ public interface NCEntity extends NCPropertyMap {
* @return
*/
String getId();
-
- /**
- * @return Internal globally unique system ID of the entity.
- */
- default String getGuid() {
- return NCUtils.genUUID().toString();
- }
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCEntityValidator.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCEntityValidator.java
index cf64c39..0b9272f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCEntityValidator.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCEntityValidator.java
@@ -24,11 +24,12 @@ import java.util.List;
*/
public interface NCEntityValidator extends NCLifecycle {
/**
- * Checks all found entities and throws exceptions if necessary.
+ *
*
* @param req
* @param cfg
- * @param toks
+ * @param ents
+ * @throws NCException
*/
- void validate(NCRequest req, NCModelConfig cfg, List<NCEntity> entities);
+ void validate(NCRequest req, NCModelConfig cfg, List<NCEntity> ents);
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntent.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntent.java
index d552f67..db3732d 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntent.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntent.java
@@ -23,33 +23,8 @@ import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
- * Annotation to bind an intent with the method serving as its callback. This
annotation takes a string value
- * that defines an intent via IDL. This annotation can also be applied to a
model's class in
- * which case it will just declare the intent without binding it and the
callback method will need to
- * use {@link NCIntentRef} annotation to actually bind it to the declared
intent. Note that multiple intents
- * can be bound to the same callback method, but only one callback method can
be bound with a given intent.
- * <p>
- * Here's an example of using this annotation (from <a target=_new
href="https://nlpcraft.apache.org/examples/light_switch.html">LightSwitch</a>
example):
- * <pre class="brush: java, highlight: [1,2]">
- * {@literal @}NCIntent("import('intents.idl')")
- * {@literal @}NCIntent("intent=act term(act)={has(tok_groups, 'act')}
term(loc)={# == 'ls:loc'}*")
- * {@literal @}NCIntentSample(Array(
- * "Turn the lights off in the entire house.",
- * "Switch on the illumination in the master bedroom closet.",
- * "Get the lights on.",
- * "Please, put the light out in the upstairs bedroom."
- * ))
- * def onMatch(
- * {@literal @}NCIntentTerm("act") actTok: NCToken,
- * {@literal @}NCIntentTerm("loc") locToks: List[NCToken]
- * ): NCResult = {
- * ...
- * }
- * </pre>
- * <p>
- * Read full documentation in <a target=_
href="https://nlpcraft.apache.org/intent-matching.html#binding">Intent
Matching</a> section and review
- * <a target=_
href="https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples">examples</a>.
- *
+ * Annotation to bind an intent with the method serving as its callback.
+ *
* @see NCIntentRef
* @see NCIntentTerm
* @see NCIntentSample
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentRef.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentRef.java
index 4976add..4babf4b 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentRef.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentRef.java
@@ -23,25 +23,8 @@ import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
- * Annotation referencing an intent defined outside of callback method
declaration. Multiple such annotations
- * can be applied to the callback method. Note that multiple intents can be
bound to the same callback method,
- * but only one callback method can be bound with a given intent.
- * <p>
- * Here's an example of using this annotation (from <a target=_new
href="https://nlpcraft.apache.org/examples/alarm_clock.html">Alarm Clock</a>
example):
- * <pre class="brush: java, highlight: [1]">
- * {@literal @}NCIntentRef("alarm")
- * {@literal @}NCIntentSampleRef("alarm_samples.txt")
- * NCResult onMatch(
- * NCIntentMatch ctx,
- * {@literal @}NCIntentTerm("nums") List<NCToken> numToks
- * ) {
- * ...
- * }
- * </pre>
- * <p>
- * Read full documentation in <a target=_
href="https://nlpcraft.apache.org/intent-matching.html#binding">Intent
Matching</a> section and review
- * <a target=_
href="https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples">examples</a>.
- *
+ * Annotation referencing an intent defined outside of callback method
declaration.
+ *
* @see NCIntent
* @see NCIntentTerm
* @see NCIntentSample
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentSample.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentSample.java
index 8f4bda6..18f334a 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentSample.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentSample.java
@@ -23,32 +23,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* The corpus of intent samples that is used for documentaiton and model
auto-validation.
- * <p>
- * This annotation defines samples of the user input that should match an
intent. This
- * annotation should be used together with {@link NCIntent} or {@link
NCIntentRef} annotations on the callback
- * methods. Method can have multiple annotations of this type and each
annotation can define multiple input
- * examples. See similar {@link NCIntentSampleRef} annotation that allows to
load samples from external resources like
- * file or URL.
- * <p>
- * Here's an example of using this annotation (from <a target=_new
href="https://nlpcraft.apache.org/examples/light_switch.html">LightSwitch</a>
example):
- * <pre class="brush: java, highlight: [2]">
- * {@literal @}NCIntent("intent=act term(act)={has(tok_groups, 'act')}
term(loc)={# == 'ls:loc'}*")
- * {@literal @}NCIntentSample(Array(
- * "Turn the lights off in the entire house.",
- * "Switch on the illumination in the master bedroom closet.",
- * "Get the lights on.",
- * "Please, put the light out in the upstairs bedroom."
- * ))
- * def onMatch(
- * {@literal @}NCIntentTerm("act") actTok: NCToken,
- * {@literal @}NCIntentTerm("loc") locToks: List[NCToken]
- * ): NCResult = {
- * ...
- * }
- * </pre>
- * <p>
- * Read full documentation in <a target=_
href="https://nlpcraft.apache.org/intent-matching.html#binding">Intent
Matching</a> section and review
- * <a target=_
href="https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples">examples</a>.
*
* @see NCIntentSampleRef
* @see NCIntent
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentSampleRef.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentSampleRef.java
index 8993864..3f5d27f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentSampleRef.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentSampleRef.java
@@ -28,26 +28,6 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* The corpus of intent samples that is used for documentaiton and model
auto-validation.
- * <p>
- * This annotation allows to load these samples from the external sources like
local file or URL and
- * should be used together with {@link NCIntent} or {@link NCIntentRef}
annotations on the callback
- * methods. Method can have multiple annotations of this type and each
annotation can define multiple input
- * examples. See similar {@link NCIntentSample} annotation that allows to
define samples in place.
- * <p>
- * Here's an example of using this annotation:
- * <pre class="brush: java, highlight: [2]">
- * {@literal @}NCIntentRef("alarm")
- * {@literal @}NCIntentSampleRef("alarm_samples.txt")
- * NCResult onMatch(
- * NCIntentMatch ctx,
- * {@literal @}NCIntentTerm("nums") List<NCToken> numToks
- * ) {
- * ...
- * }
- * </pre>
- * <p>
- * Read full documentation in <a target=_
href="https://nlpcraft.apache.org/intent-matching.html#binding">Intent
Matching</a> section and review
- * <a target=_
href="https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples">examples</a>.
*
* @see NCIntentSample
* @see NCIntent
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentTerm.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentTerm.java
index c652420..5486a5e 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentTerm.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentTerm.java
@@ -23,37 +23,8 @@ import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
/**
- * Annotation to mark callback parameter to receive intent term's tokens. This
is a companion annotation
- * to {@link NCIntent} and {@link NCIntentRef} annotations and can only be
used for
- * the parameters of the methods that are annotated with {@link NCIntent} or
{@link NCIntentRef}.
- * {@code NCIntentTerm} takes a term ID as its only mandatory parameter and
should be applied to callback
- * method parameters to get the tokens associated with that term (if and when
the intent was matched and that
- * callback was invoked).
- * <p>
- * Note that if multiple intents bound to the same callback method, all such
intents should have the named
- * terms specified by this annotation.
- * <p>
- * Here's an example of using this annotation (from <a target=_new
href="https://nlpcraft.apache.org/examples/light_switch.html">LightSwitch</a>
example):
- * <pre class="brush: java, highlight: [10,11]">
- * {@literal @}NCIntent("import('intents.idl')")
- * {@literal @}NCIntent("intent=act term(act)={has(tok_groups, 'act')}
term(loc)={# == 'ls:loc'}*")
- * {@literal @}NCIntentSample(Array(
- * "Turn the lights off in the entire house.",
- * "Switch on the illumination in the master bedroom closet.",
- * "Get the lights on.",
- * "Please, put the light out in the upstairs bedroom."
- * ))
- * def onMatch(
- * {@literal @}NCIntentTerm("act") actTok: NCToken,
- * {@literal @}NCIntentTerm("loc") locToks: List[NCToken]
- * ): NCResult = {
- * ...
- * }
- * </pre>
- * <p>
- * Read full documentation in <a target=_
href="https://nlpcraft.apache.org/intent-matching.html#binding">Intent
Matching</a> section and review
- * <a target=_
href="https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft-examples">examples</a>.
- *
+ * Annotation to mark callback parameter to receive intent term's tokens.
+ *
* @see NCIntent
* @see NCIntentRef
* @see NCIntentSample
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.java
index 97653a2..330e4ec 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfig.java
@@ -63,7 +63,7 @@ public interface NCModelConfig extends NCPropertyMap {
*
* @return
*/
- List<NCVariantsValidator> getVariantValidators();
+ List<NCVariantValidator> getVariantValidators();
/**
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfigAdapter.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfigAdapter.java
index 5db1716..5f3585c 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfigAdapter.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCModelConfigAdapter.java
@@ -23,7 +23,7 @@ import java.util.*;
*
*/
// TODO: validation for constructor and all setters.
- // TODO: do builder instaed of it.
+// TODO: do builder instead of it.
public class NCModelConfigAdapter extends NCPropertyMapAdapter implements
NCModelConfig {
private final String id;
private final String name;
@@ -34,7 +34,7 @@ public class NCModelConfigAdapter extends
NCPropertyMapAdapter implements NCMode
private final List<NCEntityParser> entParsers = new ArrayList<>();
private final List<NCTokenValidator> tokenValidators = new ArrayList<>();
private final List<NCEntityValidator> entityValidators = new ArrayList<>();
- private final List<NCVariantsValidator> variantsFilters = new
ArrayList<>();
+ private final List<NCVariantValidator> variantsFilters = new ArrayList<>();
/**
*
@@ -112,7 +112,7 @@ public class NCModelConfigAdapter extends
NCPropertyMapAdapter implements NCMode
*
* @param variantFilter
*/
- public void addVariantFilter(NCVariantsValidator variantFilter) {
+ public void addVariantFilter(NCVariantValidator variantFilter) {
Objects.requireNonNull(variantFilter, "Variant filter cannot be
null.");
variantsFilters.add(variantFilter);
@@ -164,7 +164,7 @@ public class NCModelConfigAdapter extends
NCPropertyMapAdapter implements NCMode
}
@Override
- public List<NCVariantsValidator> getVariantValidators() {
+ public List<NCVariantValidator> getVariantValidators() {
return variantsFilters;
}
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCRequest.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCRequest.java
index 468f8ac..1a98655 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCRequest.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCRequest.java
@@ -59,13 +59,6 @@ public interface NCRequest {
long getReceiveTimestamp();
/**
- * Gets string representation of the user agent that made the call with
this request.
- *
- * @return User agent description (web browser, REST client, etc.) or
{@code null} if not available.
- */
- String getUserAgent();
-
- /**
* Gets optional user request data.
*
* @return Optional user request data, can be empty but never {@code null}.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCTokenValidator.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCTokenValidator.java
index 553959d..81451af 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCTokenValidator.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCTokenValidator.java
@@ -24,7 +24,7 @@ import java.util.List;
*/
public interface NCTokenValidator extends NCLifecycle {
/**
- * Checks parsed tokens and throws exceptions if necessary.
+ * Checks parsed tokens and throws exceptions, if necessary.
*
* @param req
* @param cfg
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCVariantsValidator.java
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCVariantValidator.java
similarity index 94%
rename from nlpcraft/src/main/scala/org/apache/nlpcraft/NCVariantsValidator.java
rename to nlpcraft/src/main/scala/org/apache/nlpcraft/NCVariantValidator.java
index 8829e2f..212e242 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCVariantsValidator.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCVariantValidator.java
@@ -22,7 +22,7 @@ import java.util.List;
/**
*
*/
-public interface NCVariantsValidator extends NCLifecycle {
+public interface NCVariantValidator extends NCLifecycle {
/**
* Filters all found entities variants.
*
diff --git
a/nlpcraft/src/test/java/org/apache/nlpcraft/nlp/util/NCTestConfig.scala
b/nlpcraft/src/test/java/org/apache/nlpcraft/nlp/util/NCTestConfig.scala
index b5ff768..5e32ee1 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/nlp/util/NCTestConfig.scala
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/nlp/util/NCTestConfig.scala
@@ -40,7 +40,7 @@ object NCTestConfig:
override def getEntityParsers: JList[NCEntityParser] = new
JAList[NCEntityParser]()
override def getTokenValidators: JList[NCTokenValidator] = new
JAList[NCTokenValidator]()
override def getEntityValidators: JList[NCEntityValidator] = new
JAList[NCEntityValidator]()
- override def getVariantValidators: JList[NCVariantsValidator] = new
JAList[NCVariantsValidator]()
+ override def getVariantValidators: JList[NCVariantValidator] = new
JAList[NCVariantValidator]()
override def getId: String = "test"
override def getName: String = "test"
diff --git
a/nlpcraft/src/test/java/org/apache/nlpcraft/nlp/util/NCTestRequest.scala
b/nlpcraft/src/test/java/org/apache/nlpcraft/nlp/util/NCTestRequest.scala
index 0cbdc70..bed1050 100644
--- a/nlpcraft/src/test/java/org/apache/nlpcraft/nlp/util/NCTestRequest.scala
+++ b/nlpcraft/src/test/java/org/apache/nlpcraft/nlp/util/NCTestRequest.scala
@@ -29,7 +29,6 @@ import java.util.List
* @param userId
* @param reqId
* @param ts
- * @param userAgent
* @param data
*/
case class NCTestRequest(
@@ -37,17 +36,14 @@ case class NCTestRequest(
userId: String = null,
reqId: String = null,
ts: Long = -1,
- userAgent: String = null,
data: util.Map[String, AnyRef] = null
) extends NCRequest:
override def getUserId: String = userId
override def getRequestId: String = reqId
override def getText: String = txt
override def getReceiveTimestamp: Long = ts
- override def getUserAgent: String = userAgent
override def getRequestData: util.Map[String, AnyRef] = data
-
/**
* Java side helper.
*/