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

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


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

commit 3d539badd2f0def32f2e8c05448188774335e377
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Jan 27 18:59:03 2022 +0300

    WIP.
---
 .../scala/org/apache/nlpcraft/NCIntentObject.java  |  5 ++++
 .../nlpcraft/internal/impl/NCModelScanner.scala    |  4 +++
 .../impl/scan/NCModelIntentsInvalidArgsSpec.scala  | 12 +++------
 .../impl/scan/NCModelIntentsNestedSpec.scala       | 29 +++++++++++++++-------
 .../nlpcraft/nlp/util/NCTestModelAdapter.scala}    | 24 ++++++++----------
 5 files changed, 43 insertions(+), 31 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentObject.java 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentObject.java
index 20ff929..ae8c6cd 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentObject.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentObject.java
@@ -24,6 +24,11 @@ import java.lang.annotation.Target;
 import static java.lang.annotation.ElementType.FIELD;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
 
+/**
+ * TODO:
+ * Marker annotation. Applied to class member of main model.
+ * These fields objects scanned the same way as main model.
+ */
 @Documented
 @Retention(value=RUNTIME)
 @Target(value=FIELD)
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 299d46e..aed9f00 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
@@ -384,6 +384,10 @@ class NCModelScanner(mdl: NCModel) extends LazyLogging:
 
                 if (f.isAnnotationPresent(CLS_INTENT_OBJ))
                     val fieldObj = getFieldObject(mdlId, f, obj)
+
+                    if fieldObj == null then
+                        throw new NCException(s"Value is null for: 
${field2Str(f)}") // TODO: text
+
                     h.objects += fieldObj
                     scanObject(fieldObj)
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsInvalidArgsSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsInvalidArgsSpec.scala
index 1c44988..46dcb5b 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsInvalidArgsSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsInvalidArgsSpec.scala
@@ -30,22 +30,18 @@ import java.util
   * Note that for some kind of models (it depends on creation type) we can't 
check methods arguments during scan.
   */
 class NCModelIntentsInvalidArgsSpec:
-    abstract class NCModelAdapter extends NCModel:
-        override def getConfig: NCModelConfig = CFG
-        override def getPipeline: NCModelPipeline = EN_PIPELINE
-
-    class DefinedClassModelValid extends NCModelAdapter:
+    class DefinedClassModelValid extends NCTestModelAdapter:
         @NCIntent("intent=validList term(list)~{# == 'x'}[0,10]")
         def validList(@NCIntentTerm("list") list: List[NCEntity]): NCResult = 
processListEntity(list)
 
         @NCIntent("intent=validOpt term(opt)~{# == 'x'}?")
         def validOpt(@NCIntentTerm("opt") opt: Option[NCEntity]): NCResult = 
processOptEntity(opt)
 
-    class DefinedClassModelInvalidLst extends NCModelAdapter:
+    class DefinedClassModelInvalidLst extends NCTestModelAdapter:
         @NCIntent("intent=invalidList term(list)~{# == 'x'}[0,10]")
         def invalidList(@NCIntentTerm("list") list: List[Int]): NCResult = 
processListInt(list)
 
-    class DefinedClassModelInvalidOpt extends NCModelAdapter:
+    class DefinedClassModelInvalidOpt extends NCTestModelAdapter:
         @NCIntent("intent=invalidOpt term(opt)~{# == 'x'}?")
         def invalidOpt(@NCIntentTerm("opt") opt: Option[Int]): NCResult = 
processOptInt(opt)
 
@@ -53,7 +49,7 @@ class NCModelIntentsInvalidArgsSpec:
     private val CHECKED_MDL_INVALID_LST: NCModel = new 
DefinedClassModelInvalidLst
     private val CHECKED_MDL_INVALID_OPT: NCModel = new 
DefinedClassModelInvalidOpt
     private val UNCHECKED_MDL: NCModel =
-        new NCModelAdapter:
+        new NCTestModelAdapter:
             @NCIntent("intent=validList term(list)~{# == 'x'}[0,10]")
             def validList(@NCIntentTerm("list") list: List[NCEntity]): 
NCResult = processListEntity(list)
 
diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsNestedSpec.scala
 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsNestedSpec.scala
index 9a52cf4..fcd9800 100644
--- 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsNestedSpec.scala
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/internal/impl/scan/NCModelIntentsNestedSpec.scala
@@ -19,6 +19,7 @@ package org.apache.nlpcraft.internal.impl.scan
 
 import org.apache.nlpcraft.*
 import org.apache.nlpcraft.internal.impl.NCModelScanner
+import org.apache.nlpcraft.nlp.util.*
 import org.apache.nlpcraft.nlp.util.opennlp.*
 import org.junit.jupiter.api.Test
 
@@ -26,22 +27,17 @@ import org.junit.jupiter.api.Test
   * It tests imports and nested objects usage.
   */
 class NCModelIntentsNestedSpec:
-    private val mdl: NCModel = new NCModel :
-        override def getConfig: NCModelConfig = CFG
-        override def getPipeline: NCModelPipeline = EN_PIPELINE
-
+    private val MDL_VALID: NCModel = new NCTestModelAdapter:
         @NCIntentObject
-        val nested1: Object = new Object() {
+        val nested1: Object = new Object():
             @NCIntentObject
-            val nested2: Object = new Object() {
+            val nested2: Object = new Object():
                 @NCIntentImport(Array("scan/idl.idl"))
                 @NCIntent("intent=intent3 term(x)~{true}")
                 def intent1(@NCIntentTerm("x") x: NCEntity) = new NCResult()
-            }
 
             @NCIntent("intent=intent2 term(x)~{true}")
             def intent1(@NCIntentTerm("x") x: NCEntity) = new NCResult()
-        }
 
         @NCIntent("intent=intent1 term(x)~{true}")
         def intent1(@NCIntentTerm("x") x: NCEntity) = new NCResult()
@@ -54,5 +50,20 @@ class NCModelIntentsNestedSpec:
             @NCIntentTerm("opt") opt: Option[NCEntity]
         ): NCResult = new NCResult()
 
