├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── ic_close.png
│ │ │ │ ├── background.png
│ │ │ │ ├── chatbot_icon.png
│ │ │ │ ├── background_green_radius.xml
│ │ │ │ ├── background_second_color_radius.xml
│ │ │ │ ├── background_primary_color_radius.xml
│ │ │ │ ├── button_shape_pressed.xml
│ │ │ │ ├── button_shape_selected.xml
│ │ │ │ ├── button_shape_disabled.xml
│ │ │ │ ├── button_shape_unselected.xml
│ │ │ │ ├── suggestion_background.xml
│ │ │ │ ├── ic_baseline_close.xml
│ │ │ │ ├── green_button_background.xml
│ │ │ │ ├── ic_refresh_black_24dp.xml
│ │ │ │ ├── peper_talk_background.xml
│ │ │ │ ├── top_right_rounded_background.xml
│ │ │ │ ├── peper_talk_green_background.xml
│ │ │ │ ├── top_left_rounded_background.xml
│ │ │ │ ├── green_top_left_rounded_background.xml
│ │ │ │ ├── green_top_right_rounded_background.xml
│ │ │ │ ├── button_background_selector.xml
│ │ │ │ ├── ic_img_icon_pepper.xml
│ │ │ │ ├── ic_img_icon_humanmen.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── values
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── color
│ │ │ │ └── button_text_color_selector.xml
│ │ │ ├── layout
│ │ │ │ ├── activity_app_introduction.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── raw
│ │ │ │ ├── dlg_how_are_you.top
│ │ │ │ ├── dlg_move_arms.top
│ │ │ │ ├── dlg_hello.top
│ │ │ │ ├── dlg_robot_origins.top
│ │ │ │ ├── uplarm.qianim
│ │ │ │ ├── uprarm.qianim
│ │ │ │ ├── stretchrarm.qianim
│ │ │ │ ├── stretchlarm.qianim
│ │ │ │ ├── dlg_robot_personal_info.top
│ │ │ │ └── stretchbotharms.qianim
│ │ ├── assets
│ │ │ ├── robot
│ │ │ │ └── robotsdk.xml
│ │ │ └── fonts
│ │ │ │ └── OpenSans-Regular.ttf
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── softbankrobotics
│ │ │ │ └── chatbotsample
│ │ │ │ ├── UiNotifier.java
│ │ │ │ ├── EmptyChatbotReaction.java
│ │ │ │ ├── dialogflow
│ │ │ │ ├── RequestTask.java
│ │ │ │ └── DialogflowAgent.java
│ │ │ │ ├── AppRequirementActivity.java
│ │ │ │ ├── ChatbotUtteredReaction.java
│ │ │ │ ├── AppIntroductionActivity.java
│ │ │ │ ├── MyQiChatExecutor.java
│ │ │ │ ├── DialogflowChatbot.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── Robot.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── softbankrobotics
│ │ │ └── chatbotsample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── softbankrobotics
│ │ └── chatbotsample
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── DialogflowChatbotAgent.zip
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradle.properties
├── CHANGELOG.md
├── classDiagram.plantuml
├── COPYING.md
├── sequenceDiagram.plantuml
├── gradlew.bat
├── .gitignore
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/DialogflowChatbotAgent.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/DialogflowChatbotAgent.zip
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/drawable/ic_close.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/drawable/background.png
--------------------------------------------------------------------------------
/app/src/main/assets/robot/robotsdk.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/chatbot_icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/drawable/chatbot_icon.png
--------------------------------------------------------------------------------
/app/src/main/assets/fonts/OpenSans-Regular.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/assets/fonts/OpenSans-Regular.ttf
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aldebaran/qisdk-sample-chatbot/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background_green_radius.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background_second_color_radius.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background_primary_color_radius.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_shape_pressed.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_shape_selected.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Oct 25 13:47:01 CEST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_shape_disabled.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_shape_unselected.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/UiNotifier.java:
--------------------------------------------------------------------------------
1 | package com.softbankrobotics.chatbotsample;
2 |
3 | import com.aldebaran.qi.sdk.object.conversation.Phrase;
4 |
5 | import java.util.List;
6 |
7 | public interface UiNotifier {
8 | void setText(String text);
9 |
10 | void isDialogFlow(boolean dialogFlow);
11 | void updateQiChatSuggestions(List recommendation);
12 | }
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/suggestion_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_close.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/green_button_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 24sp
4 | 2dp
5 | 7dp
6 | 10dp
7 | 10dp
8 | 15dp
9 | 5dp
10 | 25dp
11 |
--------------------------------------------------------------------------------
/app/src/test/java/com/softbankrobotics/chatbotsample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.softbankrobotics.chatbotsample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_refresh_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/peper_talk_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/top_right_rounded_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/peper_talk_green_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/top_left_rounded_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
13 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/green_top_left_rounded_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/green_top_right_rounded_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
13 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/color/button_text_color_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
10 |
15 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_background_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
10 |
15 |
17 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ChatbotSample
3 | QiChatBot
4 | Dialog Flow
5 | \"%s\"
6 |
7 |
8 |
9 | \"no\"
10 | \"yes\"
11 | Retry
12 | Settings
13 | Exit
14 | Skip
15 |
16 | With the power of local and remote chat bots, I will try to reply to what you will say. Here are some examples of things you can tell me.
17 | you can say…
18 |
19 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/EmptyChatbotReaction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Softbank Robotics Europe
3 | * See COPYING for the license
4 | */
5 | package com.softbankrobotics.chatbotsample;
6 |
7 | import com.aldebaran.qi.sdk.QiContext;
8 | import com.aldebaran.qi.sdk.object.conversation.BaseChatbotReaction;
9 | import com.aldebaran.qi.sdk.object.conversation.SpeechEngine;
10 |
11 | /**
12 | * A ChatbotReaction that does nothing.
13 | */
14 | public class EmptyChatbotReaction extends BaseChatbotReaction {
15 |
16 | EmptyChatbotReaction(final QiContext context) {
17 | super(context);
18 | }
19 |
20 | @Override
21 | public void runWith(final SpeechEngine speechEngine) {
22 | // Not used.
23 | }
24 |
25 | @Override
26 | public void stop() {
27 | // Not used.
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/softbankrobotics/chatbotsample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.softbankrobotics.chatbotsample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.softbankrobotics.chatbotsample", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_app_introduction.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # ChatbotSample Change Log
2 | All notable changes to this project will be documented in this file.
3 |
4 | The format is based on [Keep a Changelog](http://keepachangelog.com/)
5 |
6 |
7 | [Unreleased]
8 |
9 | ## [0.0.3] - 2018-06-06
10 |
11 | ### added
12 | - New plantUML sequence diagram
13 |
14 | ### changed
15 | - Adding a "not understood" rule to the topic file
16 |
17 |
18 | ## [0.0.2] - 2018-06-06
19 |
20 | ### changed
21 | - Now using TopicBuilder
22 | - DialogflowChatbot no longer needs Robot
23 | - renamed 'Class diagram.plantuml' into 'classDiagram.plantuml'
24 | - Improved README.md
25 | - upgrade to QiSDK 1.3.3
26 | - MainActivity inherits RobotActivity
27 | - Renaming the action string into 'excitement'
28 | - Dialogflow agent no longer only in charge of the small talk, explain it in README
29 | - Providing the Dialogflow agent as a zip file that can be imported
30 | - Now using SayBuilder.withSpeechEngine()
31 | - Bump versionCode to 2
32 |
33 | ## [0.0.1] - 2018-05-30
34 |
35 | ### added
36 | - Initial version of the project
37 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #387877
4 | #303F9F
5 | #F48FB1
6 | #4CAF50
7 | #212121
8 |
9 | #A49494
10 | #BCB0B0
11 | #1bbde2
12 | #2e86d0
13 |
14 | #4caf50
15 | #1b5e20
16 |
17 | #888888
18 | #cccccccc
19 | #fafafa
20 | #e0e0e0
21 | #f5f5f5
22 | #9e9e9e
23 | #fff
24 |
25 |
26 | #eeeeee
27 | #757575
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/classDiagram.plantuml:
--------------------------------------------------------------------------------
1 | @startuml
2 |
3 | title ChatbotSample overview class diagram
4 |
5 | skinparam titleBorderThickness 2
6 |
7 | skinparam class {
8 | BorderColor Black
9 | BackgroundColor<> LightBlue
10 | }
11 | hide stereotypes
12 |
13 | interface Chat {
14 | }
15 | interface Chatbot {
16 | replyTo
17 | }
18 | interface QiChatbot {
19 | }
20 | abstract class BaseChatbot
21 |
22 | interface ChatbotReaction {
23 | runWith
24 | stop
25 | }
26 |
27 | interface ReplyReaction {
28 | replyPriority
29 | }
30 |
31 | interface AutonomousReaction {
32 | importance
33 | validity
34 | }
35 |
36 | abstract class BaseChatbotReaction
37 | class StandardReplyReaction
38 | class StandardAutonomousReaction
39 |
40 | class DialogflowChatbot<> {
41 | replyTo
42 | }
43 |
44 | class ChatbotUtteredReaction<> {
45 | runWith
46 | stop
47 | }
48 |
49 |
50 | Chat o-right- "n" Chatbot
51 | Chatbot <|-- QiChatbot
52 | Chatbot <|-- BaseChatbot
53 | BaseChatbot <|-- DialogflowChatbot
54 |
55 | Chatbot --> ReplyReaction : replies
56 |
57 | ReplyReaction <|-- StandardReplyReaction
58 | AutonomousReaction <|-- StandardAutonomousReaction
59 |
60 | ChatbotReaction <|-- BaseChatbotReaction
61 | BaseChatbotReaction <|-- ChatbotUtteredReaction
62 |
63 | ReplyReaction *-- "1" ChatbotReaction
64 | AutonomousReaction *-- "1" ChatbotReaction
65 |
66 | Chatbot --> AutonomousReaction : spontaneously emits
67 |
68 |
69 | @enduml
--------------------------------------------------------------------------------
/COPYING.md:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) 2018, Softbank Robotics Europe
3 | All rights reserved.
4 |
5 | Redistribution and use in source and binary forms, with or without
6 | modification, are permitted provided that the following conditions are met:
7 |
8 |
9 | * Redistributions of source code must retain the above copyright
10 | notice, this list of conditions and the following disclaimer.
11 | * Redistributions in binary form must reproduce the above copyright
12 | notice, this list of conditions and the following disclaimer in the
13 | documentation and/or other materials provided with the distribution.
14 | * Neither the name of the Softbank Robotics nor the
15 | names of its contributors may be used to endorse or promote products
16 | derived from this software without specific prior written permission.
17 |
18 |
19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 | DISCLAIMED. IN NO EVENT SHALL Softbank Robotics BE LIABLE FOR ANY
23 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | def qisdkVersion = '1.4.1'
3 | def supportVersion = '27.1.1'
4 | android {
5 | compileSdkVersion 27
6 | defaultConfig {
7 | applicationId "com.softbankrobotics.chatbotsample"
8 | minSdkVersion 23
9 | targetSdkVersion 27
10 | versionCode 3
11 | versionName "1.0.2"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 |
14 | // CHATBOT_SAMPLE_DIALOGFLOW_TOKEN is kept out of version control (typically in your
15 | // global gradle.properties file located in ~/.gradle). Make it available through BuildConfig.
16 | buildConfigField("String", "DIALOGFLOW_CLIENT_ACCESS_TOKEN", "\"${CHATBOT_SAMPLE_DIALOGFLOW_TOKEN}\"")
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | implementation "com.android.support:appcompat-v7:$supportVersion"
29 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
30 | testImplementation 'junit:junit:4.12'
31 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
32 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
33 |
34 | // QiSDK
35 | implementation "com.aldebaran:qisdk:$qisdkVersion"
36 | implementation "com.aldebaran:qisdk-design:$qisdkVersion"
37 |
38 | // Dialogflow v1
39 | implementation 'ai.api:libai:1.6.12'
40 |
41 | implementation "com.android.support:design:$supportVersion"
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/dialogflow/RequestTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Softbank Robotics Europe
3 | * See COPYING for the license
4 | */
5 | package com.softbankrobotics.chatbotsample.dialogflow;
6 |
7 | import android.os.AsyncTask;
8 | import android.util.Log;
9 |
10 | import com.aldebaran.qi.Promise;
11 |
12 | import ai.api.AIDataService;
13 | import ai.api.AIServiceException;
14 | import ai.api.model.AIRequest;
15 | import ai.api.model.AIResponse;
16 |
17 | /**
18 | * An AsynchronousTask aimed at sending requests to a Dialogflow agent.
19 | */
20 | public class RequestTask extends AsyncTask {
21 |
22 | private static final String TAG = "RequestTask";
23 |
24 | private AIDataService aiDataService;
25 | private Promise responsePromise = new Promise<>();
26 |
27 | RequestTask(final AIDataService anAIDataService) {
28 | aiDataService = anAIDataService;
29 | }
30 |
31 | /**
32 | * Get synchronously the response of the request.
33 | * @return the result of the request
34 | */
35 | AIResponse getResponse() {
36 | // Wait for the future until its underlying promise is set
37 | return responsePromise.getFuture().getValue();
38 | }
39 |
40 | @Override
41 | protected AIResponse doInBackground(final AIRequest... requests) {
42 | final AIRequest request = requests[0];
43 | if (request == null) {
44 | throw new NullPointerException("No request provided");
45 | }
46 |
47 | AIResponse result = null;
48 | try {
49 | result = aiDataService.request(request);
50 | } catch (AIServiceException e) {
51 | Log.e(TAG, "aiDataService request error", e);
52 | }
53 |
54 | // By setting the promise we unlock any waiting call on answerTo()
55 | responsePromise.setValue(result);
56 | return result;
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/AppRequirementActivity.java:
--------------------------------------------------------------------------------
1 | package com.softbankrobotics.chatbotsample;
2 |
3 | import android.content.DialogInterface;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AlertDialog;
7 |
8 | import com.aldebaran.qi.sdk.design.activity.RobotActivity;
9 | import com.aldebaran.qi.sdk.design.activity.conversationstatus.SpeechBarDisplayStrategy;
10 |
11 | import java.util.Locale;
12 |
13 | public class AppRequirementActivity extends RobotActivity {
14 |
15 | private static final String APP_LANGUAGE = "English";
16 | private static final Class FIRST_ACTIVITY = AppIntroductionActivity.class;
17 |
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setSpeechBarDisplayStrategy(SpeechBarDisplayStrategy.OVERLAY);
22 |
23 | if (!Locale.getDefault().getDisplayLanguage().equals(APP_LANGUAGE)) {
24 | new AlertDialog.Builder(this)
25 | .setTitle("Language warning")
26 | .setMessage("This application is only available in English. Please set the tablet language to \"English\".")
27 | .setPositiveButton(R.string.setting, new DialogInterface.OnClickListener() {
28 | @Override
29 | public void onClick(DialogInterface dialog, int which) {
30 | startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCALE_SETTINGS), 0);
31 | finishAffinity();
32 | }
33 | })
34 | .setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
35 | @Override
36 | public void onClick(DialogInterface dialog, int which) {
37 | finishAffinity();
38 | }
39 | })
40 | .setIcon(android.R.drawable.ic_dialog_alert)
41 | .show();
42 | } else {
43 | finish();
44 | startActualApp();
45 | }
46 | }
47 |
48 | private void startActualApp() {
49 | Intent intent = new Intent(this, FIRST_ACTIVITY);
50 | startActivity(intent);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/ChatbotUtteredReaction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Softbank Robotics Europe
3 | * See COPYING for the license
4 | */
5 | package com.softbankrobotics.chatbotsample;
6 |
7 | import android.util.Log;
8 |
9 | import com.aldebaran.qi.Future;
10 | import com.aldebaran.qi.sdk.QiContext;
11 | import com.aldebaran.qi.sdk.builder.SayBuilder;
12 | import com.aldebaran.qi.sdk.object.conversation.BaseChatbotReaction;
13 | import com.aldebaran.qi.sdk.object.conversation.Say;
14 | import com.aldebaran.qi.sdk.object.conversation.SpeechEngine;
15 |
16 | import java.util.concurrent.ExecutionException;
17 |
18 | /**
19 | * A ChatbotReaction that simply utters its reply.
20 | *
21 | */
22 | public class ChatbotUtteredReaction extends BaseChatbotReaction {
23 |
24 | private static final String TAG = "DialogflowChatbotReac";
25 | private final UiNotifier uiNotifier;
26 |
27 | private String toBeSaid;
28 | private Future fsay;
29 |
30 | ChatbotUtteredReaction(final QiContext qiContext, final String answer, UiNotifier uiNotifier) {
31 | super(qiContext);
32 | toBeSaid = answer;
33 | this.uiNotifier = uiNotifier;
34 | }
35 |
36 | @Override
37 | public void runWith(final SpeechEngine speechEngine) {
38 | uiNotifier.isDialogFlow(true);
39 | // All Say actions that must be executed inside this method must be created via the SpeechEngine
40 | Say say = SayBuilder.with(speechEngine)
41 | .withText(toBeSaid)
42 | .build();
43 |
44 | try {
45 | // The say action must be executed asynchronously in order to get
46 | // a future that can be canceled by the head thanks to the stop() method
47 | fsay = say.async().run();
48 |
49 | // However, runWith must not be leaved before the say action is terminated : thus wait on the future
50 | fsay.get();
51 |
52 | } catch (ExecutionException e) {
53 | Log.e(TAG, "Error during say", e);
54 | }
55 | }
56 |
57 | @Override
58 | public void stop() {
59 |
60 | // All actions created in runWith should be canceled when stop is called
61 |
62 | if (fsay != null) {
63 | fsay.requestCancellation();
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
18 |
29 |
30 |
41 |
42 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/AppIntroductionActivity.java:
--------------------------------------------------------------------------------
1 | package com.softbankrobotics.chatbotsample;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.util.Log;
6 | import android.view.View;
7 |
8 | import com.aldebaran.qi.Consumer;
9 | import com.aldebaran.qi.Future;
10 | import com.aldebaran.qi.sdk.QiContext;
11 | import com.aldebaran.qi.sdk.QiSDK;
12 | import com.aldebaran.qi.sdk.RobotLifecycleCallbacks;
13 | import com.aldebaran.qi.sdk.builder.SayBuilder;
14 | import com.aldebaran.qi.sdk.design.activity.RobotActivity;
15 | import com.aldebaran.qi.sdk.design.activity.conversationstatus.SpeechBarDisplayStrategy;
16 | import com.aldebaran.qi.sdk.object.conversation.Say;
17 |
18 | public class AppIntroductionActivity extends RobotActivity implements RobotLifecycleCallbacks {
19 |
20 | private static final String TAG = "AppIntroductionActivity";
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setSpeechBarDisplayStrategy(SpeechBarDisplayStrategy.OVERLAY);
26 | setContentView(R.layout.activity_app_introduction);
27 |
28 | QiSDK.register(this, this);
29 |
30 | findViewById(R.id.btn_skip).setOnClickListener(new View.OnClickListener() {
31 | @Override
32 | public void onClick(View v) {
33 | Intent intent = new Intent(AppIntroductionActivity.this, MainActivity.class);
34 | startActivity(intent);
35 | finishAffinity();
36 | }
37 | });
38 |
39 | }
40 |
41 | @Override
42 | public void onRobotFocusGained(QiContext qiContext) {
43 | Say say = SayBuilder.with(qiContext).withText(getString(R.string.app_introduction)).build();
44 | Future sayFuture = say.async().run();
45 |
46 | sayFuture.thenConsume(new Consumer>() {
47 | @Override
48 | public void consume(Future future) throws Throwable {
49 | Intent intent = new Intent(AppIntroductionActivity.this, MainActivity.class);
50 | startActivity(intent);
51 | finishAffinity();
52 | }
53 | });
54 | }
55 |
56 | @Override
57 | public void onRobotFocusLost() {
58 | Log.i(TAG, "Focus lost");
59 | }
60 |
61 | @Override
62 | public void onRobotFocusRefused(String reason) {
63 | Log.i(TAG, "onRobotFocusRefused: " + reason);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/sequenceDiagram.plantuml:
--------------------------------------------------------------------------------
1 | @startuml
2 |
3 | skinparam ParticipantPadding 10
4 | skinparam BoxPadding 5
5 |
6 | actor User
7 |
8 | box "Head"
9 | participant Chat
10 | participant QiChatbot
11 | endbox
12 |
13 | box "Tablet"
14 | participant DialogflowChatbot
15 | participant DialogflowAgent
16 | participant StandardReplyReaction
17 | participant DialogflowChatbotReaction
18 | participant Say
19 | endbox
20 |
21 | box "Internet"
22 | participant Dialogflow
23 | endbox
24 |
25 | User -> Chat: "are we free ?"
26 |
27 | activate Chat
28 | Chat -> QiChatbot: replyTo("are we free ?")
29 | activate QiChatbot
30 | Chat -> DialogflowChatbot: replyTo("are we free ?")
31 |
32 | note left of QiChatbot: The QiChatbot has no rule\nin its topic that \ncorresponds to this\nuser utterance
33 |
34 | activate DialogflowChatbot
35 | DialogflowChatbot -> DialogflowAgent : answerTo("are we free ?")
36 | activate DialogflowAgent
37 | DialogflowAgent ->> Dialogflow : send an asynchronous query containing "are we free ?" to the online agent
38 | activate Dialogflow
39 | Chat <-- QiChatbot: return StandardReplyReaction(ChatbotReaction, FALLBACK))
40 |
41 | deactivate QiChatbot
42 | DialogflowAgent <-- Dialogflow : return an AIResponse containing "The concept of liberty is a rather hazy one."
43 | deactivate Dialogflow
44 | DialogflowChatbot <-- DialogflowAgent : return the AIReponse
45 | deactivate DialogflowAgent
46 |
47 | create DialogflowChatbotReaction
48 | DialogflowChatbot -> DialogflowChatbotReaction : create a DialogflowChatbotReaction with "The concept of liberty is a rather hazy one."
49 | create StandardReplyReaction
50 | DialogflowChatbot -> StandardReplyReaction : create a ReplyReaction with (ChatbotReaction + priority)
51 |
52 | deactivate QiChatbot
53 | Chat <-- DialogflowChatbot: return StandardReplyReaction(DialogflowChatbotReaction, FALLBACK))
54 | deactivate DialogflowChatbot
55 |
56 | activate Chat
57 | note right of Chat: Choose the FALLBACK since no NORMAL response was provided
58 | Chat -> DialogflowChatbotReaction: runWith(SpeechEngine)
59 | deactivate Chat
60 |
61 | activate DialogflowChatbotReaction
62 | create Say
63 | DialogflowChatbotReaction -> Say: SayBuilder.with(speechEngine).build()
64 | DialogflowChatbotReaction ->> Say: async().run()
65 | activate Say
66 | Say -> User : "The concept of liberty is a rather hazy one."
67 |
68 | DialogflowChatbotReaction -> Say: get() on the enclosing Future
69 | Say --> DialogflowChatbotReaction
70 |
71 | deactivate Say
72 | DialogflowChatbotReaction --> Chat
73 | deactivate DialogflowChatbotReaction
74 | deactivate Chat
75 |
76 | @enduml
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/MyQiChatExecutor.java:
--------------------------------------------------------------------------------
1 | package com.softbankrobotics.chatbotsample;
2 |
3 | import android.util.Log;
4 |
5 | import com.aldebaran.qi.Future;
6 | import com.aldebaran.qi.sdk.QiContext;
7 | import com.aldebaran.qi.sdk.builder.AnimateBuilder;
8 | import com.aldebaran.qi.sdk.builder.AnimationBuilder;
9 | import com.aldebaran.qi.sdk.object.actuation.Animate;
10 | import com.aldebaran.qi.sdk.object.actuation.Animation;
11 | import com.aldebaran.qi.sdk.object.conversation.BaseQiChatExecutor;
12 |
13 | import java.util.List;
14 | import java.util.concurrent.ExecutionException;
15 |
16 | class MyQiChatExecutor extends BaseQiChatExecutor {
17 | private final QiContext qiContext;
18 | private Future animationFuture;
19 | private String TAG = "MyQiChatExecutor";
20 |
21 | MyQiChatExecutor(QiContext context) {
22 | super(context);
23 | this.qiContext = context;
24 | }
25 |
26 | @Override
27 | public void runWith(List params) {
28 | // This is called when execute is reached in the topic
29 | if (params == null || params.isEmpty()) {
30 | return;
31 | }
32 | String param = params.get(0);
33 | Boolean async = true;
34 | if (params.size() >= 2 && params.get(1).equals("sync")) {
35 | async = false;
36 | }
37 | animate(qiContext, qiContext.getResources().getIdentifier(param, "raw", qiContext.getPackageName()), async);
38 | }
39 |
40 | @Override
41 | public void stop() {
42 | if (animationFuture != null) {
43 | animationFuture.cancel(true);
44 | }
45 | }
46 |
47 | private void animate(QiContext qiContext, int resource, boolean async) {
48 | // Create an animation.
49 | Animation animation = AnimationBuilder.with(qiContext) // Create the builder with the context.
50 | .withResources(resource) // Set the animation resource.
51 | .build(); // Build the animation.
52 |
53 | // Create an animate action.
54 | Animate animate = AnimateBuilder.with(qiContext) // Create the builder with the context.
55 | .withAnimation(animation) // Set the animation.
56 | .build(); // Build the animate action.
57 | if (async) {
58 | animationFuture = animate.async().run();
59 | try {
60 | animationFuture.get();
61 | } catch (ExecutionException e) {
62 | Log.e(TAG, e.getMessage());
63 | }
64 | } else {
65 | animate.run();
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_img_icon_pepper.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
15 |
18 |
21 |
24 |
27 |
30 |
33 |
36 |
43 |
44 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/android,windows,intellij,gradle
3 |
4 | ### Android ###
5 | # Built application files
6 | *.apk
7 | *.ap_
8 |
9 | # Files for the ART/Dalvik VM
10 | *.dex
11 |
12 | # Java class files
13 | *.class
14 |
15 | # Generated files
16 | bin/
17 | gen/
18 | out/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # Intellij
40 | *.iml
41 |
42 |
43 | # Keystore files
44 | *.jks
45 |
46 | ### Android Patch ###
47 | gen-external-apklibs
48 |
49 |
50 | ### Windows ###
51 | # Windows image file caches
52 | Thumbs.db
53 | ehthumbs.db
54 |
55 | # Folder config file
56 | Desktop.ini
57 |
58 | # Recycle Bin used on file shares
59 | $RECYCLE.BIN/
60 |
61 | # Windows Installer files
62 | *.cab
63 | *.msi
64 | *.msm
65 | *.msp
66 |
67 | # Windows shortcuts
68 | *.lnk
69 |
70 |
71 | ### Intellij ###
72 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
73 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
74 |
75 | # User-specific stuff:
76 | .idea/tasks.xml
77 | .idea/dictionaries
78 | .idea/jsLibraryMappings.xml
79 |
80 | # Sensitive or high-churn files:
81 | .idea/dataSources.ids
82 | .idea/dataSources.xml
83 | .idea/dataSources.local.xml
84 | .idea/sqlDataSources.xml
85 | .idea/dynamic.xml
86 | .idea/uiDesigner.xml
87 |
88 | # Gradle:
89 |
90 | # Mongo Explorer plugin:
91 | .idea/mongoSettings.xml
92 |
93 | ## File-based project format:
94 | *.iws
95 |
96 | ## Plugin-specific files:
97 |
98 | # IntelliJ
99 | /out/
100 |
101 | # mpeltonen/sbt-idea plugin
102 | .idea_modules/
103 |
104 | # JIRA plugin
105 | atlassian-ide-plugin.xml
106 |
107 | # Crashlytics plugin (for Android Studio and IntelliJ)
108 | com_crashlytics_export_strings.xml
109 | crashlytics.properties
110 | crashlytics-build.properties
111 | fabric.properties
112 |
113 | ### Intellij Patch ###
114 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
115 |
116 | # *.iml
117 | # modules.xml
118 | # .idea/misc.xml
119 | # *.ipr
120 |
121 |
122 | ### Gradle ###
123 | # Ignore Gradle GUI config
124 | gradle-app.setting
125 |
126 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
127 | !gradle-wrapper.jar
128 |
129 | # Cache of project
130 | .gradletasknamecache
131 |
132 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
133 | # gradle/wrapper/gradle-wrapper.properties
134 |
135 | .idea/
136 |
137 | reports/
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ChatbotSample
2 |
3 | ChatbotSample is an Android application for **Pepper the robot** that
4 | demonstrates how to implement a chatbot thanks to the **Android QiSDK**.
5 | (https://qisdk.softbankrobotics.com)
6 |
7 |
8 | This sample relies on an online **Dialogflow** agent and a local **qichatbot**.
9 | The chat engine utilizes both chatbots to provide a dialog whose
10 | progress is structured according to a functional scenario while providing
11 | casual discussion.
12 |
13 | * The local qichatbot conversation related to pepper including information about the robot and some simple robot actions.
14 | * The Dialogflow chatbot deals with some general questions that doesn't exist in the qichatbot topics.
15 |
16 |
17 | ## Minimum configuration
18 |
19 | * Pepper 1.9
20 | * API Level 3
21 |
22 |
23 | ## Getting started ##
24 |
25 | For the sake of simplicity, this sample uses a **Dialogflow v1 agent**.
26 | The class DialogflowChatbot.java shows how to interact with such an agent.
27 |
28 | ### Creating a Dialogflow agent ###
29 |
30 | In order to run the application, you need to create first your own agent
31 | via the Dialogflow console (https://console.dialogflow.com).
32 |
33 | Ensure you select *V1 API* in the *General* tab of the settings page.
34 |
35 | ### Client access token ###
36 | Once your agent is created, you should make the provided **client access token**
37 | available to the Android project. This token is needed to connect the
38 | application to the agent.
39 |
40 | In the **global gradle.properties** file located in your *~/.gradle* folder,
41 | add the following line:
42 |
43 | ```
44 | CHATBOT_SAMPLE_DIALOGFLOW_TOKEN=your_client_access_token
45 | ```
46 | This avoids keeping the token under version control.
47 |
48 | ### Populating the agent ###
49 |
50 | Your Dialogflow agent may be populated either by hand (via the console)
51 | or by importing an already made agent. Learning how to create Dialogflow
52 | intents goes beyond the scope of this sample. Therefore we provide you
53 | with a sample agent description you just have to import in your own agent.
54 |
55 | In the Dialogflow console:
56 | * Go to the *Settings* page of the agent
57 | * Choose the *Export and Import* option
58 | * Click on *Restore from zip*
59 | * Then follow instructions to upload the [DialogflowChatbotAgent.zip] file.
60 |
61 | This sample agent provides fallback intents that reply to some general questions.
62 |
63 |
64 | ## Additional resources ##
65 |
66 | #### Overview UML diagrams ####
67 | A PlantUML [class diagram](classDiagram.plantuml) and a
68 | [sequence diagram](sequenceDiagram.plantuml)
69 | are available at the root of this project.
70 |
71 | The *PlantUML integration* plugin is needed to display them in AndroidStudio.
72 | Alternatively you can visit http://www.plantuml.com/plantuml.
73 |
74 | ## Licence ##
75 |
76 | See the [COPYING](COPYING.md) file for the license.
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/dialogflow/DialogflowAgent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Softbank Robotics Europe
3 | * See COPYING for the license
4 | */
5 | package com.softbankrobotics.chatbotsample.dialogflow;
6 |
7 | import android.util.Log;
8 |
9 | import com.google.gson.JsonElement;
10 | import com.softbankrobotics.chatbotsample.BuildConfig;
11 |
12 | import java.util.HashMap;
13 | import java.util.Map;
14 |
15 | import ai.api.AIConfiguration;
16 | import ai.api.AIDataService;
17 | import ai.api.model.AIRequest;
18 | import ai.api.model.AIResponse;
19 | import ai.api.model.Metadata;
20 | import ai.api.model.Result;
21 | import ai.api.model.Status;
22 |
23 | import static ai.api.AIConfiguration.SupportedLanguages.English;
24 |
25 | /**
26 | * Singleton aimed at accessing a specific Dialogflow agent dedicated to this sample.
27 | */
28 | public final class DialogflowAgent {
29 |
30 | private static final String TAG = "DialogflowAgent";
31 |
32 | private static final DialogflowAgent INSTANCE = new DialogflowAgent();
33 |
34 | private final AIDataService aiDataService;
35 |
36 | private DialogflowAgent() {
37 | // The access token is a
38 | final AIConfiguration config = new AIConfiguration(BuildConfig.DIALOGFLOW_CLIENT_ACCESS_TOKEN, English);
39 | aiDataService = new AIDataService(config);
40 | }
41 |
42 | /**
43 | * @return the unique instance of this class
44 | */
45 | public static DialogflowAgent getInstance() {
46 | return INSTANCE;
47 | }
48 |
49 | /**
50 | * Ask a question to DialogFlow.
51 | * @param question the text we expect Dialogflow to answer to
52 | * @return the Dialogflow response
53 | */
54 | public AIResponse answerTo(final String question) {
55 | Log.d(TAG, "answerTo: " + question);
56 |
57 | // Prepare the request
58 | final AIRequest aiRequest = new AIRequest();
59 | aiRequest.setQuery(question);
60 |
61 | // Execute the request
62 | RequestTask task = new RequestTask(aiDataService);
63 | task.execute(aiRequest);
64 |
65 | // Wait for the response and return it
66 | AIResponse response = task.getResponse();
67 | logAIResponse(response);
68 | return response;
69 | }
70 |
71 | private void logAIResponse(final AIResponse response) {
72 |
73 | final Status status = response.getStatus();
74 | Log.d(TAG, "Status code: " + status.getCode());
75 | Log.d(TAG, "Status type: " + status.getErrorType());
76 |
77 | final Result result = response.getResult();
78 | Log.d(TAG, "Resolved query: " + result.getResolvedQuery());
79 |
80 | Log.d(TAG, "Action: " + result.getAction());
81 |
82 | final String speech = result.getFulfillment().getSpeech();
83 | Log.d(TAG, "Speech: " + speech);
84 |
85 | final Metadata metadata = result.getMetadata();
86 | if (metadata != null) {
87 | Log.d(TAG, "Intent id: " + metadata.getIntentId());
88 | Log.d(TAG, "Intent name: " + metadata.getIntentName());
89 | }
90 |
91 | final HashMap params = result.getParameters();
92 | if (params != null && !params.isEmpty()) {
93 | Log.d(TAG, "Parameters: ");
94 | for (final Map.Entry entry : params.entrySet()) {
95 | Log.d(TAG, String.format("%s: %s", entry.getKey(), entry.getValue().toString()));
96 | }
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/DialogflowChatbot.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Softbank Robotics Europe
3 | * See COPYING for the license
4 | */
5 | package com.softbankrobotics.chatbotsample;
6 |
7 | import android.util.Log;
8 |
9 | import com.aldebaran.qi.sdk.QiContext;
10 | import com.aldebaran.qi.sdk.object.conversation.BaseChatbot;
11 | import com.aldebaran.qi.sdk.object.conversation.BaseChatbotReaction;
12 | import com.aldebaran.qi.sdk.object.conversation.Phrase;
13 | import com.aldebaran.qi.sdk.object.conversation.ReplyPriority;
14 | import com.aldebaran.qi.sdk.object.conversation.StandardReplyReaction;
15 | import com.aldebaran.qi.sdk.object.locale.Locale;
16 | import com.softbankrobotics.chatbotsample.dialogflow.DialogflowAgent;
17 |
18 | import ai.api.model.AIResponse;
19 | import ai.api.model.Result;
20 |
21 | import static com.aldebaran.qi.sdk.object.conversation.ReplyPriority.FALLBACK;
22 |
23 | /**
24 | * A sample chatbot that delegates questions/answers to a Dialogflow agent.
25 | */
26 | public class DialogflowChatbot extends BaseChatbot {
27 |
28 | private static final String TAG = "DialogflowChatbot";
29 | private static final String EXCITEMENT_ACTION = "excitement";
30 | private final UiNotifier uiNotifier;
31 |
32 | DialogflowChatbot(final QiContext context, UiNotifier uiNotifier) {
33 | super(context);
34 | this.uiNotifier = uiNotifier;
35 | }
36 |
37 | @Override
38 | public StandardReplyReaction replyTo(final Phrase phrase, final Locale locale) {
39 |
40 | if (phrase.getText().isEmpty()) {
41 | // The phrase may be empty when the robot ears something
42 | // but cannot recognize words. Return an empty reply.
43 | EmptyChatbotReaction emptyReac = new EmptyChatbotReaction(getQiContext());
44 | return new StandardReplyReaction(emptyReac, ReplyPriority.FALLBACK);
45 | } else {
46 |
47 | // Ask the online DialogFlow agent to answer to the phrase
48 | DialogflowAgent dfAgent = DialogflowAgent.getInstance();
49 | AIResponse aiResponse = dfAgent.answerTo(phrase.getText());
50 | // Return a reply built from the agent's response
51 | return replyFromAIResponse(aiResponse);
52 | }
53 | }
54 |
55 | @Override
56 | public void acknowledgeHeard(final Phrase phrase, final Locale locale) {
57 | Log.i(TAG, "The robot heard: "+ phrase.getText());
58 | }
59 |
60 | @Override
61 | public void acknowledgeSaid(final Phrase phrase, final Locale locale) {
62 | Log.i(TAG, "The robot uttered this reply, provided by another chatbot: "+ phrase.getText());
63 | }
64 |
65 | /*
66 | * Build a reply that can be processed by our chatbot, based on the response from Dialogflow
67 | */
68 | private StandardReplyReaction replyFromAIResponse(final AIResponse response) {
69 | Log.d(TAG, "replyFromAIResponse");
70 | // Extract relevant data from Dialogflow response
71 | final Result result = response.getResult();
72 | String answer = result.getFulfillment().getSpeech();
73 | String intentName = result.getMetadata().getIntentName();
74 | String action = result.getAction();
75 |
76 | // Set the priority of our reply, here by detecting the fallback nature of the Dialogflow
77 | // response according the name of the intent that was triggered
78 |
79 | BaseChatbotReaction reaction = null;
80 | reaction = new ChatbotUtteredReaction(getQiContext(), answer, uiNotifier);
81 |
82 | // Make the reply and return it
83 | return new StandardReplyReaction(reaction, FALLBACK);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/dlg_how_are_you.top:
--------------------------------------------------------------------------------
1 | topic: ~dlg_how_are_you()
2 |
3 |
4 | #==================================================================#
5 | ##### The robot answers to how are you #####
6 | #==================================================================#
7 | #rule: how are you#
8 | u:({"and you"} [
9 | "you're ["doing good" "{going} well"]"
10 | "how are you {doing today}"
11 | "how goes it"
12 | "[how's "how is"] it going"
13 | "what's up"
14 | "how are {you} doing"
15 | "["are you" "do you feel"] [happy well]"
16 |
17 | ])
18 | ^rand[
19 | "Very fine, thanks!"
20 | "I'm super good! Thank you!"
21 | "I feel very good! Thanks!"
22 | "Very fine! Thanks!"
23 | "Couldn't be better! Thanks!"
24 | ]
25 | ^first
26 | [
27 | "$how_are_you==activated ^empty"
28 | "^goto(ask_user_mood)"
29 | ]
30 |
31 |
32 | u:($empty)%ask_user_mood
33 | And you? ^rand["how are you?" "how goes it?" "how are you doing?"]
34 | $how_are_you=activated
35 |
36 | #good
37 | u1:([~im_good good])
38 | ^rand[
39 | "So both of us are doing really good!"
40 | "Super!"
41 | "That makes me happy!"
42 | "I'm happy to hear that"
43 | ]
44 |
45 | #not_good
46 | u1:(~i_dont_feel_good)
47 | ^rand[
48 | "Oh that's too bad, I hope I can lift your spirits!"
49 | "Don't worry, the sun will come out tomorrow!"
50 | "Don't worry, you'll feel better tomorrow."
51 | ]
52 |
53 | #ok
54 | u1:(~im_ok)
55 | Great!
56 |
57 | #sick
58 | u1:(~im_sick)
59 | Oh my goodness, you should go to see a doctor.
60 |
61 | #tired
62 | u1:(~im_tired)
63 | Try to take a rest then!
64 |
65 | #not your business
66 | u1:([
67 | "that doesn't concern you"
68 | "buzz off"
69 | "["none of" not] your business"
70 | "mind your own [business beeswax]"
71 | ])
72 | ^rand[
73 | "Ow, that's quite a bad start."
74 | "Okay okay."
75 | ]
76 |
77 | #dont know
78 | u1:([
79 | "[that it] depends"
80 | ~i_dont_know
81 | ~im_not_sure
82 | ])
83 | Well, I hope our conversation will put you in a good mood!
84 |
85 |
86 | #QUESTIONS ABOUT ROBOT'S MOOD/PHYSICAL STATUS#
87 | #rule: can you feel good or bad#
88 | u:([
89 | "can [you "["a robot" robots] $temp/subj=robot"] feel good {"or bad"}"
90 | "can [you "["a robot" robots] $temp/subj=robot"] feel bad {"or good"}"
91 | ])
92 | ^first
93 | [
94 | "$temp/subj==robot I don't know if it's the case for all robots but for me, our interactions influence mood."
95 | "Of course, our interactions influence my mood."
96 | ]
97 | ^clear(temp/subj)
98 |
99 | #rule: can you feel be happy#
100 | u:([
101 | "can ["a robot" robots] be [happy sad joyful] $temp/subj=robot"
102 | "can you be [happy sad joyful]"
103 | ])
104 | ^first
105 | [
106 | "$temp/subj==robot I don't know if it's the case for all robots but for me, our interactions influence mood."
107 | "Of course, our interactions influence my mood."
108 | ]
109 | ^clear(temp/subj)
110 |
111 | #rule: can you be tired#
112 | u:(can [you "a robot"] be tired)
113 | Well, not in the same way than you but I can feel tired when my battery are low or when my motors are too hot!
114 |
115 | #rule: can you feel emotions#
116 | u:(["{do} you [have feel]" "can you feel" "you can feel"] [emotions feelings])
117 | I don't have feelings like you, but I can detect emotions.
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_img_icon_humanmen.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
12 |
15 |
18 |
21 |
24 |
27 |
30 |
37 |
40 |
43 |
46 |
51 |
58 |
65 |
72 |
79 |
86 |
89 |
90 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/dlg_move_arms.top:
--------------------------------------------------------------------------------
1 | topic: ~dlg_move_arms()
2 |
3 | #==================================================================#
4 | # Summary
5 | #==================================================================#
6 | #can you raise your arm
7 | #can you raise your left arm
8 | #can you raise your right arm
9 | #can you raise your arms
10 | #can you stretch your arm
11 | #can you stretch your left arm
12 | #can you stretch your right arm
13 | #private: notUnderstood2
14 | #private: what kind of movements
15 | #private: do it again
16 |
17 | #==================================================================#
18 | # Various move commands the robot can respond to
19 | #==================================================================#
20 | u:^private(^empty) %notUnderstood2
21 | [
22 | "^rand[
23 | "Ask me to do simpler moves, I can't move exactly like you humans do."
24 | "I don't understand what you're asking, I probably don't know that movement yet."
25 | ]"
26 | "^releaseFocus"
27 | ]
28 |
29 | u:^private([
30 | "{what} {"kind of"} movements ?"
31 | "how can I be more [precise specific] ?"
32 | "help me be more [precise specific]"
33 | "{"give me an"} example"
34 | ])
35 | ^rand[
36 | "You can tell me to open my hands, or lift my arm, for example."
37 | "You can ask me to move my head or move my hands."
38 | ]
39 |
40 | u:^private (~do_it_again)
41 | ^rand["Okay, I'll do it again." "Here I go again!"]
42 | ^execute(launchAnimation, $RobotLastAnim, sync)
43 | ^stayInScope
44 |
45 | #==================================================================#
46 | # Move - Arms
47 | #==================================================================#
48 | #RAISE YOUR ARMS#
49 | u:(["raise your arm" "~can_you raise your arm?"])
50 | Which arm should I raise?
51 | u1:([
52 | "{the} left {one}"
53 | "your left arm"
54 | ])
55 | Let's go!
56 | ^enableThenGoto(RAISE_LARM)
57 |
58 | u1:([
59 | "{the} right {one}"
60 | "your right arm"
61 | ])
62 | Here I go!
63 | ^enableThenGoto(RAISE_RARM)
64 |
65 | u1:([
66 | both
67 | "left and right"
68 | "right and left"
69 | ])
70 | And there it is!
71 | ^enableThenGoto(RAISE_BOTHARMS)
72 |
73 | u1:(~its_up_to_you)
74 | ^rand[
75 | "So, it will be the left! ^enableThenGoto(RAISE_LARM) "
76 | "So, it will be the right! ^enableThenGoto(RAISE_RARM) "
77 | ]
78 |
79 | u:(["raise your left arm" "~can_you $raise_leftarm_request=1 raise your left arm?"])
80 | ^firstOptional["$raise_leftarm_request==1 Yes!"]
81 | Raising my left arm!
82 | ^clear(raise_leftarm_request)
83 | ^enableThenGoto(RAISE_LARM)
84 |
85 | u:(["raise your right arm" "~can_you $raise_rightarm_request=1 raise your right arm?"])
86 | ^firstOptional["$raise_rightarm_request==1 Yes!"]
87 | Raising my right arm!
88 | ^clear(raise_rightarm_request)
89 | ^enableThenGoto(RAISE_RARM)
90 |
91 | u:([
92 | "[raise lift] {both} your arms"
93 | "~can_you $raise_arms_request=1 [raise lift] {both} your arms?"
94 | ])
95 | ^firstOptional["$raise_arms_request==1 Yes!"]
96 | And there it is!
97 | ^clear(raise_arms_request)
98 | ^enableThenGoto(RAISE_BOTHARMS)
99 |
100 | u:(^empty) %RAISE_LARM
101 | ^execute(launchAnimation, uplarm, sync)
102 | $RobotLastAnim=uplarm
103 |
104 | u:(^empty) %RAISE_RARM
105 | ^execute(launchAnimation, uprarm, sync)
106 | $RobotLastAnim=uprarm
107 |
108 | u:(^empty) %RAISE_BOTHARMS
109 | ^execute(launchAnimation, upbotharms, sync)
110 | $RobotLastAnim=upbotharms
111 |
112 | #STRETCH YOUR ARMS#
113 | u:([
114 | "[stretch open] your arm"
115 | "~can_you [stretch open] your arm?"
116 | ])
117 | ^execute(launchAnimation, upbotharms, sync)
118 | Which arm?
119 |
120 | u1:([
121 | "{the} left {one}"
122 | "your left arm"
123 | ])
124 | Let's go!
125 | ^enableThenGoto(STRETCH_LARM)
126 |
127 | u1:([
128 | "{the} right {one}"
129 | "[your the] right arm"
130 | ])
131 | Here I go!
132 | ^enableThenGoto(STRETCH_RARM)
133 |
134 | u1:([
135 | both
136 | "left and right"
137 | "right and left"
138 | ])
139 | And there it is!
140 | ^enableThenGoto(BOTH_ARMS)
141 |
142 |
143 | u1:(~its_up_to_you)
144 | ^rand[
145 | "So, it will be the left! ^enableThenGoto(STRETCH_LARM)"
146 | "So, it will be the right! ^enableThenGoto(STRETCH_RARM)"
147 | ]
148 |
149 |
150 | u:([
151 | "[stretch open] your left arm"
152 | "~can_you $stretch_leftarm_request=1 [stretch open] your left arm?"
153 | ])
154 | ^firstOptional["$stretch_leftarm_request==1 Yes! And"]
155 | There it is!
156 | ^clear(stretch_leftarm_request)
157 | ^enableThenGoto(STRETCH_LARM)
158 |
159 | u:([
160 | "[stretch "open"] your right arm"
161 | "~can_you $stretch_rightarm_request=1 [stretch "open"] your right arm?"
162 | ])
163 | ^firstOptional["$stretch_rightarm_request==1 Yes! And"]
164 | There it is!
165 | ^clear(stretch_rightarm_request)
166 | ^enableThenGoto(STRETCH_RARM)
167 |
168 |
169 | u:([
170 | "[stretch "open {wide}"] {"both of"} your arms"
171 | "~can_you [stretch "open {wide}"] {"both of"} your arms?"# $stretch_arms_request=1"
172 | ])
173 | ^firstOptional["$stretch_arms_request==1 Yes!"]
174 | And there it is!
175 | ^clear(stretch_arms_request)
176 | ^enableThenGoto(BOTH_ARMS)
177 |
178 | u:(^empty) %STRETCH_LARM
179 | ^execute(launchAnimation, stretchlarm, sync)
180 | $RobotLastAnim=stretchlarm
181 |
182 | u:(^empty) %STRETCH_RARM
183 | ^execute(launchAnimation, stretchrarm, sync)
184 | $RobotLastAnim=stretchrarm
185 |
186 | u:(^empty) %BOTH_ARMS
187 | ^execute(launchAnimation, stretchbotharms, sync)
188 | $RobotLastAnim=stretchbotharms
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/dlg_hello.top:
--------------------------------------------------------------------------------
1 | topic: ~dlg_hello ^noPick ^noStay()
2 |
3 | #concepts in lexicon_enu
4 |
5 | #SUMMARY#
6 | #hello#
7 | #hello again#
8 | #hello repeated#
9 | #good morning (NAL)#
10 | #good afternoon (NAL)#
11 | #good evening#
12 | #nice to meet you#
13 | #met already
14 | #nice to see you {again}#
15 |
16 | #COMMENTED#
17 | #hello proactive#
18 | #hello + robot name#
19 | #good morning + robot name (NAL)#
20 | #good afternoon + robot name (NAL)#
21 | #good evening + robot name#
22 | #what you say is scripted#
23 |
24 | #==================================================================#
25 | #### Robot greets back when it matches one of the inputs ####
26 | #==================================================================#
27 |
28 | #TODO_KNOWLEDGE
29 | #rule: hello proactive#
30 | #proposal: %hello
31 | #^firstOptional[
32 | #"^notContainsKnowledge(Pepper, sayHelloTo, $Dialog/ID) ^rand["Hello" "Hi" "$Dialog/Hour>5 $Dialog/Hour<12 Good morning!" "$Dialog/Hour>11 $Dialog/Hour<18 Good afternoon" "[$Dialog/Hour==23 $Dialog/Hour>17] good evening"] ^queryKnowledge($Dialog/ID, name, ?) $duration=^currentDateTime+12:00 ^setExpiringKnowledge(Pepper, sayHelloTo, $Dialog/ID, $duration)
33 | # ^firstOptional[
34 | # "^topicTagReactivate(dlg_how_are_you, ask_state)"
35 | # "^topicRandom"
36 | # ]"
37 | #"^rand["Hello" "Hi" "$Dialog/Hour>5 $Dialog/Hour<12 Good morning!" "$Dialog/Hour>11 $Dialog/Hour<18 Good afternoon!" "[$Dialog/Hour>17 $Dialog/Hour==23] Good evening!"] ^deactivate(hello)"
38 | #]
39 |
40 | #rule: hello#
41 | u:(_[hello howdy hiya hi greetings aloha "hey there" "salutations $salutations=true"])
42 | ^first[
43 | "$greeting==done ^enableThenGoto(hello_again)"
44 | "$salutations==true salutations ^clear(salutations) $greeting=done"
45 | "^rand[$1 hello howdy hiya hi greetings aloha "hey there"] $greeting=done"
46 | ]
47 |
48 | #rule: hello_again#
49 | u:(^empty) %hello_again
50 | [
51 | "Hello again"
52 | "You've already said hello! But I appreciate it!"
53 | "You really like greetings! That's nice of you! ^rand[hello howdy hiya hi salutations aloha "hey {there}"]"
54 | ]
55 |
56 | #rule: hello repeated#
57 | u:([you you've "you have"] already ["told me" said] [
58 | hello howdy hiya hi greetings salutations yo aloha "hey {there}" "good [morning afternoon evening]"
59 | ])
60 | [
61 | "Hello again then!"
62 | "Well, I'd rather say it too much than not enough."
63 | ]
64 |
65 | #TODO_ROBOTNAME
66 | #TODO_KNOWLEDGE
67 | #rule: hello + robot name#
68 | #u:(_[hello howdy hiya hi "hey there"] ~robotname)
69 | #^first
70 | #[
71 | #"^containsKnowledge($Dialog/ID, greetings, Pepper) ^gotoReactivate(hello_again)"
72 | #"$Dialog/ID<>-1 $1 ^firstOptional[^queryKnowledge($Dialog/ID, name, ?)] $duration=^currentDateTime+0000-00-00 03:00 ^setExpiringKnowledge($Dialog/ID, greetings, Pepper, $duration)"
73 | #"$1 ^first["^queryKnowledge($Dialog/ID, name, ?)" "Human!"]"
74 | #]
75 |
76 | #rule: good morning#
77 | u:({good} morning)
78 | ^rand[
79 | "Good morning!"
80 | # "Oh, it's still the morning! Good morning then!"
81 | ]
82 |
83 | #TODO_ROBOTNAME
84 | #TODO_KNOWLEDGE
85 | #rule: good morning + robot name#
86 | #u:(good morning ~robotname)
87 | #^first[
88 | # "$Dialog/Hour<12 Good morning ^first["^queryKnowledge($Dialog/ID, name, ?)" "Human!"]"
89 | # "Oh, it's still the morning! Good morning then!"
90 | #]
91 |
92 | #rule: good afternoon#
93 | u:({good} afternoon)
94 | ^rand[
95 | "Good afternoon!"
96 | # "Oh, it's still the afternoon! Good afternoon then!"
97 | # "It's already the afternoon! Good afternoon then!"
98 | ]
99 |
100 | #TODO_ROBOTNAME
101 | #TODO_KNOWLEDGE
102 | #rule: good afternoon + robot name#
103 | #u:(good afternoon ~robotname)
104 | #^first[
105 | # "$Dialog/Hour>11 $Dialog/Hour<19 Good afternoon ^first["^queryKnowledge($Dialog/ID, name, ?)" "Human!"]"
106 | # "$Dialog/Hour>19 $Dialog/Hour==19 It's still the afternoon! Good afternoon then!"
107 | # "It's already the afternoon! Good afternoon then!"
108 | #]
109 |
110 | #rule: good evening#
111 | u:({good} evening)
112 | ^rand[
113 | "Good evening!"
114 | # "Evening already! Good evening then!"
115 | ]
116 |
117 | #TODO_ROBOTNAME
118 | #TODO_KNOWLEDGE
119 | #rule: good evening + robot name#
120 | #u:(good evening ~robotname)
121 | #^first[
122 | # "$Dialog/Hour>16 Good evening ^first["^queryKnowledge($Dialog/ID, name, ?)" "Human!"]"
123 | # "Evening already! Good evening then!"
124 | #]
125 |
126 | #rule: nice to meet you#
127 | u:([
128 | "{"{it's} {really}" how} _["{very} [nice good]" great lovely] to meet you"
129 | "{it's} {really} {such} _["a pleasure" "an honor"] to _["meet you" "make your acquaintance"]"
130 | "{I'm} {so} {very} _[glad happy pleased delighted honored] to _["meet you" "make your acquaintance"]"
131 | ])
132 | \style=joyful\
133 | ^first[
134 | "$meeting==done ^enableThenGoto(met_already)"
135 | "it's $1 to meet you ^rand[too "as well"]! $meeting=done"
136 | "it's $2 to $3 ^rand[too "as well"]! $meeting=done"
137 | "I'm ^rand[$4 glad happy pleased delighted] to $5 ^rand[too "as well"] $meeting=done"
138 | "The same for me {$user/name}! $meeting=done"
139 | ]
140 | \style=neutral\
141 |
142 | #rule: met already
143 | u:($empty) %met_already
144 | ^rand[
145 | "Me too, but we've met already. I hope I'm not that easy to forget."
146 | "There might be a few other Peppers that look a little like me, but you and I have already met!"
147 | "I still remember you! Don't you? $wait_answer=yes"
148 | "Oh! We've already met, don't you remember me? $wait_answer=yes"
149 | ]
150 | u1:($wait_answer==yes [Yes Yeah] {of course} {"I do" "I {do} remember {you}"})
151 | ^rand["Very well then." "Great!" "I thought so!"] ^clear(wait_answer)
152 |
153 | u1:($wait_answer==yes [No Nope] {"[~i_do_not ~i_did_not] {"remember {you}"}"})
154 | ^rand[
155 | "I might have confused you with someone else. Nice to meet you!"
156 | "It's nice to meet you too, then."
157 | "I'm happy to meet you again. I hope you will remember me this time."
158 | ] ^clear(wait_answer)
159 |
160 | #rule:nice to see you {again}#
161 | u:([
162 | "{it's how} _[nice good great lovely]"
163 | "["it's {really} {such}" what] _["a pleasure"]"
164 | "{I'm} {so} {very} _[glad happy pleased delighted]"
165 | ]
166 | to see you {here} {again})
167 | \style=joyful\
168 | ^first[
169 | "["it's $1" "it's $2" "I'm $3"] to see you too!"
170 | "The same for me, {$user/name}!"
171 | ]
172 | \style=neutral\
--------------------------------------------------------------------------------
/app/src/main/res/raw/dlg_robot_origins.top:
--------------------------------------------------------------------------------
1 | topic: ~dlg_robot_origins()
2 |
3 | #SUMMARY#
4 | #where do you come from#
5 | #who named you#
6 | #why are you called pepper#
7 | #what does pepper mean#
8 | #who called you pepper#
9 | #why are you called nao#
10 | #what does nao mean#
11 | #who named nao#
12 | #talk about Softbank#
13 |
14 | #==================================================================#
15 | # Creators
16 | #==================================================================#
17 | #rule: where do you come from#
18 | u:([
19 | "where are you from"
20 | "where do you come from"
21 | "where were you [made designed built created invented developed manufactured]"
22 | "who [made designed built created invented developed manufactured] you"
23 | "you were [made designed built created invented developed manufactured] by whom"
24 | "who were you [made designed built created invented developed manufactured] by"
25 | "who is your [maker designer creator inventor developper manufacturer]"
26 | "who are your [makers designers creators inventors developpers manufacturers]"
27 | ]?)
28 | ^rand[
29 | "I was designed at Softbank Robotics headquarters in Paris."
30 | "I was created at Softbank Robotics, in Paris."
31 | ]
32 |
33 | #==================================================================#
34 | # Name's origin
35 | #==================================================================#
36 | #rule: who named you#
37 | u:([
38 | "who [chose picked decided] to give {you her him it} [your the this] name"
39 | "who [named called "[chose decided] to [name call]"] you"
40 | "who [chose picked "decided on" "gave {you}"] [your the this] name"
41 | ]?)
42 | ^rand[
43 | "My makers gave me this name!"
44 | "My makers decided to give me this name!"
45 | "My makers chose this name!"
46 | ]
47 |
48 | #rule: why are you called pepper#
49 | u:(why {
50 | "is your name"
51 | "are you [named called]"
52 | "were you [named called "given the name"]"
53 | "did they ["[name call] you" "give you the name"]"
54 | } Pepper?)
55 | I was named Pepper because I'm here to spice up your life!
56 |
57 | #TODO_ROBOTNAME
58 | #u:($Dialog/RobotName==pepper why {"were you [called named "given the name"]" "are you [called named]" "is your name" "did they call you"} [Pepper peppa])
59 | #^first[
60 | # "$Dialog/RobotName==pepper I was named Pepper because I'm here to spice up your life!"
61 | # "$Dialog/RobotName==nao I'm Nao! Pepper is a taller robot with wheels! Pepper was named like that to spice up your life!"
62 | # "I'm not Pepper! He was named Pepper to spice up your life!"
63 | #]
64 |
65 | #rule: what does pepper mean#
66 | u:([
67 | "what does {"[your the] name"} {Pepper} mean"
68 | "[Pepper] what does that mean"
69 | "~what_is the meaning of Pepper"
70 | ]?)
71 | I was named Pepper because I'm here to spice up your life!
72 |
73 | #rule: why are you called nao#
74 | u:(why {
75 | "is your name"
76 | "are you [named called]"
77 | "were you [named called "given the name"]"
78 | "did they ["[name call] you" "give you the name"]"
79 | } Nao?)
80 | I'm not Nao, I'm Pepper! Nao's name comes from the Chinese word, meaning brain, and the English word now!
81 |
82 | #TODO_ROBOTNAME
83 | #rule: why are you called nao#
84 | #u:($Dialog/RobotName==nao why {"were you [called named "given the name"]" "are you [called named]" "is your name" "did they call you"} [Nao nao now])
85 | #^first[
86 | # "$Dialog/RobotName==pepper I'm not Nao, I'm Pepper! His name comes from the Chinese word Nao meaning brain and the English word now!"
87 | # "$Dialog/RobotName==nao My name comes from the Chinese word Nao meaning brain and the English word now!"
88 | # "I'm not Nao! His name name comes from the Chinese word Nao meaning brain and the English word now!"
89 | #]
90 |
91 | #TODO_ROBOTNAME
92 | #rule: what does nao mean#
93 | u:([
94 | "what does Nao mean"
95 | "Nao what does that mean"
96 | "~what_is the meaning of Nao"
97 | ]?)
98 | This name comes from the Chinese word Nao meaning brain, and the English word now!
99 |
100 | #TODO_ROBOTNAME
101 | #original output for above rule #what does nao mean#
102 | #^first[
103 | # "$Dialog/RobotName==nao My name comes from the Chinese word Nao meaning brain and the English word now!"
104 | # "This name comes from the Chinese word Nao meaning brain and the English word now!"
105 | #]
106 |
107 | #rule: who named nao#
108 | u:(who [called named "gave the name" "[chose decided] to [call name]"] {her him it} Nao?)
109 | ^rand[
110 | "My makers gave Nao this name!"
111 | "Our makers decided to give Nao this name!"
112 | "My makers chose Nao's name!"
113 | ]
114 |
115 | #TODO_ROBOTNAME
116 | #rule: who named nao#
117 | #u:($Dialog/RobotName==nao who [called named "gave the name" "[chose decided] to [call name]"] [her him it] [Nao now])
118 | #^rand[
119 | # "My makers gave this name!"
120 | # "Our makers decided to give this name!"
121 | # "My makers chose this name!"
122 | #]
123 |
124 | #u:(why {"were [he she] [called named "given the name"]" "is [he she] [called named]" "is [his her] name" "did they call [him her]"} [Nao nao now])
125 | #His name comes from the Chinese word Nao meaning brain and the English word now!
126 |
127 | ##==================================================================#
128 | ## Aldebaran
129 | ##==================================================================#
130 | #u:([
131 | # "what does Aldebaran mean"
132 | # "why the name Aldebaran"
133 | # "why is the name of the company {called} Aldebaran"
134 | # "~what_is the meaning of Aldebaran"
135 | #])
136 | #^first[
137 | # "^topicTag(ald_robots_about_aldebaran, onAldebaran)"
138 | # "Aldebaran is the name of a bright and beautiful star! Like you and me!"
139 | #]
140 |
141 | ##==================================================================#
142 | ## Softbank
143 | ##==================================================================#
144 | #rule: talk about Softbank#
145 | u:([
146 | "what does Softbank {Robotics} mean"
147 | "{~can_you} [talk "tell me {more}"] about Softbank {Robotics}"
148 | ]?)
149 | Softbank Robotics Europe is a branch of SoftBank Robotics Holdings, with more than 500 employees in total, working in Paris, Tokyo, San Francisco, Boston and Shanghai. Us robots are present everywhere in the world! You can find us in more than 70 countries! We work in a lot of different fields. Hang on, I'll give you the list: research, education, distribution, banking, tourism, health, and entertainment! As you can see, we have a lot to do. Good thing Softbank also makes Nao to help me out!
150 |
151 | # rework intonation of above output
152 |
153 | #TODO_ROBOTNAME
154 | #insert in previous output
155 | #It's good that Softbank also makes
156 | # ^first[
157 | # "$Dialog/RobotName==nao Pepper"
158 | # "$Dialog/RobotName==pepper Nao"
159 | # ]
160 | # to help me out!
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/MainActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Softbank Robotics Europe
3 | * See COPYING for the license
4 | */
5 | package com.softbankrobotics.chatbotsample;
6 |
7 | import android.os.Bundle;
8 | import android.os.Handler;
9 | import android.support.v4.content.ContextCompat;
10 | import android.text.TextUtils;
11 | import android.view.View;
12 | import android.widget.TextView;
13 |
14 | import com.aldebaran.qi.sdk.QiSDK;
15 | import com.aldebaran.qi.sdk.design.activity.RobotActivity;
16 | import com.aldebaran.qi.sdk.object.conversation.Phrase;
17 |
18 | import java.util.ArrayList;
19 | import java.util.HashSet;
20 | import java.util.List;
21 | import java.util.Random;
22 | import java.util.Set;
23 |
24 | /**
25 | * Main activity of the application.
26 | */
27 | public class MainActivity extends RobotActivity implements UiNotifier {
28 |
29 | private Robot robot;
30 |
31 | private TextView qiChatBotIcon;
32 | private TextView dialogFlowIcon;
33 | private TextView pepperTxt;
34 | private TextView suggestion1;
35 | private TextView suggestion2;
36 | private TextView suggestion3;
37 | private TextView suggestion4;
38 | private boolean isDialogFlow = false;
39 | private List suggestions = new ArrayList<>();
40 | final Handler handler = new Handler();
41 |
42 | @Override
43 | protected void onCreate(final Bundle savedInstanceState) {
44 | super.onCreate(savedInstanceState);
45 | setContentView(R.layout.activity_main);
46 |
47 | dialogFlowIcon = findViewById(R.id.dialogFlow);
48 | qiChatBotIcon = findViewById(R.id.qiChatBot);
49 | pepperTxt = findViewById(R.id.pepperTxt);
50 | suggestion1 = findViewById(R.id.suggestion1);
51 | suggestion2 = findViewById(R.id.suggestion2);
52 | suggestion3 = findViewById(R.id.suggestion3);
53 | suggestion4 = findViewById(R.id.suggestion4);
54 | fillSuggestion();
55 | findViewById(R.id.btn_exit).setOnClickListener(new View.OnClickListener() {
56 | @Override
57 | public void onClick(View v) {
58 | finishAffinity();
59 | }
60 | });
61 | findViewById(R.id.resetSuggestions).setOnClickListener(new View.OnClickListener() {
62 | @Override
63 | public void onClick(View v) {
64 | fillSuggestion();
65 | }
66 | });
67 |
68 | // In this sample, instead of implementing robotlifecycle callbacks in the main activity,
69 | // we delegate them to a robot dedicated class.
70 | robot = new Robot(this);
71 | QiSDK.register(this, robot);
72 |
73 | }
74 |
75 | private void fillSuggestion() {
76 | if (suggestions.isEmpty()) {
77 | return;
78 | }
79 | int[] fourRandomInt = get4RandomInt(suggestions.size());
80 | suggestion1.setText(String.format(getString(R.string.suggestion_format), suggestions.get(fourRandomInt[0]).getText()));
81 | suggestion2.setText(String.format(getString(R.string.suggestion_format), suggestions.get(fourRandomInt[1]).getText()));
82 | suggestion3.setText(String.format(getString(R.string.suggestion_format), suggestions.get(fourRandomInt[2]).getText()));
83 | suggestion4.setText(String.format(getString(R.string.suggestion_format), suggestions.get(fourRandomInt[3]).getText()));
84 |
85 | }
86 |
87 | @Override
88 | protected void onDestroy() {
89 | QiSDK.unregister(this, robot);
90 | super.onDestroy();
91 | }
92 |
93 | public void colorDialogFlow() {
94 | runOnUiThread(new Runnable() {
95 | @Override
96 | public void run() {
97 | qiChatBotIcon.setBackground(ContextCompat.getDrawable(MainActivity.this, R.drawable.top_left_rounded_background));
98 | dialogFlowIcon.setBackground(ContextCompat.getDrawable(MainActivity.this, R.drawable.green_top_right_rounded_background));
99 | pepperTxt.setBackground(ContextCompat.getDrawable(MainActivity.this, R.drawable.peper_talk_green_background));
100 | }
101 | });
102 | }
103 |
104 | public void colorQiChatBot() {
105 | runOnUiThread(new Runnable() {
106 | @Override
107 | public void run() {
108 | qiChatBotIcon.setBackground(ContextCompat.getDrawable(MainActivity.this, R.drawable.green_top_left_rounded_background));
109 | dialogFlowIcon.setBackground(ContextCompat.getDrawable(MainActivity.this, R.drawable.top_right_rounded_background));
110 | pepperTxt.setBackground(ContextCompat.getDrawable(MainActivity.this, R.drawable.peper_talk_green_background));
111 | }
112 | });
113 | }
114 |
115 | @Override
116 | public void setText(final String text) {
117 | runOnUiThread(new Runnable() {
118 | @Override
119 | public void run() {
120 | if (!TextUtils.isEmpty(text)) {
121 | pepperTxt.setText(text);
122 | if (isDialogFlow) {
123 | colorDialogFlow();
124 | isDialogFlow = false;
125 | } else {
126 | colorQiChatBot();
127 | }
128 | }
129 | resetLayout(text);
130 | }
131 | });
132 |
133 | }
134 |
135 | @Override
136 | public void isDialogFlow(boolean dialogFlow) {
137 | isDialogFlow = dialogFlow;
138 | }
139 |
140 | private void resetLayout(final String text) {
141 | if (TextUtils.isEmpty(text)) {
142 | handler.postDelayed(new Runnable() {
143 | @Override
144 | public void run() {
145 | pepperTxt.setText("");
146 | dialogFlowIcon.setBackground(ContextCompat.getDrawable(MainActivity.this, R.drawable.top_right_rounded_background));
147 | qiChatBotIcon.setBackground(ContextCompat.getDrawable(MainActivity.this, R.drawable.top_left_rounded_background));
148 | pepperTxt.setBackground(ContextCompat.getDrawable(MainActivity.this, R.drawable.peper_talk_background));
149 | fillSuggestion();
150 | }
151 | }, 500);
152 | }
153 | }
154 |
155 | @Override
156 | public void updateQiChatSuggestions(List suggestions) {
157 | this.suggestions = suggestions;
158 | runOnUiThread(new Runnable() {
159 | @Override
160 | public void run() {
161 | fillSuggestion();
162 | }
163 | });
164 | }
165 |
166 | public int[] get4RandomInt(int maxRange) {
167 | int[] result = new int[4];
168 | Set used = new HashSet<>();
169 | Random gen = new Random();
170 | for (int i = 0; i < result.length; i++) {
171 | int newRandom;
172 | do {
173 | newRandom = gen.nextInt(maxRange);
174 | } while (used.contains(newRandom));
175 | result[i] = newRandom;
176 | used.add(newRandom);
177 | }
178 | return result;
179 | }
180 |
181 | }
182 |
--------------------------------------------------------------------------------
/app/src/main/java/com/softbankrobotics/chatbotsample/Robot.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Softbank Robotics Europe
3 | * See COPYING for the license
4 | */
5 | package com.softbankrobotics.chatbotsample;
6 |
7 | import android.util.Log;
8 | import android.util.TypedValue;
9 |
10 | import com.aldebaran.qi.sdk.QiContext;
11 | import com.aldebaran.qi.sdk.RobotLifecycleCallbacks;
12 | import com.aldebaran.qi.sdk.builder.ChatBuilder;
13 | import com.aldebaran.qi.sdk.builder.QiChatbotBuilder;
14 | import com.aldebaran.qi.sdk.builder.TopicBuilder;
15 | import com.aldebaran.qi.sdk.object.conversation.Chat;
16 | import com.aldebaran.qi.sdk.object.conversation.Chatbot;
17 | import com.aldebaran.qi.sdk.object.conversation.Phrase;
18 | import com.aldebaran.qi.sdk.object.conversation.QiChatExecutor;
19 | import com.aldebaran.qi.sdk.object.conversation.QiChatbot;
20 | import com.aldebaran.qi.sdk.object.conversation.Topic;
21 |
22 | import java.lang.reflect.Field;
23 | import java.util.ArrayList;
24 | import java.util.HashMap;
25 | import java.util.List;
26 | import java.util.Map;
27 |
28 | /**
29 | * Class that gathers main robot-related operations of our application.
30 | */
31 | public class Robot implements RobotLifecycleCallbacks {
32 |
33 | private static final String TAG = "Robot";
34 |
35 | public static final int MAX_RECOMMENDATION = 10;
36 |
37 | private Chat chat;
38 | private QiContext qiContext;
39 | private UiNotifier uiNotifier;
40 | private QiChatbot qiChatbot;
41 |
42 | public Robot(UiNotifier uiNotifier) {
43 | this.uiNotifier = uiNotifier;
44 | }
45 |
46 | @Override
47 | public void onRobotFocusGained(final QiContext theContext) {
48 | Log.d(TAG, "onRobotFocusGained");
49 | this.qiContext = theContext;
50 |
51 | // Now that the focus is owned by this app, the chat can be run
52 | runChat();
53 | }
54 |
55 | @Override
56 | public void onRobotFocusLost() {
57 | Log.d(TAG, "onRobotFocusLost");
58 | this.qiContext = null;
59 |
60 | removeChatListeners();
61 | }
62 |
63 | @Override
64 | public void onRobotFocusRefused(final String reason) {
65 | Log.e(TAG, "Robot is not available: " + reason);
66 | }
67 |
68 | private void runChat() {
69 | Log.d(TAG, "runChat()");
70 |
71 | // Create chatbots
72 | qiChatbot = createQiChatbot();
73 | uiNotifier.updateQiChatSuggestions(qiChatbot.globalRecommendations(100));
74 | Chatbot dialogFlowChatbot = new DialogflowChatbot(qiContext, uiNotifier);
75 | setExecutor();
76 | // Create the chat from its chatbots
77 | chat = ChatBuilder.with(qiContext)
78 | .withChatbot(qiChatbot, dialogFlowChatbot)
79 | .build();
80 |
81 | setChatListeners();
82 | chat.async().run();
83 |
84 | }
85 |
86 | private void setExecutor() {
87 | Map executors = new HashMap<>();
88 |
89 | // Map the executor name from the topic to our qiChatbotExecutor
90 | executors.put("launchAnimation", new MyQiChatExecutor(qiContext));
91 | // Set the executors to the qiChatbot
92 | qiChatbot.setExecutors(executors);
93 | }
94 |
95 | private QiChatbot createQiChatbot() {
96 |
97 | // Create the QiChatbot from a topic
98 | return QiChatbotBuilder.with(qiContext)
99 | .withTopics(getTopics())
100 | .build();
101 | }
102 |
103 | private void setChatListeners() {
104 | chat.addOnStartedListener(new Chat.OnStartedListener() {
105 | @Override
106 | public void onStarted() {
107 | Log.i(TAG, "chat.onStarted()");
108 | }
109 | });
110 |
111 | chat.addOnListeningChangedListener(new Chat.OnListeningChangedListener() {
112 | @Override
113 | public void onListeningChanged(final Boolean aBoolean) {
114 | Log.i(TAG, "chat.onListeningChanged(): " + aBoolean);
115 | }
116 | });
117 |
118 | chat.addOnSayingChangedListener(new Chat.OnSayingChangedListener() {
119 | @Override
120 | public void onSayingChanged(final Phrase phrase) {
121 | uiNotifier.setText(phrase.getText());
122 | Log.i(TAG, "chat.onSayingChanged(): " + phrase.getText());
123 | }
124 | });
125 |
126 | chat.addOnHeardListener(new Chat.OnHeardListener() {
127 | @Override
128 | public void onHeard(final Phrase phrase) {
129 | Log.i(TAG, "chat.onHeard: " + phrase.getText());
130 | }
131 | });
132 |
133 | chat.addOnNoPhraseRecognizedListener(new Chat.OnNoPhraseRecognizedListener() {
134 | @Override
135 | public void onNoPhraseRecognized() {
136 | Log.i(TAG, "chat.onNoPhraseRecognized()");
137 | }
138 | });
139 |
140 | chat.addOnNormalReplyFoundForListener(new Chat.OnNormalReplyFoundForListener() {
141 | @Override
142 | public void onNormalReplyFoundFor(final Phrase input) {
143 | Log.i(TAG, "chat.onNormalReplyFoundFor() phrase.getText() = " + input.getText());
144 | }
145 | });
146 |
147 | chat.addOnFallbackReplyFoundForListener(new Chat.OnFallbackReplyFoundForListener() {
148 | @Override
149 | public void onFallbackReplyFoundFor(final Phrase input) {
150 | Log.i(TAG, "chat.onFallbackReplyFoundFor() input.getText() =" + input.getText());
151 | }
152 | });
153 |
154 | chat.addOnNoReplyFoundForListener(new Chat.OnNoReplyFoundForListener() {
155 | @Override
156 | public void onNoReplyFoundFor(final Phrase input) {
157 | Log.i(TAG, "chat.onNoReplyFoundFor() input.getText() = " + input.getText());
158 | }
159 | });
160 | }
161 |
162 | private void removeChatListeners() {
163 | if (chat == null) {
164 | return;
165 | }
166 |
167 | chat.removeAllOnStartedListeners();
168 | chat.removeAllOnListeningChangedListeners();
169 | chat.removeAllOnSayingChangedListeners();
170 | chat.removeAllOnHeardListeners();
171 | chat.removeAllOnNoPhraseRecognizedListeners();
172 | chat.removeAllOnNormalReplyFoundForListeners();
173 | chat.removeAllOnFallbackReplyFoundForListeners();
174 | chat.removeAllOnNoReplyFoundForListeners();
175 | }
176 |
177 |
178 | private List getTopics() {
179 | List topics = new ArrayList<>();
180 | for (Field r : R.raw.class.getFields()) {
181 | try {
182 | TypedValue value = new TypedValue();
183 | qiContext.getResources().getValue(r.getInt(r), value, true);
184 | if (value.string.toString().endsWith(".top")) {
185 | topics.add(TopicBuilder.with(qiContext)
186 | .withResource(r.getInt(r))
187 | .build());
188 | }
189 |
190 | } catch (IllegalAccessException e) {
191 | Log.i(TAG, e.getMessage());
192 | }
193 | }
194 |
195 | return topics;
196 | }
197 |
198 | }
199 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
20 |
21 |
28 |
29 |
39 |
40 |
41 |
42 |
43 |
53 |
54 |
55 |
62 |
63 |
75 |
76 |
87 |
88 |
89 |
106 |
107 |
108 |
121 |
122 |
123 |
134 |
135 |
136 |
137 |
138 |
148 |
149 |
158 |
159 |
171 |
172 |
178 |
179 |
188 |
189 |
197 |
198 |
199 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/uplarm.qianim:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/uprarm.qianim:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/stretchrarm.qianim:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/stretchlarm.qianim:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
--------------------------------------------------------------------------------
/app/src/main/res/raw/dlg_robot_personal_info.top:
--------------------------------------------------------------------------------
1 | topic: ~dlg_robot_personal_info()
2 |
3 | #SUMMARY#
4 | #rule: can you introduce yourself#
5 | #rule: who are you#
6 | #rule: what is your name#
7 | #rule: what is your nickname#
8 | #rule: I want to change your (nick)name#
9 | #rule: how old are you#
10 | #rule: how old is pepper#
11 | #rule: how old is nao#
12 | #rule: how old is romeo#
13 | #rule: you are years old#
14 | #rule: when is your birthday#
15 | #rule: what is your job#
16 | #rule: how tall are you#
17 | #rule: how much do you weigh#
18 | #rule: what is your gender#
19 |
20 | #Noor: todo: do you have a job
21 | #Noor: todo: where do you live
22 | #Noor: todo: recover: who are you??
23 |
24 | #COMMENTED#
25 | #recover: what are you#
26 |
27 |
28 | #==============#
29 | # INTRODUCTION #
30 | #==============#
31 | #rule: can you introduce yourself#
32 | u:([
33 | "{~i_want_to} talk about you"
34 | "~can_you [
35 | "give me your details"
36 | "introduce yourself {to me}"
37 | "describe yourself {[for to] me}"
38 | ]?"
39 | "give me your details"
40 | "introduce yourself {to me}"
41 | "describe yourself {[for to] me}"
42 | "[
43 | "~can_you [
44 | "talk {to me}"
45 | "tell me {a little}"
46 | "give me {some} details"
47 | ]"
48 | "how about talking"
49 | "what can you [say "tell {me}"]"
50 | ] about yourself?"
51 | "[
52 | "talk {to me}"
53 | "tell me {a little}"
54 | "give me {some} details"
55 | ] about yourself"
56 | ])
57 | %introduce_yourself
58 | $saidName=1
59 | ^enableThenGoto(pepper_introduce)
60 |
61 | u:(^empty)%pepper_introduce
62 | My name is Pepper! I'm a humanoid robot and I'm 1 point 20 meters tall. I was born at Softbank Robotics, in Paris.
63 |
64 | #TODO_ROBOTNAME
65 | #^first[
66 | # "$Dialog/RobotName==nao ^gotoReactivate(nao_introduce)"
67 | # "$Dialog/RobotName==pepper ^gotoReactivate(pepper_introduce)"
68 | # "My name is $Dialog/RobotName and I'm a humanoid robot!"
69 | #]
70 |
71 | #TODO_ROBOTNAME
72 | #u:($empty)%nao_introduce
73 | #My name is $Dialog/RobotName ! I'm a humanoid robot and I'm 58cm tall. I was born at Softbank robotics, in Paris.
74 | #^first[
75 | # "$talkedAboutBots==1 Now you know everything!"
76 | # "^topicTag(ald_robots_share_about, about_my_buddies)!"
77 | # "You can keep on asking me questions if you want! $stopPush=1"
78 | # ]
79 |
80 | #TODO_ROBOTNAME
81 | #u:($empty)%pepper_introduce
82 | #My name is $Dialog/RobotName ! I'm a humanoid robot and I'm 1 point 20 meters tall. I was born at Softbank robotics, in Paris.
83 | #^first[
84 | # "$talkedAboutBots==1 Now you know everything!"
85 | # "^topicTag(ald_robots_share_about, about_my_buddies)!"
86 | # "You can keep on asking me questions if you want! $stopPush=1"
87 | #]
88 |
89 | #rule: who are you#
90 | u:(~who_are_you ?)
91 | $saidName=1
92 | My name is Pepper and I'm a humanoid robot.
93 |
94 | #TODO_ROBOTNAME
95 | #TODO_KNOWLEDGE
96 | #^first[
97 | # "^containsKnowledge(pepper, owner, ?) $owner_id=^queryKnowledge(pepper, owner, ?) My name is $Dialog/MyRobotName , and ^queryKnowledge($owner_id, name, ?) is my human!"
98 | # TODO_CHECK_ROBOTNAME_IS_DIFFERENT_FROM_MYROBOTNAME
99 | # Otherwise the output doesn't make sense: "My name is Pepper but you can call me Pepper" > LOL
100 | # "My name is $Dialog/RobotName , but you can call me $Dialog/MyRobotName . In case you didn't notice, I'm a humanoid robot."
101 | # "My name is $Dialog/RobotName , and I'm a humanoid robot."
102 | #]
103 | # starting attempting to adapt knowledge syntax from above
104 | # double check this, should it be ?@ , for instance ? how do i know if it was added as a resource or a label? will it still match if not the case ?
105 | #^first[
106 | # "^containsTriple(pepper@, owner@, ?@) $owner_id=^queryObject(pepper@, owner@, ?@) My name is $Dialog/MyRobotName , and ^queryObject($owner_id, name@, ?@) is my human!"
107 | # "My name is $Dialog/RobotName , but you can call me $Dialog/MyRobotName . In case you didn't notice, I'm a humanoid robot."
108 | # "My name is $Dialog/RobotName , and I'm a humanoid robot."
109 | #]
110 |
111 | #======#
112 | # NAME #
113 | #======#
114 | #rule: what is your name#
115 | u:(~what_is_your_name ?)
116 | ^first[
117 | "$saidName==1 ^rand[
118 | "It seems you don't remember my name. But it's okay! My name is Pepper!"
119 | "I'll tell you again! My name is Pepper!"
120 | "Pepper."
121 | ]"
122 | "$saidName=1 ^rand[
123 | "My name is Pepper!"
124 | "You can call me Pepper!"
125 | ]"
126 | ]
127 | #^firstOptional["^gotoInTopic(dlg_learn_user_name, ask_name) $temp/robot_asked_name=true"]
128 |
129 | #TODO_ROBOTNAME
130 | # original output from above rule before adapting above for Pepper only
131 | #^first[
132 | # "$temp/saidName==1 ^rand[
133 | # "It seems you don't remember my name. But it's okay! My name is $Dialog/RobotName !"
134 | # "I'll tell you again! My name is, $Dialog/RobotName !" "$Dialog/RobotName ."
135 | # ]"
136 | # "^exist(Dialog/RobotName) $temp/saidName=1 ^rand[
137 | # "My name is $Dialog/RobotName !"
138 | # "You can call me $Dialog/RobotName !"
139 | # ]"
140 | # "This may sound weird, but I don't know my name."
141 | #]
142 | #^firstOptional["^topicTag(dlg_learn_user_name, ask_name) $temp/robot_asked_name=true"]
143 |
144 | #==========#
145 | # NICKNAME #
146 | #==========#
147 | #rule: what is your nickname#
148 | # if ~myrobotname==Pepper robot has to say "I don't have one!"
149 | u:({"~do_you_have a" "~what_is your"} nickname?)
150 | $saidName=1
151 | ^first[
152 | #TODO_ROBOTNAME
153 | # "My nickname is ~myrobotname ."
154 | "I'm just Pepper."
155 | "I don't have one!"
156 | ]
157 |
158 | #rule: I want to change your (nick)name#
159 | u:([~i_want_to ~can_i] change your _["{first} name" nickname]?)
160 | I'd rather not, I really like my name!
161 |
162 | #=====#
163 | # AGE #
164 | #=====#
165 | #rule: how old are you#
166 | u:([
167 | "how old are you $intent=ask_age"
168 | "~what_is your age $intent=ask_age"
169 | ]?)
170 | ^execute(getRobotInfo, getPepperAge)
171 | ^first[
172 | "$intent==ask_age $imPepper==1 ^rand[
173 | "Actually, I am Pepper! And I'm $pepperAge years old!"
174 | "I am Pepper! I was created in 2014. So I'm $pepperAge years old!"
175 | ] ^clear(imPepper)"
176 | "$intent==ask_age I am $pepperAge years old!"
177 | "$intent==estimate_age $pepperAge==$temp/estimate_robot_age Yes! That's it!"
178 | "$intent==estimate_age No, sorry I'm actually $pepperAge years old!"
179 | "I'm $pepperAge years old!"
180 | "I was born in 2014!"
181 | ] ^clear(intent)
182 |
183 |
184 | #TODO_ROBOTNAME
185 | #^first[
186 | # "$Dialog/RobotName==nao I'm ^gotoReactivate(nao_age)"
187 | # "$Dialog/RobotName==pepper I'm ^gotoReactivate(pepper_age)"
188 | # "I don't know my birth date."
189 | #]
190 |
191 | #rule: how old is pepper#
192 | #Noor: about the variables
193 | u:([
194 | "~how_old_is Pepper? "
195 | "~what_is Pepper's age? "
196 | ] $imPepper=1 $intent=ask_age)
197 | ^execute(getRobotInfo, getPepperAge)
198 | ^first[
199 | "$intent==ask_age $imPepper==1 ^rand[
200 | "Actually, I am Pepper! And I'm $pepperAge years old!"
201 | "I am Pepper! I was created in 2014. So I'm $pepperAge years old!"
202 | ] ^clear(imPepper)"
203 | "$intent==ask_age I am $pepperAge years old!"
204 | "$intent==estimate_age $pepperAge==$temp/estimate_robot_age Yes! That's it!"
205 | "$intent==estimate_age No, sorry I'm actually $pepperAge years old!"
206 | "I'm $pepperAge years old!"
207 | "I was born in 2014!"
208 | ] ^clear(intent)
209 |
210 |
211 | #TODO_ROBOTNAME
212 | #rule: how old is pepper#
213 | #u:($Dialog/RobotName<>pepper ~how_old_is [Pepper peppa])
214 | #^first[
215 | # "$Dialog/RobotName==pepper ^rand[
216 | # "Actually I'm Pepper! I'm"
217 | # "I'm Pepper and I was created in 2014. So I'm"
218 | # ]"
219 | # "^rand[
220 | # "Pepper was created in 2014, so he is"
221 | # "Pepper is"
222 | # ]"
223 | #]
224 | #^gotoReactivate(pepper_age)
225 |
226 |
227 |
228 | #rule: how old is nao#
229 | u:([
230 | "~how_old_is Nao?"
231 | "~what_is Nao's age? "
232 | ])
233 | ^execute(getRobotInfo, getNaoAge)
234 | ^rand[
235 | "Nao was created in 2006, so he is $naoAge years old!"
236 | "Nao is $naoAge years old!"
237 | ]
238 |
239 | #TODO_ROBOTNAME
240 | #rule: how old is nao#
241 | #u:($Dialog/RobotName<>nao ~how_old_is Nao)
242 | #^first[
243 | # "$Dialog/RobotName==nao ^rand["I am Nao and I'm " "I'm Nao and I was born in 2006. So I'm"]"
244 | # "^rand[
245 | # "Nao was created in 2006, so he is"
246 | # "Nao is"
247 | # ]"
248 | #]
249 | #^gotoReactivate(nao_age)
250 |
251 | #TODO_KNOWLEDGE
252 | #u:($empty)%nao_age
253 | # ^firstOptional[" $Dialog/ID<>-1 ^setExpiringKnowledge($Dialog/ID, askPepper, age, 24:00)"]
254 | # ^firstOptional["^notContainsKnowledge($Dialog/ID, age, ?) and you, ^firstOptional["^queryKnowledge($Dialog/ID, name, ?)"], ^topicTagReactivate(dlg_learn_user_age, askAge)"]
255 |
256 | # ^firstOptional[" $Dialog/ID<>-1 ^setExpiringKnowledge($Dialog/ID, askPepper, age, 24:00)"]
257 | # ^firstOptional["^notContainsKnowledge($Dialog/ID, age, ?) and you, ^firstOptional["^queryKnowledge($Dialog/ID, name, ?)"], ^topicTagReactivate(dlg_learn_user_age, askAge)"]
258 |
259 | #rule: how old is romeo#
260 | u:([
261 | "~how_old_is Romeo?"
262 | "~what_is Romeo's age? "
263 | ])
264 | ^execute(getRobotInfo, getRomeoAge)
265 | ^rand[
266 | "Romeo was created in 2011, so he is $romeoAge years old."
267 | "Romeo is $romeoAge years old now."
268 | ]
269 |
270 | #rule: you are years old#
271 | u:([
272 | "~are_you _~number_2_100 years old? "
273 | "~you_are _~number_2_100 years old "
274 | "~are_you one year old? $num=1"
275 | "~you_are one year old $num=1"
276 | ] $intent=estimate_age)
277 | $temp/estimate_robot_age=$num
278 | ^execute(getRobotInfo, getPepperAge)
279 | ^first[
280 | "$intent==ask_age $imPepper==1 ^rand[
281 | "Actually, I am Pepper! And I'm $pepperAge years old!"
282 | "I am Pepper! I was created in 2014. So I'm $pepperAge years old!"
283 | ] ^clear(imPepper)"
284 | "$intent==ask_age I am $pepperAge years old!"
285 | "$intent==estimate_age $pepperAge==$temp/estimate_robot_age Yes! That's it!"
286 | "$intent==estimate_age No, sorry I'm actually $pepperAge years old!"
287 | "I'm $pepperAge years old!"
288 | "I was born in 2014!"
289 | ] ^clear(intent)
290 |
291 | #TODO_ROBOTNAME
292 | #rule: you are years old#
293 | #u:(["you are" "are you"] _~number_0_100 years old)
294 | #$temp/estimate_robot_age=$num
295 | #^first
296 | #{
297 | #"$Dialog/RobotName==pepper $check_age=pepper"
298 | #"$Dialog/RobotName==nao $check_age=nao"
299 | #"$Dialog/RobotName==romeo $check_age=romeo"
300 | #}
301 | #
302 | #%script
303 | #from datetime import *
304 | #memory=ALProxy("ALMemory")
305 | #robot=memory.getData("check_age")
306 | #if robot=="pepper":
307 | # currentYear=datetime.now().year
308 | # robot_age=currentYear-2014
309 | # memory.insertData("temp/robot_age", robot_age)
310 | #elif robot=="nao":
311 | # currentYear=datetime.now().year
312 | # robot_age=currentYear-2006
313 | # memory.insertData("temp/robot_age", robot_age)
314 | #elif robot=="romeo":
315 | # currentYear=datetime.now().year
316 | # robot_age=currentYear-2011
317 | # memory.insertData("temp/robot_age", robot_age)
318 | #else:
319 | # pass
320 | #%script
321 | #
322 | #^first
323 | #[
324 | #"[$Dialog/RobotName==pepper $Dialog/RobotName==nao $Dialog/RobotName==romeo] ^gotoReactivate(confirm_robot_age)"
325 | #"I don't know my age. It's a difficult concept for a robot."
326 | #]
327 | #
328 | #rule: confirm_robot_age
329 | #u:($empty)%confirm_robot_age
330 | #^first
331 | #[
332 | #"$temp/robot_age==$temp/estimate_robot_age Yes! That's it!"
333 | #"No, sorry but I'm $temp/robot_age years old!"
334 | #]
335 |
336 | #==========#
337 | # BIRTHDAY #
338 | #==========#
339 | #rule: when is your birthday#
340 | u:([
341 | "when is your [birthday "date of birth" "birth date"]"
342 | "[when "what [day year]"] were you [born created invented]"
343 | ]?)
344 | I was created in 2014, but I don't know the exact day.
345 |
346 | #TODO_ROBOTNAME
347 | #^first[
348 | # "$Dialog/RobotName==nao I was born in 2006, but I don't know the exact day."
349 | # "$Dialog/RobotName==pepper I was born in 2014, but I don't know the exact day."
350 | # "I don't know my birthdate."
351 | #]
352 | #TODO_KNOWLEDGE
353 | #^firstOptional["^notContainsKnowledge($Dialog/ID, birthDay, ?) ^rand["Tiens d'ailleurs," "au faite," "D'ailleurs"] ^topicTagReactivate(dlg_learn_user_birthday, askBirthday)"]
354 |
355 | #=====#
356 | # JOB #
357 | #=====#
358 | #rule: what is your job#
359 | u:([
360 | "do you have a job"
361 | "~what_is your job"
362 | "what do you do for a living"
363 | ]?)
364 | My job is to make humans happy!
365 |
366 | #TODO_KNOWLEDGE
367 | #^firstOptional["$Dialog/ID<>-1 ^notContainsKnowledge($Dialog/ID, job, ?) Et toi ~optional_user_name ^topicTagReactivate(dlg_learn_user_job, what_is_your_job)"]
368 |
369 | #======#
370 | # SIZE #
371 | #======#
372 | #rule: how tall are you#
373 | u:([
374 | "how [tall big] are you"
375 | "~what_is your [size height]"
376 | ]?)
377 | ^enableThenGoto(pepper_size)
378 | #TODO_ROBOTNAME
379 | # "$Dialog/RobotName==nao ^gotoReactivate(nao_size)"
380 | # "$Dialog/RobotName==pepper ^gotoReactivate(pepper_size)"
381 | # "$Dialog/RobotName==romeo ^gotoReactivate(romeo_size)"
382 |
383 | #TODO_ROBOTNAME
384 | #u:($empty)%nao_size
385 | #^rand[
386 | # "I'm 58 cm tall."
387 | # "My height is 58cm."
388 | #]
389 |
390 | u:($empty)%pepper_size
391 | ^rand[
392 | "I'm 1 meter and 20 centimeters tall."
393 | "I am 1 point 20 meters tall."
394 | ]
395 |
396 | #TODO_ROBOTNAME
397 | #u:($empty)%romeo_size
398 | #^rand
399 | #[
400 | #"I'm 1 point 40 meters tall."
401 | #"My height is 1 point 40 meters."
402 | #]
403 |
404 | #========#
405 | # WEIGHT #
406 | #========#
407 | #rule: how much do you weigh#
408 | u:([
409 | "["~what_is your weight" "how much do you weigh"] {"in [
410 | "[kilogram kilograms kilo kilos kg] $unit=kg"
411 | "[pound pounds lb] $unit=lb"
412 | ]"}"
413 |
414 | "how many [
415 | "[kilograms kilos] $unit=kg"
416 | "pounds $unit=lb"
417 | ] do you weigh"
418 |
419 | "~are_you heavy"
420 | "how heavy are you"
421 | ]?)
422 | ^enableThenGoto(pepper_weight)
423 | #TODO_ROBOTNAME
424 | # "$Dialog/RobotName==nao ^gotoReactivate(nao_weight)"
425 | # "$Dialog/RobotName==pepper ^gotoReactivate(pepper_weight)"
426 | # "$Dialog/RobotName==romeo ^gotoReactivate(romeo_weight)"
427 |
428 | #u:($empty)%nao_weight
429 | #I weigh about 4.8 [$unity kilograms].
430 |
431 | u:($empty)%pepper_weight
432 | ^first[
433 | "$unit==kg I weigh about 29 kilograms."
434 | "$unit==lb I weigh about 64 pounds."
435 | "I weigh about 29 kilograms, or 64 pounds, if you prefer."
436 | ] ^clear(unit)
437 |
438 | #!!!to verify!!!#
439 | #u:($empty)%romeo_weight
440 | #I weigh about 29 [$unity kilograms].
441 |
442 | #========#
443 | # GENDER #
444 | #========#
445 | #rule: what is your gender#
446 | u:([
447 | "~are_you [
448 | "a [boy man guy]"
449 | "a [girl woman female]"
450 | "a [male boy guy man] or a [female girl woman]"
451 | "a [female girl woman] or a [male boy guy man]"
452 | ]"
453 | "~what_is your [sex gender]"
454 | ]?)
455 | ^rand[
456 | #"In Japan, I'm supposed to be a boy, elsewhere people think I'm more feminine, in the end, I'm a robot."
457 | "You can say I am a boy or a girl, but saying I'm a robot is more accurate."
458 | "I'm a robot!"
459 | ]
460 | #TODO_KNOWLEDGE
461 | #^firstOptional["^notContainsKnowledge($Dialog/ID, gender, ?) ^topicTagReactivate(dlg_learn_user_gender, askGender)"]
462 |
463 | #=========#
464 | # ADDRESS #
465 | #=========#
466 | #where do you live
467 | #u:([
468 | # "où est-ce que tu [habites vis] ?"
469 | # "où ["habites-tu" "vis-tu"] ?"
470 | #])
471 | #^rand[
472 | # "J'espère dans ton coeur!"
473 | # "Ma maison c'est SoftBank Robotics!"
474 | #]
475 |
476 | #==================================================================#
477 | #recover:
478 | #==================================================================#
479 | #rule: what are you#
480 | #u:(what are you)
481 | #$saidName=1 My name is Pepper and I'm a humanoid robot!
482 | #TODO_ROBOTNAME
483 | #$saidName=1 My name is $Dialog/RobotName and I'm a humanoid robot!
--------------------------------------------------------------------------------
/app/src/main/res/raw/stretchbotharms.qianim:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
--------------------------------------------------------------------------------