This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-16
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-16 by this push:
new d2b219a WIP.
d2b219a is described below
commit d2b219aa99f91b8b172f940b3a4612d9b2060532
Author: Sergey Kamov <[email protected]>
AuthorDate: Sun Mar 15 18:41:27 2020 +0300
WIP.
---
.../mgrs/nlp/enrichers/NCEnricherBaseSpec.scala | 23 ++--
.../mgrs/nlp/enrichers/NCEnricherTestModel.scala | 20 +--
.../mgrs/nlp/enrichers/NCEnrichersTestBeans.scala | 139 +++++++++++----------
.../nlp/enrichers/limit/NCEnricherLimitSpec.scala | 7 +-
4 files changed, 104 insertions(+), 85 deletions(-)
diff --git
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
index 6c9e611..18b589a 100644
---
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
+++
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherBaseSpec.scala
@@ -54,9 +54,12 @@ class NCEnricherBaseSpec {
val sens = NCTestSentence.deserialize(res.getResult.get())
- require(sens.size == 1)
+ require(sens.size == 1, s"Unexpected response size: ${sens.size}")
- assertEquals(NCTestSentence(expToks), sens.head)
+ val expSen = NCTestSentence(expToks)
+ val recSen = sens.head
+
+ assertEquals(expSen, recSen, s"Unexpected response [expected=$expSen,
received=$recSen]")
}
/**
@@ -71,12 +74,18 @@ class NCEnricherBaseSpec {
assertTrue(res.isOk)
assertTrue(res.getResult.isPresent)
- val sens1 = expToks.map(e ⇒ NCTestSentence(e))
- val sens2 = NCTestSentence.deserialize(res.getResult.get())
+ val expSens = expToks.map(NCTestSentence(_))
+ val recSens = NCTestSentence.deserialize(res.getResult.get())
- require(sens1.size == sens2.size)
+ require(
+ expSens.size == recSens.size,
+ s"Unexpected response size [expected=${expSens.size},
received=${recSens.size}]"
+ )
- for (sen ← sens1)
- require(sens2.exists(_ == sen))
+ for (sen ← expSens)
+ require(
+ recSens.exists(_ == sen),
+ s"Required sentence not found [expected=$sen,
found=${recSens.mkString("\n")}]"
+ )
}
}
diff --git
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala
index 7fa6112..8023bdc 100644
---
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala
+++
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnricherTestModel.scala
@@ -35,17 +35,17 @@ class NCEnricherTestModel extends NCModelAdapter(ID, "Model
enrichers test", "1.
override def getElements: util.Set[NCElement] =
Set(
- mkElement("A", Seq("A")),
- mkElement("B", Seq("B")),
- mkElement("C", Seq("C")),
- mkElement("A B", Seq("A B")),
- mkElement("B C", Seq("B C")),
- mkElement("A B C", Seq("A B C")),
- mkElement("D1", Seq("D")),
- mkElement("D2", Seq("D"))
+ mkElement("A", "A"),
+ mkElement("B", "B"),
+ mkElement("C", "C"),
+ mkElement("AB", "A B"),
+ mkElement("BC", "B C"),
+ mkElement("ABC", "A B C"),
+ mkElement("D1", "D"),
+ mkElement("D2", "D")
).asJava
- private def mkElement(id: String, syns: Seq[String]): NCElement =
+ private def mkElement(id: String, syns: String*): NCElement =
new NCElement {
override def getId: String = id
override def getSynonyms: util.List[String] = syns.asJava
@@ -54,7 +54,7 @@ class NCEnricherTestModel extends NCModelAdapter(ID, "Model
enrichers test", "1.
override def onContext(ctx: NCContext): NCResult =
NCResult.text(
- NCTestSentence.serialize(ctx.getVariants.asScala.map(v ⇒
NCTestSentence(v.asScala.map(t ⇒ NCTestToken(t)))))
+ NCTestSentence.serialize(ctx.getVariants.asScala.map(v ⇒
NCTestSentence(v.asScala.map(NCTestToken(_)))))
)
}
diff --git
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
index 86f7ad3..3cb0f35 100644
---
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
+++
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/NCEnrichersTestBeans.scala
@@ -28,135 +28,144 @@ import resource.managed
* Tests infrastructure beans.
*/
-sealed trait NCTestTokenKind {
+sealed trait NCTestToken {
def id: String
+ def origText: String
+ def isStop: Boolean = false
}
// Simplified set of tokens data. Added only fields for validation.
// Server enrichers.
-case class NCTestNlpToken() extends NCTestTokenKind {
+case class NCTestNlpToken(origText: String, override val isStop: Boolean)
extends NCTestToken {
override def id: String = "nlpcraft:nlp"
}
// Skip non-deteministric properties verification.
-case class NCTestDateToken() extends NCTestTokenKind {
+case class NCTestDateToken(origText: String) extends NCTestToken {
override def id: String = "nlpcraft:date"
}
-case class NCTestCoordinateToken(latitude: Double, longitude: Double) extends
NCTestTokenKind {
+case class NCTestCoordinateToken(origText: String, latitude: Double,
longitude: Double) extends NCTestToken {
override def id: String = "nlpcraft:coordinate"
}
-case class NCTestNumericToken(from: Double, to: Double) extends
NCTestTokenKind {
+case class NCTestNumericToken(origText: String, from: Double, to: Double)
extends NCTestToken {
override def id: String = "nlpcraft:num"
}
-case class NCTestCityToken(city: String) extends NCTestTokenKind {
+case class NCTestCityToken(origText: String, city: String) extends NCTestToken
{
override def id: String = "nlpcraft:city"
}
-case class NCTestCountryToken(country: String) extends NCTestTokenKind {
+case class NCTestCountryToken(origText: String, country: String) extends
NCTestToken {
override def id: String = "nlpcraft:country"
}
-case class NCTestRegionToken(region: String) extends NCTestTokenKind {
+case class NCTestRegionToken(origText: String, region: String) extends
NCTestToken {
override def id: String = "nlpcraft:region"
}
-case class NCTestContinentToken(continent: String) extends NCTestTokenKind {
+case class NCTestContinentToken(origText: String, continent: String) extends
NCTestToken {
override def id: String = "nlpcraft:continent"
}
-case class NCTestSubcontinentToken(city: String) extends NCTestTokenKind {
+case class NCTestSubcontinentToken(origText: String, city: String) extends
NCTestToken {
override def id: String = "nlpcraft:subcontinent"
}
-case class NCTestMetroToken(metro: String) extends NCTestTokenKind {
+case class NCTestMetroToken(origText: String, metro: String) extends
NCTestToken {
override def id: String = "nlpcraft:metro"
}
// Probe enrichers.
case class NCTestSortToken(
+ origText: String,
asc: Option[Boolean],
subjNotes: Seq[String],
subjIndexes: Seq[Int],
byNotes: Option[Seq[String]],
byIndexes: Option[Seq[Int]]
-) extends NCTestTokenKind {
+) extends NCTestToken {
override def id: String = "nlpcraft:sort"
}
-case class NCTestRelationToken(`type`: String, indexes: Seq[Int], note:
String) extends NCTestTokenKind {
+case class NCTestRelationToken(origText: String, `type`: String, indexes:
Seq[Int], note: String) extends NCTestToken {
override def id: String = "nlpcraft:relation"
}
-case class NCTestAggregationToken(`type`: String, indexes: Seq[Int], note:
String) extends NCTestTokenKind {
+case class NCTestAggregationToken(origText: String, `type`: String, indexes:
Seq[Int], note: String) extends NCTestToken {
override def id: String = "nlpcraft:aggregation"
}
-case class NCTestLimitToken(limit: Double, indexes: Seq[Int], note: String,
asc: Option[Boolean]) extends NCTestTokenKind {
+case class NCTestLimitToken(origText: String, limit: Double, indexes:
Seq[Int], note: String, asc: Option[Boolean]) extends NCTestToken {
override def id: String = "nlpcraft:limit"
}
+case class NCTestUserToken(origText: String, id: String) extends NCTestToken
+
// Token and sentence beans and utilities.
-case class NCTestToken(origText: String, isStop: Boolean, token:
NCTestTokenKind)
object NCTestToken {
def apply(t: NCToken): NCTestToken = {
- val note: NCTestTokenKind =
- t.getId match {
- case "nlpcraft:nlp" ⇒ NCTestNlpToken()
- case "nlpcraft:coordinate" ⇒
- NCTestCoordinateToken(latitude = t.meta("latitude"),
longitude = t.meta("longitude"))
- case "nlpcraft:num" ⇒ NCTestNumericToken(from =
t.meta("from"), to = t.meta("to"))
- case "nlpcraft:date" ⇒ NCTestDateToken()
- case "nlpcraft:city" ⇒ NCTestCityToken(city = t.meta("city"))
- case "nlpcraft:region" ⇒ NCTestRegionToken(region =
t.meta("region"))
- case "nlpcraft:country" ⇒ NCTestCountryToken(country =
t.meta("country"))
- case "nlpcraft:subcontinent" ⇒ NCTestSubcontinentToken(city =
t.meta("subcontinent"))
- case "nlpcraft:continent" ⇒ NCTestContinentToken(continent =
t.meta("continent"))
- case "nlpcraft:metro" ⇒ NCTestMetroToken(metro =
t.meta("metro"))
-
- case "nlpcraft:sort" ⇒
- NCTestSortToken(
- asc = t.meta("asc"),
- subjNotes = t.meta("subjnotes"),
- subjIndexes = t.meta("subjindexes"),
- byNotes = t.meta("bynotes"),
- byIndexes = t.meta("byindexes")
- )
- case "nlpcraft:relation" ⇒
- NCTestRelationToken(
- `type` = t.meta("type"),
- indexes = t.meta("indexes"),
- note = t.meta("note")
- )
- case "nlpcraft:aggregation" ⇒
- NCTestAggregationToken(
- `type` = t.meta("type"),
- indexes = t.meta("indexes"),
- note = t.meta("note")
- )
-
- case "nlpcraft:limit" ⇒
- NCTestLimitToken(
- limit = t.meta("limit"),
- asc = t.meta("asc"),
- indexes = t.meta("indexes"),
- note = t.meta("note")
- )
-
- case _ ⇒ throw new AssertionError(s"Unsupported token:
${t.getId}")
- }
-
- NCTestToken(t.getOriginalText, t.isStopWord, note)
+ val txt = t.getOriginalText
+
+ t.getId match {
+ case "nlpcraft:nlp" ⇒ NCTestNlpToken(txt, t.isStopWord)
+ case "nlpcraft:coordinate" ⇒
+ NCTestCoordinateToken(txt, latitude = t.meta("latitude"),
longitude = t.meta("longitude"))
+ case "nlpcraft:num" ⇒ NCTestNumericToken(txt, from =
t.meta("from"), to = t.meta("to"))
+ case "nlpcraft:date" ⇒ NCTestDateToken(txt)
+ case "nlpcraft:city" ⇒ NCTestCityToken(txt, city = t.meta("city"))
+ case "nlpcraft:region" ⇒ NCTestRegionToken(txt, region =
t.meta("region"))
+ case "nlpcraft:country" ⇒ NCTestCountryToken(txt, country =
t.meta("country"))
+ case "nlpcraft:subcontinent" ⇒ NCTestSubcontinentToken(txt, city =
t.meta("subcontinent"))
+ case "nlpcraft:continent" ⇒ NCTestContinentToken(txt, continent =
t.meta("continent"))
+ case "nlpcraft:metro" ⇒ NCTestMetroToken(txt, metro =
t.meta("metro"))
+
+ case "nlpcraft:sort" ⇒
+ NCTestSortToken(
+ txt,
+ asc = t.meta("asc"),
+ subjNotes = t.meta("subjnotes"),
+ subjIndexes = t.meta("subjindexes"),
+ byNotes = t.meta("bynotes"),
+ byIndexes = t.meta("byindexes")
+ )
+ case "nlpcraft:relation" ⇒
+ NCTestRelationToken(
+ txt,
+ `type` = t.meta("type"),
+ indexes = t.meta("indexes"),
+ note = t.meta("note")
+ )
+ case "nlpcraft:aggregation" ⇒
+ NCTestAggregationToken(
+ txt,
+ `type` = t.meta("type"),
+ indexes = t.meta("indexes"),
+ note = t.meta("note")
+ )
+
+ case "nlpcraft:limit" ⇒
+ NCTestLimitToken(
+ txt,
+ limit = t.meta("limit"),
+ asc = t.meta("asc"),
+ indexes = t.meta("indexes"),
+ note = t.meta("note")
+ )
+
+ case _ ⇒ throw new AssertionError(s"Unsupported token: ${t.getId}")
+ }
}
- def apply(origText: String, isStop: Boolean): NCTestToken = new
NCTestToken(origText, isStop, NCTestNlpToken())
+ def apply(origText: String, isStop: Boolean): NCTestToken =
NCTestNlpToken(origText, isStop)
}
-case class NCTestSentence(tokens: Seq[NCTestToken])
+case class NCTestSentence(tokens: Seq[NCTestToken]) {
+ override def toString = s"Sentence: ${tokens.mkString(", ")}"
+}
object NCTestSentence {
def serialize(sens: Iterable[NCTestSentence]): String =
diff --git
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
index 9f23c76..3b65dff 100644
---
a/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
+++
b/src/test/scala/org/apache/nlpcraft/probe/mgrs/nlp/enrichers/limit/NCEnricherLimitSpec.scala
@@ -17,7 +17,7 @@
package org.apache.nlpcraft.probe.mgrs.nlp.enrichers.limit
-import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCEnricherBaseSpec,
NCTestLimitToken ⇒ LT, NCTestToken ⇒ T}
+import org.apache.nlpcraft.probe.mgrs.nlp.enrichers.{NCEnricherBaseSpec,
NCTestLimitToken, NCTestUserToken}
import org.junit.jupiter.api.Test
/**
@@ -31,8 +31,9 @@ class NCEnricherLimitSpec extends NCEnricherBaseSpec {
@Test
def test(): Unit = {
check(
- "sort a1 by b1",
- T(origText = "text", isStop = false, token = LT(1, Seq(1), "a",
Some(true)))
+ "top 5 A",
+ NCTestLimitToken("top 5", limit = 5, indexes = Seq(1), note = "A",
asc = Some(true)),
+ NCTestUserToken("A", "A")
)
}
}