This is an automated email from the ASF dual-hosted git repository.

sergeykamov pushed a commit to branch NLPCRAFT-398
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-398 by this push:
     new b997f8b  WIP.
b997f8b is described below

commit b997f8b3316d7c0944c6ba760e5a7cd333d347dd
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Aug 9 23:11:13 2021 +0300

    WIP.
---
 .../nlpcraft/probe/mgrs/deploy/NCDeployManager.scala  | 19 ++++++++++++-------
 .../probe/mgrs/deploy/NCModelNestedSamplesSpec.scala  |  2 +-
 .../probe/mgrs/deploy/NCModelReferencesSpec.scala     |  3 +++
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
index 91beb01..6edd808 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCDeployManager.scala
@@ -1578,7 +1578,7 @@ object NCDeployManager extends NCService {
 
             val mtdStr = method2Str(m)
 
-            def bindIntent(intent: NCIdlIntent, cb: Callback): Unit = {
+            def bindIntent(intent: NCIdlIntent, cb: Callback): Unit =
                 if (intents.exists(i => i._1.id == intent.id && i._2.id != 
cb.id))
                     throw new NCE(s"The intent cannot be bound to more than 
one callback [" +
                         s"mdlId=$mdlId, " +
@@ -1590,14 +1590,19 @@ object NCDeployManager extends NCService {
                     intentDecls += intent
                     intents += (intent -> prepareCallback(mo, mdl, intent))
                 }
-            }
+
+            def existsForOtherMethod(id: String): Boolean =
+                intents.find(_._1.id == id) match {
+                    case Some((_, cb)) => cb.method != m
+                    case None => false
+                }
 
             // Process inline intent declarations by @NCIntent annotation.
-            for (ann <- m.getAnnotationsByType(CLS_INTENT); intent <- 
NCIdlCompiler.compileIntents(ann.value(), mdl, mtdStr))
-                if (
-                    intentDecls.exists(_.id == intent.id) ||
-                    intents.exists { case (i, cb) => i.id == intent.id && 
cb.method != m }
-                )
+            for (
+                ann <- m.getAnnotationsByType(CLS_INTENT);
+                intent <- NCIdlCompiler.compileIntents(ann.value(), mdl, 
mtdStr)
+            )
+                if (intentDecls.exists(_.id == intent.id && 
existsForOtherMethod(intent.id)))
                     throw new NCE(s"Duplicate intent ID [" +
                         s"mdlId=$mdlId, " +
                         s"origin=${mdl.getOrigin}, " +
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelNestedSamplesSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelNestedSamplesSpec.scala
index 017adba..9bf3e95 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelNestedSamplesSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelNestedSamplesSpec.scala
@@ -22,7 +22,7 @@ import org.apache.nlpcraft.model.{NCIntent, NCIntentSample, 
NCModelAdapter, NCRe
 import org.apache.nlpcraft.probe.mgrs.model.NCModelManager
 import org.junit.jupiter.api.Test
 
-abstract class NCModelNested extends 
NCModelAdapter("nlpcraft.samples.test.mdl", "Test Model", "1.0") {
+class NCModelNested extends NCModelAdapter("nlpcraft.samples.test.mdl", "Test 
Model", "1.0") {
     @NCIntentSample(Array("a"))
     @NCIntent("intent=nested term={tok_id() == 'a'}*")
     def m(): NCResult = NCResult.text("OK")
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelReferencesSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelReferencesSpec.scala
index 8f57ad2..844db2f 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelReferencesSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/probe/mgrs/deploy/NCModelReferencesSpec.scala
@@ -23,6 +23,9 @@ import org.junit.jupiter.api.Test
 
 import java.util
 
+/**
+  * Note than we can't name packages 'java' and 'scala', so their names are 
'jc' and 'sc'.
+  */
 @NCTestEnvironment(model = 
classOf[org.apache.nlpcraft.probe.mgrs.deploy.sc.NCModelClassesWrapper], 
startClient = true)
 class NCModelClassesWrapperScalaSpec extends NCTestContext {
     @Test

Reply via email to