You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by se...@apache.org on 2020/12/21 12:32:14 UTC

[incubator-nlpcraft] branch NLPCRAFT-204 created (now 75d96cd)

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

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


      at 75d96cd  WIP.

This branch includes the following new commits:

     new 75d96cd  WIP.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-nlpcraft] 01/01: WIP.

Posted by se...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 75d96cd889fbc1f4ab470b1c5c3847e01d76ac3c
Author: Sergey Kamov <se...@apache.org>
AuthorDate: Mon Dec 21 15:32:03 2020 +0300

    WIP.
---
 .../apache/nlpcraft/model/NCIntentDslSpec.scala    | 61 ++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala
new file mode 100644
index 0000000..19913b2
--- /dev/null
+++ b/nlpcraft/src/test/scala/org/apache/nlpcraft/model/NCIntentDslSpec.scala
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nlpcraft.model
+
+import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
+import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
+import org.junit.jupiter.api.Test
+
+import scala.language.implicitConversions
+
+/**
+  * Intents DSL test model.
+  */
+class NCIntentDslSpecModel extends NCModelAdapter(
+    "nlpcraft.intents.dsl.test", "Intents DSL Test Model", "1.0"
+) {
+    private implicit def convert(s: String): NCResult = NCResult.text(s)
+
+    // Moscow population filter.
+    @NCIntent("intent=bigCity term(city)~{id == 'nlpcraft:city' && ~nlpcraft:city:citymeta['population'] >= 10381222}")
+    private def onBigCity(ctx: NCIntentMatch): NCResult = "OK"
+
+    @NCIntent("intent=otherCity term(city)~{id == 'nlpcraft:city' }")
+    private def onOtherCity(ctx: NCIntentMatch): NCResult = "OK"
+}
+
+/**
+  * Intents DSL test.
+  */
+@NCTestEnvironment(model = classOf[NCIntentDslSpecModel], startClient = true)
+class NCIntentDslSpec extends NCTestContext {
+    private def check(txt: String, intent:  String): Unit = {
+        val res = getClient.ask(txt)
+
+        assertTrue(res.isOk, s"Checked: $txt")
+        assertTrue(res.getResult.isPresent, s"Checked: $txt")
+        assertEquals(intent, res.getIntentId, s"Checked: $txt")
+    }
+
+    @Test
+    def testBigCity(): Unit = check("Moscow", "bigCity")
+
+    @Test
+    def testOtherCity(): Unit = check("San Francisco", "otherCity")
+}
+