
function [hashmap_size, hashmap, lines_out, word_to_stem_map] = registreerisonad(model, lines, min_word_len, output_registered_words, word_to_stem_map)



    if nargin<3 || isempty(min_word_len)
        min_word_len = model.min_word_len;
    end
    
    if nargin<4 || isempty(output_registered_words)
        output_registered_words = '';
    end
    
    if nargin<5
        word_to_stem_map = [];
    end



    num_lines = rows(lines);
    
    
    % reg = regexp
    
    
    wordslist = {};
    
    
    hashmap = java.util.Properties;
    hashmap_size = 0;
    
    lines_out = cell(num_lines, 1);
    
    % word_i = 1;
    for i = 1:num_lines
        
        % explode(' ', char(corpus.est(1)))
        line = char(lines(i));
        
        line = html_tilded(line);
        
        % line = remove_chars(line, ';,:.');
        line = remove_crap(line);
        
        words = explode(' ', line, true);   % skip empty strings
        
        
        if ~isempty(word_to_stem_map)
           
            stems = words_to_stems(words, word_to_stem_map);
            
        else
            
            stems = {};
            
        end     % if ~isempty(word_to_stem_map)
        
        
        lines_out(i, 1) = {words};
        
        if ~isempty(output_registered_words)
            [hashmap_size, hashmap, wordslist] = update_hashmap(words, hashmap_size, hashmap, min_word_len, wordslist, stems, 1);
        else
            [hashmap_size, hashmap, wordslist] = update_hashmap(words, hashmap_size, hashmap, min_word_len, wordslist, stems, model.min_wordcount);
        end
        
        
    end     % for i = 1:num_lines
    
    
    
    if ~isempty(output_registered_words)
        
        % mapsize = size(hashmap);
        mapsize = length(wordslist);
        wordlist_filename = [output_registered_words '.txt'];
        fid = fopen(wordlist_filename, 'w');
        
        for i = 1:mapsize            
            
            word = char(wordslist(i));
            fprintf(fid, '%s.\n', word);
            
        end        
        
        fclose(fid);
        
        
        stemmer_output_filename = 'source.txt';
        word_to_stem_map = stemmer_output_to_stemlist(stemmer_output_filename);  % TODO: for other language we should use separate map/container
        
        
        
        [hashmap_size, hashmap, lines_out] = registreerisonad(model, lines, min_word_len, [], word_to_stem_map);
        
        
    end     % if ~isempty(output_registered_words)
    


end
