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 01868cb WIP.
01868cb is described below
commit 01868cb8e216a66dc8c0fc4df4f99b6ed77f0b30
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sat Jul 31 23:40:34 2021 -0700
WIP.
---
.../model/intent/compiler/NCIdlCompilerBase.scala | 2 +-
.../idl/compiler/functions/NCIdlFunctions.scala | 18 +++++++-------
.../compiler/functions/NCIdlFunctionsCompany.scala | 2 +-
.../compiler/functions/NCIdlFunctionsCustom.scala | 6 ++---
.../compiler/functions/NCIdlFunctionsMeta.scala | 20 ++++++++--------
.../compiler/functions/NCIdlFunctionsRequest.scala | 2 +-
.../compiler/functions/NCIdlFunctionsToken.scala | 28 ++++++++++++----------
.../functions/NCIdlFunctionsTokensUsed.scala | 8 +++----
.../compiler/functions/NCIdlFunctionsUser.scala | 2 +-
9 files changed, 46 insertions(+), 42 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 81ac827..888bcdc 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
@@ -162,7 +162,7 @@ trait NCIdlCompilerBase {
def rtFunError(fun: String, cause: Exception)(implicit ctx: PRC): NCE =
newRuntimeError(s"Runtime error in IDL function: $fun()", cause)
def rtUnavailFunError(fun: String)(implicit ctx: PRC): NCE =
- newRuntimeError(s"IDL function is unavailable in this context: $fun()")
+ newRuntimeError(s"Function '$fun()' is unavailable in this IDL
context.")
/**
*
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
index 9587f40..78a6899 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctions.scala
@@ -55,7 +55,7 @@ private[functions] trait NCIdlFunctions {
case class TestDesc(
truth: String,
token: Option[NCToken] = None,
- idlCtx: NCIdlContext = ctx(),
+ idlCtx: NCIdlContext,
isCustom: Boolean = false,
expectedRes: Boolean = true,
tokensUsed: Option[Int] = None
@@ -84,7 +84,7 @@ private[functions] trait NCIdlFunctions {
TestDesc(truth = truth, token = Some(token), idlCtx = idlCtx)
def apply(truth: String, token: NCToken): TestDesc =
- TestDesc(truth = truth, token = Some(token))
+ TestDesc(truth = truth, token = Some(token), idlCtx =
mkIdlContext(toks = Seq(token)))
}
private def t2s(t: NCToken): String = {
@@ -93,7 +93,8 @@ private[functions] trait NCIdlFunctions {
s"text=${nvl(t.getOriginalText, "text")} [${nvl(t.getId, "id")}]"
}
- protected def ctx(
+ protected def mkIdlContext(
+ toks: Seq[NCToken] = Seq.empty,
reqUsr: NCUser = null,
reqComp: NCCompany = null,
reqSrvReqId: String = null,
@@ -107,6 +108,7 @@ private[functions] trait NCIdlFunctions {
fragMeta: ScalaMeta = Map.empty[String, AnyRef]
): NCIdlContext =
NCIdlContext(
+ toks = toks,
intentMeta = intentMeta,
convMeta = convMeta,
fragMeta = fragMeta,
@@ -122,7 +124,7 @@ private[functions] trait NCIdlFunctions {
}
)
- protected def tkn(
+ protected def mkToken(
id: String = null,
srvReqId: String = null,
parentId: String = null,
@@ -134,7 +136,7 @@ private[functions] trait NCIdlFunctions {
ancestors: Seq[String] = Seq.empty,
aliases: Set[String] = Set.empty,
partTokens: Seq[NCToken] = Seq.empty,
- isAbstr: Boolean = false,
+ `abstract`: Boolean = false,
meta: Map[String, AnyRef] = Map.empty[String, AnyRef]
): NCToken = {
val map = new util.HashMap[String, AnyRef]
@@ -156,7 +158,7 @@ private[functions] trait NCIdlFunctions {
override def getGroups: util.List[String] = if (groups.isEmpty &&
id != null) Collections.singletonList(id) else groups.asJava
override def getStartCharIndex: Int = start
override def getEndCharIndex: Int = end
- override def isAbstract: Boolean = isAbstr
+ override def isAbstract: Boolean = `abstract`
override def getMetadata: util.Map[String, AnyRef] = map
}
}
@@ -169,7 +171,7 @@ private[functions] trait NCIdlFunctions {
f.idlCtx.vars ++= f.term.decls
// Execute term's predicate.
- f.term.pred.apply(f.token.getOrElse(tkn()), f.idlCtx)
+ f.term.pred.apply(f.token.getOrElse(mkToken()), f.idlCtx)
}
catch {
case e: NCE => throw e
@@ -224,5 +226,5 @@ private[functions] trait NCIdlFunctions {
}
}
- protected implicit def convert(pred: String): TestDesc = TestDesc(truth =
pred)
+ protected implicit def convert(pred: String): TestDesc = TestDesc(truth =
pred, idlCtx = mkIdlContext())
}
\ No newline at end of file
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
index 4d74aff..715b5f2 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCompany.scala
@@ -58,7 +58,7 @@ class NCIdlFunctionsCompany extends NCIdlFunctions {
}
private def test(comp: NCCompany): Unit = {
- val idlCtx = ctx(reqComp = comp)
+ val idlCtx = mkIdlContext(reqComp = comp)
def mkTestDesc(truth: String): TestDesc = TestDesc(truth = truth,
idlCtx = idlCtx)
def get(opt: Optional[String]): String = if (opt.isEmpty) null else
s"'${opt.get()}'"
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
index 1dae27a..a8946d2 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsCustom.scala
@@ -66,13 +66,13 @@ class NCIdlFunctionsCustom extends NCIdlFunctions {
TestDesc(
truth = s"$C#trueOn123",
isCustom = true,
- token = Some(tkn(txt = "123")),
+ token = Some(mkToken(txt = "123")),
tokensUsed = Some(1)
),
TestDesc(
truth = s"$C#trueOn123",
isCustom = true,
- token = Some(tkn(txt = "456")),
+ token = Some(mkToken(txt = "456")),
expectedRes = false,
tokensUsed = Some(1)
),
@@ -80,7 +80,7 @@ class NCIdlFunctionsCustom extends NCIdlFunctions {
// Method defined in model.
truth = s"#trueAlwaysCustomToken",
isCustom = true,
- token = Some(tkn(txt = "any"))
+ token = Some(mkToken(txt = "any"))
)
)
}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMeta.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMeta.scala
index 4efbc96..00cf4c2 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMeta.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsMeta.scala
@@ -46,35 +46,35 @@ class NCIdlFunctionsMeta extends NCIdlFunctions {
def testMetaToken(): Unit =
testValue(
"meta_tok",
- token = Some(tkn(meta = Map("k1" -> "v1")))
+ token = Some(mkToken(meta = Map("k1" -> "v1")))
)
@Test
def testMetaRequest(): Unit =
testValue(
"meta_req",
- ctx(reqData = Map("k1" -> "v1"))
+ mkIdlContext(reqData = Map("k1" -> "v1"))
)
@Test
def testMetaConv(): Unit =
testValue(
"meta_conv",
- ctx(convMeta = Map("k1" -> "v1"))
+ mkIdlContext(convMeta = Map("k1" -> "v1"))
)
@Test
def testMetaFrag(): Unit =
testValue(
"meta_frag",
- ctx(fragMeta = Map("k1" -> "v1"))
+ mkIdlContext(fragMeta = Map("k1" -> "v1"))
)
@Test
def testMetaUser(): Unit =
testValue(
"meta_user",
- ctx(reqUsr =
+ mkIdlContext(reqUsr =
new NCUser {
override def getId: Long = -1
override def getFirstName: Optional[String] =
Optional.empty()
@@ -93,7 +93,7 @@ class NCIdlFunctionsMeta extends NCIdlFunctions {
def testMetaCompany(): Unit =
testValue(
"meta_company",
- ctx(reqComp =
+ mkIdlContext(reqComp =
new NCCompany {
override def getId: Long = -1
override def getName: String = "name"
@@ -111,15 +111,15 @@ class NCIdlFunctionsMeta extends NCIdlFunctions {
// Simplified test.
@Test
- def testMetaModel(): Unit = testNoValue("meta_model", ctx())
+ def testMetaModel(): Unit = testNoValue("meta_model", mkIdlContext())
// Simplified test.
@Test
- def testMetaIntent(): Unit = testNoValue("meta_intent", ctx())
+ def testMetaIntent(): Unit = testNoValue("meta_intent", mkIdlContext())
- private def testValue(f: String, idlCtx: => NCIdlContext = ctx(), token:
Option[NCToken] = None): Unit =
+ private def testValue(f: String, idlCtx: => NCIdlContext = mkIdlContext(),
token: Option[NCToken] = None): Unit =
test(TestDesc(truth = s"$f('k1') == 'v1'", token = token, idlCtx =
idlCtx))
- private def testNoValue(f: String, idlCtx: => NCIdlContext = ctx(), token:
Option[NCToken] = None): Unit =
+ private def testNoValue(f: String, idlCtx: => NCIdlContext =
mkIdlContext(), token: Option[NCToken] = None): Unit =
test(TestDesc(truth = s"$f('k1') == null", token = token, idlCtx =
idlCtx))
}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
index 7c38880..3d3356c 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsRequest.scala
@@ -31,7 +31,7 @@ class NCIdlFunctionsRequest extends NCIdlFunctions {
val reqAddr = "address"
val reqAgent = "agent"
- val idlCtx = ctx(
+ val idlCtx = mkIdlContext(
reqSrvReqId = reqSrvReqId,
reqNormText = reqNormText,
reqTstamp = reqTstamp,
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 d7cad02..b0d5824 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
@@ -42,14 +42,14 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
"nlpcraft:nlp:unid" -> "21421"
)
- private def mkMeta(truth: String):TestDesc = TestDesc(truth = truth, token
= tkn(meta = meta))
+ private def mkMeta(truth: String):TestDesc = TestDesc(truth = truth, token
= mkToken(meta = meta))
@Test
def test(): Unit =
test(
TestDesc(
truth = "tok_id() == 'a'",
- token = tkn(id = "a")
+ token = mkToken(id = "a")
),
mkMeta(truth = s"tok_lemma() == '${meta("nlpcraft:nlp:lemma")}'"),
mkMeta(truth = s"tok_stem() == '${meta("nlpcraft:nlp:stem")}'"),
@@ -58,7 +58,7 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
mkMeta(truth = s"tok_unid() == '${meta("nlpcraft:nlp:unid")}'"),
TestDesc(
truth = s"tok_is_abstract() == true",
- token = tkn(isAbstr = true)
+ token = mkToken(`abstract` = true)
),
mkMeta(truth = s"tok_is_abstract() == false"),
mkMeta(truth = s"tok_is_bracketed() ==
${meta("nlpcraft:nlp:bracketed")}"),
@@ -71,41 +71,43 @@ class NCIdlFunctionsToken extends NCIdlFunctions {
mkMeta(truth = s"tok_is_swear() == ${meta("nlpcraft:nlp:swear")}"),
TestDesc(
truth = s"tok_is_user() == true",
- token = tkn(id = "aa")
+ token = mkToken(id = "aa")
),
TestDesc(
truth = s"tok_is_user() == false",
- token = tkn(id = "nlpcraft:nlp")
+ token = mkToken(id = "nlpcraft:nlp")
),
mkMeta(truth = s"tok_is_wordnet() ==
${meta("nlpcraft:nlp:dict")}"),
TestDesc(
truth = s"tok_ancestors() == list('1', '2')",
- token = tkn(ancestors = Seq("1", "2"))
+ token = mkToken(ancestors = Seq("1", "2"))
),
TestDesc(
truth = s"tok_parent() == 'parentId'",
- token = tkn(parentId = "parentId")
+ token = mkToken(parentId = "parentId")
),
TestDesc(
truth = "tok_groups() == list('1', '2')",
- token = tkn(groups = Seq("1", "2"))
+ token = mkToken(groups = Seq("1", "2"))
),
TestDesc(
truth = "tok_value() == 'value'",
- token = tkn(value = "value")
+ token = mkToken(value = "value")
),
TestDesc(
truth = "tok_value() == null",
- token = tkn()
+ token = mkToken()
),
TestDesc(
truth = "tok_start_idx() == 123",
- token = tkn(start = 123)
+ token = mkToken(start = 123)
),
TestDesc(
truth = "tok_end_idx() == 123",
- token = tkn(end = 123)
+ token = mkToken(end = 123)
),
- TestDesc(truth = "tok_this() == tok_this()")
+ TestDesc(truth = "tok_this() == tok_this()"),
+ TestDesc(truth = "tok_is_first() == true"),
+ TestDesc(truth = "tok_is_last() == true")
)
}
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsTokensUsed.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsTokensUsed.scala
index 3c4aa69..ea0c1cb 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsTokensUsed.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsTokensUsed.scala
@@ -32,22 +32,22 @@ class NCIdlFunctionsTokensUsed extends NCIdlFunctions {
),
TestDesc(
truth = "tok_id() == 'a'",
- token = Some(tkn(id = "a")),
+ token = Some(mkToken(id = "a")),
tokensUsed = Some(1)
),
TestDesc(
truth = "tok_id() == 'a' && tok_id() == 'a'",
- token = Some(tkn(id = "a")),
+ token = Some(mkToken(id = "a")),
tokensUsed = Some(2)
),
TestDesc(
truth = "tok_id() == 'a' && tok_parent() == 'b'",
- token = Some(tkn(id = "a", parentId = "b")),
+ token = Some(mkToken(id = "a", parentId = "b")),
tokensUsed = Some(2)
),
TestDesc(
truth = "tok_id() == 'a' && tok_id() == 'a' && tok_parent() ==
'b'",
- token = Some(tkn(id = "a", parentId = "b")),
+ token = Some(mkToken(id = "a", parentId = "b")),
tokensUsed = Some(3)
)
)
diff --git
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
index caf5bb0..35b5580 100644
---
a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
+++
b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/intent/idl/compiler/functions/NCIdlFunctionsUser.scala
@@ -59,7 +59,7 @@ class NCIdlFunctionsUser extends NCIdlFunctions {
}
private def test(usr: NCUser): Unit = {
- val idlCtx = ctx(reqUsr = usr)
+ val idlCtx = mkIdlContext(reqUsr = usr)
def mkTestDesc(truth: String): TestDesc = TestDesc(truth = truth,
idlCtx = idlCtx)
def get(opt: Optional[String]): String = if (opt.isEmpty) null else
s"'${opt.get()}'"