WIP.
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index c1254fc..df50ab1 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -215,6 +215,25 @@
}
/**
+ * Recursively removes quotes and replaces escaped quotes from given string.
+ *
+ * @param s
+ * @return
+ */
+ @tailrec
+ def escapesQuotes(s: String): String =
+ if (s.nonEmpty) {
+ if (s.head == '\'' && s.last == '\'')
+ escapesQuotes(s.substring(1, s.length - 1).replace("\'", "'"))
+ else if (s.head == '"' && s.last == '"')
+ escapesQuotes(s.substring(1, s.length - 1).replace("\\\"", "\""))
+ else
+ s
+ }
+ else
+ s
+
+ /**
*
* @param s
* @param sep
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
index a85c13c..9d5f282 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCIdlCompilerBase.scala
@@ -500,7 +500,7 @@
try
Double.box(JDouble.parseDouble(num)) // Try 'double'.
catch {
- case _: NumberFormatException ⇒ U.trimEscapesQuotes(txt) // String in the end.
+ case _: NumberFormatException ⇒ U.escapesQuotes(txt) // String in the end.
}
}
}
@@ -525,6 +525,16 @@
val x = f()
+ x match {
+ case p: Product ⇒
+ for (e ← p.productIterator)
+ if (e == stack.PLIST_MARKER)
+ rtMissingParamError(argNum, fun)
+ case _ ⇒
+ if (x.asInstanceOf[ST] == stack.PLIST_MARKER)
+ rtMissingParamError(argNum, fun)
+ }
+
// Make sure to pop up the parameter list stack frame marker.
popMarker(argNum)
@@ -562,7 +572,7 @@
() ⇒ {
val (v1, v2, n) = extract2(x1, x2)
- Z(util.Arrays.asList(toStr(v1).split(toStr(v2))), n)
+ Z(util.Arrays.asList(toStr(v1).split(toStr(v2)):_*), n)
}
)
}
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCollections.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCollections.scala
index 6ccef37..8f3805f 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCollections.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCollections.scala
@@ -35,8 +35,7 @@
"has(list(1, 2, 3), 1) == true",
"has(list(1.1, 2.1, 3.1), 1.1) == true",
"has(list(1.0, 2.0, 3.0), 1.0) == true",
- // Different types.
- "has(list(1.0, 2.0, 3.0), 1) == false",
+ "has(list(1.0, 2.0, 3.0), 1) == false", // Different types.
"has(list('1', '2', '3'), '1') == true",
"has(list(1, 2, 3), 5) == false",
"has(list(1.1, 2.1, 3.1), 5.1) == false",
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
index c07cd21..3ef44fa 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMath.scala
@@ -45,7 +45,7 @@
"rint(1.8) == 2.0",
"round(1.8) == 2",
s"to_double(25) == 25.0",
- s"to_double(25) == 25", // double != int without rounding.
+ s"to_double(25) == 25",
s"round(to_double(25)) == 25",
"signum(-1.8) == -1.0",
"sqrt(4) - 2 < 0.001",
diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
index ca9cb81..88658d8 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsStrings.scala
@@ -52,17 +52,17 @@
// "substr('abc', 0, 2) == 'ab'",
// "replace('abc', 'a', 'X') == 'Xbc'",
// "replace('abc', '0', '0') == 'abc'",
-// "split('1 A') == list('1', '2')",
-// "split_trim('1 A ') == list('1', '2')",
-//
-// // Whitespaces.
+ "split('1 A', ' ') == list('1', 'A')",
+// "split_trim('1 A ', ' ') == list('1', 'A')",
+
+ // Whitespaces.
// "replace('abc', 'ab', '') == 'c'",
// "substr('abc', 20, 30) == ''",
- "is_alphanumspace(' ') == true",
- "is_alphanumspace(' ') == true",
- "is_alphanumspace(' ') == true",
- "is_whitespace(' ') == true",
- "trim(' ') == ''"
+// "is_alphanumspace(' ') == true",
+// "is_alphanumspace(' ') == true",
+// "is_alphanumspace(' ') == true",
+// "is_whitespace(' ') == true",
+// "trim(' ') == ''"
)
@Test