Giter Club home page Giter Club logo

nuwacustombehaviorexample's Introduction

NuwaCustomBehaviorExample

Nuwa CustomBehavior allow developer receive notify from NLP result.

This example is a simple auto reception of company counter(受付).

  • Target SDK : 2.0.0.06

Nuwa Website

NOTICE : Please get NuwaSDK from Nuwarobotics Developer Website

Support Robot Product

Robot Generation 2

  • Kebbi Air : Taiwan、China、Japan

CustomBehavior SDK

SOP : How to use example

  • Build APK
    • Get NuwaSDK from official website
    • Copy NuwaSDK to /app/libs folder
    • Modify NuwaSDK file name on /app/build.gradle
    • Build Example.
  • Install App and StartService
    • Install to Robot
    • Launch Example App and Press button to start CustomBehaviorService.
  • Setup TrainKit(トレーニングキット)
    • Setup Your Q&A on TrainKit(トレーニングキット) Website.
    • Deploy TrainKit to Robot by SN.
    • Setup SOP
  • Start Test
    • speak question you setup to kebbi

Custom Behavior

System behavior allows developer to customize response behavior of a NLP result.

Developer need to setup Chatbot Q&A from NUWA Trainkit website which allow developer setup Custom Intention for a sentence.

Following sample code will present how to register receive this CustomIntentation notify and implement customize response.

class BaseBehaviorService

Developer should implement a class to determine how to react when receiving a customized NLP response from NUWA Trainkit.

This could be achieved by extending from class BaseBehaviorService.

BaseBehaviorService declared three important functions which onInitialize(), createCustomBehavior() and notifyBehaviorFinished().

There are two functions need to be implemented which onInitialize() and createCustomBehavior().

  • onInitialize()

    • When the extending class has been started, developer could initialize resource here.
  • createCustomBehavior()

    • After that, the other function createCustomBehavior should create a CustomBehavior object. CustomBehavior is a interface which define custom behavior once receiving customized NLP result. It declared three callback functions for developer to implement customized behavior.
  • notifyBehaviorFinished()

    • To notify robot behavior system that the process has been completed.

class ISystemBehaviorManager

This class has been encapsulated in BaseBehavior. Developer can get this instance which is created by BaseBehavior.

  • register(String pkgName, CustomBehavior action)

    • Register a CustomBehavior object to robot behavior system by app package name.
  • unregister(String pkgName, CustomBehavior action)

    • Unregister a CustomBehavior object to robot behavior system by app package name.
  • setWelcomeSentence(String[] sentences)

    • To set welcome sentence when robot detected someone.
  • resetWelcomeSentence()

    • To reset welcome sentence.
  • completeCustomBehavior()

    • To notify robot behavior system that the process has been completed.

class CustomBehavior

The Object which let developer define how to to deal with customized NLP response.

  • prepare(String parameter)

    • Once NLP response which is defined form TrainKit has been reached, the robot behavior system will start to prepare resource for this session. The system notifies 3rd party APP and it could do something while preparing.
  • process(String parameter)

    • Developer could implement his logic here to deal with NLP response which has been defined from TrainKit. As robot behavior system is ready, this function call will be invoked. Note that the process might be an asynchronous task so that the developer must notify robot behavior system that the process when will be completed by notifyBehaviorFinished().
  • finish(String parameter)

    • When this customized behavior has been completed, robot behavior system will clean related resources and finish this session. At the same time, it notifies the 3rd party app this session has been finished by this function call.

Sample code

public class CustomBehaviorImpl extends BaseBehaviorService {

    @Override
    public void onInitialize() {
        handler = new Handler(Looper.getMainLooper());
        try {
        	// TODO initialize 
            mSystemBehaviorManager.setWelcomeSentence(new String[]{"你好, %s.這是一個歡迎詞的測試!", "%s, 挖底家", "%s, 有什麼可以為您服務的嗎?"});
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    @Override
    public CustomBehavior createCustomBehavior() {
        return new CustomBehavior.Stub() {
            @Override
            public void prepare(final String parameter) {
				// TODO write your preparing work
            }

            @Override
            public void process(final String parameter) {
				// TODO the actual process logic

                // TODO simulate asynchronous task while process complete
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            notifyBehaviorFinished();
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        }
                    }
                }, 5000);
            }

            @Override
            public void finish(final String parameter) {
            	// TODO the whole session has been finished. 
            }
        };
    }

}

nuwacustombehaviorexample's People

Contributors

nuwarobotics avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.