This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-443
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-443 by this push:
new 22568a3 WIP.
22568a3 is described below
commit 22568a3499609de6ca381e8f14d54001d8b4d17e
Author: Sergey Kamov <[email protected]>
AuthorDate: Sat Sep 25 21:29:52 2021 +0300
WIP.
---
.../probe/mgrs/synonyms/NCSynonymsManager.scala | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 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 8de2fe7..369fa9d 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
@@ -38,7 +38,7 @@ object NCSynonymsManager extends NCService {
private lazy val cache =
mutable.HashMap.empty[String, mutable.HashMap[Int,
mutable.HashMap[Seq[T], mutable.HashSet[Synonym]]]]
- def isUnprocessed(elemId: String, s: Synonym, tokens: Seq[T]): Boolean
= {
+ def isUnprocessed(elemId: String, s: Synonym, tokens: Seq[T]): Boolean
=
cache.
getOrElseUpdate(
elemId,
@@ -52,7 +52,6 @@ object NCSynonymsManager extends NCService {
tokens,
mutable.HashSet.empty[Synonym]
).add(s)
- }
}
private case class SavedIdlKey(id: String, startCharIndex: Int,
endCharIndex: Int, other: Map[String, AnyRef] = Map.empty)
@@ -102,10 +101,7 @@ object NCSynonymsManager extends NCService {
private def isMatch(tok: NlpToken, chunk: NCProbeSynonymChunk): Boolean =
chunk.kind match {
case TEXT => chunk.wordStem == tok.stem
- case REGEX =>
- val regex = chunk.regex
-
- regex.matcher(tok.origText).matches() ||
regex.matcher(tok.normText).matches()
+ case REGEX => chunk.regex.matcher(tok.origText).matches() ||
chunk.regex.matcher(tok.normText).matches()
case IDL => throw new AssertionError()
case _ => throw new AssertionError()
}
@@ -191,7 +187,7 @@ object NCSynonymsManager extends NCService {
savedIdl.
getOrElseUpdate(req.getServerRequestId, mutable.HashMap.empty).
getOrElseUpdate(SavedIdlKey(tok), mutable.ArrayBuffer.empty) +=
- Value(req, variantsToks, pred)
+ Value(req, variantsToks, pred)
}
/**
@@ -230,7 +226,8 @@ object NCSynonymsManager extends NCService {
(tow, chunk),
{
def get0[T](fromToken: NCToken => T, fromWord: NlpToken =>
T): T =
- if (tow.isToken) fromToken(tow.token) else
fromWord(tow.word)
+ if (tow.isToken) fromToken(tow.token)
+ else fromWord(tow.word)
chunk.kind match {
case TEXT => chunk.wordStem == get0(_.stem, _.stem)
@@ -255,8 +252,8 @@ object NCSynonymsManager extends NCService {
case _ => throw new AssertionError()
}
- }
- )
+ }
+ )
/**
*
@@ -306,7 +303,7 @@ object NCSynonymsManager extends NCService {
if (
toks.length == s.length &&
- toks.count(_.isToken) >= s.idlChunks && {
+ toks.count(_.isToken) >= s.idlChunks && {
toks.zip(s).sortBy(p => getSort(p._2.kind)).forall {
case (tow, chunk) => isMatch(tow, chunk, req,
variantsToks)
}
@@ -364,8 +361,7 @@ object NCSynonymsManager extends NCService {
syn,
toks,
(t: IdlToken, chunk: NCProbeSynonymChunk) => isMatch(t, chunk,
req, variantsToks),
- (t: IdlToken) =>
- if (t.isToken) t.token.getStartCharIndex else
t.word.startCharIndex,
+ (t: IdlToken) => if (t.isToken) t.token.getStartCharIndex else
t.word.startCharIndex,
shouldBeNeighbors = !syn.sparse
) match {
case Some(res) => callback(res)