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 2021/09/27 19:28:11 UTC
[incubator-nlpcraft] branch master updated: Code cleanup.
This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/master by this push:
new 1a20b57 Code cleanup.
1a20b57 is described below
commit 1a20b57d3c4153de22bcbf834fdc96c4faf05d5b
Author: Sergey Kamov <sk...@gmail.com>
AuthorDate: Mon Sep 27 22:23:48 2021 +0300
Code cleanup.
---
.../probe/mgrs/synonyms/NCSynonymsManager.scala | 40 ++++++++++++----------
1 file changed, 21 insertions(+), 19 deletions(-)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/synonyms/NCSynonymsManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/synonyms/NCSynonymsManager.scala
index e2d59f6..622f025 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/synonyms/NCSynonymsManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/synonyms/NCSynonymsManager.scala
@@ -76,8 +76,10 @@ object NCSynonymsManager extends NCService {
override def toString: String = variants.toString()
}
+ private case class IdlChunkKey(token: IdlToken, chunk: NCProbeSynonymChunk)
+
private val savedIdl = mutable.HashMap.empty[String, mutable.HashMap[SavedIdlKey, mutable.ArrayBuffer[Value]]]
- private val idlChunksCache = mutable.HashMap.empty[String, mutable.HashMap[(IdlToken, NCProbeSynonymChunk), Boolean]]
+ private val idlChunksCache = mutable.HashMap.empty[String, mutable.HashMap[IdlChunkKey, Boolean]]
private val idlCaches = mutable.HashMap.empty[String, CacheHolder[IdlToken]]
private val tokCaches = mutable.HashMap.empty[String, CacheHolder[Int]]
@@ -222,10 +224,10 @@ object NCSynonymsManager extends NCService {
): Boolean =
idlChunksCache.
getOrElseUpdate(req.getServerRequestId,
- mutable.HashMap.empty[(IdlToken, NCProbeSynonymChunk), Boolean]
+ mutable.HashMap.empty[IdlChunkKey, Boolean]
).
getOrElseUpdate(
- (tow, chunk),
+ IdlChunkKey(tow, chunk),
{
def get0[T](fromToken: NCToken => T, fromWord: NlpToken => T): T =
if (tow.isToken) fromToken(tow.token) else fromWord(tow.word)
@@ -270,14 +272,16 @@ object NCSynonymsManager extends NCService {
require(toks != null)
require(!syn.sparse && !syn.hasIdl)
- if (
- toks.length == syn.length && {
- if (syn.isTextOnly)
- toks.zip(syn).forall(p => p._1.stem == p._2.wordStem)
- else
- toks.zip(syn).sortBy(p => getSort(p._2.kind)).forall { case (tok, chunk) => isMatch(tok, chunk) }
- }
- )
+ lazy val matched =
+ if (syn.isTextOnly)
+ toks.zip(syn).
+ forall(p => p._1.stem == p._2.wordStem)
+ else
+ toks.zip(syn).
+ sortBy(p => getSort(p._2.kind)).
+ forall { case (tok, chunk) => isMatch(tok, chunk) }
+
+ if (toks.length == syn.length && matched)
callback()
}
@@ -303,14 +307,12 @@ object NCSynonymsManager extends NCService {
if (isUnprocessedIdl(srvReqId, elemId, s, toks)) {
require(toks != null)
- if (
- toks.length == s.length &&
- toks.count(_.isToken) >= s.idlChunks && {
- toks.zip(s).sortBy(p => getSort(p._2.kind)).forall {
- case (tow, chunk) => isMatch(tow, chunk, req, variantsToks)
- }
- }
- )
+ lazy val matched =
+ toks.zip(s).
+ sortBy(p => getSort(p._2.kind)).
+ forall { case (tow, chunk) => isMatch(tow, chunk, req, variantsToks) }
+
+ if (toks.length == s.length && toks.count(_.isToken) >= s.idlChunks && matched)
callback()
}