<commit_before>
package htm.core;

import htm.Input;
import htm.InputProvider;
import htm.InputSet;
import java.util.ArrayList;
import java.util.Collection;

/**
 *
 * @author david.charubini
 */
public class HTM extends Thread {

    private final InputProvider inputProvider;
    private final Pooler spatialPooler;
    private final Pooler temporalPooler;
    private final Region[][] regionsByLevel;
    
    private volatile boolean running = false;

    public HTM(InputProvider inputProvider, Region[][] regionsByLevel, Pooler spatialPooler, Pooler temporalPooler) {
        super();
        this.inputProvider = inputProvider;
        this.regionsByLevel = regionsByLevel;
        this.spatialPooler = spatialPooler;
        this.temporalPooler = temporalPooler;
    }

    public void initialize() {
        this.running = true;
        this.start();
    }
    
    @Override
    public void run() {
        while (this.running) {
            InputSet inputSet = null;
            try {
                inputSet = this.inputProvider.take();
            } catch (InterruptedException ie) {
                ie.printStackTrace();
            }
            
            this.process(inputSet);
            // TODO: process output - via queue?
        }
    }
    
    public Collection<Input<?>> getConnectedInputs() {
        // TBD: take the connected synapses from the upper levels 
        // and feed downward?
        
        Collection<Input<?>> connectedInputs = new ArrayList<Input<?>>();
        
        for (Region region : this.regionsByLevel[0]) {
            region.getConnectedInputs(connectedInputs);
        }
        <commit_msg>Adding check for running before dropping a stack trace<commit_after>
package htm.core;

import htm.Input;
import htm.InputProvider;
import htm.InputSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.concurrent.TimeUnit;

/**
 *
 * @author david.charubini
 */
public class HTM extends Thread {

    private final InputProvider inputProvider;
    private final Pooler spatialPooler;
    private final Pooler temporalPooler;
    private final Region[][] regionsByLevel;
    
    private volatile boolean running = false;

    public HTM(InputProvider inputProvider, Region[][] regionsByLevel, Pooler spatialPooler, Pooler temporalPooler) {
        super();
        this.inputProvider = inputProvider;
        this.regionsByLevel = regionsByLevel;
        this.spatialPooler = spatialPooler;
        this.temporalPooler = temporalPooler;
    }

    public void initialize() {
        this.running = true;
        this.start();
    }
    
    @Override
    public void run() {
        while (this.running) {
            InputSet inputSet = null;
            try {
                inputSet = this.inputProvider.take();
            } catch (InterruptedException ie) {
                if (this.running) {
                    ie.printStackTrace();
                }
            }
            
            this.process(inputSet);
            // TODO: process output - via queue?
        }
    }
    
    public Collection<Input<?>> getConnectedInputs() {
        // TBD: take the connected synapses from the upper levels 
        // and feed downward?
        
        Collection<Input<?>> connectedInputs = new ArrayList<Input<?>>();
        
        for (Region region : this.regionsByLevel[0]) {
            region.getConnectedInputs(connectedInputs);
        }
        
{'fraction_non_alphanumeric': 0.09027576197387518, 'fraction_numerical': 0.0005805515239477503, 'mean_word_length': 2.1527904849039343, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '6178497', 'n_tokens_mistral': 915, 'n_tokens_neox': 893, 'n_words': 234}