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 3d64b4b WIP.
3d64b4b is described below
commit 3d64b4bfeb2766b582e4f0ff484f776ef1ab3444
Author: Aaron Radzinski <[email protected]>
AuthorDate: Fri Mar 12 20:30:40 2021 -0800
WIP.
---
.../model/intent/compiler/NCDslCompilerBase.scala | 20 +++++++++++++++++++-
.../nlpcraft/common/makro/NCMacroParserSpec.scala | 8 ++++----
.../org/apache/nlpcraft/model/NCIntentDslSpec.scala | 2 +-
.../model/abstract/NCAbstractTokensModel.scala | 6 +++---
.../nlpcraft/model/synonyms/NCSynonymsSpec.scala | 2 +-
.../enrichers/model/NCEnricherNestedModelSpec2.scala | 2 +-
.../enrichers/model/NCEnricherNestedModelSpec3.scala | 2 +-
.../enrichers/model/NCEnricherNestedModelSpec4.scala | 2 +-
8 files changed, 31 insertions(+), 13 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompilerBase.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompilerBase.scala
index 3bc9f52..1551344 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompilerBase.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/intent/compiler/NCDslCompilerBase.scala
@@ -479,6 +479,24 @@ trait NCDslCompilerBase {
pushBool(asJList(v1).contains(v2), f1 || f2)
}
+ def doGet(): Unit = {
+ ensureStack(2)
+
+ val (col, key, f1, f2) = pop2() // NOTE: pop2() corrects for
stack's LIFO order.
+ val f = f1 || f2
+
+ if (isJList(col)) {
+ if (isJLong(key))
+
pushAny(asJList(col).get(asJLong(key).intValue()).asInstanceOf[Object], f)
+ else
+ rtParamTypeError(fun, key, "numeric")
+ }
+ else if (isJMap(col))
+ pushAny(asJMap(col).get(key).asInstanceOf[Object], f)
+ else
+ rtParamTypeError(fun, col, "list or map")
+ }
+
def doMap(): Unit = {
if (stack.size % 2 != 0)
throw rtParamNumError(fun)
@@ -674,7 +692,7 @@ trait NCDslCompilerBase {
// Collection functions.
case "list" ⇒ doList()
case "map" ⇒ doMap()
- case "get" ⇒
+ case "get" ⇒ doGet()
case "index" ⇒
case "has" ⇒ doHas()
case "tail" ⇒
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala
index 9d7dcf1..efe491b 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/common/makro/NCMacroParserSpec.scala
@@ -143,11 +143,11 @@ class NCMacroParserSpec {
checkEq("a {b|_|{//[]{}//}[1,2]}", Seq("a", "a b", "a //[]{}//", "a
//[]{}// //[]{}//"))
checkEq("a {b|_|{//[]^^// ^^{_}^^}[1,2]}", Seq("a", "a b", "a //[]^^//
^^{_}^^", "a //[]^^// ^^{_}^^ //[]^^// ^^{_}^^"))
checkEq("//[a-zA-Z0-9]+//", Seq("//[a-zA-Z0-9]+//"))
- checkEq("the ^^[internal](id == 'anyWord')^^", Seq("the
^^[internal](id == 'anyWord')^^"))
- checkEq("{A}[0,1] ^^[internal](id == 'anyWord')^^",
Seq("^^[internal](id == 'anyWord')^^", "A ^^[internal](id == 'anyWord')^^"))
+ checkEq("the ^^[internal]{id() == 'anyWord'}^^", Seq("the
^^[internal]{id() == 'anyWord'}^^"))
+ checkEq("{A}[0,1] ^^[internal]{id() == 'anyWord'}^^",
Seq("^^[internal]{id() == 'anyWord'}^^", "A ^^[internal]{id() == 'anyWord'}^^"))
checkEq("w1 ^^id == 'nlpcraft:num'^^ w2", Seq("w1 ^^id ==
'nlpcraft:num'^^ w2"))
- checkEq("before limit ^^[limitAlias](id == 'nlpcraft:limit')^^",
Seq("before limit ^^[limitAlias](id == 'nlpcraft:limit')^^"))
- checkEq("wrap ^^[wrapLimitAlias](id == 'wrapLimit')^^", Seq("wrap
^^[wrapLimitAlias](id == 'wrapLimit')^^"))
+ checkEq("before limit ^^[limitAlias]{id() == 'nlpcraft:limit'}^^",
Seq("before limit ^^[limitAlias]{id() == 'nlpcraft:limit'}^^"))
+ checkEq("wrap ^^[wrapLimitAlias]{id() == 'wrapLimit'}^^", Seq("wrap
^^[wrapLimitAlias]{id() == 'wrapLimit'}^^"))
checkError("a {| b")
checkError("{a}}")
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala
index 09351b8..5e33497 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala
@@ -36,7 +36,7 @@ class NCIntentDslSpecModel extends NCModelAdapter(
override def getElements: util.Set[NCElement] = Set(NCTestElement("paris"))
// Moscow population filter.
- @NCIntent("intent=bigCity term(city)={id() == 'nlpcraft:city' &&
~nlpcraft:city:citymeta['population'] >= 10381222}")
+ @NCIntent("intent=bigCity term(city)={id() == 'nlpcraft:city' &&
value(meta_token('nlpcraft:city:citymeta'), 'population') >= 10381222}")
private def onBigCity(ctx: NCIntentMatch): NCResult = "OK"
@NCIntent("intent=otherCity term(city)={id() == 'nlpcraft:city' }")
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/abstract/NCAbstractTokensModel.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/abstract/NCAbstractTokensModel.scala
index 32e7c78..c37c5fe 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/abstract/NCAbstractTokensModel.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/abstract/NCAbstractTokensModel.scala
@@ -29,10 +29,10 @@ class NCAbstractTokensModel extends NCModelAdapter(
override def getElements: util.Set[NCElement] =
Set(
NCTestElement("anyWord", "//[a-zA-Z0-9]+//"),
- NCTestElement("wrapAnyWord", "the ^^[internal](id ==
'anyWord')^^"),
+ NCTestElement("wrapAnyWord", "the ^^[internal](id() ==
'anyWord')^^"),
NCTestElement("wrapNum", "w1 ^^id == 'nlpcraft:num'^^ w2"),
- NCTestElement("wrapLimit", "before limit ^^[limitAlias](id ==
'nlpcraft:limit')^^"),
- NCTestElement("wrapWrapLimit", "wrap ^^[wrapLimitAlias](id ==
'wrapLimit')^^")
+ NCTestElement("wrapLimit", "before limit ^^[limitAlias](id() ==
'nlpcraft:limit')^^"),
+ NCTestElement("wrapWrapLimit", "wrap ^^[wrapLimitAlias](id() ==
'wrapLimit')^^")
)
override def getAbstractTokens: util.Set[String] = Set("nlpcraft:num",
"anyWord").asJava
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/synonyms/NCSynonymsSpec.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/synonyms/NCSynonymsSpec.scala
index 73627e9..bf4cc29 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/synonyms/NCSynonymsSpec.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/synonyms/NCSynonymsSpec.scala
@@ -39,7 +39,7 @@ class NCSynonymsSpecModel extends
NCModelAdapter("nlpcraft.syns.test.mdl", "Syno
NCTestElement("e3", "{//AA//}[3, 3]"),
// Nested - 3 words.
- NCTestElement("e4", "{^^(id == 'e1')^^}[3, 3]")
+ NCTestElement("e4", "{^^(id() == 'e1')^^}[3, 3]")
)
@NCIntent("intent=onE1 term(t)={id() == 'e1'}")
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec2.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec2.scala
index 2dbf7f1..8d8a06d 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec2.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec2.scala
@@ -28,7 +28,7 @@ import java.util
*/
class NCNestedTestModel21 extends NCModelAdapter("nlpcraft.nested2.test.mdl",
"Nested Test Model", "1.0") {
override def getElements: util.Set[NCElement] =
- Set(NCTestElement("e1", "{^^(id == 'nlpcraft:num')^^|_} word"))
+ Set(NCTestElement("e1", "{^^(id() == 'nlpcraft:num')^^|_} word"))
@NCIntent("intent=onE1 term(t1)={id() == 'e1'}")
def onAB(ctx: NCIntentMatch): NCResult = NCResult.text("OK")
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec3.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec3.scala
index d065386..1eb1115 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec3.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec3.scala
@@ -33,7 +33,7 @@ class NCNestedTestModel3 extends NCModelAdapter(
override def getElements: util.Set[NCElement] =
Set(
NCTestElement("e1", "//[a-zA-Z0-9]+//"),
- NCTestElement("e2", "^^(id == 'e1')^^"),
+ NCTestElement("e2", "^^(id() == 'e1')^^"),
)
override def getAbstractTokens: util.Set[String] = Set("e1").asJava
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec4.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec4.scala
index 5c89eb2..75bcff2 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec4.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/model/NCEnricherNestedModelSpec4.scala
@@ -33,7 +33,7 @@ class NCNestedTestModel4 extends NCModelAdapter(
override def getElements: util.Set[NCElement] =
Set(
NCTestElement("e1", "//[a-zA-Z0-9]+//"),
- NCTestElement("e2", "the ^^(id == 'e1')^^")
+ NCTestElement("e2", "the ^^(id() == 'e1')^^")
)
override def getAbstractTokens: util.Set[String] = Set("e1").asJava