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 2bbf715 WIP.
2bbf715 is described below
commit 2bbf71512f828d5a0ee45249c83f2673d7dc5f75
Author: Aaron Radzinski <[email protected]>
AuthorDate: Wed Feb 10 15:08:40 2021 -0800
WIP.
---
.../intent/impl/ver2/NCIntentDslCompiler.scala | 41 ++++++++++++++++++++--
.../model/intent/utils/ver2/NCDslIntent.scala | 2 +-
2 files changed, 40 insertions(+), 3 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslCompiler.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslCompiler.scala
index f62cd04..d965800 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslCompiler.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCIntentDslCompiler.scala
@@ -50,8 +50,11 @@ object NCIntentDslCompiler extends LazyLogging {
private var termConv: Boolean = _
private var min = 1
private var max = 1
+ private var termClsName: String = _
+ private var termMtdName: String = _
- type Instr = (NCToken, NCDslTermContext) ⇒ NCDslTermRetVal
+ type StackType = mutable.ArrayStack[NCDslTermRetVal]
+ type Instr = (NCToken, StackType, NCDslTermContext) ⇒ Unit
// Term's code, i.e. list of instructions.
private var termCode = mutable.Buffer.empty[Instr]
@@ -77,6 +80,40 @@ object NCIntentDslCompiler extends LazyLogging {
assert(false)
}
+ override def exitExpr(ctx: NCIntentDslParser.ExprContext): Unit = {
+ if (ctx.`val`() != null) {} // Just a val - no-op.
+ else if (ctx.LPAREN() != null && ctx.RPAREN() != null) {} // Just
a val in brackets - no-op.
+ else if (ctx.COMMA() != null) { // Collection.
+ termCode += ((_, stack: StackType, _) ⇒ {
+ require(stack.nonEmpty)
+
+ val NCDslTermRetVal(lastVal, usedTok) = stack.pop()
+
+ val newVal = lastVal match {
+ case list: List[Any] ⇒ mkVal(ctx.`val`().getText) ::
list
+ case _ ⇒ List(lastVal)
+ }
+
+ stack.push(NCDslTermRetVal(newVal, usedTok))
+ })
+ }
+ else if (ctx.MINUS() != null || ctx.PLUS() != null || ctx.STAR()
!= null || ctx.FSLASH() != null) {
+ termCode += ((_, stack: StackType, _) ⇒ {
+ require(stack.size >= 2)
+
+ val NCDslTermRetVal(lastVal1, usedTok1) = stack.pop()
+ val NCDslTermRetVal(lastVal2, usedTok2) = stack.pop()
+ })
+ }
+ }
+
+ override def exitClsNer(ctx: NCIntentDslParser.ClsNerContext): Unit = {
+ if (ctx.javaFqn() != null)
+ termClsName = ctx.javaFqn().getText.strip()
+
+ termMtdName = ctx.ID().getText.strip()
+ }
+
override def exitTermId(ctx: NCIntentDslParser.TermIdContext): Unit = {
termId = ctx.ID().getText.trim
}
@@ -108,7 +145,7 @@ object NCIntentDslCompiler extends LazyLogging {
}
override def exitVal(ctx: NCIntentDslParser.ValContext): Unit = {
- termCode += ((_, _) ⇒ NCDslTermRetVal(mkVal(ctx.getText), usedTok
= false))
+ termCode += ((_, stack, _) ⇒
stack.push(NCDslTermRetVal(mkVal(ctx.getText), usedTok = false)))
}
/**
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslIntent.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslIntent.scala
index c86b415..a686453 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslIntent.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslIntent.scala
@@ -48,5 +48,5 @@ case class NCDslIntent(
}
override def toString: String =
- s"Intent: '$id'"
+ s"intent=$id"
}