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 2020/06/14 07:16:43 UTC

[incubator-nlpcraft] branch NLPCRAFT-80 created (now f3666c9)

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

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


      at f3666c9  WIP.

This branch includes the following new commits:

     new f3666c9  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 ar...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f3666c930b7d1186090e5f99104841e20f80c75d
Author: Aaron Radzinzski <ar...@datalingvo.com>
AuthorDate: Sun Jun 14 00:16:20 2020 -0700

    WIP.
---
 .../apache/nlpcraft/examples/alarm/AlarmModel.java | 17 +++++-----
 .../examples/lightswitch/LightSwitchModel.scala    | 13 ++++++++
 .../apache/nlpcraft/examples/phone/PhoneModel.java | 15 ++++++---
 .../apache/nlpcraft/examples/time/TimeModel.java   | 39 ++++++++++++----------
 .../nlpcraft/examples/weather/WeatherModel.java    |  9 +++++
 .../org/apache/nlpcraft/model/NCIntentExample.java | 11 ++++--
 6 files changed, 71 insertions(+), 33 deletions(-)

diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/AlarmModel.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/AlarmModel.java
index 2182df7..2eb26a4 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/AlarmModel.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/alarm/AlarmModel.java
@@ -18,15 +18,11 @@
 package org.apache.nlpcraft.examples.alarm;
 
 import org.apache.nlpcraft.model.*;
+import java.time.*;
+import java.time.format.*;
+import java.util.*;
 
-import java.time.LocalDateTime;
-import java.time.ZoneId;
-import java.time.format.DateTimeFormatter;
-import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
-
-import static java.time.temporal.ChronoUnit.MILLIS;
+import static java.time.temporal.ChronoUnit.*;
 
 /**
  * Alarm example data model.
@@ -58,6 +54,11 @@ public class AlarmModel extends NCModelFileAdapter {
      * @return Query result.
      */
     @NCIntentRef("alarm")
+    @NCIntentExample({
+        "Ping me in 3 minutes",
+        "Buzz me in an hour and 15mins",
+        "Set my alarm for 30s"
+    })
     private NCResult onMatch(
         NCIntentMatch ctx,
         @NCIntentTerm("nums") List<NCToken> numToks
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
index 5f001e3..8cd5512 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchModel.scala
@@ -40,6 +40,19 @@ class LightSwitchModel extends NCModelFileAdapter("org/apache/nlpcraft/examples/
       * @return Query result to be sent to the REST caller.
       */
     @NCIntentRef("ls")
+    @NCIntentExample(Array(
+        "Turn the lights off in the entire house.",
+        "Switch on the illumination in the master bedroom closet.",
+        "Get the lights on.",
+        "Please, put the light out in the upstairs bedroom.",
+        "Set the lights on in the entire house.",
+        "Turn the lights off in the guest bedroom.",
+        "Could you please switch off all the lights?",
+        "Dial off illumination on the 2nd floor.",
+        "Please, no lights!",
+        "Kill off all the lights now!",
+        "No lights in the bedroom, please."
+    ))
     def onMatch(
         @NCIntentTerm("act") actTok: NCToken,
         @NCIntentTerm("loc") locToks: List[NCToken]
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/phone/PhoneModel.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/phone/PhoneModel.java
index 6ca8d26..1aad7c0 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/phone/PhoneModel.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/phone/PhoneModel.java
@@ -18,9 +18,8 @@
 package org.apache.nlpcraft.examples.phone;
 
 import org.apache.nlpcraft.model.*;
-
-import java.util.List;
-import java.util.stream.Collectors;
+import java.util.*;
+import java.util.stream.*;
 
 
 /**
@@ -59,7 +58,15 @@ public class PhoneModel extends NCModelFileAdapter {
         // Either organization, person or a phone number (or a combination of).
         "term(rcpt)={id == 'google:organization' || id == 'google:person' || id == 'google:phone_number'}[1,3]"
     )
-    NCResult onMatch(NCIntentMatch ctx, @NCIntentTerm("rcpt") List<NCToken> rcptToks) {
+    @NCIntentExample({
+        "Call to Apple office",
+        "Can you please ping John Smith?",
+        "Could you dial +7 (931) 188 34 58 and ask Mike?"
+    })
+    NCResult onMatch(
+        NCIntentMatch ctx,
+        @NCIntentTerm("rcpt") List<NCToken> rcptToks
+    ) {
         String rcpt = rcptToks.stream().map(tok -> {
             String txt = tok.meta("nlpcraft:nlp:origtext");
 
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java
index e6d7e2e..872640f 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/time/TimeModel.java
@@ -17,26 +17,20 @@
 
 package org.apache.nlpcraft.examples.time;
 
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
-import org.apache.commons.text.WordUtils;
-import org.apache.nlpcraft.common.NCException;
-import org.apache.nlpcraft.examples.misc.geo.cities.CitiesDataProvider;
-import org.apache.nlpcraft.examples.misc.geo.cities.City;
-import org.apache.nlpcraft.examples.misc.geo.cities.CityData;
-import org.apache.nlpcraft.examples.misc.geo.keycdn.GeoManager;
-import org.apache.nlpcraft.examples.misc.geo.keycdn.beans.GeoDataBean;
+import com.fasterxml.jackson.core.*;
+import com.fasterxml.jackson.databind.*;
+import com.fasterxml.jackson.dataformat.yaml.*;
+import org.apache.commons.text.*;
+import org.apache.nlpcraft.common.*;
+import org.apache.nlpcraft.examples.misc.geo.cities.*;
+import org.apache.nlpcraft.examples.misc.geo.keycdn.*;
+import org.apache.nlpcraft.examples.misc.geo.keycdn.beans.*;
 import org.apache.nlpcraft.model.*;
+import java.time.*;
+import java.time.format.*;
+import java.util.*;
 
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
-import static java.time.format.FormatStyle.MEDIUM;
+import static java.time.format.FormatStyle.*;
 
 /**
  * Time example data model.
@@ -101,6 +95,9 @@ public class TimeModel extends NCModelFileAdapter {
      * @return Query result.
      */
     @NCIntent("intent=intent1 conv=false term={id=='x:time'}")
+    @NCIntentExample({
+        "What's the local time?"
+    })
     private NCResult onLocalMatch(NCIntentMatch ctx) {
         // NOTE:
         // We need to have two intents vs. one intent with an optional GEO. The reason is that
@@ -132,6 +129,12 @@ public class TimeModel extends NCModelFileAdapter {
      * @return Query result.
      */
     @NCIntent("intent=intent2 term={id=='x:time'} term(city)={id=='nlpcraft:city'}")
+    @NCIntentExample({
+        "What time is it now in New York City?",
+        "What's the current time in Moscow?",
+        "Show me time of the day in London.",
+        "Can you please give me the San Francisco's current date and time.",
+    })
     private NCResult onRemoteMatch(@NCIntentTerm("city") NCToken cityTok) {
         String city = cityTok.meta("nlpcraft:city:city");
         String cntry = cityTok.meta("nlpcraft:city:country");
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java
index 2d56039..86657c0 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/weather/WeatherModel.java
@@ -221,6 +221,9 @@ public class WeatherModel extends NCModelFileAdapter {
      * @return Query result.
      */
     @NCIntent("intent=fcast term={id == 'wt:fcast'} term(city)={id == 'nlpcraft:city'}? term(date)={id == 'nlpcraft:date'}?")
+    @NCIntentExample({
+        "What's the weather forecast in Moscow?"
+    })
     public NCResult onForecastMatch(
         NCIntentMatch ctx,
         @NCIntentTerm("city") Optional<NCToken> cityTokOpt,
@@ -236,6 +239,9 @@ public class WeatherModel extends NCModelFileAdapter {
      * @return Query result.
      */
     @NCIntent("intent=hist term={id == 'wt:hist'} term(city)={id == 'nlpcraft:city'}? term(date)={id == 'nlpcraft:date'}?")
+    @NCIntentExample({
+        "What was the weather history in Moscow?"
+    })
     public NCResult onHistoryMatch(
         NCIntentMatch ctx,
         @NCIntentTerm("city") Optional<NCToken> cityTokOpt,
@@ -251,6 +257,9 @@ public class WeatherModel extends NCModelFileAdapter {
      * @return Query result.
      */
     @NCIntent("intent=curr term={id == 'wt:curr'} term(city)={id == 'nlpcraft:city'}? term(date)={id == 'nlpcraft:date'}?")
+    @NCIntentExample({
+        "What's the current weather in Moscow"
+    })
     public NCResult onCurrentMatch(
         NCIntentMatch ctx,
         @NCIntentTerm("city") Optional<NCToken> cityTokOpt,
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentExample.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentExample.java
index db54388..4c2f149 100644
--- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentExample.java
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentExample.java
@@ -25,12 +25,12 @@ import static java.lang.annotation.RetentionPolicy.*;
 /**
  * Annotation to define one or more examples of the user input that should match a corresponding intent. This
  * annotation can only be used together with {@link NCIntent} or {@link NCIntentRef} annotations on the callback
- * methods.
+ * methods. Method can have multiple annotations of this type and each annotation can define multiple input
+ * examples.
  * <p>
  * Note that the examples provided by this annotation not only serve the documentation purpose but are also
  * used internally by various parts of NLPCraft for uint testing, synonym detection, etc. It is highly
- * advised to provide multiple examples per each intent either through this annotation of in external model
- * declaration.
+ * advisable to provide multiple examples (the more the better) per each intent through this annotation.
  * <p>
  * Read full documentation in <a target=_ href="https://nlpcraft.apache.org/intent-matching.html">Intent Matching</a> section and review
  * <a target=_ href="https://github.com/apache/incubator-nlpcraft/tree/master/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/">examples</a>.
@@ -46,5 +46,10 @@ import static java.lang.annotation.RetentionPolicy.*;
 @Retention(value=RUNTIME)
 @Target(value=METHOD)
 public @interface NCIntentExample {
+    /**
+     * Gets set of user input examples that should match corresponding intent.
+     *
+     * @return Set of user input examples that should match corresponding intent.
+     */
     String[] value();
 }