This is an automated email from the ASF dual-hosted git repository. aradzinski pushed a commit to branch NLPCRAFT-359 in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
commit 3ab290d948918f00978cf166b2722d3a649958a7 Author: Aaron Radzinski <[email protected]> AuthorDate: Thu Jul 8 11:43:53 2021 -0700 WIP on NLPCRAFT-359 --- .../apache/nlpcraft/examples/alarm/AlarmModel.java | 10 ++++---- .../alarm/src/main/resources/alarm_samples.txt | 6 ++++- .../alarm/src/main/resources/intents.idl | 6 ++--- .../org/apache/nlpcraft/model/NCIntentSample.java | 27 +++++++++++++--------- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/nlpcraft-examples/alarm/src/main/java/org/apache/nlpcraft/examples/alarm/AlarmModel.java b/nlpcraft-examples/alarm/src/main/java/org/apache/nlpcraft/examples/alarm/AlarmModel.java index ed4b11d..2ff018a 100644 --- a/nlpcraft-examples/alarm/src/main/java/org/apache/nlpcraft/examples/alarm/AlarmModel.java +++ b/nlpcraft-examples/alarm/src/main/java/org/apache/nlpcraft/examples/alarm/AlarmModel.java @@ -41,7 +41,7 @@ public class AlarmModel extends NCModelFileAdapter { private final Timer timer = new Timer(); public AlarmModel() { - // Loading the model from the file in the classpath. + // Loading the model from the file. super("alarm_model.json"); } @@ -51,8 +51,8 @@ public class AlarmModel extends NCModelFileAdapter { * @param ctx Intent solver context. * @return Query result. */ - @NCIntentRef("alarm") - @NCIntentSampleRef("alarm_samples.txt") + @NCIntentRef("alarm") // Intent is defined in JSON model file (alarm_model.json and intents.idl). + @NCIntentSampleRef("alarm_samples.txt") // Samples supplied in an external file. NCResult onMatch( NCIntentMatch ctx, @NCIntentTerm("nums") List<NCToken> numToks @@ -72,7 +72,7 @@ public class AlarmModel extends NCModelFileAdapter { for (NCToken num : numToks) { String unit = num.meta("nlpcraft:num:unit"); - // Skip possible fractional to simplify. + // Skip possible fractionals to simplify. long v = ((Double)num.meta("nlpcraft:num:from")).longValue(); if (v <= 0) @@ -88,7 +88,7 @@ public class AlarmModel extends NCModelFileAdapter { case "year": { dt = dt.plusYears(v); break; } default: - // It shouldn't be assert, because 'datetime' unit can be extended. + // It shouldn't be an assert, because 'datetime' unit can be extended. throw new NCRejection("Unsupported time unit: " + unit); } } diff --git a/nlpcraft-examples/alarm/src/main/resources/alarm_samples.txt b/nlpcraft-examples/alarm/src/main/resources/alarm_samples.txt index d17c1a8..599387c 100644 --- a/nlpcraft-examples/alarm/src/main/resources/alarm_samples.txt +++ b/nlpcraft-examples/alarm/src/main/resources/alarm_samples.txt @@ -15,7 +15,11 @@ # limitations under the License. # +# +# Set of samples (corpus) for automatic unit and regression testing. +# + Ping me in 3 minutes Buzz me in an hour and 15mins Set my alarm for 30s -Wake me up in twenty five minutes \ No newline at end of file +Please, wake me up in twenty five minutes! \ No newline at end of file diff --git a/nlpcraft-examples/alarm/src/main/resources/intents.idl b/nlpcraft-examples/alarm/src/main/resources/intents.idl index 7d9ab7e..bae42ae 100644 --- a/nlpcraft-examples/alarm/src/main/resources/intents.idl +++ b/nlpcraft-examples/alarm/src/main/resources/intents.idl @@ -19,14 +19,14 @@ fragment=buzz term~{tok_id() == 'x:alarm'} fragment=when term(nums)~{ - // Demonstrating term variable. + // Demonstrating term variables. @type = meta_tok('nlpcraft:num:unittype') - @iseq = meta_tok('nlpcraft:num:isequalcondition') + @iseq = meta_tok('nlpcraft:num:isequalcondition') // Excludes conditional statements. tok_id() == 'nlpcraft:num' && @type == 'datetime' && @iseq == true }[0,7] -// Intents +// Intents (using fragments). intent=alarm fragment(buzz) fragment(when) \ No newline at end of file diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentSample.java b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentSample.java index ec09899..c3b0199 100644 --- a/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentSample.java +++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/model/NCIntentSample.java @@ -24,11 +24,22 @@ import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.*; /** - * Annotation to define one or more samples 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 + * Annotation to define one or more samples (a corpus) of the user input that should match a corresponding intent. This + * annotation should be used together with {@link NCIntent} or {@link NCIntentRef} annotations on the callback * methods. Method can have multiple annotations of this type and each annotation can define multiple input - * examples. + * examples. See similar {@link NCIntentSampleRef} annotation that allows to load samples from external resources like + * file or URL. * <p> + * The corpus of intent samples serve several important roles in NLPCraft: + * <ul> + * <li> + * + * </li> + * </ul> + * + * + * + * * Note that the samples provided by this annotation not only serve the documentation purpose but are also * used by {@link NCTestAutoModelValidator} class from built-in test framework for auto-validation between * data models and intents. @@ -40,14 +51,7 @@ import static java.lang.annotation.RetentionPolicy.*; * "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." + * "Please, put the light out in the upstairs bedroom." * )) * def onMatch( * {@literal @}NCIntentTerm("act") actTok: NCToken, @@ -60,6 +64,7 @@ import static java.lang.annotation.RetentionPolicy.*; * 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-examples">examples</a>. * + * @see NCIntentSampleRef * @see NCIntent * @see NCIntentRef * @see NCIntentTerm
