This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-385
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-385 by this push:
new a667f12 WIP on NLPCRAFT-385.
a667f12 is described below
commit a667f12b1b320fb2701035bed640a3500d806df1
Author: Aaron Radzinzski <[email protected]>
AuthorDate: Sun Aug 1 20:03:06 2021 -0700
WIP on NLPCRAFT-385.
---
.../model/intent/compiler/NCIdlCompilerBase.scala | 20 ++++-----
.../compiler/functions/NCIdlFunctionsToken.scala | 48 ++++++++++++++++++----
2 files changed, 49 insertions(+), 19 deletions(-)
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 888bcdc..010de1a 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
@@ -526,10 +526,10 @@ trait NCIdlCompilerBase {
val fun = id.getText
- def ensureStack(min: Int): Unit = if (stack.size < min) throw
rtMissingParamError(min, fun)
def popMarker(argNum: Int): Unit = if (pop1() != stack.PLIST_MARKER)
throw rtTooManyParamsError(argNum, fun)
def arg[X](argNum: Int, f: () => X): X = {
- ensureStack(argNum + 1) // +1 for the frame marker.
+ if (stack.size < argNum + 1) // +1 for stack frame marker.
+ throw rtMissingParamError(argNum, fun)
val x = f()
@@ -1074,26 +1074,22 @@ trait NCIdlCompilerBase {
}
def doIsBefore(f: (NCToken, String) => Boolean): Unit = {
- val (x1, x2) = arg2()
+ val x = arg1()
stack.push(() => {
- val (t, a, n) = extract2(x1, x2)
-
- val tok = toToken(t)
+ val Z(arg, n) = x()
- Z(idlCtx.toks.exists(t => t.getIndex > tok.getIndex && f(t,
toStr(a))), n)
+ Z(idlCtx.toks.exists(t => t.getIndex > tok.getIndex && f(t,
toStr(arg))), n)
})
}
def doIsAfter(f: (NCToken, String) => Boolean): Unit = {
- val (x1, x2) = arg2()
+ val x = arg1()
stack.push(() => {
- val (t, a, n) = extract2(x1, x2)
-
- val tok = toToken(t)
+ val Z(arg, n) = x()
- Z(idlCtx.toks.exists(t => t.getIndex < tok.getIndex && f(t,
toStr(a))), n)
+ Z(idlCtx.toks.exists(t => t.getIndex < tok.getIndex && f(t,
toStr(arg))), n)
})
}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
index 347f63a..4e768f9 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsToken.scala
@@ -45,7 +45,7 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
private def mkMeta(truth: String):TestDesc = TestDesc(truth = truth, token
= mkToken(meta = meta))
@Test
- def test(): Unit =
+ def testMainTokenProperties(): Unit =
test(
TestDesc(
truth = "tok_id() == 'a'",
@@ -57,7 +57,7 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
mkMeta(truth = s"tok_sparsity() ==
${meta("nlpcraft:nlp:sparsity")}"),
mkMeta(truth = s"tok_unid() == '${meta("nlpcraft:nlp:unid")}'"),
TestDesc(
- truth = s"tok_is_abstract() == true",
+ truth = s"tok_is_abstract()",
token = mkToken(`abstract` = true)
),
mkMeta(truth = s"tok_is_abstract() == false"),
@@ -70,11 +70,11 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
mkMeta(truth = s"tok_is_stopword() ==
${meta("nlpcraft:nlp:stopword")}"),
mkMeta(truth = s"tok_is_swear() == ${meta("nlpcraft:nlp:swear")}"),
TestDesc(
- truth = s"tok_is_user() == true",
+ truth = s"tok_is_user()",
token = mkToken(id = "aa")
),
TestDesc(
- truth = s"tok_is_user() == false",
+ truth = s"!tok_is_user()",
token = mkToken(id = "nlpcraft:nlp")
),
mkMeta(truth = s"tok_is_wordnet() ==
${meta("nlpcraft:nlp:dict")}"),
@@ -110,22 +110,56 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
)
@Test
- def testTokenOrder(): Unit = {
+ def testTokenFirstLast(): Unit = {
val tok = mkToken(id = "a")
tok.getMetadata.put("nlpcraft:nlp:index", 0)
test(
TestDesc(
- truth = "tok_is_first() == true",
+ truth = "tok_is_first()",
token = tok,
idlCtx = mkIdlContext(toks = Seq(tok))
),
TestDesc(
- truth = "tok_is_last() == true",
+ truth = "tok_is_last()",
token = tok,
idlCtx = mkIdlContext(toks = Seq(tok))
)
)
}
+
+ @Test
+ def testTokenBeforeId(): Unit = {
+ val tok1 = mkToken(id = "1")
+ val tok2 = mkToken(id = "2")
+
+ tok1.getMetadata.put("nlpcraft:nlp:index", 0)
+ tok2.getMetadata.put("nlpcraft:nlp:index", 1)
+
+ test(
+ TestDesc(
+ truth = "tok_is_before_id('2')",
+ token = tok1,
+ idlCtx = mkIdlContext(Seq(tok1, tok2))
+ )
+ )
+ }
+
+ @Test
+ def testTokenAfterId(): Unit = {
+ val tok1 = mkToken(id = "1")
+ val tok2 = mkToken(id = "2")
+
+ tok1.getMetadata.put("nlpcraft:nlp:index", 0)
+ tok2.getMetadata.put("nlpcraft:nlp:index", 1)
+
+ test(
+ TestDesc(
+ truth = "tok_is_after_id('1')",
+ token = tok2,
+ idlCtx = mkIdlContext(Seq(tok1, tok2))
+ )
+ )
+ }
}