<commit_before>import {JovoResponse, SpeechBuilder, SessionConstants, SessionData} from "jovo-core";
import _get = require('lodash.get');
import _set = require('lodash.set');

export interface SessionAttributes {
    [key: string]: any; //tslint:disable-line
}

export interface Directive {
    type: string;
    updatedIntent?: object;
    slotToElicit?: string;
}

export interface Response {
    shouldEndSession?: boolean;
    directives?: Directive[];
}

export interface AlexaResponseJSON {
    version: string;
    response: Response;
    sessionAttributes?: SessionAttributes;
}

/**
 * Thanks to @see http://choly.ca/post/typescript-json/
 */


export class AlexaResponse implements JovoResponse {
    version: string;
    response: Response;
    sessionAttributes?: SessionAttributes;

    constructor() {
        this.version = '1.0';
        this.response = {
            shouldEndSession: true,
        };
        this.sessionAttributes = {};
    }

    getCard() {
        return _get(this, 'response.card');
    }

    getSessionData(path?: string) {
        if (path) {
            return this.getSessionAttribute(path);
        } else {
            return this.getSessionAttributes();
        }
    }

    hasSessionData(name: string, value?: any): boolean { // tslint:disable-line
        return this.hasSessionAttribute(name, value);
    }

    setSessionData(sessionData: SessionData) {
        return this.setSessionAttributes(sessionData);
    }

    getSessionAttributes() {
        return _get(this, 'sessionAttributes');
    }



    setSessionAttributes(sessionData: SessionData) {
        _set(this, 'sessionAttributes', sessionData);
        return this;
    }

    getSpeech() {
        if (!_get(this, 'response.outputSpeech.ssml')) {
            return;
        }
        return SpeechBuilder.removeSpeakTags(_get(this, 'response.outputSpeech.ssml'));
    }
    getReprompt() {
        if (!_get(this, 'response.outputSpeech.ssml')) {
            return;
        }
        return SpeechBuilder.removeSpeakTags(_get(this, 'response.reprompt.outputSpeech.ssml'));
    }


    getSpeechPlain() {
        const speech = this.getSpeech();
        if (!speech) {
            return;
        }

        return SpeechBuilder.removeSSML(speech);
    }
    getRepromptPlain() {
        const reprompt = this.getReprompt();
        if (!reprompt) {
            return;
        }

        return SpeechBuilder.removeSSML(reprompt);
    }

    getSessionAttribute(name: string) {
        return _get(this, `sessionAttributes.${name}`);
    }

    /**
     *
     * @param {string} name
     * @param {any} value
     * @return {boolean}
     */
    hasSessionAttribute(name: string, value?: any): boolean { // tslint:disable-line
        if (!this.getSessionAttribute(name)) {
            return false;
        }

        if (typeof value !== 'undefined') {
            if (this.getSessionAttribute(name) !== value) {
                return false;
            }
        }

        return true;

    }

    hasState(state: string): boolean {
        return this.hasSessionAttribute(SessionConstants.STATE, state);
    }

    hasSessionEnded() {
        return _get(this, 'response.shouldEndSession');
    }

    /**
     * Checks if response object contains a simple card.
     * @param {string} title
     * @param {string} text
     * @return {boolean}
     */
    hasSimpleCard(title: string, text: string): boolean {
        const cardObject = this.getCard();

        if (!cardObject) {
            return false;
        }

        if (cardObject.type !== 'Simple') {
            return false;
        }

        if (title) {
            if (title !== cardObject.title) {
                return false;
            }
        }
        if (text) {
            if (text !== cardObject.text) {
                return false;
            }
        }

        return true;
    }

