WIP on NLPCRAFT-359.
diff --git a/nlpcraft-examples/alarm/src/main/java/org/apache/nlpcraft/examples/alarm/AlarmModel.java b/nlpcraft-examples/alarm/src/main/java/org/apache/nlpcraft/examples/alarm/AlarmModel.java
index 8c26ae1..ed4b11d 100644
--- a/nlpcraft-examples/alarm/src/main/java/org/apache/nlpcraft/examples/alarm/AlarmModel.java
+++ b/nlpcraft-examples/alarm/src/main/java/org/apache/nlpcraft/examples/alarm/AlarmModel.java
@@ -52,11 +52,7 @@
* @return Query result.
*/
@NCIntentRef("alarm")
- @NCIntentSample({
- "Ping me in 3 minutes",
- "Buzz me in an hour and 15mins",
- "Set my alarm for 30s"
- })
+ @NCIntentSampleRef("alarm_samples.txt")
NCResult onMatch(
NCIntentMatch ctx,
@NCIntentTerm("nums") List<NCToken> numToks
diff --git a/nlpcraft-examples/alarm/src/main/resources/alarm_samples.txt b/nlpcraft-examples/alarm/src/main/resources/alarm_samples.txt
new file mode 100644
index 0000000..043fb08
--- /dev/null
+++ b/nlpcraft-examples/alarm/src/main/resources/alarm_samples.txt
@@ -0,0 +1,21 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (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
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Ping me in 3 minutes
+Buzz me in an hour and 15mins
+Set my alarm for 30s
+Set my alarm clock at 8:00 am in the morning
\ No newline at end of file
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
index becbb36..4503970 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/util/NCUtils.scala
@@ -2269,7 +2269,6 @@
/**
*
* @param src
- * @throws
* @return
*/
@throws[NCE]
@@ -2281,7 +2280,6 @@
else if (isUrl(src))
Using.resource(new URL(src).openStream()) { is => readStream(is) }
else {
- // TODO:
- throw new NCE(s"Source is not found: $src")
+ throw new NCE(s"Source not found: $src")
}
}
\ No newline at end of file
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 0657c89..a72b6c0 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
@@ -1617,31 +1617,28 @@
val refAnns = m.getAnnotationsByType(CLS_INTENT_REF)
if (smpAnns.nonEmpty || smpAnnsRef.nonEmpty) {
- if (intAnns.isEmpty && refAnns.isEmpty) {
- // TODO:
+ if (intAnns.isEmpty && refAnns.isEmpty)
throw new NCE(s"@NCIntentSample or @NCIntentSampleRef annotations without corresponding @NCIntent or @NCIntentRef annotations: $mtdStr")
- }
else {
- def read[T](arr: Array[T], claxx: Class[_], getValue: T => Seq[String]): Seq[Seq[String]] = {
- val seq = arr.toSeq.map(getValue).map(_.map(_.strip))
+ def read[T](arr: Array[T], annName: String, getValue: T => Seq[String]): Seq[Seq[String]] = {
+ val seq = arr.toSeq.map(getValue).map(_.map(_.strip).filter(s => s.nonEmpty && s.head != '#'))
if (seq.exists(_.isEmpty))
- logger.warn(s"@${claxx.getName} annotation is empty: $mtdStr")
+ logger.warn(s"$annName annotation has no samples: $mtdStr")
seq
}
val seqSeq =
read[NCIntentSample](
- smpAnns, classOf[NCIntentSample], _.value().toSeq
+ smpAnns, "@NCIntentSample", _.value().toSeq
) ++
read[NCIntentSampleRef](
- smpAnnsRef, classOf[NCIntentSampleRef], a => U.readAnySource(a.value())
+ smpAnnsRef, "@NCIntentSampleRef", a => U.readAnySource(a.value())
)
- // TODO: text
if (U.containsDups(seqSeq.flatten.toList))
- logger.warn(s"@NCIntentSample and @NCIntentSampleRef annotations have duplicates: $mtdStr")
+ logger.warn(s"@NCIntentSample and @NCIntentSampleRef annotations have duplicates (safely ignoring): $mtdStr")
val distinct = seqSeq.map(_.distinct).distinct
@@ -1652,10 +1649,8 @@
samples += (ann.value() -> distinct)
}
}
- else if (intAnns.nonEmpty || refAnns.nonEmpty) {
- // TODO: text
+ else if (intAnns.nonEmpty || refAnns.nonEmpty)
logger.warn(s"@NCIntentSample or @NCIntentSampleRef annotations are missing for: $mtdStr")
- }
}
if (samples.nonEmpty) {
@@ -1685,7 +1680,6 @@
if (!allSyns.exists(_.intersect(seq).nonEmpty)) {
// Not a warning since the parent class can contain direct synonyms (NLPCRAFT-348).
// See NLPCRAFT-349 for the additional issue.
- // TODO: text
logger.debug(s"@NCIntentSample or @NCIntentSampleRef sample doesn't contain any direct synonyms (check if its parent class contains any) [" +
s"mdlId=$mdlId, " +
s"origin=${mdl.getOrigin}, " +