This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-287
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-287 by this push:
new 7a20a4e WIP.
7a20a4e is described below
commit 7a20a4ebe77e21ba8c4c4d1eed5a272fe42457df
Author: Sergey Kamov <[email protected]>
AuthorDate: Thu Apr 15 15:39:40 2021 +0300
WIP.
---
.../probe/mgrs/nlp/NCProbeEnrichmentManager.scala | 2 ++
.../probe/mgrs/sentence/NCSentenceManager.scala | 19 ++++++++++++++++---
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
index 4a1466e..aab00ed 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
@@ -517,6 +517,8 @@ object NCProbeEnrichmentManager extends NCService with
NCOpenCensusModelStats {
)
})
+ NCSentenceManager.clearCache(srvReqId)
+
// Final validation before execution.
try
sensSeq.foreach(NCValidateManager.postValidate(mdl, _, span))
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 541966a..f77e035 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
@@ -37,6 +37,10 @@ import scala.language.implicitConversions
object NCSentenceManager extends NCService {
@volatile private var pool: java.util.concurrent.ForkJoinPool = _
+ type CacheKey = Seq[Set[NCNlpSentenceNote]]
+ type CacheValue = Seq[Seq[NCNlpSentenceNote]]
+ private val combCache = mutable.HashMap.empty[String,
mutable.HashMap[CacheKey, CacheValue]]
+
case class PartKey(id: String, start: Int, end: Int) {
require(start <= end)
@@ -685,8 +689,12 @@ object NCSentenceManager extends NCService {
toSeq.sortBy(-_.size)
val seqSens =
-
NCSentenceHelper.findCombinations(toksByIdx.map(_.asJava).asJava,
pool).asScala.map(_.asScala).
- par.
+ combCache.
+ getOrElseUpdate(sen.srvReqId,
mutable.HashMap.empty[CacheKey, CacheValue]).
+ getOrElseUpdate(
+ toksByIdx,
+
NCSentenceHelper.findCombinations(toksByIdx.map(_.asJava).asJava,
pool).asScala.map(_.asScala)
+ ).par.
flatMap(delComb ⇒ {
val nsClone = sen.clone()
@@ -774,8 +782,13 @@ object NCSentenceManager extends NCService {
* @param mdl
* @param sen
* @param lastPhase
- * @return
*/
def collapse(mdl: NCModel, sen: NCNlpSentence, lastPhase: Boolean =
false): Seq[NCNlpSentence] =
collapseSentence(sen, mdl, lastPhase)
+
+ /**
+ *
+ * @param srvReqId
+ */
+ def clearCache(srvReqId: String): Unit = combCache -= srvReqId
}