    /**
     * Checks if response object contains a standard card.
     * @param {string} title
     * @param {string} text
     * @param {string} smallImageUrl
     * @param {string} largeImageUrl
     * @return {boolean}
     */
    hasStandardCard(title: string, text: string, smallImageUrl: string, largeImageUrl: string): boolean {
        const cardObject = this.getCard();

        if (!cardObject) {
            return false;
        }

        if (cardObject.type !== 'Standard') {
            return false;
        }

        if (title) {
            if (title !== cardObject.title) {
                return false;
            }
        }
        if (text) {
            if (text !== cardObject.text) {
                return false;
            }
        }
        if (smallImageUrl) {<commit_msg>:recycle: Make hasSimpleCard, hasStandardCard parameters optional<commit_after>import {JovoResponse, SpeechBuilder, SessionConstants, SessionData} from "jovo-core";
import _get = require('lodash.get');
import _set = require('lodash.set');

export interface SessionAttributes {
    [key: string]: any; //tslint:disable-line
}

export interface Directive {
    type: string;
    updatedIntent?: object;
    slotToElicit?: string;
}

export interface Response {
    shouldEndSession?: boolean;
    directives?: Directive[];
}

export interface AlexaResponseJSON {
    version: string;
    response: Response;
    sessionAttributes?: SessionAttributes;
}

/**
 * Thanks to @see http://choly.ca/post/typescript-json/
 */


export class AlexaResponse implements JovoResponse {
    version: string;
    response: Response;
    sessionAttributes?: SessionAttributes;

    constructor() {
        this.version = '1.0';
        this.response = {
            shouldEndSession: true,
        };
        this.sessionAttributes = {};
    }

    getCard() {
        return _get(this, 'response.card');
    }

    getSessionData(path?: string) {
        if (path) {
            return this.getSessionAttribute(path);
        } else {
            return this.getSessionAttributes();
        }
    }

    hasSessionData(name: string, value?: any): boolean { // tslint:disable-line
        return this.hasSessionAttribute(name, value);
    }

    setSessionData(sessionData: SessionData) {
        return this.setSessionAttributes(sessionData);
    }

    getSessionAttributes() {
        return _get(this, 'sessionAttributes');
    }



    setSessionAttributes(sessionData: SessionData) {
        _set(this, 'sessionAttributes', sessionData);
        return this;
    }

    getSpeech() {
        if (!_get(this, 'response.outputSpeech.ssml')) {
            return;
        }
        return SpeechBuilder.removeSpeakTags(_get(this, 'response.outputSpeech.ssml'));
    }
    getReprompt() {
        if (!_get(this, 'response.outputSpeech.ssml')) {
            return;
        }
        return SpeechBuilder.removeSpeakTags(_get(this, 'response.reprompt.outputSpeech.ssml'));
    }


    getSpeechPlain() {
        const speech = this.getSpeech();
        if (!speech) {
            return;
        }

        return SpeechBuilder.removeSSML(speech);
    }
    getRepromptPlain() {
        const reprompt = this.getReprompt();
        if (!reprompt) {
            return;
        }

        return SpeechBuilder.removeSSML(reprompt);
    }

    getSessionAttribute(name: string) {
        return _get(this, `sessionAttributes.${name}`);
    }

    /**
     *
     * @param {string} name
     * @param {any} value
     * @return {boolean}
     */
    hasSessionAttribute(name: string, value?: any): boolean { // tslint:disable-line
        if (!this.getSessionAttribute(name)) {
            return false;
        }

        if (typeof value !== 'undefined') {
            if (this.getSessionAttribute(name) !== value) {
                return false;
            }
        }

        return true;

    }

    hasState(state: string): boolean {
        return this.hasSessionAttribute(SessionConstants.STATE, state);
    }

    hasSessionEnded() {
        return _get(this, 'response.shouldEndSession');
    }

    /**
     * Checks if response object contains a simple card.
     * @param {string} title
     * @param {string} text
     * @return {boolean}
     */
    hasSimpleCard(title?: string, text?: string): boolean {
        const cardObject = this.getCard();

        if (!cardObject) {
            return false;
        }

        if (cardObject.type !== 'Simple') {
            return false;
        }

        if (title) {
            if (title !== cardObject.title) {
                return false;
            }
        }
        if (text) {
            if (text !== cardObject.text) {
                return false;
            }
        }

        return true;
    }

    /**
     * Checks if response object contains a standard card.
     * @param {string} title
     * @param {string} text
     * @param {string} smallImageUrl
     * @param {string} largeImageUrl
     * @return {boolean}
     */
    hasStandardCard(title?: string, text?: string, smallImageUrl?: string, largeImageUrl?: string): boolean {
        const cardObject = this.getCard();

        if (!cardObject) {
            return false;
        }

        if (cardObject.type !== 'Standard') {
            return false;
        }

        if (title) {
            if (title !== cardObject.title) {
                return false;
            }
        }
        if (text) {
            if (text !== cardObject.text) {
                return false;
            }
        }
        if (smallImageUrl) {
{'fraction_non_alphanumeric': 0.11741703656732191, 'fraction_numerical': 0.0004227436060029592, 'mean_word_length': 1.9776589049716804, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3108369', 'n_tokens_mistral': 2703, 'n_tokens_neox': 2612, 'n_words': 585}