All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.cmu.sv.system_action.GenericCommandSchema Maven / Gradle / Ivy

Go to download

A library that allows rapid prototyping of dialog systems (language understanding, discourse modelling, dialog management, language generation).

There is a newer version: 0.7.0
Show newest version
package edu.cmu.sv.system_action;

import edu.cmu.sv.domain.ontology.Verb;
import edu.cmu.sv.semantics.SemanticsModel;
import edu.cmu.sv.system_action.non_dialog_task.NonDialogTask;
import org.json.simple.JSONObject;

/**
 * Created by David Cohen on 12/19/14.
 */
public class GenericCommandSchema extends ActionSchema {
    private Verb verbClass;
    private Class taskClass;

    public GenericCommandSchema(Verb verbClass, Class taskClass) {
        this.verbClass = verbClass;
        this.taskClass = taskClass;
    }

    @Override
    public boolean matchSchema(SemanticsModel resolvedMeaning) {
        return (resolvedMeaning.newGetSlotPathFiller("verb.class")!=null &&
                resolvedMeaning.newGetSlotPathFiller("verb.class").equals(verbClass.name) &&
                resolvedMeaning.newGetSlotPathFiller("dialogAct").equals("Command"));
    }

    @Override
    public NonDialogTask applySchema(SemanticsModel resolvedMeaning) {
        try {
            NonDialogTask task = taskClass.newInstance();
            task.setTaskSpec(SemanticsModel.parseJSON(((JSONObject) resolvedMeaning.newGetSlotPathFiller("verb")).toJSONString()));
            return task;
        } catch (InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy