This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-387
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-387 by this push:
new a600aa7 Fuzzy numerics logic fixes.
a600aa7 is described below
commit a600aa7f568c52f8e687b90fe7cedb5a78d63867
Author: Sergey Kamov <[email protected]>
AuthorDate: Tue Aug 3 11:32:12 2021 +0300
Fuzzy numerics logic fixes.
---
.../nlpcraft/examples/alarm/NCAlarmModelSpec.scala | 12 ++++++---
.../common/nlp/numeric/NCNumericFuzzy.scala | 30 +++++++++++-----------
.../common/nlp/numeric/NCNumericManager.scala | 12 ++++-----
3 files changed, 29 insertions(+), 25 deletions(-)
diff --git
a/nlpcraft-examples/alarm/src/test/java/org/apache/nlpcraft/examples/alarm/NCAlarmModelSpec.scala
b/nlpcraft-examples/alarm/src/test/java/org/apache/nlpcraft/examples/alarm/NCAlarmModelSpec.scala
index 0cb90ad..f2f6e66 100644
---
a/nlpcraft-examples/alarm/src/test/java/org/apache/nlpcraft/examples/alarm/NCAlarmModelSpec.scala
+++
b/nlpcraft-examples/alarm/src/test/java/org/apache/nlpcraft/examples/alarm/NCAlarmModelSpec.scala
@@ -58,12 +58,18 @@ class NCAlarmModelSpec extends NCTestContext {
def mkPeriod(hours: Int, mins: Int, secs: Int = 0): Long =
now.until(now.plusHours(hours).plusMinutes(mins).plusSeconds(secs), MILLIS)
- // Fuzzy.
+ // Fuzzy `single`.
+ check("Buzz me in a minute or two.", mkPeriod(0, 1))
+ check("Buzz me in hour or two.", mkPeriod(1, 0))
+ check("Buzz me in an hour.", mkPeriod(1, 0))
+
+ // Fuzzy `few`.
check("Buzz me in few minutes.", mkPeriod(0, 2))
- check("Buzz me in a minute or two.", mkPeriod(0, 2))
check("Buzz me in one or two minutes.", mkPeriod(0, 2))
+ check("Buzz me in one or two hours.", mkPeriod(2, 0))
check("Buzz me in a couple of minutes.", mkPeriod(0, 2))
- check("Buzz me in an hour.", mkPeriod(1, 0))
+
+ // Fuzzy `bit`.
check("Buzz me in a bit.", mkPeriod(0, 2))
// Complex periods.
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericFuzzy.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericFuzzy.scala
index 4222667..c8d19f1 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericFuzzy.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericFuzzy.scala
@@ -35,13 +35,13 @@ object NCNumericFuzzy {
val singleDt =
Map(
- "in second {or two|_}" -> U("second", "datetime"),
- "in hour {or two|_}" -> U("hour", "datetime"),
- "in minute {or two|_}" -> U("minute", "datetime"),
- "in day {or two|_}" -> U("day", "datetime"),
- "in week {or two|_}" -> U("week", "datetime"),
- "in month {or two|_}" -> U("month", "datetime"),
- "in year {or two|_}" -> U("year", "datetime")
+ "in {a|an|_} second {or two|_}" -> U("second", "datetime"),
+ "in {a|an|_} hour {or two|_}" -> U("hour", "datetime"),
+ "in {a|an|_} minute {or two|_}" -> U("minute", "datetime"),
+ "in {a|an|_} day {or two|_}" -> U("day", "datetime"),
+ "in {a|an|_} week {or two|_}" -> U("week", "datetime"),
+ "in {a|an|_} month {or two|_}" -> U("month", "datetime"),
+ "in {a|an|_} year {or two|_}" -> U("year", "datetime")
).flatMap { case (txt, u) => make(txt, u, 1) }
val bitDt =
@@ -51,15 +51,15 @@ object NCNumericFuzzy {
val fewDt =
Map(
- "in {a|an|_} {few|couple|one or two|two or three} seconds" ->
U("second", "datetime"),
- "in {a|an|_} {few|couple|one or two|two or three} minutes" ->
U("minute", "datetime"),
- "in {a|an|_} {few|couple|one or two|two or three} hours" ->
U("hour", "datetime"),
- "in {a|an|_} {few|couple|one or two|two or three} days" ->
U("day", "datetime"),
- "in {a|an|_} {few|couple|one or two|two or three} weeks" ->
U("week", "datetime"),
- "in {a|an|_} {few|couple|one or two|two or three} months" ->
U("month", "datetime"),
- "in {a|an|_} {few|couple|one or two|two or three} years" ->
U("year", "datetime")
+ "in {a|an|_} {few|couple of|one or two|two or three} seconds"
-> U("second", "datetime"),
+ "in {a|an|_} {few|couple of|one or two|two or three} minutes"
-> U("minute", "datetime"),
+ "in {a|an|_} {few|couple of|one or two|two or three} hours" ->
U("hour", "datetime"),
+ "in {a|an|_} {few|couple of|one or two|two or three} days" ->
U("day", "datetime"),
+ "in {a|an|_} {few|couple of|one or two|two or three} weeks" ->
U("week", "datetime"),
+ "in {a|an|_} {few|couple of|one or two|two or three} months"
-> U("month", "datetime"),
+ "in {a|an|_} {few|couple of|one or two|two or three} years" ->
U("year", "datetime")
).flatMap { case (txt, u) => make(txt, u, 2) }
- singleDt ++ fewDt ++ bitDt
+ singleDt ++ bitDt ++ fewDt
}
}
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericManager.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericManager.scala
index a502117..a428ab9 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericManager.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/common/nlp/numeric/NCNumericManager.scala
@@ -451,13 +451,11 @@ object NCNumericManager extends NCService {
val usedToks = nums.flatMap(_.tokens)
- val res =
- (nums ++ ns.filter(t =>
!usedToks.contains(t)).flatMap(mkSolidNumUnit)).sortBy(_.tokens.head.index).distinct
-
- val resToks = res.flatMap(_.tokens)
-
- // Adds detected special datetime cases with lowest priority.
- res ++ findFuzzy(ns).filter(p =>
!resToks.exists(p.tokens.contains))
+ (
+ nums ++
+ ns.filter(t => !usedToks.contains(t)).flatMap(mkSolidNumUnit)
++
+ findFuzzy(ns)
+ ).sortBy(_.tokens.head.index).distinct
}
}
}