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 b6b88a0 WIP.
b6b88a0 is described below
commit b6b88a0e2a6f8ee7be87c4d33960bc9ee81f803a
Author: Aaron Radzinski <[email protected]>
AuthorDate: Tue Feb 9 20:46:15 2021 -0800
WIP.
---
.../intent/impl/ver2/NCIntentDslCompiler.scala | 8 ++++++--
.../model/intent/utils/ver2/NCDslTerm.scala | 2 +-
.../{NCDslTerm.scala => NCDslTermContext.scala} | 23 +++++++---------------
.../{NCDslTerm.scala => NCDslTermRetVal.scala} | 22 +++++----------------
4 files changed, 19 insertions(+), 36 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 7d1f734..f62cd04 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
@@ -21,6 +21,7 @@ import com.typesafe.scalalogging.LazyLogging
import org.antlr.v4.runtime._
import org.antlr.v4.runtime.tree.ParseTreeWalker
import org.apache.nlpcraft.common._
+import org.apache.nlpcraft.model.NCToken
import org.apache.nlpcraft.model.intent.impl.antlr4._
import org.apache.nlpcraft.model.intent.utils.ver2._
@@ -50,7 +51,10 @@ object NCIntentDslCompiler extends LazyLogging {
private var min = 1
private var max = 1
- private var cval: Any = _
+ type Instr = (NCToken, NCDslTermContext) ⇒ NCDslTermRetVal
+
+ // Term's code, i.e. list of instructions.
+ private var termCode = mutable.Buffer.empty[Instr]
/**
*
@@ -104,7 +108,7 @@ object NCIntentDslCompiler extends LazyLogging {
}
override def exitVal(ctx: NCIntentDslParser.ValContext): Unit = {
- cval = mkVal(ctx.getText)
+ termCode += ((_, _) ⇒ NCDslTermRetVal(mkVal(ctx.getText), usedTok
= false))
}
/**
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
index 9cc3ad4..3edc892 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
@@ -24,7 +24,7 @@ import org.apache.nlpcraft.model.NCToken
*/
case class NCDslTerm(
id: String,
- pred: NCToken ⇒ Boolean,
+ pred: (NCToken, NCDslTermContext) ⇒ (Boolean/*Predicate.*/,
Boolean/*Whether or not token was used.*/),
min: Int,
max: Int,
conv: Boolean
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTermContext.scala
similarity index 60%
copy from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
copy to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTermContext.scala
index 9cc3ad4..91fce72 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTermContext.scala
@@ -17,22 +17,13 @@
package org.apache.nlpcraft.model.intent.utils.ver2
-import org.apache.nlpcraft.model.NCToken
+import org.apache.nlpcraft.common.ScalaMeta
/**
- * DSL term.
+ *
*/
-case class NCDslTerm(
- id: String,
- pred: NCToken ⇒ Boolean,
- min: Int,
- max: Int,
- conv: Boolean
-) {
- if (pred == null)
- throw new IllegalArgumentException("Intent DSL term must be defined.")
- if (min < 0 || min > max)
- throw new IllegalArgumentException(s"Invalid intent DSL term min
quantifiers: $min (must be min >= 0 && min <= max).")
- if (max < 1)
- throw new IllegalArgumentException(s"Invalid intent DSL term max
quantifiers: $max (must be max >= 1).")
-}
+case class NCDslTermContext(
+ reqMeta: ScalaMeta,
+ usrMeta: ScalaMeta,
+ compMeta: ScalaMeta
+)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTermRetVal.scala
similarity index 60%
copy from
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
copy to
nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTermRetVal.scala
index 9cc3ad4..f9563a4 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTerm.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/utils/ver2/NCDslTermRetVal.scala
@@ -17,22 +17,10 @@
package org.apache.nlpcraft.model.intent.utils.ver2
-import org.apache.nlpcraft.model.NCToken
-
/**
- * DSL term.
+ *
*/
-case class NCDslTerm(
- id: String,
- pred: NCToken ⇒ Boolean,
- min: Int,
- max: Int,
- conv: Boolean
-) {
- if (pred == null)
- throw new IllegalArgumentException("Intent DSL term must be defined.")
- if (min < 0 || min > max)
- throw new IllegalArgumentException(s"Invalid intent DSL term min
quantifiers: $min (must be min >= 0 && min <= max).")
- if (max < 1)
- throw new IllegalArgumentException(s"Invalid intent DSL term max
quantifiers: $max (must be max >= 1).")
-}
+case class NCDslTermRetVal (
+ retVal: Any,
+ usedTok: Boolean
+)