<commit_before>package edu.cmu.sphinx.tools.corpus;

import java.io.*;

/**
 * Copyright 1999-2006 Carnegie Mellon University.
 * Portions Copyright 2002 Sun Microsystems, Inc.
 * Portions Copyright 2002 Mitsubishi Electric Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * <p/>
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL
 * WARRANTIES.
 * <p/>
 * User: <NAME>
 * Date: Mar 9, 2006
 * Time: 10:05:04 PM
 */

/**
 * This a sample program that demonstrates the Corpus API and AudioRecorder API.  It implements
 * a trivial corpus collection.  It reads transcripts from a text file, with each transcript separated by a LF.
 * It then creates a Corpus with an Utterance for each transcript.   It then prompts the user with the
 * transcript and records 5 seconds of audio.  Finally, it saves the Corpus as an XML file.
 */
public class CorpusRecorderSample {


    public static void main(String[] args) {
        try {

            if (args.length != 2) {
                throw new Error("USAGE: CorpusRecorderSample inputTranscriptFile outputCorpuXMLFile");
            }

            Corpus corpus = makeCorpusWithOnlyTrascripts(args[0]);

            for (Utterance utterance : corpus.getUtterances()) {
                recordAudioData(utterance);
            }

            FileOutputStream out = new FileOutputStream(args[1]);
            corpus.writeToXML(out);

        } catch (FileNotFoundException e) {
            throw new Error(e);
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    /**
     * Given a text file of transcripts, create a Corpus with Utterances that only contain transcripts.
     *
     * @param transcriptFile

     * @return
     * @throws IOException
     */
    private static Corpus makeCorpusWithOnlyTrascripts(String transcriptFile) throws IOException {

        // transcripts are stored as LF separated text
        LineNumberReader in = new LineNumberReader(new FileReader(transcriptFile));

        // create a new corpus
        Corpus corpus = new Corpus();

        // for each transcript in the file
        //   create a new utterance associated with that transcript
        //   add it to the corpus<commit_msg>Added argument to @return tag<commit_after>/**
 * Copyright 1999-2006 Carnegie Mellon University.
 * Portions Copyright 2002 Sun Microsystems, Inc.
 * Portions Copyright 2002 Mitsubishi Electric 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.tools.corpus;

import java.io.*;

/**
 * This a sample program that demonstrates the Corpus API and AudioRecorder API.  It implements
 * a trivial corpus collection.  It reads transcripts from a text file, with each transcript separated by a LF.
 * It then creates a Corpus with an Utterance for each transcript.   It then prompts the user with the
 * transcript and records 5 seconds of audio.  Finally, it saves the Corpus as an XML file.
 *
 * User: <NAME>
 * Date: Mar 9, 2006
 * Time: 10:05:04 PM
 */
public class CorpusRecorderSample {


    public static void main(String[] args) {
        try {

            if (args.length != 2) {
                throw new Error("USAGE: CorpusRecorderSample inputTranscriptFile outputCorpuXMLFile");
            }

            Corpus corpus = makeCorpusWithOnlyTrascripts(args[0]);

            for (Utterance utterance : corpus.getUtterances()) {
                recordAudioData(utterance);
            }

            FileOutputStream out = new FileOutputStream(args[1]);
            corpus.writeToXML(out);

        } catch (FileNotFoundException e) {
            throw new Error(e);
        } catch (IOException e) {
            throw new Error(e);
        }
    }

    /**
     * Given a text file of transcripts, create a Corpus with Utterances that only contain transcripts.
     *
     * @param transcriptFile
     * @return the corpus
     * @throws IOException
     */
    private static Corpus makeCorpusWithOnlyTrascripts(String transcriptFile) throws IOException {

        // transcripts are stored as LF separated text
        LineNumberReader in = new LineNumberReader(new FileReader(transcriptFile));

        // create a new corpus
        Corpus corpus = new Corpus();

        // for each transcript in the file
        //   create a new utterance associated with that transcript
        //   add it to the corpus
{'fraction_non_alphanumeric': 0.07397793640493186, 'fraction_numerical': 0.013411204845338524, 'mean_word_length': 2.5624036979969183, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2886722', 'n_tokens_mistral': 1322, 'n_tokens_neox': 1169, 'n_words': 478}