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

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


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

commit c3aaa729d96afa16db9baed4550ba17e6015931f
Author: Sergey Kamov <[email protected]>
AuthorDate: Wed Apr 29 14:02:04 2020 +0300

    WIP.
---
 .../mgrs/nlp/enrichers/limit/NCLimitEnricher.scala | 35 ++++++++++++----------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git 
a/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
 
b/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
index 69500a8..87f02c9 100644
--- 
a/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
+++ 
b/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCLimitEnricher.scala
@@ -234,25 +234,30 @@ object NCLimitEnricher extends NCProbeEnricher {
         val i2 = toks.last.index
 
         val refCands = toks.filter(_.exists(n ⇒ n.isUser && 
n.tokenIndexes.head >= i1 && n.tokenIndexes.last <= i2))
-        val commonNotes = getCommonNotes(refCands)
+        val commonRefNotes = getCommonNotes(refCands)
 
-        if (commonNotes.nonEmpty) {
+        if (commonRefNotes.nonEmpty) {
             val matchCands = toks.diff(refCands)
+            val idxs = refCands.map(_.index)
+
+            val minRefIdx = idxs.min
 
             def try0(group: Seq[NCNlpSentenceToken]): Option[Match] =
-                groupsMap.get(group) match {
-                    case Some(h) ⇒
-                        val idxs = refCands.map(_.index).asJava
-
-                        if (LIMITS.contains(h.value) || h.isFuzzyNum)
-                            Some(Match(h.limit, Some(h.asc), matchCands, 
commonNotes, idxs))
-                        else
-                            numsMap.get(group) match {
-                                case Some(num) ⇒ Some(Match(num.value, None, 
matchCands, commonNotes, idxs))
-                                case None ⇒ None
-                            }
-                    case None ⇒ None
-                }
+                // All references must be after token for limits.
+                if (group.forall(_.index < minRefIdx))
+                    groupsMap.get(group) match {
+                        case Some(h) ⇒
+                            if (LIMITS.contains(h.value) || h.isFuzzyNum)
+                                Some(Match(h.limit, Some(h.asc), matchCands, 
commonRefNotes, idxs.asJava))
+                            else
+                                numsMap.get(group) match {
+                                    case Some(num) ⇒ Some(Match(num.value, 
None, matchCands, commonRefNotes, idxs.asJava))
+                                    case None ⇒ None
+                                }
+                        case None ⇒ None
+                    }
+                else
+                    None
 
             try0(matchCands) match {
                 case Some(m) ⇒ Some(m)

Reply via email to