This is an automated email from the ASF dual-hosted git repository. sergeykamov pushed a commit to branch NLPCRAFT-500 in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit 4cc1f0e326b1be72e37be69a740bcacc46a86ca4 Author: Sergey Kamov <[email protected]> AuthorDate: Thu Aug 25 11:19:32 2022 +0300 IDL fragments related fixes. --- .../scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala | 2 ++ .../nlpcraft/internal/intent/compiler/NCIDLFragmentsSpec.scala | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala index b799136e..cdb61d2e 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala @@ -414,11 +414,13 @@ object NCModelScanner extends LazyLogging: var compiler = new NCIDLCompiler(mdl.getConfig) + // Overrides current compiler with new intents but without any cache (imports ang fragments) def callNoCache[T](f: () => T): T = val cp = compiler.clone() try f() finally compiler = cp.clone(compiler) + // Recovers initial compiler state if any error occur, clears all intermediate results. def callClear[T](f: () => T): T = val cp = compiler.clone() try f() diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragmentsSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragmentsSpec.scala index 164fa271..fbce3af0 100644 --- a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragmentsSpec.scala +++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/intent/compiler/NCIDLFragmentsSpec.scala @@ -48,17 +48,18 @@ class NCIDLFragmentsSpec: @NCIntent("intent=intent2 term~{# == 'x:time'} fragment(f)") private def m(ctx: NCContext, im: NCIntentMatch): NCResult = null - // Fragment. Reference from method (inside a). + // Fragment. Reference from method (inside). class M4 extends NCModelAdapter(mkCfg("m4"), PL) : @NCIntent("fragment=f term(city)~{# == 'opennlp:location'} intent=intent2 term~{# == 'x:time'} fragment(f)") private def m(ctx: NCContext, im: NCIntentMatch): NCResult = null // Bad models. - // Invalid fragment. + // Missed fragment definition. @NCIntent("intent=intent2 term~{# == 'x:time'} fragment(f)") class E1 extends NCModelAdapter(mkCfg("e1"), PL) + // Attempt to reference on fragment defined in method. class E2 extends NCModelAdapter(mkCfg("e2"), PL): @NCIntent("fragment=f term(city)~{# == 'opennlp:location'} intent=intent1 term~{# == 'x:time'} fragment(f)") private def m1(ctx: NCContext, im: NCIntentMatch): NCResult = null @@ -66,6 +67,7 @@ class NCIDLFragmentsSpec: @NCIntent("intent=intent2 term~{# == 'x:time'} fragment(f)") private def m2(ctx: NCContext, im: NCIntentMatch): NCResult = null + // Attempt to reference on fragment defined in method. class E3 extends NCModelAdapter(mkCfg("e3"), PL): @NCIntent("fragment=f term(city)~{# == 'opennlp:location'} intent=intent1 term~{# == 'x:time'} fragment(f)") private def m2(ctx: NCContext, im: NCIntentMatch): NCResult = null
