classdef lang1
    properties (Constant)
        name = "lang1"
        utterances = [
            utterance("a", lang1_sound.A, lang1_meaning.GRAIN)
            utterance("e", lang1_sound.E, lang1_meaning.EGG)
            utterance("i", lang1_sound.I, lang1_meaning.EGGS)
            utterance("o", lang1_sound.O, lang1_meaning.GOAT)
            utterance("u", lang1_sound.U, lang1_meaning.GOATS)
            ]
        n_utterances = size(lang1.utterances, 1)
        n_sound_nodes = lang1_sound.n_auditory_nodes
        n_meaning_nodes = lang1_meaning.n_semantic_nodes
        n_input_nodes = lang1_sound.n_auditory_nodes + lang1_meaning.n_semantic_nodes
    end
    
    methods (Static)
        function m_index = get_meaning_of_sound(s_index)
            % NONE
            if isequal(s_index, lang1_sound.n_vowels + 1)
                m_index = lang1_meaning.n_meanings + 1;
            % not NONE
            else
                sound = lang1_sound.get_sound_by_index(s_index);
                for i = 1:size(lang1.utterances, 1)
                    if isequal(sound, lang1.utterances(i).sound)
                        m_index = lang1.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, lang1_meaning.n_meanings + 1)
                s_index = lang1_sound.n_vowels + 1;
            % not NONE
            else
                meaning = lang1_meaning.get_meaning_by_index(m_index);
                for i = 1:size(lang1.utterances, 1)
                    if isequal(meaning, lang1.utterances(i).meaning)
                        s_index = lang1.utterances(i).sound.v_index;
                        break
                    end
                end
            end
        end

        function [s_vector, m_vector] = split_utterance_vector(utterance_vector)
            assert(size(utterance_vector, 2) == lang1.n_input_nodes, ...
                "logical error: wrong size of utterance vector")

            ns = lang1_sound.n_auditory_nodes;
            nm = lang1_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] = lang1.split_utterance_vector(utterance_vector);

            lang1_sound.draw_output(s_vector);
            lang1_meaning.draw_output(m_vector);
        end
    end
end

