Corpus
Corpus paths, loading helpers, and FANTASTIC-style corpus statistics.
- compute_corpus_ngrams(melodies, n_range=(1, 5), phrase_gap=1.5, njobs=-1)[source]
Compute n-gram frequencies across the entire corpus using multiprocessing.
- Parameters:
- Returns:
Dictionary containing corpus-wide n-gram statistics
- Return type:
Dict
- save_corpus_stats(stats, filename)[source]
Save corpus statistics to a JSON file.
- Parameters:
stats (Dict) – Corpus statistics from compute_corpus_ngrams
filename (str) – Path to save JSON file
- Return type:
None
- load_corpus_stats(filename)[source]
Load corpus statistics from a JSON file.
- Parameters:
filename (str) – Path to JSON file. If no extension is provided, .json will be added.
- Returns:
Corpus statistics dictionary
- Return type:
Dict
- load_melodies_from_directory(directory, file_type='json', njobs=-1)[source]
Load melodies from a directory containing either JSON or MIDI files.
- make_corpus_stats(midi_dir, output_file, n_range=(1, 5), phrase_gap=1.5)[source]
Process a directory of MIDI files and save corpus statistics.
- Parameters:
midi_dir (str) – Path to directory containing MIDI files
output_file (str) – Path where to save the corpus statistics JSON file
n_range (Tuple[int, int], optional) – Inclusive range of n-gram lengths (min, max), by default (1, 5)
phrase_gap (float, optional) – Phrase-gap threshold in quarter-note units used by tokenization.
- Return type:
None
- make_corpus_stats_from_json(json_file, output_file, n_range=(1, 5), phrase_gap=1.5)[source]
Process a JSON file containing melody data and save corpus statistics.
- Parameters:
json_file (str) – Path to JSON file containing melody data
output_file (str) – Path where to save the corpus statistics JSON file
n_range (Tuple[int, int], optional) – Inclusive range of n-gram lengths (min, max), by default (1, 5)
phrase_gap (float, optional) – Phrase-gap threshold in quarter-note units used by tokenization.
- Return type:
None
- get_corpus_path(corpus_name)[source]
Get the path to a bundled corpus.
- Parameters:
corpus_name (str) – Name of the corpus. Currently supports: ‘essen’, ‘pearce_default_idyom’.
- Returns:
Path to the corpus directory
- Return type:
Path
- Raises:
ValueError – If the corpus name is not recognized
FileNotFoundError – If the corpus directory does not exist
- get_corpus_files(corpus_name, max_files=None)[source]
Get a list of MIDI files from a bundled corpus.
- Parameters:
- Returns:
List of MIDI file paths
- Return type:
List[Path]
- Raises:
ValueError – If the corpus name is not recognized
FileNotFoundError – If the corpus directory does not exist