Normal..._Fields(3pm)
π NAME π
Normalize::Text::Music_Fields β bestie, this one normalizes names of people and (musical) works. It's giving "let me clean up your messy database" energy π
β¨ SYNOPSIS β¨
$name = $obj->Normalize::Text::Music_Fields::normalize_person($name);
$work = $obj->Normalize::Text::Music_Fields::normalize_piece($work);
# $obj should have methods `name_for_field_normalization', 'shorted_person'
so like, heads up: $obj needs to have the methods name_for_field_normalization and shorted_person. No cap π«Ά
π DESCRIPTION π
okay so the databases of names and of works-per-name are pulled from plain-text files (optionally in mail-header format, iykyk). Names live in *.lst files. Works live in .comp files, and those are named after the shortened name of the composer. iconic.
The directories where these files get looked for come from the environment variable MUSIC_FIELDS_PATH β if it's defined, it gets split the same way as PATH β or in $ENV{HOME}/.music_fields, and - (and yeah, that - gets replaced by the directory named as the module file with .pm dropped, fr fr).
At runtime, you can swap the whole list by calling the function Normalize::Text::Music_Fields::set_path() with the list of directories as the argument. slay.
β οΈ Since parsed files are cached, replacing the directory list should be done as early as possible. Like, before you get attached. periodt.
Files may be managed with utility subroutines provided with the module β and here are ALL of them, in their full glory, don't skip:
# Translate from one-per-line to mail-header format:
perl -wple "BEGIN {print q(# format = mail-header)} s/#\s*normalized\s*$//; $_ = qq(Title: $_) unless /^\s*(#|$)/; $_ = qq(\n$_) if $p and not /^##/; $_ .= qq(\n) unless $p = /^##/" Normalize::Text::Music_Fields-G_Gershwin.comp >Music_Fields-G_Gershwin.comp-mail
# (inverse transformation:) Dump pieces listed in mail-header format
perl -MNormalize::Text::Music_Fields -wle "print for Normalize::Text::Music_Fields::read_composer_file(shift, shift)" gershwin Music_Fields-G_Gershwin.comp-mail > o
# Normalize data in 1-line-per piece format
perl -MNormalize::Text::Music_Fields -wle "Normalize::Text::Music_Fields::prepare_tag_object_comp(shift)->Normalize::Text::Music_Fields::normalize_file_lines(shift)"
# Create a mail-header file from a semi-processed (with "bold" fields)
# mail-header file (with xml escapes, preceded by opus number)
perl -MNormalize::Text::Music_Fields -00wnle "BEGIN {$tag = Normalize::Text::Music_Fields::prepare_tag_object_comp(shift @ARGV); print q(# format = mail-header)} print Normalize::Text::Music_Fields::emit_as_mail_header($tag,$_, q(bold,xml,opus),$pre)" shostakovich o-xslt-better >Music_Fields-D_Shostakovich.comp-mail1
# Likewise, from work-per-line with opus-numbers:
perl -MNormalize::Text::Music_Fields -wnle "BEGIN {$tag = Normalize::Text::Music_Fields::prepare_tag_object_comp(shift @ARGV); print qq(# format = mail-header\n)} print Normalize::Text::Music_Fields::emit_as_mail_header($tag,$_, q(opus), $pre)" schnittke o-schnittke-better >Music_Fields-A_Schnittke.comp-mail2
# A primitive tool for merging additional info into the database:
perl -MNormalize::Text::Music_Fields -wnle "BEGIN {$tag = Normalize::Text::Music_Fields::prepare_tag_object_comp(shift @ARGV); print qq(# format = mail-header\n)} next unless s/^\s*\+\+\s*//; print Normalize::Text::Music_Fields::merge_info($tag,$_, q(opus,xml), qr(^(58|70|76|116|118|119)($|-)))" brahms o-brahms-op-no1-xslt
# Minimal consistency check of persons database.
perl -MNormalize::Text::Music_Fields -wle "BEGIN{binmode $_, ':encoding(cp866)' for \*STDIN, \*STDOUT, \*STDERR} print Normalize::Text::Music_Fields->check_persons"
# Minimal testing code:
perl -MNormalize::Text::Music_Fields -e Normalize::Text::Music_Fields::test_normalize_piece
ngl, typing all of those out is a whole cardio session π so it may be easier if one uses manage_M_N_F.pm, which exports the mentioned subroutines to the main namespace (available in examples directory of a distribution of MP3::Tag). E.g., the last example becomes:
perl -Mmanage_M_N_F -e test_normalize_piece
look at that glow-up. main character energy β¨π¦
and that's the whole page, bestie π this lil doc shipped as perl v5.36.0, dated 2022-12-30, part of the User Contributed Perl Documentation collection, filed under Normalize::Text::Music_Fields(3pm). go normalize something gorgeous πΈ
π¦ where this page comes from
- debian bookworm: libmp3-tag-perl 1.16-1 Β· Artistic-1.0-Perl
- debian trixie: libmp3-tag-perl 1.16-1 Β· Artistic-1.0-Perl
- ubuntu noble: libmp3-tag-perl 1.16-1 Β· Artistic-1.0-Perl
- ubuntu resolute: libmp3-tag-perl 1.16-1 Β· Artistic-1.0-Perl
- ubuntu stonking: libmp3-tag-perl 1.16-1 Β· Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms