You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2021/07/23 05:39:25 UTC
[incubator-nlpcraft] 01/02: WIP on NLPCRAFT-369.
This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-369
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit ff7dcd32b6bde70568923bc2abfd6c16eaa56fec
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Thu Jul 22 14:07:05 2021 -0700
WIP on NLPCRAFT-369.
---
.../model/intent/compiler/NCIdlCompiler.scala | 8 ++--
.../intent/idl/compiler/NCIdlCompilerSpec.scala | 48 +++++++++++++++++++++-
2 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompiler.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompiler.scala
index 7ba490c..e5d2653 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompiler.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompiler.scala
@@ -122,17 +122,17 @@ object NCIdlCompiler extends LazyLogging {
def boolVal(k: String, v: Object): Boolean =
v match {
case b: java.lang.Boolean if b != null => b
- case _ => throw newSyntaxError(s"Invalid intent option: $k")(ctx)
+ case _ => throw newSyntaxError(s"Invalid intent option value: $k")(ctx)
}
for ((k, v) <- json) {
if (k == "ordered")
opts.ordered = boolVal(k, v)
- if (k == "unused_free_words")
+ else if (k == "unused_free_words")
opts.ignoreUnusedFreeWords = boolVal(k, v)
- if (k == "unused_sys_toks")
+ else if (k == "unused_sys_toks")
opts.ignoreUnusedSystemTokens = boolVal(k, v)
- if (k == "unused_user_toks")
+ else if (k == "unused_user_toks")
opts.ignoreUnusedUserTokens = boolVal(k, v)
else
throw newSyntaxError(s"Unknown intent option: $k")(ctx)
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala
index 6fbc15a..adb717c 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/NCIdlCompilerSpec.scala
@@ -101,6 +101,10 @@ class NCIdlCompilerSpec {
| * +=====================+
| */
|intent=i1
+ | options={
+ | 'ordered': true,
+ | 'unused_free_words': false
+ | }
| flow="a[^0-9]b" // Flow comment.
| term(t1)={has(json("{'a': true, 'b\'2': {'arr': [1, 2, 3]}}"), list("موسكو\"", 'v1\'v1', "k2", "v2"))}
| fragment(f1, {'a': true, 'b': ["s1", "s2"]}) /* Another fragment. */
@@ -118,6 +122,7 @@ class NCIdlCompilerSpec {
| term~/class#method/
|
|intent=i1
+ | options={}
| flow="a[^0-9]b"
| term(t1)={has(json("{'a': true, 'b\'2': {'arr': [1, 2, 3]}}"), list("موسكو\"", 'v1\'v1', "k2", "v2"))}
| fragment(f21, {'a': true, 'b': ["s1", "s2"]})
@@ -129,7 +134,47 @@ class NCIdlCompilerSpec {
@throws[NCException]
def testInlineCompileFail(): Unit = {
NCIdlCompilerGlobal.clearCache(MODEL_ID)
-
+
+ checkCompileError(
+ """
+ |intent=i1
+ | options={'ordered': 1}
+ | flow="a[^0-9]b"
+ | meta={'a': true, 'b': {'Москва': [1, 2, 3]}}
+ | term(t1)={2 == 2 && size(tok_id()) != -25}
+ |""".stripMargin
+ )
+
+ checkCompileError(
+ """
+ |intent=i1
+ | options={'ordered1': false}
+ | flow="a[^0-9]b"
+ | meta={'a': true, 'b': {'Москва': [1, 2, 3]}}
+ | term(t1)={2 == 2 && size(tok_id()) != -25}
+ |""".stripMargin
+ )
+
+ checkCompileError(
+ """
+ |intent=i1
+ | options={'ordered': false, 'unknown': 1}
+ | flow="a[^0-9]b"
+ | meta={'a': true, 'b': {'Москва': [1, 2, 3]}}
+ | term(t1)={2 == 2 && size(tok_id()) != -25}
+ |""".stripMargin
+ )
+
+ checkCompileError(
+ """
+ |intent=i1
+ | options={'ordered': false_1} # Broken JSON.
+ | flow="a[^0-9]b"
+ | meta={'a': true, 'b': {'Москва': [1, 2, 3]}}
+ | term(t1)={2 == 2 && size(tok_id()) != -25}
+ |""".stripMargin
+ )
+
checkCompileError(
"""
|intent=i1
@@ -228,6 +273,7 @@ class NCIdlCompilerSpec {
checkCompileError(
"""
|fragment=f111
+ | options={'ordered': 1}
| term(t1)={2==2}
| term~/class#method/
|