<commit_before>/*
 * Copyright (C) 2012 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.github.fhirschmann.clozegen.lib.frequency;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import nu.xom.*;

/**
 *
 * @author <NAME> <<EMAIL>>
 */
public abstract class AbstractFrequencyList<T> {
    private final List<ValueCount<T>> frequencies = new ArrayList<ValueCount<T>>();

    abstract void processChild(Element child);

    public void load(final String xmlFile)
            throws ParsingException, ValidityException, IOException {
        final InputStream stream = this.getClass().getClassLoader().
                getResourceAsStream(xmlFile);
<commit_msg>documented AbstractFrequencyList<commit_after>/*
 * Copyright (C) 2012 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.github.fhirschmann.clozegen.lib.frequency;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import nu.xom.*;

/**
 * Base class for all Frequency Distribution Lists.
 * <p>
 * This base class allows you to load a list of frequencies from an XML
 * file. These XML files must be of the following nature:
 * <pre>
 * <frequencies>
 *     <frequency value="1234" ... />
 *     <frequency value="4563" ... />
 * </frequencies>
 * </pre>
 * The only required xml attribute here is the "value" attribute which indicates
 * how many times the subject has occurred. You can add as many attributes
 * as you like and process them in processChild(), so the population
 * of the frequencies with ValueCount<T> is up to you.
 *
 * @author <NAME> <<EMAIL>>
 */
public abstract class AbstractFrequencyList<T> {
    /** The frequency count. */
    private final List<ValueCount<T>> frequencies = new ArrayList<ValueCount<T>>();

    /**
     * This method lets you process individual frequency-children in the XML file.
     *
     * @param child
     */
    abstract void processChild(Element child);

    /**
     * Loads the frequency list from an XML file.
     *
     * @param xmlFile
     * @throws ParsingException
     * @throws ValidityException
     * @throws IOException
     */
    public void load(final String xmlFile)
            throws ParsingException, ValidityException, IOException {
        final InputStream stream = this.getClass().getClassLoader().
                getResourceAsStream(xmlFile);

{'fraction_non_alphanumeric': 0.08771021992238033, 'fraction_numerical': 0.011901681759379043, 'mean_word_length': 3.5322391559202813, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '1378318', 'n_tokens_mistral': 1037, 'n_tokens_neox': 994, 'n_words': 446}