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/01/22 21:30:48 UTC
[incubator-nlpcraft] branch master updated: NLPCRAFT-92: Create
Groovy-based example for NLPCraft.
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.git
The following commit(s) were added to refs/heads/master by this push:
new 853d91a NLPCRAFT-92: Create Groovy-based example for NLPCraft.
new dc9a5bf Merge pull request #11 from paulk-asert/nlpcraft92
853d91a is described below
commit 853d91a30a95b4c81c920b02149ee48140a1a81c
Author: Paul King <pa...@asert.com.au>
AuthorDate: Tue Jan 19 15:36:53 2021 +1000
NLPCRAFT-92: Create Groovy-based example for NLPCraft.
---
.../lightswitch/LightSwitchGroovyModel.groovy | 75 ++++++++++++++++++++++
pom.xml | 35 ++++++++++
2 files changed, 110 insertions(+)
diff --git a/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchGroovyModel.groovy b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchGroovyModel.groovy
new file mode 100644
index 0000000..4d1aff9
--- /dev/null
+++ b/nlpcraft/src/main/scala/org/apache/nlpcraft/examples/lightswitch/LightSwitchGroovyModel.groovy
@@ -0,0 +1,75 @@
+/*
+ * 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.examples.lightswitch
+
+import org.apache.nlpcraft.model.*
+
+/**
+ * This example provides very simple implementation for NLI-powered light switch.
+ * You can say something like this:
+ * <ul>
+ * <li>"Turn the lights off in the entire house."</li>
+ * <li>"Switch on the illumination in the master bedroom closet."</li>
+ * </ul>
+ * You can easily modify intent callbacks to perform the actual light switching using
+ * HomeKit or Arduino-based controllers.
+ * <p>
+ * See 'README.md' file in the same folder for running and testing instructions.
+ */
+class LightSwitchGroovyModel extends NCModelFileAdapter {
+ LightSwitchGroovyModel() {
+ // Loading the model from the file in the classpath.
+ super("org/apache/nlpcraft/examples/lightswitch/lightswitch_model.yaml")
+ }
+
+ /**
+ * Intent and its on-match callback.
+ *
+ * @param actTok Token from 'act' term (guaranteed to be one).
+ * @param locToks Tokens from 'loc' term (zero or more).
+ * @return Query result to be sent to the REST caller.
+ */
+ @NCIntentRef("ls")
+ @NCIntentSample([
+ "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!",
+ "Kill the illumination now!"
+ ])
+ NCResult onMatch(
+ @NCIntentTerm("act") NCToken actTok,
+ @NCIntentTerm("loc") List<NCToken> locToks) {
+ String status = actTok.id == "ls:on" ? "on" : "off"
+ String locations = locToks ? locToks.collect{ it.meta("nlpcraft:nlp:origtext") }.join(", ") : "entire house"
+
+ // Add HomeKit, Arduino or other integration here.
+
+ // By default - just return a descriptive action string.
+ NCResult.text("Lights are [$status] in [${locations.toLowerCase()}].")
+ }
+}
diff --git a/pom.xml b/pom.xml
index 6852d13..919c5c3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,6 +74,7 @@
<!-- Major Scala version. -->
<scala.base>2.12</scala.base>
<kotlin.ver>1.4.21</kotlin.ver>
+ <groovy.ver>3.0.7</groovy.ver>
<!-- Versions. -->
<ignite.ver>2.9.1</ignite.ver>
@@ -515,6 +516,11 @@
<version>${kotlin.ver}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ <version>${groovy.ver}</version>
+ </dependency>
</dependencies>
<repositories>
@@ -661,6 +667,35 @@
<jvmTarget>1.8</jvmTarget>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.codehaus.gmavenplus</groupId>
+ <artifactId>gmavenplus-plugin</artifactId>
+ <version>1.12.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <sources>
+ <source>
+ <directory>${project.basedir}/src/main/scala</directory>
+ <includes>
+ <include>**/*.groovy</include>
+ </includes>
+ </source>
+ </sources>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ <version>${groovy.ver}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
</plugins>
</build>