You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nlpcraft.apache.org by ar...@apache.org on 2021/09/28 23:54:47 UTC
[incubator-nlpcraft] branch NLPCRAFT-384 updated: WIP on
NLPCRAFT-384
This is an automated email from the ASF dual-hosted git repository.
aradzinski pushed a commit to branch NLPCRAFT-384
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-384 by this push:
new 65fe9ca WIP on NLPCRAFT-384
65fe9ca is described below
commit 65fe9cab96918c04a591b271d866222c86e758a6
Author: Aaron Radzinski <ar...@datalingvo.com>
AuthorDate: Tue Sep 28 16:54:42 2021 -0700
WIP on NLPCRAFT-384
---
.../nlpcraft/examples/cargps/CarGpsModel.scala | 8 +++----
.../cargps/src/main/resources/cargps_intents.idl | 27 +++++++++++++++++-----
.../cargps/src/main/resources/cargps_model.yaml | 17 +++++++++-----
.../resources/samples/cargps_cancel_samples.txt | 10 ++++----
.../resources/samples/cargps_navigate_samples.txt | 2 ++
.../samples/cargps_remove_waypoint_samples.txt | 2 ++
.../examples/cargps/NCCarGpsModelSpec.scala | 20 ++++++++++++++--
.../probe/mgrs/nlp/NCProbeEnrichmentManager.scala | 1 +
.../nlpcraft/server/query/NCQueryManager.scala | 1 +
9 files changed, 65 insertions(+), 23 deletions(-)
diff --git a/nlpcraft-examples/cargps/src/main/java/org/apache/nlpcraft/examples/cargps/CarGpsModel.scala b/nlpcraft-examples/cargps/src/main/java/org/apache/nlpcraft/examples/cargps/CarGpsModel.scala
index 9b6cf41..2e79a2b 100644
--- a/nlpcraft-examples/cargps/src/main/java/org/apache/nlpcraft/examples/cargps/CarGpsModel.scala
+++ b/nlpcraft-examples/cargps/src/main/java/org/apache/nlpcraft/examples/cargps/CarGpsModel.scala
@@ -27,7 +27,7 @@ class CarGpsModel extends NCModelFileAdapter("cargps_model.yaml") {
*
* @return
*/
- @NCIntentRef("int:navigate")
+ @NCIntentRef("navigate")
@NCIntentSampleRef("samples/cargps_navigate_samples.txt")
def onNavigation(): NCResult = {
NCResult.text(s"")
@@ -37,7 +37,7 @@ class CarGpsModel extends NCModelFileAdapter("cargps_model.yaml") {
*
* @return
*/
- @NCIntentRef("int:cancel")
+ @NCIntentRef("cancel")
@NCIntentSampleRef("samples/cargps_cancel_samples.txt")
def onCancel(): NCResult = {
NCResult.text(s"")
@@ -47,7 +47,7 @@ class CarGpsModel extends NCModelFileAdapter("cargps_model.yaml") {
*
* @return
*/
- @NCIntentRef("int:add:waypoint")
+ @NCIntentRef("add:waypoint")
@NCIntentSampleRef("samples/cargps_add_waypoint_samples.txt")
def onAddWaypoint(): NCResult = {
NCResult.text(s"")
@@ -57,7 +57,7 @@ class CarGpsModel extends NCModelFileAdapter("cargps_model.yaml") {
*
* @return
*/
- @NCIntentRef("int:remove:waypoint")
+ @NCIntentRef("remove:waypoint")
@NCIntentSampleRef("samples/cargps_remove_waypoint_samples.txt")
def onRemoveWaypoint(): NCResult = {
NCResult.text(s"")
diff --git a/nlpcraft-examples/cargps/src/main/resources/cargps_intents.idl b/nlpcraft-examples/cargps/src/main/resources/cargps_intents.idl
index e90b7b5..b0608bf 100644
--- a/nlpcraft-examples/cargps/src/main/resources/cargps_intents.idl
+++ b/nlpcraft-examples/cargps/src/main/resources/cargps_intents.idl
@@ -22,13 +22,28 @@
// Reusable fragments.
fragment=hey term={# == "x:hey" && tok_is_first()}
-// Intents.
-intent=int:cancel
+// Cancel intent.
+intent=cancel
// Ignore any other user or system tokens if we found 'cancel' token.
options={'unused_usr_toks': true, 'unused_sys_toks': true}
- fragment(hey)
+ fragment(hey) // Always, salutation 1st.
term={# == "x:cancel"}
-intent=int:navigate options={'ordered': true} fragment(hey) term={# == "x:navigate"} term={# == "x:addr"}
-intent=int:add:waypoint fragment(hey) term={# == "x:add-waypoint"}
-intent=int:remove:waypoint fragment(hey) term={# == "x:remove-waypoint"}
\ No newline at end of file
+// Navigate intent.
+intent=navigate
+ options={'ordered': true} // Order of terms is important.
+ fragment(hey) // Always, salutation 1st.
+ term={# == "x:navigate"} // Then word 'navigate'.
+ term={# == "x:addr"} // Then where to navigate.
+
+// Add a waypoint intent.
+intent=add:waypoint
+ fragment(hey) // Always, salutation 1st.
+ term={# == "x:add-waypoint"}
+ term={# == "x:addr"}
+
+// Remove a waypoint intent.
+// Assumes last waypoint.
+intent=remove:waypoint
+ fragment(hey) // Always, salutation 1st.
+ term={# == "x:remove-waypoint"}
\ No newline at end of file
diff --git a/nlpcraft-examples/cargps/src/main/resources/cargps_model.yaml b/nlpcraft-examples/cargps/src/main/resources/cargps_model.yaml
index 62f45c8..d443d69 100644
--- a/nlpcraft-examples/cargps/src/main/resources/cargps_model.yaml
+++ b/nlpcraft-examples/cargps/src/main/resources/cargps_model.yaml
@@ -33,11 +33,14 @@ macros:
- name: "<CANCEL>"
macro: "{cancel|stop|abort|finish|cease|quit} {off|_}"
- name: "<WAYPOINT>"
- macro: "{waypoint|location|point|stopover|stop over|way station|stop|checkpoint|stop point} {point|station|_}"
+ macro: "{waypoint|stopover|stop over|way station|stop|checkpoint|stop point} {point|station|_}"
+# Make sure 'howdy' is not marked as a stopword.
excludedStopWords:
- howdy
+# Don't surface these tokens as standalone one. They are used only
+# as building blocks for other tokens.
abstractTokens:
- x:addr:kind
- x:addr:num
@@ -53,24 +56,25 @@ elements:
- "{street|drive|court|plaza|avenue|alley|anex|beach|bend|boulevard|bridge|canyon|causeway|way|circle|corner|creek|fork|harbor|highway|expressway|island|lane|lake|loop|motorway|park|path|point|ramp|route|rue|row|skyway|square|station|summit|trail|tunnel|walk|road}"
- "{st|str|dr|crt|plz|ave|blvd|hwy|rd}"
+ # Street number.
- id: "x:addr:num"
synonyms:
+ # Straight number.
- "^^{# == 'nlpcraft:num' && meta_tok('nlpcraft:num:unit') == null && meta_tok('nlpcraft:num:isequalcondition')}^^"
+ # Street name.
- id: "x:addr:st"
greedy: false
synonyms:
+ # Alphanumeric and must be after street number and before street kind.
- "{^^{is_alphanum(tok_txt) && tok_is_between_ids('x:addr:num', 'x:addr:kind') == true}^^}[1,3]"
- id: "x:addr"
synonyms:
- "^^[num]{# == 'x:addr:num'}^^ ^^[name]{# == 'x:addr:st'}^^ ^^[kind]{# == 'x:addr:kind'}^^"
- #
- # Salutation.
- # -----------
- id: "x:hey"
- description: "NLI prompt"
+ description: "NLI prompt, salutation."
synonyms:
- "<HEY> {car|vehicle|truck}"
@@ -91,8 +95,9 @@ elements:
- "stop by"
- id: "x:remove-waypoint"
- description: "Remove 'waypoint' action."
+ description: "Remove last 'waypoint' action."
synonyms:
+ # NOTE: assumes the LAST waypoint, if any.
- "{skip|remove} {over|_} {last|latest|current|_} <WAYPOINT>"
- "<NAVIGATE> without {stopping|<WAYPOINT>}"
diff --git a/nlpcraft-examples/cargps/src/main/resources/samples/cargps_cancel_samples.txt b/nlpcraft-examples/cargps/src/main/resources/samples/cargps_cancel_samples.txt
index 0e4cb3d..c6b132d 100644
--- a/nlpcraft-examples/cargps/src/main/resources/samples/cargps_cancel_samples.txt
+++ b/nlpcraft-examples/cargps/src/main/resources/samples/cargps_cancel_samples.txt
@@ -19,10 +19,10 @@
# Set of samples (corpus) for automatic unit and regression testing.
#
-#Hey truck - stop the navigation!
+Hey truck - stop the navigation!
Howdy, car, please cancel the routing now.
-#Hi car - stop the route.
-#Hi car - stop the navigation...
+Hi car - stop the route.
+Hi car - stop the navigation...
Howdy truck - quit navigating.
-#Hi car - finish off the driving.
-#Hi car - cancel the journey.
\ No newline at end of file
+Hi car - finish off the driving.
+Hi car - cancel the journey.
\ No newline at end of file
diff --git a/nlpcraft-examples/cargps/src/main/resources/samples/cargps_navigate_samples.txt b/nlpcraft-examples/cargps/src/main/resources/samples/cargps_navigate_samples.txt
index 029340e..24aab32 100644
--- a/nlpcraft-examples/cargps/src/main/resources/samples/cargps_navigate_samples.txt
+++ b/nlpcraft-examples/cargps/src/main/resources/samples/cargps_navigate_samples.txt
@@ -19,3 +19,5 @@
# Set of samples (corpus) for automatic unit and regression testing.
#
hey car, navigate to 21 table rock drive
+howdy, truck - drive to 2121 5th avenue please
+hey truck, drive to 21 x x drive
diff --git a/nlpcraft-examples/cargps/src/main/resources/samples/cargps_remove_waypoint_samples.txt b/nlpcraft-examples/cargps/src/main/resources/samples/cargps_remove_waypoint_samples.txt
index 4c3f520..de31ca0 100644
--- a/nlpcraft-examples/cargps/src/main/resources/samples/cargps_remove_waypoint_samples.txt
+++ b/nlpcraft-examples/cargps/src/main/resources/samples/cargps_remove_waypoint_samples.txt
@@ -18,4 +18,6 @@
#
# Set of samples (corpus) for automatic unit and regression testing.
#
+hey truck, cancel the last waypoint
+hey truck, cancel the stopover location
diff --git a/nlpcraft-examples/cargps/src/test/java/org/apache/nlpcraft/examples/cargps/NCCarGpsModelSpec.scala b/nlpcraft-examples/cargps/src/test/java/org/apache/nlpcraft/examples/cargps/NCCarGpsModelSpec.scala
index f7f5ca1..a3092ae 100644
--- a/nlpcraft-examples/cargps/src/test/java/org/apache/nlpcraft/examples/cargps/NCCarGpsModelSpec.scala
+++ b/nlpcraft-examples/cargps/src/test/java/org/apache/nlpcraft/examples/cargps/NCCarGpsModelSpec.scala
@@ -20,10 +20,26 @@ package org.apache.nlpcraft.examples.cargps
import org.apache.nlpcraft.{NCTestContext, NCTestEnvironment}
import org.junit.jupiter.api.Test
+/**
+ *
+ */
@NCTestEnvironment(model = classOf[CarGpsModel], startClient = true)
class NCCarGpsModelSpec extends NCTestContext {
@Test
- def test(): Unit = {
- checkIntent("hey truck, drive to 21 x x drive", "int:navigate")
+ def testNavigate(): Unit = {
+ checkIntent("hey truck, drive to 21 x x drive", "navigate")
+ checkIntent("hey car, navigate to 21 table rock drive", "navigate")
+ checkIntent("howdy, truck - drive to 2121 5th avenue please", "navigate")
+ }
+
+ @Test
+ def testCancel(): Unit = {
+ checkIntent("Hey truck - stop the navigation!", "cancel")
+ checkIntent("Howdy, car, please cancel the routing now.", "cancel")
+ checkIntent("Hi car - stop the route.", "cancel")
+ checkIntent("Hi car - stop the navigation...", "cancel")
+ checkIntent("Howdy truck - quit navigating.", "cancel")
+ checkIntent("Hi car - finish off the driving.", "cancel")
+ checkIntent("Hi car - cancel the journey.", "cancel")
}
}
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
index fde865f..2fce8df 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/probe/mgrs/nlp/NCProbeEnrichmentManager.scala
@@ -234,6 +234,7 @@ object NCProbeEnrichmentManager extends NCService with NCOpenCensusModelStats {
val tbl = NCAsciiTable()
tbl += (s"${b("Text")}", nlpSens.map(s => bo(s.text)))
+ tbl += ("", bo("-") * nlpSens.maxBy(_.text.length).text.length)
tbl += (s"${b("Model ID")}", mdlId)
tbl += (s"${b("User:")}", "")
tbl += (s"${b(" ID")}", usrId)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala
index 60c3d41..dd92ef8 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/server/query/NCQueryManager.scala
@@ -263,6 +263,7 @@ object NCQueryManager extends NCService with NCIgniteInstance with NCOpenCensusS
val tbl = NCAsciiTable()
tbl += (s"${b("Text")}", bo(txt0))
+ tbl += ("", bo("-") * txt0.length)
tbl += (s"${b("User ID")}", usr.id)
tbl += (s"${b("Model ID")}", mdlId)
tbl += (s"${b("Agent")}", usrAgent.getOrElse("<n/a>"))