+    private val MDL_INVALID: NCModel = new NCTestModelAdapter :
+        @NCIntentObject
+        val nested1: Object = new Object():
+            @NCIntentObject
+            val nested2: Object = null
+
     @Test
-    def test(): Unit = require(new NCModelScanner(mdl).scan().sizeIs == 4)
+    def test(): Unit = require(new NCModelScanner(MDL_VALID).scan().sizeIs == 
4)
+
+    @Test
+    def testNull(): Unit =
+        try
+            new NCModelScanner(MDL_INVALID).scan()
+
+            require(false)
+        catch
+            case e: NCException => e.printStackTrace(System.out)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentObject.java 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestModelAdapter.scala
similarity index 64%
copy from nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentObject.java
copy to 
nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestModelAdapter.scala
index 20ff929..2151173 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/NCIntentObject.java
+++ 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/util/NCTestModelAdapter.scala
@@ -6,7 +6,7 @@
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
  *
- *      http://www.apache.org/licenses/LICENSE-2.0
+ *      https://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,18 +15,14 @@
  * limitations under the License.
  */
 
-package org.apache.nlpcraft;
+package org.apache.nlpcraft.nlp.util
 
-import java.lang.annotation.Documented;
-import java.lang.annotation.Retention;
-import java.lang.annotation.Target;
+import org.apache.nlpcraft.*
+import org.apache.nlpcraft.nlp.util.opennlp.*
 
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-@Documented
-@Retention(value=RUNTIME)
-@Target(value=FIELD)
-public @interface NCIntentObject {
-    // No-op.
-}
+/**
+  *
+  */
+abstract class NCTestModelAdapter extends NCModel:
+    override def getConfig: NCModelConfig = CFG
+    override def getPipeline: NCModelPipeline = EN_PIPELINE
\ No newline at end of file

Reply via email to