This is an automated email from the ASF dual-hosted git repository. sergeykamov pushed a commit to branch NLPCRAFT-472 in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-472 by this push: new 7e23e24 WIP. 7e23e24 is described below commit 7e23e2452a017bc61d2630c6e4b70f640f4a6463 Author: Sergey Kamov <skhdlem...@gmail.com> AuthorDate: Mon Jan 10 14:27:15 2022 +0300 WIP. --- .../semantic/impl/NCSemanticEntityParserImpl.scala | 2 +- .../semantic/impl/NCSemanticSynonymsProcessor.scala | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticEntityParserImpl.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticEntityParserImpl.scala index 9d81e13..8e6a9a2 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticEntityParserImpl.scala +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticEntityParserImpl.scala @@ -203,7 +203,7 @@ class NCSemanticEntityParserImpl( if cache.add(idxs) then h.textSynonyms.get(variant.map(p => stems(p)).mkString(" ")) match - case Some(keys) => keys.foreach(key => add(key.elemId, key.value)) + case Some(keys) => keys.foreach(key => add(key.elementId, key.value)) case None => for ((elemId, syns) <- h.mixedSynonyms.getOrElse(variant.size, Seq.empty)) var found = false diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticSynonymsProcessor.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticSynonymsProcessor.scala index 13aed2c..3305fd7 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticSynonymsProcessor.scala +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/entity/parser/semantic/impl/NCSemanticSynonymsProcessor.scala @@ -33,10 +33,20 @@ import scala.collection.mutable import scala.collection.mutable.ArrayBuffer import scala.jdk.CollectionConverters.* -private[impl] case class NCSemanticSynonymsKey(elemId: String, value: Option[String]) +/** + * + * @param elementId + * @param value + */ +private[impl] case class NCSemanticSynonymsValue(elementId: String, value: Option[String]) +/** + * + * @param textSynonyms + * @param mixedSynonyms + */ private[impl] case class NCSemanticSynonymsHolder( - textSynonyms: Map[String, Set[NCSemanticSynonymsKey]], + textSynonyms: Map[String, Set[NCSemanticSynonymsValue]], mixedSynonyms: Map[Int, Map[String, Seq[NCSemanticSynonym]]] ) @@ -233,12 +243,12 @@ private[impl] object NCSemanticSynonymsProcessor extends LazyLogging: buf --= txtBuf - val txtSyns: Map[String, Set[NCSemanticSynonymsKey]] = + val txtSyns = txtBuf.groupBy(_.synonym.stem). map { (stem, hs) => stem -> hs.map(h => - NCSemanticSynonymsKey(h.elementId, Option.when(h.synonym.value != null)(h.synonym.value)) + NCSemanticSynonymsValue(h.elementId, Option.when(h.synonym.value != null)(h.synonym.value)) ).toSet }