You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2021/07/08 15:41:59 UTC
[incubator-nlpcraft] branch NLPCRAFT-359 updated: WIP on
NLPCRAFT-359.
This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-359
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-359 by this push:
new 34f853a WIP on NLPCRAFT-359.
34f853a is described below
commit 34f853ad6970c28aa9bef79478673e548413a8a4
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Thu Jul 8 08:41:14 2021 -0700
WIP on NLPCRAFT-359.
---
.../apache/nlpcraft/examples/alarm/AlarmModel.java | 6 +-----
.../alarm/src/main/resources/alarm_samples.txt | 21 +++++++++++++++++++++
.../org/apache/nlpcraft/common/util/NCUtils.scala | 4 +---
.../probe/mgrs/deploy/NCDeployManager.scala | 22 ++++++++--------------
4 files changed, 31 insertions(+), 22 deletions(-)
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 @@ public class AlarmModel extends NCModelFileAdapter {
* @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 @@ object NCUtils extends LazyLogging {
/**
*
* @param src
- * @throws
* @return
*/
@throws[NCE]
@@ -2281,7 +2280,6 @@ object NCUtils extends LazyLogging {
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 @@ object NCDeployManager extends NCService {
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 @@ object NCDeployManager extends NCService {
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 @@ object NCDeployManager extends NCService {
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}, " +