% EnsembleParser does not parse the patterns, but classifiers (which act
% in an ensemble as a kind of pattern)%
classdef janis_ensembleParser < janis_patternParser

    methods
        % Constructor
        function pp = janis_ensembleParser(classCollection)
            pp = pp@janis_patternParser(classCollection);
            if ~isa(classCollection,'janis_classCollection')
                throw(MException('janis:WrongClass','This is not a janis_classCollection!'));
            end
        end

        % gets all Patterns from all subjects and generates a Matrix
        % which is used to return the a matrix by specified subjects
        function pp = init(pp)
            % I think I will nothing do here and provide instead a function
            % to add new classifiers
%            % init helper Matrices
%            % Patternsize: Voxels X Subjects
            pp.patternLabels = zeros(pp.classCollection.patternCount,1);
            actualIndex = 1;
%            % go through all classes
            for cl=1:pp.classCollection.size
               % for each class
               actualClass = pp.classCollection.get(cl);
               pp.patternLabels(actualIndex:actualIndex+actualClass.size-1) = cl -1;
               actualIndex = actualIndex + actualClass.size;
            end
            for k=1:size(pp.patternMat,2)
               pp.patternMat{k}.patternParser.init;
            end
        end

        % get patterns according to indices specified.
        function [trainPattern, trainLabels, testPattern, testLabels] = get(pp,indices)
             trainPattern = pp.patternMat;
             trainLabels = indices;
             testLabels  = ~indices;
             testPattern = testLabels;
        end

        % add new classifier/validator to ensemble.
        function pp = addValidatorToEnsemble(pp,validatorNode)
            % TODO: check Node for classCollection similar.
            if ~isa(validatorNode,'janis_validator')
                throw(MException('janis:WrongClass','This is not a validator-Class!'));
            else
                 pp.patternMat{size(pp.patternMat,2)+1} = validatorNode;
            end
        end

        % This is not (and probably will never) be implemented.
        function pattern = reconstructFromProcessors(pp,pattern)
            error('This function is not implemented!');
        end

        % returns labels of patterns
        function labelsAll = getLabels(pp)
            labelsAll = pp.patternLabels;
        end
    end
end