in nlpcraft/src/main/scala/org/apache/nlpcraft/nlp/enrichers/NCBracketsTokenEnricher.scala [46:63]
override def enrich(req: NCRequest, cfg: NCModelConfig, toks: List[NCToken]): Unit =
val stack = new java.util.Stack[String]()
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 = toksVals += t -> !stack.isEmpty
for (t <- toks if ok; txt = t.getText)
if BRACKETS.contains(txt) then
add(t)
stack.push(txt)
else
BRACKETS_REVERSED.get(txt).foreach(check)
add(t)
if ok && stack.isEmpty then
toksVals.foreach { (tok, b) => tok.put("brackets", b) }