This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-443-1
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-443-1 by this push:
new 9acc695 WIP.
9acc695 is described below
commit 9acc6959822c77c665e0e615b133cbd72df6901f
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Sep 23 09:22:00 2021 +0300
WIP.
---
.../nlpcraft/common/nlp/NCNlpSentenceNote.scala | 61 ++++++++++------------
.../nlpcraft/probe/mgrs/NCProbeVariants.scala | 2 +-
.../probe/mgrs/sentence/NCSentenceManager.scala | 2 +-
3 files changed, 30 insertions(+), 35 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentenceNote.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentenceNote.scala
index c457aa7..fb9a016 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentenceNote.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/NCNlpSentenceNote.scala
@@ -30,11 +30,11 @@ import
scala.jdk.CollectionConverters.{CollectionHasAsScala, SeqHasAsJava}
/**
* Sentence token note is a typed map of KV pairs.
*/
-class NCNlpSentenceNote(private val values: Map[String, JSerializable])
extends JSerializable with NCAsciiLike {
+class NCNlpSentenceNote(private val values: mutable.HashMap[String,
JSerializable]) extends JSerializable with NCAsciiLike {
import NCNlpSentenceNote._
- private lazy val dataWithoutIndexes: Map[String, JSerializable] =
this.filter(p => !SKIP_CLONE.contains(p._1))
- private lazy val skipNlp: Map[String, JSerializable] =
dataWithoutIndexes.filter { case (key, _) => key != "noteType" }
+ private lazy val dataWithoutIndexes = this.filter(p =>
!SKIP_CLONE.contains(p._1)).toMap
+ private lazy val skipNlp = dataWithoutIndexes.filter { case (key, _) =>
key != "noteType" }
@transient
@@ -72,16 +72,15 @@ class NCNlpSentenceNote(private val values: Map[String,
JSerializable]) extends
/**
* Clones this note.
*/
- def clone(indexes: Seq[Int], wordIndexes: Seq[Int], params: (String,
Any)*): NCNlpSentenceNote =
- NCNlpSentenceNote(
+ def clone(indexes: Seq[Int], wordIndexes: Seq[Int], params: (String,
JSerializable)*): NCNlpSentenceNote =
+ apply(
indexes,
Some(wordIndexes),
noteType,
- dataWithoutIndexes.toSeq ++ params:_*
+ dataWithoutIndexes ++ params.toMap
)
- override def clone(): NCNlpSentenceNote =
- new NCNlpSentenceNote((mutable.HashMap.empty[String, JSerializable] ++
values).toMap)
+ override def clone(): NCNlpSentenceNote = new
NCNlpSentenceNote(values.clone())
/**
*
@@ -124,13 +123,8 @@ class NCNlpSentenceNote(private val values: Map[String,
JSerializable]) extends
*
* @param kvs
*/
- def clone(kvs : (String, JSerializable)*): NCNlpSentenceNote = {
- val m = mutable.HashMap.empty[String, JSerializable] ++ values
-
- kvs.foreach(kv => m += kv._1 -> kv._2)
-
- new NCNlpSentenceNote(m.toMap)
- }
+ def clone(kvs : (String, JSerializable)*): NCNlpSentenceNote =
+ new NCNlpSentenceNote(mutable.HashMap.empty[String, JSerializable] ++
values ++ kvs)
/**
*
@@ -211,7 +205,7 @@ object NCNlpSentenceNote {
/**
* To immutable map.
*/
- implicit def values(note: NCNlpSentenceNote): Map[String, JSerializable] =
note.values
+ implicit def values(note: NCNlpSentenceNote): mutable.HashMap[String,
JSerializable] = note.values
/**
* Creates new note with given parameters.
@@ -225,7 +219,7 @@ object NCNlpSentenceNote {
indexes: Seq[Int],
wordIndexesOpt: Option[Seq[Int]],
typ: String,
- params: (String, Any)*
+ params: Map[String, Any]
): NCNlpSentenceNote = {
def calc(seq: Seq[Int]): (Int, Int, Int, JList[Int], Int) =
(U.calcSparsity(seq), seq.min, seq.max, seq.asJava, seq.length)
@@ -233,18 +227,19 @@ object NCNlpSentenceNote {
val (sparsity, tokMinIndex, tokMaxIndex, tokWordIndexes, len) =
calc(wordIndexesOpt.getOrElse(indexes))
new NCNlpSentenceNote(
- mutable.HashMap[String, JSerializable]((
- params.filter(_._2 != null) :+
- ("noteType" -> typ) :+
- ("tokMinIndex" -> indexes.min) :+
- ("tokMaxIndex" -> indexes.max) :+
- ("tokWordIndexes" -> indexes.asJava) :+
- ("minIndex" -> tokMinIndex) :+
- ("maxIndex" -> tokMaxIndex) :+
- ("wordIndexes" -> tokWordIndexes) :+
- ("wordLength" -> len) :+
- ("sparsity" -> sparsity)
- ).map(p => p._1 -> p._2.asInstanceOf[JSerializable]): _*).toMap
+ mutable.HashMap.empty[String, JSerializable] ++
+ params.filter(_._2 != null).map(p => p._1 ->
p._2.asInstanceOf[JSerializable]) ++
+ Map[String, JSerializable](
+ "noteType" -> typ,
+ "tokMinIndex" -> indexes.min,
+ "tokMaxIndex" -> indexes.max,
+ "tokWordIndexes" -> indexes.asJava.asInstanceOf[JSerializable],
+ "minIndex" -> tokMinIndex,
+ "maxIndex" -> tokMaxIndex,
+ "wordIndexes" -> tokWordIndexes.asInstanceOf[JSerializable],
+ "wordLength" -> len,
+ "sparsity" -> sparsity
+ )
)
}
@@ -256,7 +251,7 @@ object NCNlpSentenceNote {
* @param params Parameters.
*/
def apply(indexes: Seq[Int], typ: String, params: (String, Any)*):
NCNlpSentenceNote =
- apply(indexes, None, typ, params: _*)
+ apply(indexes, None, typ, params.toMap)
/**
* Creates new note with given parameters.
@@ -266,7 +261,7 @@ object NCNlpSentenceNote {
* @param params Parameters.
*/
def apply(indexes: mutable.Seq[Int], typ: String, params: (String, Any)*):
NCNlpSentenceNote =
- apply(indexes.toSeq, None, typ, params: _*)
+ apply(indexes.toSeq, None, typ, params.toMap)
/**
* Creates new note with given parameters.
@@ -277,7 +272,7 @@ object NCNlpSentenceNote {
* @param params Parameters.
*/
def apply(indexes: Seq[Int], wordIndexes: Seq[Int], typ: String, params:
(String, Any)*): NCNlpSentenceNote =
- apply(indexes, Some(wordIndexes), typ, params: _*)
+ apply(indexes, Some(wordIndexes), typ, params.toMap)
/**
* Creates new note with given parameters.
@@ -288,5 +283,5 @@ object NCNlpSentenceNote {
* @param params Parameters.
*/
def apply(indexes: mutable.Seq[Int], wordIndexes: mutable.Seq[Int], typ:
String, params: (String, Any)*): NCNlpSentenceNote =
- apply(indexes.toSeq, Some(wordIndexes.toSeq), typ, params: _*)
+ apply(indexes.toSeq, Some(wordIndexes.toSeq), typ, params.toMap)
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
index 0596783..8aced5f 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/NCProbeVariants.scala
@@ -268,7 +268,7 @@ object NCProbeVariants {
for ((tok, tokNlp) <- toks.zip(nlpSen) if tokNlp.isUser)
process(tok, tokNlp)
- ok = ok && (!lastPhase ||
NCSynonymsManager.isStillValid(srvReqId, toks.toSeq))
+ ok = ok && NCSynonymsManager.isStillValid(srvReqId, toks.toSeq)
if (ok) Some(new NCVariantImpl(toks.asJava)) else None
})
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
index 34c3f87..d57e5a9 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/sentence/NCSentenceManager.scala
@@ -707,7 +707,7 @@ object NCSentenceManager extends NCService {
Holder(
// We have to delete some keys to have possibility to
compare sentences.
- notes.map(_.clone().filter { case (name, _) => name !=
"direct" }).toSeq,
+ notes.map(_.clone().toMap.filter { case (name, _) =>
name != "direct" }).toSeq,
sen,
notes.filter(_.isNlp).map(p => if (p.isDirect) 0 else
1).sum
)