<commit_before>
/*
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electronic Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */

package edu.cmu.sphinx.research.parallel;

import edu.cmu.sphinx.knowledge.acoustic.HMMState;

import edu.cmu.sphinx.decoder.search.ActiveList;
import edu.cmu.sphinx.decoder.search.TokenStack;
import edu.cmu.sphinx.decoder.search.ArrayTokenStack;

import edu.cmu.sphinx.decoder.linguist.simple.HMMStateState;
import edu.cmu.sphinx.decoder.linguist.simple.SentenceHMMState;

import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;


/**
 * Represents an HMMStateState in a parallel SentenceHMM.
 * The only difference this class and the HMMStateState class is
 * in the getName() method, which tells you which of the
 * parallel branches this HMMStateState is in. See the getName()
 * method for details.
 */
public class ParallelHMMStateState extends HMMStateState 
implements ParallelState {

    private static List allStates;
    static {
	allStates = new LinkedList();
    }

    private String modelName;
    private TokenStack tokenStack;


    /**
     * Clear out all the ParallelHMMStateStates in the JVM.
     */
    public static void clearAllStates() {
	for (Iterator i = allStates.iterator(); i.hasNext(); ) {
	    ParallelHMMStateState state = (ParallelHMMStateState)i.next();
	    state.clear();
	}
    }

    
    /**
     * Creates a ParallelHMMStateState
     *
     * @param parent the parent of this state
     * @param modelName the name of the acoustic model behind this HMMState
     * @param hmmState the hmmState associated with this state
     */
    public ParallelHMMStateState(SentenceHMMState parent,
				 String modelName,
				 HMMState hmmState,
                                 int tokenStackSize) {
	super(parent, hmmState);
	this.modelName = modelName;
        if (tokenStackSize > 0) {
            this.tokenStack = new ArrayTokenStack(tokenStackSize);
        } else {
            this.tokenStack = null;
        }
	allStates.add(this);
    }


    /**
     * Returns the token stack of this ParallelHMMStateState.
     *
     * @return the token stack
     */
    public TokenStack getTokenStack() {
        return tokenStack;
    }
        

    /**
     * Returns the name of the acoustic model behind this 
     * ParallelHMMStateState.
     *
     * @return the name of the acoustic model
     */
    public String getModelName() {
	return modelName;
    }

    
    /**
     * Returns the name of this ParallelHMMStateState.
     * It is in the form of "Hx.y", where y is the index of the
     * parallel branch, and x is which state within the branch.
     * For example, the first state in the first parallel branch
     * might have name "H0.0".
     *
     * @return the name of this ParallelHMMStateState
     */
    public String getName() {
	String name = super.getName();
	return name + "." + modelName;
    }



    /**
     * Clears/resets any accumulated state or history
     */
    public void clear() {
        // super.clear();  BUG: fix me
        if (tokenStack != null) {
            tokenStack.clear();
        }
    }<commit_msg>Changes the reference to the name string a feature stream to a reference to the FeatureStream object.<commit_after>
/*
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electronic Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */

package edu.cmu.sphinx.research.parallel;

import edu.cmu.sphinx.knowledge.acoustic.HMMState;

import edu.cmu.sphinx.decoder.search.ActiveList;
import edu.cmu.sphinx.decoder.search.TokenStack;
import edu.cmu.sphinx.decoder.search.ArrayTokenStack;

import edu.cmu.sphinx.decoder.linguist.simple.HMMStateState;
import edu.cmu.sphinx.decoder.linguist.simple.SentenceHMMState;

import java.io.Serializable;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;


/**
 * Represents an HMMStateState in a parallel SentenceHMM.
 * The only difference this class and the HMMStateState class is
 * in the getName() method, which tells you which of the
 * parallel branches this HMMStateState is in. See the getName()
 * method for details.
 */
public class ParallelHMMStateState extends HMMStateState 
implements ParallelState {

    private static List allStates;
    static {
	allStates = new LinkedList();
    }

    private FeatureStream stream;
    private TokenStack tokenStack;


    /**
     * Clear out all the ParallelHMMStateStates in the JVM.
     */
    public static void clearAllStates() {
	for (Iterator i = allStates.iterator(); i.hasNext(); ) {
	    ParallelHMMStateState state = (ParallelHMMStateState)i.next();
	    state.clear();
	}
    }

    
    /**
     * Creates a ParallelHMMStateState
     *
     * @param parent the parent of this state
     * @param modelName the name of the acoustic model behind this HMMState
     * @param hmmState the hmmState associated with this state
     */
    public ParallelHMMStateState(SentenceHMMState parent,
				 FeatureStream stream,
				 HMMState hmmState,
                                 int tokenStackSize) {
	super(parent, hmmState);
	this.stream = stream;
        if (tokenStackSize > 0) {
            this.tokenStack = new ArrayTokenStack(tokenStackSize);
        } else {
            this.tokenStack = null;
        }
	allStates.add(this);
    }


    /**
     * Returns the token stack of this ParallelHMMStateState.
     *
     * @return the token stack
     */
    public TokenStack getTokenStack() {
        return tokenStack;
    }
        

    /**
     * Returns the FeatureStream of the acoustic model behind this 
     * ParallelHMMStateState.
     *
     * @return the FeatureStream of the acoustic model
     */
    public FeatureStream getFeatureStream() {
	return stream;
    }

    
    /**
     * Returns the name of this ParallelHMMStateState.
     * It is in the form of "Hx.y", where y is the index of the
     * parallel branch, and x is which state within the branch.
     * For example, the first state in the first parallel branch
     * might have name "H0.0".
     *
     * @return the name of this ParallelHMMStateState
     */
    public String getName() {
	return (super.getName() + "." + stream.getName());
    }



    /**
     * Clears/resets any accumulated state or history
     */
    public void clear() {
        // super.clear();  BUG: fix me
        if (tokenStack != null) {
            tokenStack.clear();
        }
    }
{'fraction_non_alphanumeric': 0.08373821091740498, 'fraction_numerical': 0.0054301228922549296, 'mean_word_length': 2.683684210526316, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6612222', 'n_tokens_mistral': 2152, 'n_tokens_neox': 2006, 'n_words': 647}