Skip to content
This repository has been archived by the owner on Jun 30, 2024. It is now read-only.

Creating a module guide

JohnPersano edited this page Nov 10, 2014 · 1 revision

These tutorials will demonstrate the process of creating a new module for Benson. For the purposes of these tutorials, some knowledge of Android/Java programming will be assumed.


Creating a basic module

Under the lexicon/modules directory, create a new class with the name Basic with the following code.

package com.github.johnpersano.benson.lexicon.modules;

import android.content.Context;

import com.github.johnpersano.benson.lexicon.Query;
import com.github.johnpersano.benson.lexicon.Response;

import java.util.Arrays;
import java.util.List;

import me.palazzetti.adktoolkit.AdkManager;

public class Basic extends Query {

    @Override
    public List<String> getInputs() {

        return Arrays.asList("basic");

    }

    @Override
    public Response getResponse(Context context, String hypothesis, AdkManager adkManager) {

        return new Response()
                .setReply("It is basic indeed.");

    }

}

Don't forget to tell Benson he has new responses for his lexicon. In the Lexicon class, add a new instance of the Basic class to the end of the list.

package com.github.johnpersano.benson.lexicon;

import com.github.johnpersano.benson.lexicon.modules.Component;
import com.github.johnpersano.benson.lexicon.modules.Time;
import com.github.johnpersano.benson.lexicon.modules.Hello;
import com.github.johnpersano.benson.lexicon.modules.HowAreYou;
import com.github.johnpersano.benson.lexicon.modules.Joke;
import com.github.johnpersano.benson.lexicon.modules.Basic;

import java.util.Arrays;
import java.util.List;

/* This class holds the default lexicon for Benson. If any new modules are added, be sure to add them here as well. */
public class Lexicon {

    public final List<? extends Query> lexicon = Arrays.asList(new Component(), new Hello(), new HowAreYou(), new Joke(), new Time(), new Basic());

}

That's it! Now, when Benson hears the word "basic" in any sentence, he will respond with "It is basic indeed.".

Clone this wiki locally