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

aradzinski pushed a commit to branch NLPCREAFT-321
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCREAFT-321 by this push:
     new de8d2bb  WIP.
de8d2bb is described below

commit de8d2bb9cfc59d669d53876685b0b0cf1fd23784
Author: unknown <[email protected]>
AuthorDate: Sun May 16 11:52:45 2021 -0700

    WIP.
---
 .../examples/lightswitch/LightSwitchKotlinModel.kt |  2 +-
 nlpcraft/src/main/resources/nlpcraft.conf          |  4 +-
 .../apache/nlpcraft/model/NCDialogFlowItem.java    | 16 +++----
 .../model/intent/solver/NCIntentSolver.scala       |  7 ++-
 .../mgrs/dialogflow/NCDialogFlowManager.scala      | 50 ++++++++++++----------
 5 files changed, 46 insertions(+), 33 deletions(-)

diff --git 
a/nlpcraft-examples/lightswitch/src/main/java/org/apache/nlpcraft/examples/lightswitch/LightSwitchKotlinModel.kt
 
b/nlpcraft-examples/lightswitch/src/main/java/org/apache/nlpcraft/examples/lightswitch/LightSwitchKotlinModel.kt
index 13a12e5..3ef6e0d 100644
--- 
a/nlpcraft-examples/lightswitch/src/main/java/org/apache/nlpcraft/examples/lightswitch/LightSwitchKotlinModel.kt
+++ 
b/nlpcraft-examples/lightswitch/src/main/java/org/apache/nlpcraft/examples/lightswitch/LightSwitchKotlinModel.kt
@@ -69,7 +69,7 @@ class LightSwitchKotlinModel : 
NCModelFileAdapter("lightswitch_model.yaml") {
         // Add HomeKit, Arduino or other integration here.
 
         // By default - just return a descriptive action string.
-        return NCResult.text("Lights are [" + status + "] in [" + 
locations.toLowerCase() + "].")
+        return NCResult.text("Lights are [" + status + "] in [" + 
locations.lowercase() + "].")
     }
 
     override fun getId(): String {
diff --git a/nlpcraft/src/main/resources/nlpcraft.conf 
b/nlpcraft/src/main/resources/nlpcraft.conf
index 864916e..88f8f29 100644
--- a/nlpcraft/src/main/resources/nlpcraft.conf
+++ b/nlpcraft/src/main/resources/nlpcraft.conf
@@ -18,7 +18,9 @@
 #
 # This is joint configuration file for both the server and the data probes. 
Note that
 # server and probe configuration can be placed into separate files - each file 
containing only
-# 'nlpcraft.server' or 'nlpcraft.probe' sub-sections.
+# 'nlpcraft.server' or 'nlpcraft.probe' sub-sections. By default, the server 
looks for
+# 'server.conf' and then 'nlpcraft.conf' file, while data probe looks for 
'probe.conf' and
+# then 'nlpcraft.conf' file.
 #
 # You can also provide configuration properties or override the default ones 
via environment variables.
 # To use environment variables override:
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 644138e..acb4608 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCDialogFlowItem.java
@@ -27,7 +27,7 @@ import java.util.*;
  * Read full documentation in <a target=_ 
href="https://nlpcraft.apache.org/intent-matching.html";>Intent Matching</a> 
section and review
  * <a target=_ 
href="https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/";>examples</a>.
  */
-public interface NCDialogFlowItem {
+public interface NCDialogFlowItem extends NCMetadata {
     /**
      * Gets ID of the matched intent.
      *
@@ -36,6 +36,13 @@ public interface NCDialogFlowItem {
     String getIntentId();
 
     /**
+     * Gets the winning intent's callback result.
+     *
+     * @return Winning intent's callback result.
+     */
+    NCResult getResult();
+
+    /**
      * Gets a subset of tokens representing matched intent. This subset is 
grouped by the matched terms
      * where a {@code null} sub-list defines an optional term. Order and index 
of sub-lists corresponds
      * to the order and index of terms in the matching intent. Number of 
sub-lists will always be the same
@@ -44,19 +51,14 @@ public interface NCDialogFlowItem {
      * Note that unlike {@link #getVariant()} method
      * this method returns only subset of the tokens that were part of the 
matched intent. Specifically, it will
      * not return tokens for free words, stopwords or unmatched ("dangling") 
tokens.
-     * <p>
-     * Consider using {@link NCIntentTerm} annotation instead for simpler 
access to intent tokens.
      *
      * @return List of list of tokens representing matched intent.
      * @see #getVariant()
-     * @see NCIntentTerm
      */
     List<List<NCToken>> getIntentTokens();
 
     /**
      * Gets tokens for given term. This is a companion method for {@link 
#getIntentTokens()}.
-     * <p>
-     * Consider using {@link NCIntentTerm} annotation instead for simpler 
access to intent tokens.
      *
      * @param idx Index of the term (starting from <code>0</code>).
      * @return List of tokens, potentially {@code null}, for given term.
@@ -67,8 +69,6 @@ public interface NCDialogFlowItem {
 
     /**
      * Gets tokens for given term. This is a companion method for {@link 
#getIntentTokens()}.
-     * <p>
-     * Consider using {@link NCIntentTerm} annotation instead for simpler 
access to intent tokens.
      *
      * @param termId ID of the term for which to get tokens.
      * @return List of tokens, potentially {@code null}, for given term.
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolver.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolver.scala
index 084da88..02d6157 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolver.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolver.scala
@@ -123,10 +123,14 @@ class NCIntentSolver(intents: 
List[(NCIdlIntent/*Intent*/, NCIntentMatch ⇒ NCR
                 var cbRes: NCResult = null
     
                 startScopedSpan("intentCallback", span) { _ ⇒
+                    /*
+                     * This can throw NCIntentSkip exception.
+                     * ======================================
+                     */
                     cbRes = res.fn.apply(intentMatch)
                 }
                 
-                // Store winning intent match in the input.
+                // Store won intent match in the input.
                 in.intentMatch = intentMatch
                 
                 // Don't override if user already set it.
@@ -141,6 +145,7 @@ class NCIntentSolver(intents: List[(NCIdlIntent/*Intent*/, 
NCIntentMatch ⇒ NCR
                 NCDialogFlowManager.addMatchedIntent(
                     intentMatch,
                     res,
+                    cbRes,
                     ctx,
                     span
                 )
diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/dialogflow/NCDialogFlowManager.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/dialogflow/NCDialogFlowManager.scala
index f8bb4cb..08b48f6 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/dialogflow/NCDialogFlowManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/dialogflow/NCDialogFlowManager.scala
@@ -20,9 +20,11 @@ package org.apache.nlpcraft.probe.mgrs.dialogflow
 import io.opencensus.trace.Span
 import org.apache.nlpcraft.common.{NCService, _}
 import org.apache.nlpcraft.model.intent.solver.NCIntentSolverResult
-import org.apache.nlpcraft.model.{NCContext, NCDialogFlowItem, NCIntentMatch}
+import org.apache.nlpcraft.model.{NCCompany, NCContext, NCDialogFlowItem, 
NCIntentMatch, NCResult, NCToken, NCUser, NCVariant}
 import org.apache.nlpcraft.probe.mgrs.model.NCModelManager
 
+import java.util
+import java.util.Optional
 import scala.collection._
 
 /**
@@ -88,13 +90,15 @@ object NCDialogFlowManager extends NCService {
     }
 
     /**
-      * Adds matched (winning) intent to the dialog flow.
-      *
-      * @param intentMatch
-      * @param res Intent match result.
-      * @param ctx Original query context.
-      */
-    def addMatchedIntent(intentMatch: NCIntentMatch, res: 
NCIntentSolverResult, ctx: NCContext, parent: Span = null): Unit = {
+     * Adds matched (winning) intent to the dialog flow.
+     *
+     * @param intentMatch
+     * @param res Intent match result.
+     * @param cbRes Intent callback result.
+     * @param ctx Original query context.
+     * @param parent
+     */
+    def addMatchedIntent(intentMatch: NCIntentMatch, res: 
NCIntentSolverResult, cbRes: NCResult, ctx: NCContext, parent: Span = null): 
Unit = {
         val usrId = ctx.getRequest.getUser.getId
         val mdlId = ctx.getModel.getId
         val intentId = res.intentId
@@ -105,20 +109,22 @@ object NCDialogFlowManager extends NCService {
                 
                 val key = Key(usrId, mdlId)
                 val item: NCDialogFlowItem = new NCDialogFlowItem {
-                    override val getIntentId = intentId
-                    override val getIntentTokens = intentMatch.getIntentTokens
-                    override def getTermTokens(idx: Int) = 
intentMatch.getTermTokens(idx)
-                    override def getTermTokens(termId: String) = 
intentMatch.getTermTokens(termId)
-                    override val getVariant = intentMatch.getVariant
-                    override val isAmbiguous = !res.isExactMatch
-                    override val getUser = req.getUser
-                    override val getCompany = req.getCompany
-                    override val getServerRequestId = req.getServerRequestId
-                    override val getNormalizedText = req.getNormalizedText
-                    override val getReceiveTimestamp = req.getReceiveTimestamp
-                    override val getRemoteAddress = req.getRemoteAddress
-                    override val getClientAgent = req.getClientAgent
-                    override val getRequestData = req.getRequestData
+                    override val getIntentId: String = intentId
+                    override val getIntentTokens: 
util.List[util.List[NCToken]] = intentMatch.getIntentTokens
+                    override def getTermTokens(idx: Int): util.List[NCToken] = 
intentMatch.getTermTokens(idx)
+                    override def getTermTokens(termId: String): 
util.List[NCToken] = intentMatch.getTermTokens(termId)
+                    override val getVariant: NCVariant = intentMatch.getVariant
+                    override val isAmbiguous: Boolean = !res.isExactMatch
+                    override val getUser: NCUser = req.getUser
+                    override val getCompany: NCCompany = req.getCompany
+                    override val getServerRequestId: String = 
req.getServerRequestId
+                    override val getNormalizedText: String = 
req.getNormalizedText
+                    override val getReceiveTimestamp: Long = 
req.getReceiveTimestamp
+                    override val getRemoteAddress: Optional[String] = 
req.getRemoteAddress
+                    override val getClientAgent: Optional[String] = 
req.getClientAgent
+                    override val getRequestData: util.Map[String, AnyRef] = 
req.getRequestData
+                    override lazy val getMetadata: util.Map[String, AnyRef] = 
new util.HashMap[String, Object]
+                    override def getResult: NCResult = cbRes
                 }
                 
                 flow.getOrElseUpdate(key, 
mutable.ArrayBuffer.empty[NCDialogFlowItem]).append(item)

Reply via email to