classdef lang2
    properties (Constant)
        name = "lang2"
        utterances = [
            utterance("sova",  lang2_sound.SOVA,  lang2_meaning.SOVA)
            utterance("sovy",  lang2_sound.SOVY,  lang2_meaning.SOVY)
            utterance("roza",  lang2_sound.ROZA,  lang2_meaning.ROZA)
            utterance("rozy",  lang2_sound.ROZY,  lang2_meaning.ROZY)
            utterance("kot",   lang2_sound.KOT,   lang2_meaning.KOT)
            utterance("koty",  lang2_sound.KOTY,  lang2_meaning.KOTY)
            utterance("bot",   lang2_sound.BOT,   lang2_meaning.BOT)
            utterance("boty",  lang2_sound.BOTY,  lang2_meaning.BOTY)
            utterance("moja",  lang2_sound.MOJA,  lang2_meaning.MOJA)
            utterance("moj",   lang2_sound.MOJ,   lang2_meaning.MOJ)
            utterance("mojy",  lang2_sound.MOJY,  lang2_meaning.MOJY)
            utterance("zhara", lang2_sound.ZHARA, lang2_meaning.ZHARA)
            utterance("zhar",  lang2_sound.ZHAR,  lang2_meaning.ZHAR)
            utterance("zhaba", lang2_sound.ZHABA, lang2_meaning.ZHABA)
            utterance("zhaby", lang2_sound.ZHABY, lang2_meaning.ZHABY)
            utterance("taz",   lang2_sound.TAZ,   lang2_meaning.TAZ)
            utterance("tazy",  lang2_sound.TAZY,  lang2_meaning.TAZY)
            utterance("bar",   lang2_sound.BAR,   lang2_meaning.BAR)
            utterance("bary",  lang2_sound.BARY,  lang2_meaning.BARY)
            utterance("raba",  lang2_sound.RABA,  lang2_meaning.RABA)
            utterance("rab",   lang2_sound.RAB,   lang2_meaning.RAB)
            utterance("raby",  lang2_sound.RABY,  lang2_meaning.RABY)
            ]
        n_utterances = size(lang2.utterances, 1)
        n_sound_nodes = lang2_sound.n_auditory_nodes
        n_meaning_nodes = lang2_meaning.n_semantic_nodes
        n_input_nodes = lang2_sound.n_auditory_nodes + lang2_meaning.n_semantic_nodes
    end
    
    methods (Static)
        function m_index = get_meaning_of_sound(s_index)
            % NONE
            if isequal(s_index, lang2_sound.n_sounds + 1)
                m_index = lang2_meaning.n_meanings + 1;
            % not NONE
            else
                sound = lang2_sound.get_sound_by_index(s_index);
                for i = 1:size(lang2.utterances, 1)
                    if isequal(sound, lang2.utterances(i).sound)
                        m_index = lang2.utterances(i).meaning.all_meanings_index;
                        break
                    end
                end
            end
        end

        function s_index = get_sound_of_meaning(m_index)
            % NONE
            if isequal(m_index, lang2_meaning.n_meanings + 1)
                s_index = lang2_sound.n_sounds + 1;
            % not NONE
            else
                meaning = lang2_meaning.get_meaning_by_index(m_index);
                for i = 1:size(lang2.utterances, 1)
                    if isequal(meaning, lang2.utterances(i).meaning)
                        s_index = lang2.utterances(i).sound.all_sounds_index;
                        break
                    end
                end
            end
        end

        function [s_vector, m_vector] = split_utterance_vector(utterance_vector)
            assert(size(utterance_vector, 2) == lang2.n_input_nodes, ...
                "logical error: wrong size of utterance vector")
            
            ns = lang2_sound.n_auditory_nodes;
            nm = lang2_meaning.n_semantic_nodes;
            
            s_vector = utterance_vector(1:ns);
            m_vector = utterance_vector(ns+1:ns+nm);
        end

        function draw_output(utterance_vector)
            [s_vector, m_vector] = lang2.split_utterance_vector(utterance_vector);

            lang2_sound.draw_output(s_vector);
            lang2_meaning.draw_output(m_vector);
        end
    end
end