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

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

commit bfb80d31f558ff53ce3f38b03718fa2d6cde4b8a
Author: Sergey Kamov <[email protected]>
AuthorDate: Mon Nov 14 13:27:21 2022 +0400

    Intent trait API.
---
 .../org/apache/nlpcraft/nlp/test/TimeTestModel.scala   | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git 
a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/test/TimeTestModel.scala 
b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/test/TimeTestModel.scala
index dee4385e..7caa0108 100644
--- a/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/test/TimeTestModel.scala
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/nlp/test/TimeTestModel.scala
@@ -34,3 +34,21 @@ class TimeTestModel extends NCModel(
                 Option.when(cities.length == 1 && times.length == 1 && 
varEnts.forall(p => p.getId == "opennlp:location" || p.getId == 
"x:time"))(CityTimeData(cities.head.mkText))
             override def mkResult(mi: NCMatchInput, data: CityTimeData): 
NCResult = NCResult(s"Asked for ${data.city}") // TBI.
     )
+
+
+object NCAlternative:
+    // Event shorter. but we can't support debugAsk here.
+    trait NCIntentOneMethod(val id: String):
+        def execute(mi: NCMatchInput): Option[NCResult]
+
+    class NCIntentOneMethodImpl extends NCIntentOneMethod("id1"):
+        override def execute(mi: NCMatchInput): Option[NCResult] =
+            val varEnts = mi.getVariant4Match.getEntities
+            val allEnts = mi.getAllEntities
+
+            val cities = varEnts.filter(_.getId == "opennlp:location")
+            val times = allEnts.filter(_.getId == "x:time")
+
+            Option.when(cities.length == 1 && times.length == 1 && 
varEnts.forall(p => p.getId == "opennlp:location" || p.getId == 
"x:time"))(cities.head.mkText) match
+                case Some(city) => Option(NCResult(s"Asked for $city"))
+                case None => None

Reply via email to