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 203d3b4 WIP.
203d3b4 is described below
commit 203d3b44d54d6939b74270972f551e4bd3171122
Author: Aaron Radzinzski <[email protected]>
AuthorDate: Sat Feb 27 01:03:45 2021 -0800
WIP.
---
.../model/intent/impl/antlr4/NCIntentDsl.g4 | 8 ++--
.../model/intent/impl/ver2/NCBaseDslCompiler.scala | 3 +-
.../intent/impl/ver2/NCIntentDslCompiler.scala | 48 +++++++++++++++-------
3 files changed, 40 insertions(+), 19 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/antlr4/NCIntentDsl.g4
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/antlr4/NCIntentDsl.g4
index b051044..960c336 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/antlr4/NCIntentDsl.g4
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/antlr4/NCIntentDsl.g4
@@ -101,7 +101,10 @@ minMaxShortcut
| MULT
;
minMaxRange: LBR INT COMMA INT RBR;
-id: ID | FUN_NAME;
+id
+ : ID
+ | FUN_NAME // Function name can overlap with ID so we detect both.
+ ;
// Lexer.
FUN_NAME
@@ -224,11 +227,10 @@ FUN_NAME
| 'day_of_year'
| 'hour'
| 'minute'
- | 'sec'
+ | 'second'
| 'week_of_month'
| 'week_of_year'
| 'quarter'
- | 'msec'
| 'now'
;
FRAG: 'fragment'; // To resolve ambiguity with ANTLR4 keyword.
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCBaseDslCompiler.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCBaseDslCompiler.scala
index d15c241..3b6cfdf 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCBaseDslCompiler.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/impl/ver2/NCBaseDslCompiler.scala
@@ -721,11 +721,10 @@ trait NCBaseDslCompiler {
case "day_of_year" ⇒ doDayOfYear()
case "hour" ⇒
case "minute" ⇒
- case "sec" ⇒
+ case "second" ⇒
case "week_of_month" ⇒
case "week_of_year" ⇒
case "quarter" ⇒
- case "msec" ⇒
case "now" ⇒ // Epoc time.
case _ ⇒ throw rtUnknownFunError(fun) // Assertion.
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 dc6acf8..3f8014b 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
@@ -133,7 +133,7 @@ object NCIntentDslCompiler extends LazyLogging {
val pred =
if (termMtdName != null) { // User-code defined term.
(tok: NCToken, termCtx: NCDslTermContext) ⇒ {
- val javaCtx = new NCTokenPredicateContext {
+ val javaCtx: NCTokenPredicateContext = new
NCTokenPredicateContext {
override lazy val getRequest: NCRequest =
termCtx.req
override lazy val getToken: NCToken = tok
override lazy val getIntentMeta:
Optional[NCMetadata] =
@@ -216,7 +216,7 @@ object NCIntentDslCompiler extends LazyLogging {
* @param msg
* @param line
* @param charPos
- * @param dsl
+ * @param dsl Original DSL text (input).
* @param mdlId
* @return
*/
@@ -226,10 +226,15 @@ object NCIntentDslCompiler extends LazyLogging {
charPos: Int, // 0, 1, 2, ...
dsl: String,
mdlId: String): String = {
- val dash = "-" * dsl.length
- val pos = Math.max(0, charPos)
+ val aLine = dsl.split("\n")(line - 1)
+ val preLen = aLine.length
+ val dslLine = aLine.strip()
+ val postLen = dslLine.length
+ val delta = preLen - postLen
+ val dash = "-" * dslLine.length
+ val pos = Math.max(0, charPos - delta)
val posPtr = dash.substring(0, pos) + r("^") + y(dash.substring(pos +
1))
- val dslPtr = dsl.substring(0, pos) + r(dsl.charAt(pos)) +
y(dsl.substring(pos + 1))
+ val dslPtr = dslLine.substring(0, pos) + r(dslLine.charAt(pos)) +
y(dslLine.substring(pos + 1))
s"Intent DSL syntax error at line $line:${charPos + 1} - $msg\n" +
s" |-- ${c("Model:")} $mdlId\n" +
@@ -273,20 +278,35 @@ object NCIntentDslCompiler extends LazyLogging {
msg: String,
e: RecognitionException): Unit = throw new NCE(mkSyntaxError(msg,
line, charPos - 1, dsl, mdlId))
}
-
+
/**
- *
- * @param dsl Intent DSL to parse.
- * @param mdlId ID of the model the intent belongs to.
- * @return
- */
+ * Compile individual fragment or intent. Note that fragments are
accumulated in a static
+ * map keyed by model ID. Only intents are returned, if any.
+ *
+ * @param filePath *.nc DSL file to compile.
+ * @param mdlId ID of the model *.nc file belongs to.
+ * @return
+ */
+ def compileFile(
+ filePath: String,
+ mdlId: String
+ ): Set[NCDslIntent] = ???
+
+ /**
+ * Compile individual fragment or intent. Note that fragments are
accumulated in a static
+ * map keyed by model ID. Only intents are returned, if any.
+ *
+ * @param dsl DSL to compile.
+ * @param mdlId ID of the model DSL belongs to.
+ * @return
+ */
def compile(
dsl: String,
mdlId: String
- ): NCDslIntent = {
+ ): Set[NCDslIntent] = {
require(dsl != null)
- val src = dsl.strip().replace("\r\n", " ").replace("\n", " ")
+ val src = dsl.strip()
val intent: NCDslIntent = cache.getOrElseUpdate(src, {
// ANTLR4 armature.
@@ -310,6 +330,6 @@ object NCIntentDslCompiler extends LazyLogging {
fsm.getBuiltIntent
})
- intent
+ Set(intent) // TODO
}
}