This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-206
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-206 by this push:
new 5fb372e WIP.
5fb372e is described below
commit 5fb372e7e8fb909c1dac51e29686953c0e139476
Author: Aaron Radzinski <[email protected]>
AuthorDate: Tue Mar 9 16:51:50 2021 -0800
WIP.
---
.../NCDslTermContext.scala => NCDslContext.scala} | 22 ++++++-------
.../model/intent/{utils => }/NCDslIntent.scala | 23 +++++++-------
.../NCDslSynonym.scala => NCDslPredicate.scala} | 10 ++----
.../model/intent/{utils => }/NCDslSynonym.scala | 8 +++--
.../model/intent/{utils => }/NCDslTerm.scala | 18 +++++------
...aselCompiler.scala => NCDslBaselCompiler.scala} | 30 +++++++++---------
...IntentDslCompiler.scala => NCDslCompiler.scala} | 36 ++++++++--------------
.../NCDslExprRetVal.scala} | 4 +--
.../intent/{utils => compiler}/NCDslFragment.scala | 14 +++++----
...ragmentCache.scala => NCDslFragmentCache.scala} | 4 +--
.../model/intent/solver/NCIntentSolver.scala | 2 +-
.../model/intent/solver/NCIntentSolverEngine.scala | 11 ++++---
.../apache/nlpcraft/probe/mgrs/NCProbeModel.scala | 2 +-
.../mgrs/model/NCModelSynonymDslCompiler.scala | 2 +-
...lCompilerSpec.scala => NCDslCompilerSpec.scala} | 18 +++++------
15 files changed, 95 insertions(+), 109 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslTermContext.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslContext.scala
similarity index 70%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslTermContext.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslContext.scala
index e903854..4a89d59 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslTermContext.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslContext.scala
@@ -15,22 +15,22 @@
* limitations under the License.
*/
-package org.apache.nlpcraft.model.intent.utils
+package org.apache.nlpcraft.model.intent
import org.apache.nlpcraft.common.ScalaMeta
import org.apache.nlpcraft.model.NCRequest
/**
- *
- * @param intentMeta Intent metadata.
- * @param reqMeta User request ('data' parameter) metadata.
- * @param usrMeta User object metadata.
- * @param compMeta Company metadata.
- * @param convMeta Conversation metadata.
- * @param fragMeta Optional fragment (argument) metadata passed during intent
fragment reference.
- * @param req Server request holder.
- */
-case class NCDslTermContext(
+ *
+ * @param intentMeta Intent metadata.
+ * @param reqMeta User request ('data' parameter) metadata.
+ * @param usrMeta User object metadata.
+ * @param compMeta Company metadata.
+ * @param convMeta Conversation metadata.
+ * @param fragMeta Optional fragment (argument) metadata passed during intent
fragment reference.
+ * @param req Server request holder.
+ */
+case class NCDslContext(
intentMeta: ScalaMeta,
reqMeta: ScalaMeta,
usrMeta: ScalaMeta,
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslIntent.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslIntent.scala
similarity index 86%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslIntent.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslIntent.scala
index 69a26fc..5722cc9 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslIntent.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslIntent.scala
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.nlpcraft.model.intent.utils
+package org.apache.nlpcraft.model.intent
import org.apache.nlpcraft.common.ScalaMeta
@@ -23,14 +23,14 @@ import java.util.regex.Pattern
/**
* DSL intent.
- *
- * @param dsl Original DSL of this intent.
- * @param id
- * @param ordered
- * @param meta
- * @param flow
- * @param terms
- */
+ *
+ * @param dsl Original DSL of this intent.
+ * @param id
+ * @param ordered
+ * @param meta
+ * @param flow
+ * @param terms
+ */
case class NCDslIntent(
dsl: String,
id: String,
@@ -51,9 +51,8 @@ case class NCDslIntent(
case Some(r) ⇒ Some(Pattern.compile(r))
case None ⇒ None
}
-
+
lazy val isFlowDefined = flow.isDefined || flowMtdName.isDefined
- override def toString: String =
- s"intent=$id"
+ override def toString: String = s"intent=$id"
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslSynonym.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslPredicate.scala
similarity index 81%
copy from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslSynonym.scala
copy to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslPredicate.scala
index 8c9ea03..39b6844 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslSynonym.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslPredicate.scala
@@ -15,17 +15,11 @@
* limitations under the License.
*/
-package org.apache.nlpcraft.model.intent.utils
+package org.apache.nlpcraft.model.intent
import org.apache.nlpcraft.model.NCToken
/**
- * DSl synonym.
*
- * @param alias
- * @param pred
*/
-case class NCDslSynonym(
- alias: Option[String],
- pred: (NCToken, NCDslTermContext) ⇒ Boolean,
-)
+trait NCDslPredicate extends ((NCToken, NCDslContext) ⇒ (Boolean
/*Predicate.*/ , Boolean /*Whether or not token was used.*/ ))
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslSynonym.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslSynonym.scala
similarity index 90%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslSynonym.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslSynonym.scala
index 8c9ea03..ef6ca09 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslSynonym.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslSynonym.scala
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.nlpcraft.model.intent.utils
+package org.apache.nlpcraft.model.intent
import org.apache.nlpcraft.model.NCToken
@@ -27,5 +27,7 @@ import org.apache.nlpcraft.model.NCToken
*/
case class NCDslSynonym(
alias: Option[String],
- pred: (NCToken, NCDslTermContext) ⇒ Boolean,
-)
+ pred: NCDslPredicate,
+) {
+ require(pred != null)
+}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslTerm.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslTerm.scala
similarity index 83%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslTerm.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslTerm.scala
index 97e8efd..3b4ebe3 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslTerm.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/NCDslTerm.scala
@@ -15,22 +15,22 @@
* limitations under the License.
*/
-package org.apache.nlpcraft.model.intent.utils
+package org.apache.nlpcraft.model.intent
import org.apache.nlpcraft.model.NCToken
/**
* DSL term.
- *
- * @param id Optional ID of this term.
- * @param pred
- * @param min
- * @param max
- * @param conv
- */
+ *
+ * @param id Optional ID of this term.
+ * @param pred
+ * @param min
+ * @param max
+ * @param conv
+ */
case class NCDslTerm(
id: Option[String],
- pred: (NCToken, NCDslTermContext) ⇒ (Boolean/*Predicate.*/,
Boolean/*Whether or not token was used.*/),
+ pred: NCDslPredicate,
min: Int,
max: Int,
conv: Boolean,
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIntentDslBaselCompiler.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslBaselCompiler.scala
similarity index 97%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIntentDslBaselCompiler.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslBaselCompiler.scala
index 44d9a2a..6983876 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIntentDslBaselCompiler.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslBaselCompiler.scala
@@ -20,16 +20,16 @@ package org.apache.nlpcraft.model.intent.compiler
import org.apache.commons.lang3.StringUtils
import org.apache.nlpcraft.common.{NCE, U}
import org.apache.nlpcraft.model.NCToken
-import org.apache.nlpcraft.model.intent.utils.{NCDslTermContext,
NCDslTermRetVal}
import org.antlr.v4.runtime.{ParserRuleContext ⇒ PRC}
import org.antlr.v4.runtime.tree.{TerminalNode ⇒ TN}
+import org.apache.nlpcraft.model.intent.NCDslContext
-import java.lang.{Long ⇒ JLong, Double ⇒ JDouble}
+import java.lang.{Double ⇒ JDouble, Long ⇒ JLong}
import java.time.LocalDate
import java.util.{Collections, ArrayList ⇒ JArrayList, HashMap ⇒ JHashMap}
import scala.collection.mutable
-trait NCIntentDslBaselCompiler {
+trait NCDslBaselCompiler {
def syntaxError(errMsg: String, srcName: String, line: Int, pos: Int): NCE
def runtimeError(errMsg: String, srcName: String, line: Int, pos: Int,
cause: Exception = null): NCE
@@ -57,8 +57,8 @@ trait NCIntentDslBaselCompiler {
runtimeError(errMsg, tok.getTokenSource.getSourceName, tok.getLine,
tok.getCharPositionInLine, cause)
}
- type StackType = mutable.ArrayStack[NCDslTermRetVal]
- type Instr = (NCToken, StackType, NCDslTermContext) ⇒ Unit
+ type StackType = mutable.ArrayStack[NCDslExprRetVal]
+ type Instr = (NCToken, StackType, NCDslContext) ⇒ Unit
//noinspection ComparingUnrelatedTypes
def isJLong(v: Object): Boolean = v.isInstanceOf[JLong]
@@ -74,10 +74,10 @@ trait NCIntentDslBaselCompiler {
def asToken(v: Object): NCToken = v.asInstanceOf[NCToken]
def asBool(v: Object): Boolean = v.asInstanceOf[Boolean]
- def pushAny(any: Object, usedTok: Boolean)(implicit stack: StackType):
Unit = stack.push(NCDslTermRetVal(any, usedTok))
- def pushLong(any: Long, usedTok: Boolean)(implicit stack: StackType): Unit
= stack.push(NCDslTermRetVal(Long.box(any), usedTok))
- def pushDouble(any: Double, usedTok: Boolean)(implicit stack: StackType):
Unit = stack.push(NCDslTermRetVal(Double.box(any), usedTok))
- def pushBool(any: Boolean, usedTok: Boolean)(implicit stack: StackType):
Unit = stack.push(NCDslTermRetVal(Boolean.box(any), usedTok))
+ def pushAny(any: Object, usedTok: Boolean)(implicit stack: StackType):
Unit = stack.push(NCDslExprRetVal(any, usedTok))
+ def pushLong(any: Long, usedTok: Boolean)(implicit stack: StackType): Unit
= stack.push(NCDslExprRetVal(Long.box(any), usedTok))
+ def pushDouble(any: Double, usedTok: Boolean)(implicit stack: StackType):
Unit = stack.push(NCDslExprRetVal(Double.box(any), usedTok))
+ def pushBool(any: Boolean, usedTok: Boolean)(implicit stack: StackType):
Unit = stack.push(NCDslExprRetVal(Boolean.box(any), usedTok))
// Runtime errors.
def rtUnaryOpError(op: String, v: Object)(implicit ctx: PRC): NCE =
@@ -102,8 +102,8 @@ trait NCIntentDslBaselCompiler {
require(stack.size >= 2)
// Stack pops in reverse order of push...
- val NCDslTermRetVal(val2, f2) = stack.pop()
- val NCDslTermRetVal(val1, f1) = stack.pop()
+ val NCDslExprRetVal(val2, f2) = stack.pop()
+ val NCDslExprRetVal(val1, f1) = stack.pop()
(val1, val2, f1, f2)
}
@@ -117,9 +117,9 @@ trait NCIntentDslBaselCompiler {
require(stack.size >= 3)
// Stack pops in reverse order of push...
- val NCDslTermRetVal(val3, f3) = stack.pop()
- val NCDslTermRetVal(val2, f2) = stack.pop()
- val NCDslTermRetVal(val1, f1) = stack.pop()
+ val NCDslExprRetVal(val3, f3) = stack.pop()
+ val NCDslExprRetVal(val2, f2) = stack.pop()
+ val NCDslExprRetVal(val1, f1) = stack.pop()
(val1, val2, val3, f1, f2, f3)
}
@@ -132,7 +132,7 @@ trait NCIntentDslBaselCompiler {
def pop1()(implicit stack: StackType): (Object, Boolean) = {
require(stack.nonEmpty)
- val NCDslTermRetVal(v, f) = stack.pop()
+ val NCDslExprRetVal(v, f) = stack.pop()
(v, f)
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIntentDslCompiler.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompiler.scala
similarity index 96%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIntentDslCompiler.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompiler.scala
index 55793c2..682e054 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIntentDslCompiler.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompiler.scala
@@ -22,18 +22,18 @@ import org.antlr.v4.runtime.tree.ParseTreeWalker
import org.antlr.v4.runtime._
import org.apache.nlpcraft.common._
import
org.apache.nlpcraft.model.intent.compiler.antlr4.{NCIntentDslBaseListener,
NCIntentDslLexer, NCIntentDslParser ⇒ IDP}
-import org.apache.nlpcraft.model.intent.utils._
-import org.apache.nlpcraft.model.intent.compiler.{NCIntentDslFragmentCache ⇒
FragCache}
+import org.apache.nlpcraft.model.intent.compiler.{NCDslFragmentCache ⇒
FragCache}
import org.apache.nlpcraft.model._
-import scala.collection.JavaConverters._
+import org.apache.nlpcraft.model.intent.{NCDslContext, NCDslIntent,
NCDslSynonym, NCDslTerm}
+import scala.collection.JavaConverters._
import java.nio.file.Path
import java.util.Optional
import java.util.regex.{Pattern, PatternSyntaxException}
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
-object NCIntentDslCompiler extends LazyLogging {
+object NCDslCompiler extends LazyLogging {
// Compiler caches.
private val intentCache = new mutable.HashMap[String, Set[NCDslIntent]]
private val synCache = new mutable.HashMap[String, NCDslSynonym]
@@ -43,7 +43,7 @@ object NCIntentDslCompiler extends LazyLogging {
* @param dsl
* @param mdlId
*/
- class FiniteStateMachine(dsl: String, mdlId: String) extends
NCIntentDslBaseListener with NCIntentDslBaselCompiler {
+ class FiniteStateMachine(dsl: String, mdlId: String) extends
NCIntentDslBaseListener with NCDslBaselCompiler {
// Accumulators for parsed objects.
private val intents = ArrayBuffer.empty[NCDslIntent]
private var synonym: NCDslSynonym = _
@@ -81,19 +81,12 @@ object NCIntentDslCompiler extends LazyLogging {
* Shared/common implementation.
*/
override def exitUnaryExpr(ctx: IDP.UnaryExprContext): Unit = instrs
+= parseUnaryExpr(ctx.MINUS(), ctx.NOT())(ctx)
-
override def exitMultExpr(ctx: IDP.MultExprContext): Unit = instrs +=
parseMultExpr(ctx.MULT(), ctx.MOD(), ctx.DIV())(ctx)
-
override def exitPlusExpr(ctx: IDP.PlusExprContext): Unit = instrs +=
parsePlusExpr(ctx.PLUS(), ctx.MINUS())(ctx)
-
override def exitCompExpr(ctx: IDP.CompExprContext): Unit = instrs +=
parseCompExpr(ctx.LT(), ctx.GT(), ctx.LTEQ(), ctx.GTEQ())(ctx)
-
override def exitLogExpr(ctx: IDP.LogExprContext): Unit = instrs +=
parseLogExpr(ctx.AND, ctx.OR())(ctx)
-
override def exitEqExpr(ctx: IDP.EqExprContext): Unit = instrs +=
parseEqExpr(ctx.EQ, ctx.NEQ())(ctx)
-
override def exitCallExpr(ctx: IDP.CallExprContext): Unit = instrs +=
parseCallExpr(ctx.FUN_NAME())(ctx)
-
override def exitAtom(ctx: IDP.AtomContext): Unit = instrs +=
parseAtom(ctx.getText)(ctx)
/**
@@ -160,10 +153,10 @@ object NCIntentDslCompiler extends LazyLogging {
val code = mutable.Buffer.empty[Instr] ++ instrs // Local copy.
- synonym = NCDslSynonym(
+ synonym = intent.NCDslSynonym(
Option(alias),
- (tok: NCToken, termCtx: NCDslTermContext) ⇒ {
- val stack = new mutable.ArrayStack[NCDslTermRetVal]()
+ (tok: NCToken, termCtx: NCDslContext) ⇒ {
+ val stack = new mutable.ArrayStack[NCDslExprRetVal]()
// Execute all instructions.
code.foreach(_ (tok, stack, termCtx))
@@ -187,11 +180,8 @@ object NCIntentDslCompiler extends LazyLogging {
}
override def exitTermEq(ctx: IDP.TermEqContext): Unit = termConv =
ctx.TILDA() != null
-
override def exitFragMeta(ctx: IDP.FragMetaContext): Unit = fragMeta =
U.jsonToScalaMap(ctx.jsonObj().getText)
-
override def exitMetaDecl(ctx: IDP.MetaDeclContext): Unit = intentMeta
= U.jsonToScalaMap(ctx.jsonObj().getText)
-
override def exitOrderedDecl(ctx: IDP.OrderedDeclContext): Unit =
ordered = ctx.BOOL().getText == "true"
override def exitFragRef(ctx: IDP.FragRefContext): Unit = {
@@ -246,7 +236,7 @@ object NCIntentDslCompiler extends LazyLogging {
val clsName = refClsName.orNull
val mtdName = refMtdName.orNull
- (tok: NCToken, termCtx: NCDslTermContext) ⇒ {
+ (tok: NCToken, termCtx: NCDslContext) ⇒ {
val javaCtx: NCTokenPredicateContext = new
NCTokenPredicateContext {
override lazy val getRequest: NCRequest =
termCtx.req
override lazy val getToken: NCToken = tok
@@ -301,8 +291,8 @@ object NCIntentDslCompiler extends LazyLogging {
code ++= instrs
- (tok: NCToken, termCtx: NCDslTermContext) ⇒ {
- val stack = new mutable.ArrayStack[NCDslTermRetVal]()
+ (tok: NCToken, termCtx: NCDslContext) ⇒ {
+ val stack = new mutable.ArrayStack[NCDslExprRetVal]()
// Execute all instructions.
code.foreach(_ (tok, stack, termCtx))
@@ -318,7 +308,7 @@ object NCIntentDslCompiler extends LazyLogging {
}
// Add term.
- terms += NCDslTerm(
+ terms += intent.NCDslTerm(
Option(termId),
pred,
min,
@@ -341,7 +331,7 @@ object NCIntentDslCompiler extends LazyLogging {
}
override def exitIntent(ctx: IDP.IntentContext): Unit = {
- intents += NCDslIntent(
+ intents += intent.NCDslIntent(
dsl,
intentId,
ordered,
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslTermRetVal.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslExprRetVal.scala
similarity index 91%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslTermRetVal.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslExprRetVal.scala
index d23cfe5..1ee8ef1 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslTermRetVal.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslExprRetVal.scala
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.nlpcraft.model.intent.utils
+package org.apache.nlpcraft.model.intent.compiler
/**
*
*/
-case class NCDslTermRetVal (
+case class NCDslExprRetVal(
retVal: Object,
usedTok: Boolean
)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslFragment.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslFragment.scala
similarity index 79%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslFragment.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslFragment.scala
index 9831fe9..66e5daa 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/NCDslFragment.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslFragment.scala
@@ -15,14 +15,16 @@
* limitations under the License.
*/
-package org.apache.nlpcraft.model.intent.utils
+package org.apache.nlpcraft.model.intent.compiler
+
+import org.apache.nlpcraft.model.intent.NCDslTerm
/**
- * DSL fragment.
- *
- * @param id ID of this fragment (must be unique within a model).
- * @param terms List of terms this fragment defines.
- */
+ * DSL fragment.
+ *
+ * @param id ID of this fragment (must be unique within a model).
+ * @param terms List of terms this fragment defines.
+ */
case class NCDslFragment(
id: String,
terms: List[NCDslTerm]
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIntentDslFragmentCache.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslFragmentCache.scala
similarity index 94%
rename from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIntentDslFragmentCache.scala
rename to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslFragmentCache.scala
index fbb2998..cc3e207 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIntentDslFragmentCache.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslFragmentCache.scala
@@ -17,15 +17,13 @@
package org.apache.nlpcraft.model.intent.compiler
-import org.apache.nlpcraft.model.intent.utils.NCDslFragment
-
import scala.collection.concurrent.TrieMap
import scala.collection.mutable
/**
* Global intent DSL fragment cache.
*/
-object NCIntentDslFragmentCache {
+object NCDslFragmentCache {
private final val cache = TrieMap.empty[String /* Model ID. */ ,
mutable.Map[String, NCDslFragment]]
/**
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 7198adf..9cea556 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
@@ -24,7 +24,7 @@ import org.apache.nlpcraft.common.debug.NCLogHolder
import org.apache.nlpcraft.common.opencensus.NCOpenCensusTrace
import org.apache.nlpcraft.common.util.NCUtils
import org.apache.nlpcraft.model.impl.NCVariantImpl
-import org.apache.nlpcraft.model.intent.utils.NCDslIntent
+import org.apache.nlpcraft.model.intent.NCDslIntent
import org.apache.nlpcraft.model.{NCContext, NCIntentMatch, NCIntentSkip,
NCModel, NCRejection, NCResult, NCToken, NCVariant}
import org.apache.nlpcraft.probe.mgrs.dialogflow.NCDialogFlowManager
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
index 01d1c4b..f15bd07 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/solver/NCIntentSolverEngine.scala
@@ -6,10 +6,11 @@ import org.apache.nlpcraft.common.debug.{NCLogGroupToken,
NCLogHolder}
import org.apache.nlpcraft.common.opencensus.NCOpenCensusTrace
import org.apache.nlpcraft.common._
import org.apache.nlpcraft.model.impl.NCTokenLogger
-import org.apache.nlpcraft.model.intent.utils.{NCDslIntent, NCDslTerm,
NCDslTermContext}
+import org.apache.nlpcraft.model.intent.utils.NCDslTerm
import org.apache.nlpcraft.model.{NCContext, NCIntentMatch, NCResult, NCToken}
import org.apache.nlpcraft.probe.mgrs.dialogflow.NCDialogFlowManager
import org.apache.nlpcraft.model.impl.NCTokenPimp._
+import org.apache.nlpcraft.model.intent.{NCDslContext, NCDslIntent, NCDslTerm}
import java.util.function.Function
import scala.collection.mutable
@@ -466,7 +467,7 @@ object NCIntentSolverEngine extends LazyLogging with
NCOpenCensusTrace {
val ordered = intent.ordered
var lastTermMatch: TermMatch = null
- val termCtx = NCDslTermContext(
+ val termCtx = NCDslContext(
intentMeta = intent.meta,
reqMeta = ctx.getRequest.getRequestData,
usrMeta = ctx.getRequest.getUser.getMetadata,
@@ -585,7 +586,7 @@ object NCIntentSolverEngine extends LazyLogging with
NCOpenCensusTrace {
@throws[NCE]
private def solveTerm(
term: NCDslTerm,
- ctx: NCDslTermContext,
+ ctx: NCDslContext,
senToks: Seq[UsedToken],
convToks: Seq[UsedToken]
): Option[TermMatch] =
@@ -634,8 +635,8 @@ object NCIntentSolverEngine extends LazyLogging with
NCOpenCensusTrace {
*/
@throws[NCE]
private def solvePredicate(
- pred: (NCToken, NCDslTermContext) ⇒ (Boolean /*Predicate.*/ , Boolean
/*Whether or not token was used.*/ ),
- ctx: NCDslTermContext,
+ pred: (NCToken, NCDslContext) ⇒ (Boolean /*Predicate.*/ , Boolean
/*Whether or not token was used.*/ ),
+ ctx: NCDslContext,
min: Int,
max: Int,
senToks: Seq[UsedToken],
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeModel.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeModel.scala
index bc2cd72..fec4552 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeModel.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeModel.scala
@@ -17,8 +17,8 @@
package org.apache.nlpcraft.probe.mgrs
+import org.apache.nlpcraft.model.intent.NCDslIntent
import org.apache.nlpcraft.model.intent.solver.NCIntentSolver
-import org.apache.nlpcraft.model.intent.utils.NCDslIntent
import org.apache.nlpcraft.model.{NCElement, NCModel}
import scala.collection.{Map, Seq}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelSynonymDslCompiler.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelSynonymDslCompiler.scala
index 92faf7b..81b7175 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelSynonymDslCompiler.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/model/NCModelSynonymDslCompiler.scala
@@ -22,7 +22,7 @@ import org.antlr.v4.runtime._
import org.antlr.v4.runtime.tree._
import org.apache.nlpcraft.common._
import org.apache.nlpcraft.model.NCToken
-import org.apache.nlpcraft.model.intent.utils
+import org.apache.nlpcraft.model.intent.{NCDslSynonym, utils}
import org.apache.nlpcraft.model.intent.utils._
import org.apache.nlpcraft.probe.mgrs.model.antlr4.{NCSynonymDslBaseListener,
NCSynonymDslLexer, NCSynonymDslParser}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/dsl/compiler/NCIntentDslCompilerSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/dsl/compiler/NCDslCompilerSpec.scala
similarity index 92%
rename from
nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/dsl/compiler/NCIntentDslCompilerSpec.scala
rename to
nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/dsl/compiler/NCDslCompilerSpec.scala
index 761f5e3..2fc1c0f 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/dsl/compiler/NCIntentDslCompilerSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/dsl/compiler/NCDslCompilerSpec.scala
@@ -18,7 +18,7 @@
package org.apache.nlpcraft.model.intent.dsl.compiler
import org.apache.nlpcraft.common._
-import org.apache.nlpcraft.model.intent.compiler.{NCIntentDslCompiler,
NCIntentDslFragmentCache}
+import org.apache.nlpcraft.model.intent.compiler.{NCDslCompiler,
NCDslFragmentCache}
import org.apache.nlpcraft.model.intent.impl.NCIntentDslFragmentCache
import org.junit.jupiter.api.Test
@@ -27,7 +27,7 @@ import java.nio.file.{Path, Paths}
/**
* Tests for DSL compiler.
*/
-class NCIntentDslCompilerSpec {
+class NCDslCompilerSpec {
private final val MODEL_ID = "test.mdl.id"
/**
@@ -36,7 +36,7 @@ class NCIntentDslCompilerSpec {
*/
private def checkCompileOk(dsl: String): Unit =
try {
- NCIntentDslCompiler.compileIntents(dsl, MODEL_ID)
+ NCDslCompiler.compileIntents(dsl, MODEL_ID)
assert(true)
}
@@ -50,7 +50,7 @@ class NCIntentDslCompilerSpec {
*/
private def checkPathCompileOk(path: Path): Unit =
try {
- NCIntentDslCompiler.compileIntents(path, MODEL_ID)
+ NCDslCompiler.compileIntents(path, MODEL_ID)
assert(true)
}
@@ -64,7 +64,7 @@ class NCIntentDslCompilerSpec {
*/
private def checkCompileError(txt: String): Unit =
try {
- NCIntentDslCompiler.compileIntents(txt, MODEL_ID)
+ NCDslCompiler.compileIntents(txt, MODEL_ID)
assert(false)
} catch {
@@ -76,15 +76,15 @@ class NCIntentDslCompilerSpec {
@Test
@throws[NCException]
def testPathCompileOk(): Unit = {
- NCIntentDslFragmentCache.clear(MODEL_ID)
+ NCDslFragmentCache.clear(MODEL_ID)
-
checkPathCompileOk(Paths.get(classOf[NCIntentDslCompilerSpec].getResource("test_ok.nc").toURI))
+
checkPathCompileOk(Paths.get(classOf[NCDslCompilerSpec].getResource("test_ok.nc").toURI))
}
@Test
@throws[NCException]
def testInlineCompileOk(): Unit = {
- NCIntentDslFragmentCache.clear(MODEL_ID)
+ NCDslFragmentCache.clear(MODEL_ID)
checkCompileOk(
"""
@@ -140,7 +140,7 @@ class NCIntentDslCompilerSpec {
@Test
@throws[NCException]
def testInlineCompileFail(): Unit = {
- NCIntentDslFragmentCache.clear(MODEL_ID)
+ NCDslFragmentCache.clear(MODEL_ID)
checkCompileError(
"""