You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2020/09/13 15:09:34 UTC
[incubator-nlpcraft] branch NLPCRAFT-120 updated: WIP.
This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-120
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-120 by this push:
new 11ee7b9 WIP.
11ee7b9 is described below
commit 11ee7b99ec8d253dc76b55d5c1b8ac4ee8d9985a
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Sun Sep 13 18:09:27 2020 +0300
WIP.
---
.../org/apache/nlpcraft/common/util/NCUtils.scala | 9 +++--
.../probe/mgrs/deploy/NCDeployManager.scala | 39 +++++++++++++---------
2 files changed, 27 insertions(+), 21 deletions(-)
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 ff045ad..226d48e 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
@@ -1209,13 +1209,13 @@ object NCUtils extends LazyLogging {
/**
* Checks duplicated elements in collection.
*
- * @param seq Collection.
+ * @param list Collection. Note, it should be list.
* @param seen Checked elements.
* @see #getDups
*/
@annotation.tailrec
- def containsDups[T](seq: Seq[T], seen: Set[T] = Set.empty[T]): Boolean =
- seq match {
+ def containsDups[T](list: List[T], seen: Set[T] = Set.empty[T]): Boolean =
+ list match {
case x :: xs ⇒ if (seen.contains(x)) true else containsDups(xs, seen + x)
case _ ⇒ false
}
@@ -1228,8 +1228,7 @@ object NCUtils extends LazyLogging {
* @return
* @see #containsDups
*/
- def getDups[T](seq: Seq[T]): Set[T] =
- seq.diff(seq.distinct).toSet
+ def getDups[T](seq: Seq[T]): Set[T] = seq.diff(seq.distinct).toSet
/**
* Gets a sequence without dups. It works by checking for dups first, before creating a new
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 44ff6d8..29b90eb 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
@@ -318,7 +318,7 @@ object NCDeployManager extends NCService with DecorateAsScala {
// Add straight element synonyms (dups printed as warnings).
val synsChunks = for (syn ← elm.getSynonyms.asScala.flatMap(parser.expand)) yield chunkSplit(syn)
- if (U.containsDups(synsChunks.flatten))
+ if (U.containsDups(synsChunks.flatten.toList))
logger.trace(s"Model element synonym dups found (ignoring) [" +
s"mdlId=$mdlId, " +
s"elmId=$elmId, " +
@@ -332,7 +332,7 @@ object NCDeployManager extends NCService with DecorateAsScala {
(if (elm.getValueLoader != null) elm.getValueLoader.load(elm).asScala else Seq.empty)
// Add value synonyms.
- val valNames = vals.map(_.getName)
+ val valNames = vals.map(_.getName).toList
if (U.containsDups(valNames))
logger.trace(s"Model element values names dups found (ignoring) [" +
@@ -1051,7 +1051,7 @@ object NCDeployManager extends NCService with DecorateAsScala {
s"]")
// Gets terms identifiers.
- val termIds = tokParamAnns.zipWithIndex.map {
+ val termIds = tokParamAnns.toList.zipWithIndex.map {
case (anns, idx) ⇒
def mkArg(): String = arg2Str(mtd, idx, ctxFirstParam)
@@ -1075,6 +1075,15 @@ object NCDeployManager extends NCService with DecorateAsScala {
}
}
+
+ if (U.containsDups(termIds))
+ throw new NCE(s"@NCIntentTerm values duplicated [" +
+ s"mdlId=$mdlId, " +
+ s"duplicated=${U.getDups(termIds).mkString(", ")}, " +
+ s"callback=${method2Str(mtd)}" +
+ s"]"
+ )
+
val terms = intent.terms.toSeq
// Checks correctness of term IDs.
@@ -1467,7 +1476,7 @@ object NCDeployManager extends NCService with DecorateAsScala {
None
}
else {
- var samples = smpAnn.value().toList
+ val samples = smpAnn.value().toList
if (samples.isEmpty) {
logger.warn(s"@NCTestSample annotation is empty [" +
@@ -1477,20 +1486,18 @@ object NCDeployManager extends NCService with DecorateAsScala {
None
}
- else {
- if (U.containsDups(samples)) {
- logger.warn(s"@NCTestSample annotation has duplicates [" +
- s"mdlId=$mdlId, " +
- s"callback=$mkMethodName, " +
- s"duplicates=${samples.groupBy(p ⇒ p).filter(_._2.size > 1).map(_._1).mkString(", ")}" +
- s"]"
- )
-
- samples = samples.distinct
- }
+ else if (U.containsDups(samples)) {
+ logger.warn(s"@NCTestSample annotation has duplicates [" +
+ s"mdlId=$mdlId, " +
+ s"callback=$mkMethodName, " +
+ s"duplicated=${U.getDups(samples).mkString(", ")}" +
+ s"]"
+ )
- Some(mkIntentId() → samples)
+ Some(mkIntentId() → samples.distinct)
}
+ else
+ Some(mkIntentId() → samples)
}
}
else {