This is an automated email from the ASF dual-hosted git repository.

sergeykamov pushed a commit to branch NLPCRAFT-520
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git


The following commit(s) were added to refs/heads/NLPCRAFT-520 by this push:
     new 4f1d3870 WIP.
4f1d3870 is described below

commit 4f1d387078d4e216c93c59aeda6ce34b3feca5f7
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Dec 19 15:48:58 2022 +0400

    WIP.
---
 .../nlpcraft/nlp/enrichers/NCBracketsTokenEnricher.scala       | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/enrichers/NCBracketsTokenEnricher.scala
 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/enrichers/NCBracketsTokenEnricher.scala
index b4d8f563..70ce779a 100644
--- 
a/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/enrichers/NCBracketsTokenEnricher.scala
+++ 
b/nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/enrichers/NCBracketsTokenEnricher.scala
@@ -47,24 +47,22 @@ class NCBracketsTokenEnricher extends NCTokenEnricher with 
LazyLogging:
     /** @inheritdoc */
     override def enrich(req: NCRequest, cfg: NCModelConfig, toks: 
List[NCToken]): Unit =
         val stack = new java.util.Stack[String]()
-        val map = mutable.HashMap.empty[NCToken, Boolean]
+        val toksVals = mutable.HashMap.empty[NCToken, Boolean]
         var ok = true
 
         def check(expected: String): Unit = if stack.empty() || stack.pop() != 
expected then ok = false
-        def add(t: NCToken): Unit = map += t -> !stack.isEmpty
+        def add(t: NCToken): Unit = toksVals += t -> !stack.isEmpty
 
         for (t <- toks if ok; txt = t.getText)
             if BRACKETS.contains(txt) then
                 add(t)
                 stack.push(txt)
-            else if BRACKETS_REVERSED.contains(txt) then
-                check(BRACKETS_REVERSED(txt))
-                add(t)
             else
+                BRACKETS_REVERSED.get(txt).foreach(check)
                 add(t)
 
         if ok && stack.isEmpty then
-            map.foreach { (tok, b) => tok.put("brackets", b) }
+            toksVals.foreach { (tok, b) => tok.put("brackets", b) }
         else
             toks.foreach(_.put("brackets",false))
             logger.warn(s"Detected invalid brackets in: ${req.getText}")
\ No newline at end of file

Reply via email to