<commit_before>package edu.cmu.sphinx.frontend.util;

import edu.cmu.sphinx.frontend.DataBlocker;
import edu.cmu.sphinx.frontend.DataProcessor;
import edu.cmu.sphinx.frontend.FrontEnd;
import edu.cmu.sphinx.frontend.window.RaisedCosineWindower;

/**
 * Some little helper methods to ease the handling of frontend-processor chains.
 *
 * @author <NAME>
 */
public class FrontEndUtils {


    /** Returns a the next <code>DataProcessor</code> of type <code>predecClass</code> which preceeds <code>dp</code> */
    public static DataProcessor getDataSource(DataProcessor dp, Class<? extends DataProcessor> predecClass) {
        while (!predecClass.isInstance(dp.getPredecessor())) {
            dp = dp.getPredecessor();

            if (dp == null)
                return null;

            if (dp instanceof FrontEnd)
                dp = ((FrontEnd) dp).getLastDataProcessor();
        }


        return dp;
    }


    /**
     * Applies several heuristics in order to determine the shift-size of the fronted a given <code>DataProcessor</code>
     * belongs to.
     * <p/>
     * <p/>
     * The shift-size is searched using the following procedure <ol> <li> Try to determine the window shift-size used by
     * the <code>RaisedCosineWindower</code> which precedes the given <code>DataProcessor</code>. <li> If a data-blocker
     * is found within the precding processor chain but no <code>RaisedCosineWindower</code> 0 is returned. </ol>
     * <p/>
     * <p/>
     * If both approaches fail, an <code>AssertionError</code> becomes thrown.
     *
     * @param dp The <code>DataProcessor</code> which predecessors are searched backwards to find an instance of a
     *           <code>RaisedCosineWindower</code>
     * @return The window shift size of the found <code>RaisedCosineWindower</code>
     * @throws AssertionError if there was no <code>RaisedCosineWindower</code> within the predecessor list of
     *                        <code>dp</code>
     */
    public static float getWindowShiftMs(DataProcessor dataProc) {
        DataProcessor dp = dataProc;

        while (!(dp instanceof RaisedCosineWindower)) {
            dp = dp.getPredecessor();

            if (dp == null)
                break;

            if (dp instanceof FrontEnd)
                dp = ((FrontEnd) dp).getLastDataProcessor();
        }

        if (dp != null)
            return ((RaisedCosineWindower) dp).getWindowShiftInMs();

        dp = dataProc;
        while (!(dp instanceof DataBlocker)) {
            dp = dp.getPredecessor();

            if (dp == null)
                break;

            if (dp instanceof FrontEnd)
                dp = ((FrontEnd) dp).getLastDataProcessor();
        }

        if (dp != null)
            return 0;

        assert false : "Can not dermine the current shift-size of the given feature frontend.";
        return -1;
    }
}<commit_msg>added missing brackets and updated some outdated javadoc sections<commit_after>package edu.cmu.sphinx.frontend.util;

import edu.cmu.sphinx.frontend.DataBlocker;
import edu.cmu.sphinx.frontend.DataProcessor;
import edu.cmu.sphinx.frontend.FrontEnd;
import edu.cmu.sphinx.frontend.window.RaisedCosineWindower;

/**
 * Some little helper methods to ease the handling of frontend-processor chains.
 *
 * @author <NAME>
 */
public class FrontEndUtils {


    /** Returns a the next <code>DataProcessor</code> of type <code>predecClass</code> which preceeds <code>dp</code> */
    public static DataProcessor getDataSource(DataProcessor dp, Class<? extends DataProcessor> predecClass) {
        while (!predecClass.isInstance(dp.getPredecessor())) {
            dp = dp.getPredecessor();

            if (dp == null)
                return null;

            if (dp instanceof FrontEnd)
                dp = ((FrontEnd) dp).getLastDataProcessor();
        }


        return dp;
    }


    /**
     * Applies several heuristics in order to determine the shift-size of the fronted a given <code>DataProcessor</code>
     * belongs to.
     * <p/>
     * <p/>
     * The shift-size is searched using the following procedure <ol> <li> Try to determine the window shift-size used by
     * the <code>RaisedCosineWindower</code> which precedes the given <code>DataProcessor</code>. <li> If a data-blocker
     * is found within the precding processor chain but no <code>RaisedCosineWindower</code> 0 is returned. </ol>
     * <p/>
     * <p/>
     * If both approaches fail, an <code>AssertionError</code> becomes thrown.
     *
     * @param dataProc The <code>DataProcessor</code> which predecessors are searched backwards to some hints about the
     *                 used window shift size.
     * @return The found window shift size
     * @throws RuntimeException If both approaches fail, an <code>AssertionError</code> becomes thrown.
     */
    public static float getWindowShiftMs(DataProcessor dataProc) {
        DataProcessor dp = dataProc;

        while (!(dp instanceof RaisedCosineWindower)) {
            dp = dp.getPredecessor();

            if (dp == null) {
                break;
            }

            if (dp instanceof FrontEnd) {
                dp = ((FrontEnd) dp).getLastDataProcessor();
            }
        }

        if (dp != null) {
            return ((RaisedCosineWindower) dp).getWindowShiftInMs();
        }

        dp = dataProc;
        while (!(dp instanceof DataBlocker)) {
            dp = dp.getPredecessor();

            if (dp == null) {
                break;
            }

            if (dp instanceof FrontEnd) {
                dp = ((FrontEnd) dp).getLastDataProcessor();
            }
        }

        if (dp != null) {
            return 0;
        }

        throw new RuntimeException("Can not dermine the current shift-size of the given feature frontend.");
    }
}
{'fraction_non_alphanumeric': 0.1022903392457379, 'fraction_numerical': 0.0008610297916307905, 'mean_word_length': 2.2981260647359454, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 69, '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': '13028', 'n_tokens_mistral': 1710, 'n_tokens_neox': 1609, 'n_words': 490}