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

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


The following commit(s) were added to refs/heads/master by this push:
     new 6338fae  WIP.
6338fae is described below

commit 6338faefc3687611581424f3c2d6e79efd504f01
Author: Aaron Radzinski <[email protected]>
AuthorDate: Sun Nov 29 11:50:53 2020 -0800

    WIP.
---
 data-model.html   | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/script.html |   8 ++-
 2 files changed, 158 insertions(+), 2 deletions(-)

diff --git a/data-model.html b/data-model.html
index 39ce295..04598a8 100644
--- a/data-model.html
+++ b/data-model.html
@@ -45,6 +45,158 @@ id: data_model
             You don't have to use additional web-based tools to manage some 
aspects of your
             data models - your entire model and all of its components are part 
of your project source code.
         </p>
+        <p>
+            Here's two quick examples of the fully-functional data model 
implementations (from <a href="/examples/light_switch.html">Light Switch</a> and
+            <a href="/examples/alarm_clock.html">Alarm Clock</a> examples):
+        </p>
+        <nav>
+            <div class="nav nav-tabs" role="tablist">
+                <a class="nav-item nav-link active" data-toggle="tab" 
href="#scala-model-ex" role="tab" aria-controls="nav-home" 
aria-selected="true">LightSwitchModel.scala</a>
+                <a class="nav-item nav-link" data-toggle="tab" 
href="#java-model-ex" role="tab" aria-controls="nav-home" 
aria-selected="true">AlarmModel.java</a>
+            </div>
+        </nav>
+        <div class="tab-content">
+            <div class="tab-pane fade show active" id="scala-model-ex" 
role="tabpanel">
+                <pre class="brush: java">
+package org.apache.nlpcraft.examples.lightswitch
+
+import org.apache.nlpcraft.model.{NCIntentTerm, _}
+
+class LightSwitchModel extends 
NCModelFileAdapter("org/apache/nlpcraft/examples/lightswitch/lightswitch_model.yaml")
 {
+    @NCIntentRef("ls")
+    @NCIntentSample(Array(
+        "Turn the lights off in the entire house.",
+        "Switch on the illumination in the master bedroom closet.",
+        "Get the lights on.",
+        "Lights up in the kitchen.",
+        "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.",
+        "Light up the garage, please!"
+    ))
+    def onMatch(
+        @NCIntentTerm("act") actTok: NCToken,
+        @NCIntentTerm("loc") locToks: List[NCToken]
+    ): NCResult = {
+        val status = if (actTok.getId == "ls:on") "on" else "off"
+        val locations =
+            if (locToks.isEmpty)
+                "entire house"
+            else
+                
locToks.map(_.meta[String]("nlpcraft:nlp:origtext")).mkString(", ")
+
+        // Add HomeKit, Arduino or other integration here.
+
+        // By default - just return a descriptive action string.
+        NCResult.text(s"Lights are [$status] in [${locations.toLowerCase}].")
+    }
+}
+                </pre>
+            </div>
+            <div class="tab-pane fade show" id="java-model-ex" role="tabpanel">
+                <pre class="brush: java">
+package org.apache.nlpcraft.examples.alarm;
+
+import org.apache.nlpcraft.model.*;
+import java.time.*;
+import java.time.format.*;
+import java.util.*;
+
+import static java.time.temporal.ChronoUnit.*;
+
+public class AlarmModel extends NCModelFileAdapter {
+    private static final DateTimeFormatter FMT =
+        DateTimeFormatter.ofPattern("HH'h' mm'm' 
ss's'").withZone(ZoneId.systemDefault());
+
+    private final Timer timer = new Timer();
+
+    public AlarmModel() {
+        // Loading the model from the file in the classpath.
+        super("org/apache/nlpcraft/examples/alarm/alarm_model.json");
+    }
+
+    @NCIntentRef("alarm")
+    @NCIntentSample({
+        "Ping me in 3 minutes",
+        "Buzz me in an hour and 15mins",
+        "Set my alarm for 30s"
+    })
+    NCResult onMatch(
+        NCIntentMatch ctx,
+        @NCIntentTerm("nums") List&lt;NCToken&gt; numToks
+    ) {
+        if (ctx.isAmbiguous())
+            throw new NCRejection("Not exact match.");
+
+        long unitsCnt = numToks.stream().map(tok -&gt; 
(String)tok.meta("num:unit")).distinct().count();
+
+        if (unitsCnt != numToks.size())
+            throw new NCRejection("Ambiguous time units.");
+
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime dt = now;
+
+        for (NCToken num : numToks) {
+            String unit = num.meta("nlpcraft:num:unit");
+
+            // Skip possible fractional to simplify.
+            long v = ((Double)num.meta("nlpcraft:num:from")).longValue();
+
+            if (v <= 0)
+                throw new NCRejection("Value must be positive: " + unit);
+
+            switch (unit) {
+                case "second": { dt = dt.plusSeconds(v); break; }
+                case "minute": { dt = dt.plusMinutes(v); break; }
+                case "hour": { dt = dt.plusHours(v); break; }
+                case "day": { dt = dt.plusDays(v); break; }
+                case "week": { dt = dt.plusWeeks(v); break; }
+                case "month": { dt = dt.plusMonths(v); break; }
+                case "year": { dt = dt.plusYears(v); break; }
+
+                default:
+                    // It shouldn't be assert, because 'datetime' unit can be 
extended.
+                    throw new NCRejection("Unsupported time unit: " + unit);
+            }
+        }
+
+        long ms = now.until(dt, MILLIS);
+
+        assert ms &gt;= 0;
+
+        timer.schedule(
+            new TimerTask() {
+                @Override
+                public void run() {
+                    System.out.println(
+                        "BEEP BEEP BEEP for: " + 
ctx.getContext().getRequest().getNormalizedText() + ""
+                    );
+                }
+            },
+            ms
+        );
+
+        return NCResult.text("Timer set for: " + FMT.format(dt));
+    }
+
+    @Override
+    public void onDiscard() {
+        // Clean up when model gets discarded (e.g. during testing).
+        timer.cancel();
+    }
+}
+                </pre>
+            </div>
+        </div>
+        <p>
+            Further sub-sections will provide details on model's static 
configuration and dynamic programmable
+            logic implementation.
+        </p>
     </section>
     <section id="dataflow">
         <h2 class="section-title">Model Dataflow</h2>
diff --git a/tools/script.html b/tools/script.html
index 3864066..c7d6d72 100644
--- a/tools/script.html
+++ b/tools/script.html
@@ -79,7 +79,7 @@ id: script
         </p>
         <h2 class="section-sub-title">Get Command List</h2>
         <p>
-            Type <code>help</code> to list of all supported commands (or run 
<code>bin/nlpcraft.sh help</code> if in command line mode):
+            Type <code>help</code> to list all supported commands (or run 
<code>bin/nlpcraft.sh help</code> if in command line mode):
         </p>
         <p>
             <img class="non-fluid-img" src="/images/cli2.png" alt="">
@@ -93,11 +93,15 @@ id: script
         </p>
         <p>
             Hit <span class="keyboard">Tab</span> key anytime for 
auto-suggestion and auto-completion for
-            commands and their parameters while in REPL mode:
+            commands and their parameters while in REPL mode, use <span 
class="keyboard">↑</span> and
+            <span class="keyboard">↓</span> keys to scroll through command 
history:
         </p>
         <p>
             <img class="non-fluid-img" alt="" src="/images/cli8.png">
         </p>
+        <p>
+            To exit <code>bin/nlpcraft.{sh|cmd}</code> script in REPL mode 
type <code>quit</code>.
+        </p>
     </section>
     <section id="os_commands">
         <h2 class="section-title">OS Commands</h2>

Reply via email to