1.6.8. Speech Command Proposer

The Speech-Command-Proposer can make suggestions on what to say to the dialog-system in the apartment. It is capable of managing active rules, give random examples for rules and sending them as a DialogAct. The Speech Visualizer holds a visualization for the Speech-Command-Proposer, the GrammarHelper.

1.6.8.2. Interfaces

Input/Output:

This tool provides various methods for remote-calls.
The property of -s or --scope serves as prefix.

Scope (Local Server) + Method Argument Type Return Type
prefix/setGrammar() String Boolean
prefix/getGrammarPath()   String
prefix/getActiveRules()   Value
prefix/setActiveRules() Value  
prefix/setAllRulesActive()    
prefix/getExampleForRule() String String
prefix/sendDA() String Boolean
prefix/setDaScope() String String
prefix/getRuleDicts()   DictionaryCollection
removed since 1.3    
prefix/getAllRules()   Value
prefix/getRuleByDepthMap() Int Dictionary
Scope (Informer) Type
prefix/grammarhelper/rulechange String
serverMethod/setDaScope() DialogAct
  • setGrammar returns whether setting the grammar was successful or not.
  • sent values (argument and return type) are from type array which are holding strings.
  • the rule-change-informer triggers whenever the active-rule-list or grammar is changed and sends a redundant string to Grammar Helper.
  • the dialogact-informer is triggered by servermethod sendDA().

1.6.8.3. Example

With the speech-command-proposer up running, you can call methods from another tool.

About active rules:
  • all rules are active by default.
  • setting a list of active rules will overwrite the previous list of active rules.
Value.Builder stringBuilder = ValueType.Value.newBuilder().setType(ValueType.Value.Type.STRING);
Value.Builder arrBuilder = ValueType.Value.newBuilder().setType(ValueType.Value.Type.ARRAY);
try {

    final RemoteServer server = Factory.getInstance().createRemoteServer(
            "/exampleRsbScope");
    server.activate();

    try {
        //retrieve current used grammar-path
        Event gramCheck = server.call("getGrammarPath");
        System.out.println(gramCheck.getData().toString());

        //set scope for sending dialogacts
        server.call("setDaScope", "/scopeForDialogActs");

        //we need a list for the rules.
        List<String> l = new LinkedList<String>();

        //set a grammar
        Object gramCall = server.call("setGrammar", "./example.gram");
        Boolean grBool = Boolean.valueOf(gramCall.toString());
        System.out.println("setting grammar successful: " + grBool);
        if (grBool) {
            //call server-method getRuleDicts
            DictionaryCollectionType.DictionaryCollection dc =
           (DictionaryCollectionType.DictionaryCollection) server.call("getRuleDicts");
            //each dictionary is a representation for one rule
            for (Dictionary d : dc.getElementList()) {
                //there are three different keys for the key-value-pairs
                String ruleName = "";
                String example = "";
                long depth = 0;
                boolean active;
                for (KeyValuePair kvp : d.getEntriesList()) {
                    switch (kvp.getKey()) {
                        case "rule":
                            ruleName = kvp.getValue().getString();
                            System.out.println("\t" + kvp.getKey() + " " + ruleName);
                            break;
                        case "example":
                            example = kvp.getValue().getString();
                            System.out.println("\t" + kvp.getKey() + " " + example);
                            break;
                        case "active":
                            active = kvp.getValue().getBool();
                            System.out.println("\t" + kvp.getKey() + " " + String.valueOf(active));
                            break;
                    }
                    //send an dialogact for each rule in the collection
                    server.call("sendDA", ruleName + ";" + example);

                    //we want to have all rules active,
                    //so we fill the list with them here.
                    l.add(ruleName);

                }
            }

            //set a list of active rules
            for (String s : l) {
                Value value1 = stringBuilder.setString(s).build();
                arrBuilder.addArray(value1);
            }
            server.call("setActiveRules", new Event(Value.class, arrBuilder.build()));

            //call server for active rules
            Event ruleCall = server.call("getActiveRules");
            Value v = (Value) ruleCall.getData();
            for (Value va : v.getArrayList()) {
                String rule = va.getString();
                //call server for example
                Object exampleCall = server.call("getExampleForRule", rule);
                System.out.println("exampleCall for rule: " + rule + ": "
                        + exampleCall.toString());
            }

            //set all rules back to active
            server.call("setAllRulesActive");
        }
        }
    } catch (ExecutionException | TimeoutException | InterruptedException ex) {
        Logger.getLogger(TestProject.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            server.deactivate();
        } catch (InterruptedException ex) {
            Logger.getLogger(TestProject.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
} catch (RSBException ex) {
    Logger.getLogger(TestProject.class.getName()).log(Level.SEVERE, null, ex);
}