-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperkins.pl
executable file
·7033 lines (6098 loc) · 398 KB
/
perkins.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env perl
#use warnings;
use File::Copy; # Module for copying files. Used to replace output file with temp cleaned-up file. #
use utf8; # Required to process Unicode text (the phonetic symbols). #
use Encode; # Module for dealing with different text encodings, such as UTF-8. #
use File::Slurp::Unicode; # Allows Unicode files to be slurped in. Required for final clean-up process #
use Getopt::Long qw(:config no_auto_abbrev); # Module for processing command line options. #
use Lingua::ES::Numeros; # Module to convert numerals to Spanish text. #
# NOTE: Do NOT use 'strict' -- it produces incorrect output!
my $version = "1.0.6";
# 11 July 2016
#######################################################################################
# Perkins #
# Copyright (c) 2016 Scott Sadowsky #
# #
# http://sadowsky.cl - ssadowsky at gmail period com #
# Licensed under the GNU Affero General Public License, version 3 (GNU AGPLv3) #
# #
# For help, run the program with the -h switch. #
# #
#######################################################################################
# #
# Script to phonetically transcribe, silabify and determine accents in Spanish text. #
# #
# USE: ./perkins.pl [OPTIONS] -i=input_file.txt [-o=output_file.txt] #
# #
# NOTE: Input and config files MUST be ISO-8859-1 (Latin-1) text. Output (and #
# optional debugging) files will be in UTF-8. #
# #
# Known bug (as of 102): convert_backchannel_vocalizations produces t͡ʃ.̩ː (with #
# spurious syllable dot). (Fixed as of 104?) #
# #
#######################################################################################
#################################################################################
# Perkins, the Phonetician's Assistant. #
# Copyright (C) 2016 Scott Sadowsky #
# http://sadowsky.cl · s s a d o w s k y A T g m a i l D O T com #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Affero General Public License as published #
# by the Free Software Foundation, either version 3 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 Affero General Public License for more details. #
# #
# You should have received a copy of the GNU Affero General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
#################################################################################
#################################################################################
# SET DEFAULT VALUES FOR PROGRAM OPTIONS AND VARIABLES #
#################################################################################
###################################################
# OPTIONS THAT USERS MAY CONFIGURE #
###################################################
# USER OPTIONS - PROGRAM BEHAVIOR #
our $debug = 0;
our $debug_syllab_sub = 0;
our $debug_to_logfile = 0;
our $silent_mode = 0;
our $batch_mode = 0; # Set to 1 for batch mode. This suppresses output to stdout, etc.
my $use_config_file = 0; # Choose whether or not to process the perkins.ini config file.
my $lang = "en"; # Default program message language
# META OPTIONS - FOR SPECIFIC COMBINATIONS OF VARIABLES
our $corpus_running_text = 0; # Select settings for the Coscach / Codicach: Running text syllabified at sentence
# level, one character per phoneme, etc. This overrides most other settings, to make
# sure that the corpus is processed uniformly, so turn it off to specify other options.
our $syllable_list = 0; # Select settings for producing output that is easy to process at the syllable level (each
# syllable is separated from others by a space). This overrides most other settings, to make
# sure that the corpus is processed uniformly, so turn it off to specify other options.
our $vrt_format = 0; # Select settings for generating one-word-per-line IMS Corpus Workbench-compatible
# vertical text (.vrt). Currently (381), Perkins only produces the transcribed form.
# This overrides most other settings to make sure that the corpus is processed
#uniformly, so turn it off to specify other options.
our $all_year_ranges = 1; # Process all date ranges (1-3 digit, 4 digit, BC dates).
# USER OPTIONS - FORMAT OR MODE OF TRANSCRIPTION OUTPUT #
our $output_PHON = 1; # Set output to phonemic transcription
our $output_CV = 0; # Instead of outputting phonemes, output C (consonant) or V (vowel)
our $output_CVG = 0; # Instead of outputting phonemes, output C (consonant), V (vowel) or G (glide)
our $output_CVNLRG = 0; # Instead of outputting phonemes, output Vowel, Nasal, Liquid, Rhotic,
# Glide or (misc) Consonant
our $output_manner = 0; # Instead of outputting phonemes, output the manner of articulation
our $output_place = 0; # Instead of outputting phonemes, output the mode of articulation
our $voicing = 0; # Instead of outputting phonemes, output the voicing
# USER OPTIONS - FOR SPECIFIC PHONEMES#
our $multichars = 1; # Represent certain phonemes using more than one character (e.g. use "t̠͡ʃ" instead of "ʧ")
our $tr_is_group = 0; # Treat /tr/ as a group. If on, it produces "t͡ɾ" with multichars and "ʂ" without it.
our $ch_dzh_retracted = 0; # Add retracted diacritic to the /t̠͡ʃ/ and /d̠͡ʒ/ digraphs (if /ʝ/ is not used)
our $ye_phoneme_is_fricative = 1; # Represent the phoneme "ye" (<ll> in "ella", <y> in "yo") with the palatal frictive symbol ʝ
# instead of the affricate ʤ
our $ye_phoneme_is_affricate = 0; # MUST have opposite value of $ye_phoneme_is_fricative !
our $use_ligatures = 1; # Use ligatures in /ʧ/ and /ʤ/ (/ʝ/)
our $use_one_char_ch_symbol = 0; # Use the /ʧ/ symbol to represent /ʧ/ regardless of the multichar setting. It was a stupid decision of mine to link the two!
our $use_one_char_ye_symbol = 1; # Use the /ʝ/ symbol to represent /ʝ/ regardless of the multichar setting. It was a stupid decision of mine to link the two!
our $use_dental_diacr = 1; # Use dental diacritic with /d/ and /t/
our $add_epenthetic_g = 0; # Add an epenthetic [g] before /w/. Traditionally believed ubiquitous in Chilean Spanish, but turns out to be rather uncommon.
# USER OPTIONS - FOR GLIDES #
our $glides_with_diacritics = 0; # Controls the following two variables.
our $non_syl_u_with_u_diacr = 0; # Represent the non-syllabic /u/ as /u̯/, not /w/
our $non_syl_i_with_i_diacr = 0; # Represent the non-syllabic /i/ as /i̯/, not /j/
# USER OPTIONS - STRESS #
our $stress_using_tildes = 0; # If 1, mark stress with tildes on stressed vowels; if 0, mark it with IPA apostrophes.
our $no_stress_marks = 0; # Don't include any type of stress indication. Only for special cases.
our $non_ipa_apostrophes = 0; # Use the standard orthographic apostrophe (') instead of the IPA one (which doesn't show in Praat)
# Added in 376
# USER OPTIONS - SYLLABLES #
our $insert_syllable_dots = 1; # Insert dots between each syllable
our $split_at_syllables = 0; # Put a newline at each syllable break.
our $syllabify_by_sentence = 1; # Syllabifies by sentence instead of by word. Means that "los hombres" > /lo.som.bres/
# instead of /los om.bres/
our $syllable_dots_are_spaces = 0; # Separate syllables with spaces instead of dots. Designed to facilitate processing
# and research on syllables in the Codicach, etc. (lets syls be treated as words)
# USER OPTIONS - PAUSES #
our $ipa_pause_symbols = 1; # Use the IPA's | and ‖ method of representing pauses #
our $ipa_long_pause_two_singles = 0; # For long IPA pauses, use two single pause bars (||) instead of one#
# double bar (‖). This is useful b/c Praat can't show the double bar.#
our $add_comma_pauses = 1; # Commas are converted into short pauses: (.) #
our $add_colon_pauses = 1; # Colons are converted into medium pauses: (..) #
our $add_semicolon_pauses = 1; # Semicolons are converted into long pauses: (...) #
our $add_sentence_breaks = 1; # Periods are converted into absolute breaks: ## #
our $add_paragraph_breaks = 1; # Paragraph breaks are converted into longest pause: ### #
# This can be in addition to newlines. #
our $add_ellipsis_pauses = 1; # Ellipses are converted into a long pause: (...) #
our $add_bracket_pauses = 1; # Convert [ and ] into short pauses (.) #
our $add_paren_pauses = 1; # Convert ( and ) into short pauses (.) #
# USER OPTIONS - NUMBERS #
our $numerals_to_words = 1; # Convert numerals (123) to words (uno dos tres) #
our $num_symbol = "·"; # Symbol used to replace numerals if that option is chosen #
our $narrow_year_ranges = 1; # Treat two consecutive 4-digit numbers separated by "-" as a range of years #
# (e.g. "1900-1950" > "1900 a 1950") instead of an equation (1900 minus 1950) #
# IF AND ONLY IF the second number is larger than the first. #
our $broad_year_ranges = 1; # Treat two consecutive 1-4 digit numbers separated by "-" as a range of years #
# (e.g. "211-300" > "211 a 300") instead of an equation (211 minus 300) #
# IF AND ONLY IF the second number is larger than the first. #
our $bc_dates_included = 1; # Remove restriction on second number having to be larger than the first from #
# $narrow_year_ranges and $broad_year_ranges. #
# USER OPTIONS - ODD CHARACTERS #
our $fix_umlauts = 1; # Change vowels with umlauts to bare vowels (except ü for diéresis) #
our $fix_grave_accents = 1; # Change vowels with umlauts to bare vowels (tù, està > tú, está) #
our $fix_circumflexes = 1; # Change vowels with circumflexes to bare vowels (hôstel > hostel) #
our $fix_nasal_tildes = 1; # Change vowels with nasal tildes to bare vowels (S~ao > Sao) #
# USER OPTIONS - SUBSTITUTIONS #
our $moneda = "pésos"; # String used to replace "$" character #
our $slash = "eslách"; # String used to replace "/" character #
our $process_urls = 1; # Process URLs, treating them as linguistic strings. #
our $process_email = 1; # Process e-mail addresses, treating them as linguistic strings. #
# NEW IN 0406 ->
our $name_for_v = "becórta"; # Name for letter "v" to be used when spelling individual letters out.#
# Suggested values: "becórta", "bechíca", "úve" (with tilde on #
# accented syl. and written as one word). #
# USER OPTIONS - MISC #
our $keep_paragraphs = 1; # Keep paragraphs in the source text. Otherwise, output will be one big block. #
our $vertical_output = 0; # Output contains one word per line. #
# NEW IN 104. TESTING!
our $double_vowels_to_singles = 1; # Reduce two identical vowels ("aa", "ee", "ii", etc.) to a single one.
###################################################
# OPTIONS THAT USERS MAY *NOT* CONFIGURE #
###################################################
our $semi_narrow = 0; # NOT YET IMPLEMENTED. Select whether to process the broad transcription once it's produced, in order #
# to create a semi-narrow transcription #
our $cleanup_output_file = 1; # WARNING Must ALWAYS be 1! After processing the input file and producing the output #
# file, this option makes Perkins open the output file again to perform cleanup.#
our $no_separate_cleanup_file = 1; # WARNING Must ALWAYS be 1! Determines if the cleaned up version goes to a separate text#
# file or replaces the output file ONLY IN BETA MODE. #
# OUTPUT: CLEANUP OPTIONS #
our $preclean_orthographic = 1; # WARNING Must ALWAYS be 1! Apply the clean-up routine for words in their orthographic form
our $preclean_semiphonemic = 1; # WARNING Must ALWAYS be 1! Apply the clean-up routine for words in their semi-phonemic form
our $preclean_phonemic = 0; # WARNING NOT IMPLEMENTED YET! # Apply the clean-up routine for words in their phonemic form
# MISC #
my $upper_case = 0; # Sets whether output is uppercased (CV, CVG, etc.; bad for phonemic transcription)
our $kill_common_words = 0; # FOR TESTING. Eliminate common words to make it easier to find novel mistakes.
# INTERNAL VARIABLES THAT NEED INITIALIZED - DON'T CHANGE!
my $helpme = 0; # Should help message be printed to terminal?
my $useme = 0; # Should usage message be printed to terminal?
my $config_file_present = 0;
my $output_filename = "";
my $progname = "";
# Set program name according to OS. Assumes Windows users will use #
# the .exe version of Perkins. #
if ( $^O eq "MSWin32" ) { $progname = "perkins.exe " }
else { $progname = "./perkins.pl" }
############################################################################
# DECLARE VARIABLES THAT REQUIRE A (DEFAULT) VALUE #
# DON'T CHANGE ANYTHING HERE UNLESS YOU ARE REWRITING THE ENTIRE PROGRAM #
############################################################################
my $accent = "";
my $acute_consonants = "(b|ʧ|d|ʤ|ʝ|f|g|j|k|l|m|ɲ|p|ɾ|r|ʂ|t|w|x|y|z)";
my $acute_consonants_except_j = "(b|ʧ|d|ʤ|ʝ|f|g|k|l|m|ɲ|p|ɾ|r|ʂ|t|w|x|y|z)";
my $all_consonants = "(b|ʧ|d|ʤ|ʝ|f|g|j|k|l|m|ɲ|n|p|ɾ|r|s|ʂ|t|w|x|y|z)";
my $all_consonants_but_glides = "(b|ʧ|d|ʤ|ʝ|f|g|k|l|m|ɲ|n|p|ɾ|r|s|ʂ|t|x|y|z)";
my $non_liquids = "(b|ʧ|d|ʤ|ʝ|f|g|j|k|m|ɲ|n|p|s|ʂ|t|w|x|y|z)";
my $orthog_epenth_e_cons = "(b|c|d|f|g|j|k|l|m|n|p|q|r|s|t|v|x|y|z)";
my $stressed_vowels = "(á|é|í|ó|ú)";
my $unstressed_vowels = "(a|e|i|o|u)";
my $all_vowels = "(a|e|i|o|u|á|é|í|ó|ú)";
my $strong_vowels = "(a|e|o)";
my $weak_vowels = "(i|u)";
# For sentence-level syllabification
my $all_consonants_diacr = "(b|ʧ|t͡ʃ|t̠͡ʃ|d|d̪|ʤ|d͡ʒ|d̠͡ʒ|ʝ|f|g|j|k|l|m|ɲ|n|p|ɾ|r|s|ʂ|t|t̪|tɾ|t̪ɾ|t͡ɾ|t̪͡ɾ|w|x|y|z)";
my $all_vowels_diacr = "(a|e|i|o|u|á|é|í|ó|ú|i̯|u̯)";
# The following are for the routine that replaces phonemes with C, V, N, L, G, etc.
my $misc_cons = "(b|ʧ|d|ʤ|ʝ|f|g|k|p|s|ʂ|t|x)";
my $nasals = "(m|n|ɲ)";
my $liquids = "(l)";
my $glides = "(j|w)";
my $rhotics = "(r|ɾ)";
my $vowels_glides = "(a|e|i|o|u|á|é|í|ó|ú|j|w)";
# The /tr/ group... always fun! NOTE: Not used much by Perkins -- ʂ is normally hard-coded
my $tr = "(ʂ)";
# The following are for the routine that replaces phonemes with MANNERS of articulation
my $plosives = "(b|d|g|k|p|t)";
# $nasals is declared above.
my $trills = "(r)";
my $taps = "(ɾ)";
my $fricatives = "(f|s|x|ʝ)";
my $laterals = "(l)";
my $affricates = "(ʧ|ʤ)";
my $aproximants = "(j|w)";
# The following are for the routine that replaces phonemes with PLACES of articulation
my $bilabials = "(b|m|p)";
my $labiodentals = "(f)";
my $dentals = "(d|t)";
my $alveolars = "(n|ɾ|r|s|l)";
my $postalveolars = "(ʧ|ʤ)";
my $palatals = "(j|ʝ|ɲ)";
my $velars = "(k|g|x)";
my $labiovelars = "(w)";
# The following are for the routine that replaces phonemes with VOICING
my $voiced = "(a|e|i|o|u|á|é|í|ó|ú|b|d|g|ʤ|ʝ|j|l|m|ɲ|n|ɾ|r|w)";
my $unvoiced = "(ʧ|f|k|p|s|ʂ|t|x)";
############################################################################
# DECLARE EMPTY LOCAL VARIABLES #
############################################################################
my (
@character, $character, $input_line, $last_vowel_pos, @rev_vowels, $sec_last_vowel_pos,
@syllable, $curr_syl, $vowel_count, $vowels, $word, @word_array,
$i, $sentence_break, $comma_pause, $semicolon_pause, $colon_pause, $ellipsis_pause,
$initial_bracket_pause, $final_bracket_pause, $initial_paren_pause, $final_paren_pause, $syl_count, $prev_input_line,
@whole_file_array, $whole_file, $input_filename, $in_basename, $beta_file, @utterance_array,
$utterance, $item, @uniquearray, $next_char_syl_break, $sr_input_line, @sr_array,
$output_format, $cfg_file_was_read, $print_usage, $current_numeral, $numeral_converter_obj, $word_list,
$temp, $debug_message, $user_message, $eng, $esp, $coscach_mode, $long_pause_symbol
);
#################################################################################
# CREATE HASH OF ALLOPHONE > SYMBOL MAPPINGS BY READING EXTERNAL FILE #
# IF SEMI-NARROW TRANSCRIPTION OPTION IS CHOSEN #
# NOTE NOTE NOT YET IMPLEMENTED! NOTE NOTE #
#################################################################################
#if ( $semi_narrow == 1 ) {
# our %allophone_table = ();
# do "tabla_alofonos.pl";
#}
############################################################################
# PROCESS THE CONFIGURATION FILE (perkins.ini) IF IT EXISTS #
# If $use_config_file is true, then these options supercede the defaults #
############################################################################
# Open config file, if the option set at beginning of this file allows it #
if ( $use_config_file == 1 ) {
open( CONFIGFILE, '<:encoding(iso-8859-1)', "perkins.ini" ) # Input must be ISO-8859-1
|| &config_file_failed;
}
# Process the config file and assign to variables the values found therein. #
if ( ( $use_config_file == 1 ) && ( $config_file_present == 1 ) ) {
while (<CONFIGFILE>) {
chomp; # Kill newlines
s/#.*//; # Kill comments
s/^\s+//; # Kill leading whitespace
s/\s+$//; # Kill trailing whitespace
next unless length; # Is anything left?
my ( $var, $value ) = split( /\s*=\s*/, $_, 2 ); # Split input strings
$$var = $value; # Assign values to variables
}
}
#################################################################################
# Read and clean up CLI options #
#################################################################################
GetOptions(
"debug|d!" => \$debug, # Debug Perkins.
"lang|l=s" => \$lang, # Language for program messages
"es" => \$esp, # Spanish language program messages selected (alt method)
"en" => \$eng, # English language program messages selected (alt method)
"debug-log|log|dl!" => \$debug_to_logfile, # Write debug info to log file
"input|i=s" => \$input_filename,
"output|o=s" => \$output_filename,
"help|ayuda|h|?" => \$helpme, # See if user needs help
"usage|use|uso|u" => \$useme, # Print usage information to terminal
"format|formato|f:s" => \$output_format, # Output format: --f=manner
"trg|tg!" => \$tr_is_group, # Treat TR as group: --trg
"yef|yf!" => \$ye_phoneme_is_fricative, # Render YE as fricative: --
"yea|ya!" => \$ye_phoneme_is_affricate, # Render YE as affricate: --
"afr|ar!" => \$ch_dzh_retracted, # Affricates retracted: --afr
"st|at!" => \$stress_using_tildes, # Represent stress with tilde, NOT IPA apostrophe. #
"multi|mc|ms!" => \$multichars, # Use more than one IPA symbol for certain phonemes (e.g. t̠͡ʃ). #
"glides-dia|gd!" => \$glides_with_diacritics, # Representar glides como vocal + diacrítico "no silábico" #
"wvd|wv!" => \$non_syl_u_with_u_diacr, # Represent wau with a u + non-syllabic diacritic. #
"yvd|yv!" => \$non_syl_i_with_i_diacr, # Represent yod with an i + non-syllabic diacritic. #
"batch|bm|b|quiet|callate!" => \$batch_mode, # Run Perkins in batch mode: no STDOUT output. #
"pausas-afi|ipa-pauses|ip|pi!" => \$ipa_pause_symbols, # Represent pauses using IPA's | and || symbols. #
"lp2|pl2!" => \$ipa_long_pause_two_singles, # Represent IPA long pause as 2 single pause bars #
"pco|cmp!" => \$add_comma_pauses, # Convert commas into pauses. #
"pdp|clp!" => \$add_colon_pauses, # Convert colons into pauses. #
"ppc|scp!" => \$add_semicolon_pauses, # Convert semicolons into pauses. #
"por|snp!" => \$add_sentence_breaks, # Add breaks between sentences. #
"ppa|ppp!" => \$add_paragraph_breaks, # Add breaks between paragraphs. #
"pel|elp!" => \$add_ellipsis_pauses, # Convert ellipses into pauses. #
"pcr|brp!" => \$add_bracket_pauses, # Convert brackets into pauses. #
"ppn|pnp!" => \$add_paren_pauses, # Convert parentheses into pauses. #
"n2w|nap!" => \$numerals_to_words, # Convert numerals into words. #
"sn:s" => \$num_symbol, # Replace numbers with this symbol. #
"mon|cur:s" => \$moneda, # Replace $ symbol with this text. #
"lo|sl:s" => \$slash, # Replace / symbol with this text. #
"no-stress-marks|nsm|nma!" => \$no_stress_marks, # Don't include any type of stress indication. #
"split-syls|div-sil|sas|des|split-syls!" => \$split_at_syllables, # Put each syllable on a line of its own. #
"upl|owl|saw|dep|vo|split-words!" => \$vertical_output, # Output has one word per line. #
# the "cwr" CL optins was killed in 407 -- it's an internal variable!
# "cwr!" => \$cfg_file_was_read, # Set to 1 if config file was successfully read. #
"mp|kp!" => \$keep_paragraphs, # Keep paragraph breaks. Otherwise, output is a wall of transcription.#
# Permit output format options to be chosen as simple switches:
"cv!" => \$output_CV,
"cvg!" => \$output_CVG,
"cvn|cvnlrg!" => \$output_CVNLRG,
"manner|man|modo|m!" => \$output_manner,
"place|pl|punto|p!" => \$output_place,
"voicing|voice|v|sonoridad|son|s!" => \$voicing,
"kill-common|eliminar-comunes|kcw|kc|epc|ep!" => \$kill_common_words,
"phon|fon|ph|IPA|AFI" => \$output_PHON,
"cfg|ini!" => \$use_config_file,
"nia|oa|ao!" => \$non_ipa_apostrophes,
"syl-dots|sil-puntos|sd|sp!" => \$insert_syllable_dots,
"syl-spaces|sil-esp|ss|se!" => \$syllable_dots_are_spaces,
"sbs|sbu|spe|spo!" => \$syllabify_by_sentence,
"silent-mode|silent|sil|sm!" => \$silent_mode,
"rt|tc|corpus!" => \$corpus_running_text,
"coscach|csc" => \$coscach_mode,
"syl-list|lista-sil|sl|ls!" => \$syllable_list,
"word-list|lista-pal|wl|lp!" => \$word_list,
"vrt!" => \$vrt_format,
"urls|pu!" => \$process_urls,
"email|pe!" => \$process_email,
"nyr|rae!" => \$narrow_year_ranges,
"byr|raa!" => \$broad_year_ranges,
"bcy|aac!" => \$bc_dates_included,
"ayr|tra" => \$all_year_ranges,
"lig!" => \$use_ligatures,
"och!" => \$use_one_char_ch_symbol,
"oye!" => \$use_one_char_ye_symbol,
"dent|dd!" => \$use_dental_diacr,
"aeg|age!" => \$add_epenthetic_g,
"dvs!" => \$double_vowels_to_singles
);
############################################################################
# SET PROGRAM INTERFACE LANGUAGE IF BINARY SWITCHES USED #
############################################################################
if ( $eng == 1 ) { $lang = "en" }
if ( $esp == 1 ) { $lang = "es" }
############################################################################
# DEFINE LANGUAGE STRINGS FOR LOCALIZATION #
############################################################################
&assign_lang_str;
############################################################################
# IF USER NEEDS HELP, RUN HELP SUBROUTINE AND DIE #
############################################################################
if ( $helpme == 1 ) {
&print_help;
exit;
}
############################################################################
# IF USER REQUESTS USAGE INFO, RUN THAT SUBROUTINE AND DIE #
############################################################################
if ( $useme == 1 ) {
&print_usage;
exit;
}
# Lowercase any text provided with the -f (output format) switch #
$output_format = lc($output_format);
############################################################################
# SET OPTIONS FOR DEBUGGING TO LOG FILE #
############################################################################
if ( $debug_to_logfile == 1 ) {
$debug = 1;
}
############################################################################
# VERIFY CLI OPTIONS #
# Only checks some of them. #
############################################################################
&verify_cli_options;
############################################################################
# AUTOMATICALLY SELECT VRT FORMAT IF INPUT FILE ENDS IN ".VRT" #
############################################################################
if ( $input_filename =~ m/\.vrt$/ ) {
$vrt_format = 1;
}
############################################################################
# OPEN INPUT FILE, CREATE LOG FILE #
############################################################################
&open_input_and_log_files;
############################################################################
# Print bug log header, status messages, CLI info and cfg file status #
# message #
############################################################################
my $current_time = localtime(); # Get local time for log file
&print_header_CLI_status_msgs;
############################################################################
# ASSIGN DEFAULT OUTPUT FILENAME IF NECESSARY (.phnm extension) #
############################################################################
if ( $output_filename eq "" ) {
&assign_default_output_filename;
}
############################################################################
# OPEN OUTPUT FILE - Output will be UTF-8 #
############################################################################
&open_output_file;
############################################################################
# PROCESS COMMAND LINE OPTIONS #
# If there are any, they supercede both the defaults and the .ini file #
############################################################################
&process_command_line_options;
############################################################################
# FORCIBLY SET VARIABLES THAT DEPEND ON OTHER VARIABLES #
# This has to be done here, and not earlier, so as to receive any changed #
# variable values from the config file or command line options. #
############################################################################
&forcibly_set_variables;
############################################################################
# CONSOLE GREETING #
# This is printed in normal (non-batch/non-silent) mode, but only if the #
# debug to log file option is OFF. #
############################################################################
if ( ( $batch_mode == "0" ) && ( $debug_to_logfile == 0 ) ) {
&print_console_greeting;
}
############################################################################
# Print message to log file if config file couldn't be read. #
# Only done if debug is ON and debug to log file is ON. #
############################################################################
if ( ( $debug == 1 ) && ( $debug_to_logfile == 1 ) ) {
print LOGFILE "\nDEBUG IO: *WARINING* External config file couldn't be opened.";
print LOGFILE "\nDEBUG IO: Using defaults instead.";
}
sub start_of_program {
# This is a dummy subroutine. Its only purpose is to generate an automatic
# link in my IDE.
}
############################################################################
# #
# BEGIN PROCESSING THE INPUT TEXT FILE #
# #
############################################################################
while (<INPUTFILE>) {
chomp;
$input_line = lc;
############################################################################
# .VRT COLUMN STRIPPING #
# If reading .vrt text files produced by Connexor, eliminate all text but #
# the second column (word forms) #
############################################################################
# TODO: Allow user to specify the column to keep.
if ( $vrt_format == 1 ) {
#print STDOUT "VRT-STRIPPING-BEF:$current_item:\n"; # AD-HOC DEBUG
$input_line =~ s/^.+?\t(.+?)\t.+$/$1/g;
#print STDOUT "VRT-STRIPPING-AFT:$current_item:\n"; # AD-HOC DEBUG
}
############################################################################
# .VRT DISASTEROUS CHARACTER ELIMINATION #
# Kill odd characters that are used internally by Perkins, before anything #
# else is replaced. #
############################################################################
if ( $vrt_format == 1 ) {
$input_line = kill_disasterous_vrt_chars($input_line);
}
############################################################################
# PROCESS INTERNET STUFF #
# This must be run before "-" is converted into a space, etc. #
############################################################################
$input_line = &process_internet_stuff($input_line);
### VRT-PP was here (400)
############################################################################
# FIX MISCELLANEOUS PUNCTUATION #
############################################################################
$input_line = &fix_misc_punctuation($input_line);
############################################################################
# EXPAND ABBREVIATIONS IN ORTHOGRAPHIC FORM #
############################################################################
$input_line = &expand_abbreviations_ortho($input_line);
############################################################################
# CONVERT NUMERALS TO WORDS #
############################################################################
if ( $numerals_to_words == 1 ) {
$input_line = &convert_numerals_to_words($input_line);
}
# If numeral to word option not selected, turn numbers into a special symbol
else {
$input_line =~ s/[0-9]/$num_symbol/g;
}
############################################################################
# CHANGE CERTAIN SYMBOLS TO WORD FORM #
############################################################################
$input_line = &change_some_symbols_to_words($input_line);
############################################################################
# SEARCH AND REPLACE MULTI-WORD PHRASES #
# (e.g. "data show", "blue jeans") #
############################################################################
$input_line = &replace_multiword_phrases($input_line);
############################################################################
# PRE-PROCESSING: Fix specific rarities #
############################################################################
# NOTE Moved from word section (below) to input_line section in 380
$input_line = &fix_specific_rarities($input_line);
############################################################################
# PRE-PROCESSING: Fix odd characters #
############################################################################
# NOTE Moved from word section (below) to input_line section in 380
$input_line = &fix_odd_characters($input_line);
############################################################################
# VRT PRE-PROCESSING #
# If reading .vrt text files produced by Connexor, replace <tags>, commas, #
# periods, etc. with special characters (which will be converted into the #
# original Connexor symbols later) #
############################################################################
# WARNING: In 400 moved this from *before* the convert nums to words sub to here
if ( $vrt_format == 1 ) {
$input_line = &do_vrt_preprocessing($input_line);
#print "\nAFT-VRT-PRE-PROCESSING:$input_line\n"; # AD-HOC DEBUG
}
############################################################################
# SPLIT LINES INTO WORDS #
############################################################################
@word_array = split / /, $input_line;
foreach my $word (@word_array) {
#print "\nBEF-CHANGE-¬-TO-SPACE :$word\n"; # AD-HOC DEBUG
# Change ¬ to space (for VRT format). If the ¬ is not inserted previously, #
# then the above split will break up VRT lines into one word per line, #
# utterly mangling the output file's line-by-line correspondence to the #
# input .vrt file. #
$word =~ s/¬/ /g;
#print "AFT-CHANGE-¬-TO-SPACE :$word\n"; # AD-HOC DEBUG
#######################################################################
# KILL COMMON WORDS (FOR TESTING) #
#######################################################################
if ( $kill_common_words == 1 ) {
$word = &kill_common_words($word);
}
#################################################################################
# HACK: CLEAN UP WORDS IN THEIR ORTHOGRAPHIC FORM #
# You can use regular expressions here. At this stage, the words #
# are in orthographic form, and your replacement expressions should #
# be, too. This doesn't allow certain changes -- they're reverted later #
# on by the script. To fix those, go to the hacks section at the end. #
#################################################################################
if ( $preclean_orthographic == 1 ) {
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# NOTE: The following routine does work, but it's incredibly slow. #
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# #################################################################################
# # REPLACE SINGLE WORDS IN ORTHOGRAPHIC FORM, USING AN EXTERNAL FILE AS SOURCE #
# # FOR S&R ARGUMENTS. Input file must be ISO-8859-1. #
# #################################################################################
# open( WORDSRFILE, '<:encoding(iso-8859-1)', "perkins-reemplazar-palabras.ini" );
#
# #print STDOUT "\n*** Orthographic S&R file (perkins-reemplazar-palabras.ini) successfully read. ***\n\n";
#
# while (<WORDSRFILE>) {
# chomp;
# $sr_input_line = lc;
#
# # Reduce all whitespace to a single tab
# $sr_input_line =~ s/(\W+)/\t/g;
#
# # Extract from each line the expected two arguments, separated by whitespace: search arg + replace arg.
# my ( $search_arg, $repl_arg ) = split /\t/, $sr_input_line;
#
# # Do the actual searching and replacing.
# $word =~ s/(^|\.|,|:|;|"|-|‖|\[|\(|\{)$search_arg($|\.|,|:|;|"|-|‖|\]|\)|\})/$1$repl_arg$2/g;
# }
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
##################################################################
# MODIFY SINGLE WORDS IN ORTHOGRAPHIC FORM #
##################################################################
$word = modify_single_ortho_words($word);
######################################################################
# DANGER NEW in 104! #
# PRE-PROCESSING: Convert double (or more) vowels to singles #
######################################################################
$word = &double_vowels_to_single_vowels($word);
##################################################################
# SPELL OUT SINGLE LETTERS #
##################################################################
$word = spell_out_single_letters($word);
##################################################################
# FIX LETTER PATTERNS #
##################################################################
$word = fix_letter_patters($word);
#print "PRECLEAN-ORTHO-AFT :$word:\n"; # AD-HOC DEBUG
}
#######################################################################
# #
# BROAD (PHONEMIC) TRANSCRIPTION #
# #
#######################################################################
#######################################################################
# CONVERT PUNCTUATION TO PAUSES #
#######################################################################
$word = convert_punctuation_to_pauses($word);
#print "CNVRT-PUNCT-TO.PAUSES:$word:\n"; # AD-HOC DEBUG
#print "AFT-CNVT-PUNCT-PAUSES :$word\n"; # AD-HOC DEBUG
############################################################################
# CONVERT (MOST) GRAPHEMES TO INTERMEDIATE REPRESENTATIONS OF PHONEMES #
############################################################################
$word = convert_graphemes_to_interm_phonemes($word);
############################################################################
# CHANGE INTERMEDIATE REPRESENTATIONS OF PHONEMES TO THEIR DEFINITIVE #
# **ONE-CHARACTER** FORMS #
############################################################################
$word = change_interm_phonemes_to_one_char($word);
#print "CHNG-INTERM-PHNM-1CHR:$word:\n"; # AD-HOC DEBUG
############################################################################
# PROCESS DIPHTHONGS #
# /j/ and /w/ are used as intermetiate representations of #
# non-syllabic vowels #
############################################################################
$word = process_diphthongs($word);
###############################################################################
# #
# STRESS ACCENT ROUTINE - PREPARATION #
# #
###############################################################################
# NOTE: This section need to be *here*, before tildes are removed from vowels.#
###############################################################################
if ( $vrt_format == 0 ) {
$word = stress_accent_routine($word);
}
else { # Process VRT Files. WARNING: New in 400
############################################################################
# Split each line (utterance) into individual words if VRT format is used. #
# Multi-word lines are (mainly, if not exclusively) generated by the #
# numbers > words routine; the Connexor files fed into VRT are strictly #
# one word per line. #
############################################################################
my @current_segments = split /\s/, $word;
foreach my $current_segment (@current_segments) {
$current_segment = stress_accent_routine($current_segment);
}
$word = join( " ", @current_segments );
#$temp = Encode::encode_utf8( $word ); # AD-HOC DEBUG
#print STDOUT "AFT-SPLIT-VRT-LINES2WD:$temp\n"; # AD-HOC DEBUG
}
############################################################################
# FINAL TOUCHES TO THE BROAD TRANSCRIPTION #
############################################################################
$word = final_touches_broad_transcr($word);
#$temp = Encode::encode_utf8( $word );
#print STDOUT "AFT-FINAL-TCH-BRD-TR :$temp\n"; # AD-HOC DEBUG
############################################################################
# PERFORM SYLLABIFICATION #
# If there are any, they supercede both the defaults and the .ini file #
############################################################################
$word = perform_syllabification($word);
#$temp = Encode::encode_utf8( $word ); # AD-HOC DEBUG
#print STDOUT "AFT-PERFORM-SYLLABIFIC:$temp\n"; # AD-HOC DEBUG
# Remove spurious syllabification dots inserted at beginning of words #
# when a "word" is actually a phrase (FOR .VRT FORMAT) #
if ( $vrt_format == 1 ) {
$word =~ s/ \./ /g;
#$temp = Encode::encode_utf8( $word ); # AD-HOC DEBUG
#print STDOUT "AFT-PERFORM-SYLLABIFIC:$temp\n"; # AD-HOC DEBUG
}
#print STDOUT "AFT-PERFORM-SYLLABIFIC :$word\n"; # AD-HOC DEBUG
if ( $debug_syllab_sub == 1 ) {
print STDOUT "\t\$word = $word"; # NOTE DEBUG
}
############################################################################
# CONVERT BACKCHANNEL VOCALIZATIONS (MM, HM, EH...) TO UNICODE IPA #
# DANGER! WARNING! NEW IN 102. +++++ #
############################################################################
$word = convert_backchannel_vocalizations($word);
#################################################################################
# ==OPTIONAL== #
# CONVERT VOWELS WITH TILDES INTO NORMAL VOWELS WITH IPA #
# STRESS ACCENT APOSTROPHES AT THE BEGINNING OF THEIR SYLLABLE #
# ( es.tá > es.'ta ) #
#################################################################################
if ( $stress_using_tildes == 0 ) {
$word = opt_tildes_to_ipa_apostrophes($word);
}
#######################################################################
# REPRESENT PHONEME "YE" AS FRICATIVE (ʝ) (OPTIONAL) #
#######################################################################
if ( $ye_phoneme_is_fricative == 1 ) {
$word =~ s/ʤ/ʝ/g;
}
#######################################################################
# ==OPTIONAL== #
# USE MULTI-CHARACTER PHONEME SYMBOLS #
# ( ʧ > t̠͡ʃ, ʤ > d̠͡ʒ, etc. ) #
#######################################################################
if ( $multichars == 1 ) {
$word = opt_use_multichars($word);
}
#######################################################################
# OPTIONAL PHONEME TRANSFORMATIONS #
#######################################################################
$word = opt_phoneme_transforms($word);
#######################################################################
# #
# OUTPUT FORMAT TRANSFORMATIONS #
# #
#######################################################################
#######################################################################
# IF SELECTED, CONVERT PHONEMES TO C OR V #
#######################################################################
if ( $output_CV == 1 ) {
$word = opt_convert_phonemes_cv($word);
}
#######################################################################
# IF SELECTED, CONVERT PHONEMES TO C, V OR G #
#######################################################################
if ( $output_CVG == 1 ) {
$word = opt_convert_phonemes_cvg($word);
}
#######################################################################
# IF SELECTED, CONVERT PHONEMES TO C, V, N, L, R OR G #
#######################################################################
if ( $output_CVNLRG == 1 ) {
$word = opt_convert_phonemes_cvnlrg($word);
}
#######################################################################
# IF SELECTED, CONVERT PHONEMES TO MANNERS OF ARTICULATION #
#######################################################################
if ( $output_manner == 1 ) {
$word = opt_convert_phonemes_manners($word);
}
#######################################################################
# IF SELECTED, CONVERT PHONEMES TO PLACES OF ARTICULATION #
#######################################################################
if ( $output_place == 1 ) {
$word = opt_convert_phonemes_places($word);
}
#######################################################################
# IF SELECTED, CONVERT PHONEMES TO VOICING #
#######################################################################
if ( $voicing == 1 ) {
$word = opt_convert_phonemes_voicing($word);
}
#######################################################################
# IMPLEMENT PUNCTUATION > PAUSES #
#######################################################################
if ( $ipa_pause_symbols == 1 ) {
$word = punct_to_pauses_ipa($word);
}
# Insert non-IPA pauses: (.) (..) (...) ## ### #
else {
$word = punct_to_pauses_non_ipa($word);
}
##########################################################################
# SPLIT AT SYLLABLES: PUT A NEWLINE AT EACH SYLLABLE BOUNDARY IF DESIRED #
##########################################################################
if ( $split_at_syllables == 1 ) {
$word = opt_split_at_syllables($word);
}
#######################################################################
# ELIMINATE STRESS MARKS IF DESIRED #
#######################################################################
if ( $no_stress_marks == 1 ) {
$word =~ s/ˈ//g;
}
#######################################################################
# CONVERT IPA STRESS MARKS TO ORTHOGRAPHIC APOSTROPHES IF DESIRED #
# WARNING NEW IN 376 #
#######################################################################
if ( $non_ipa_apostrophes == 1 ) {
$word =~ s/ˈ/\'/g; # MAKE SURE THE APOSTROPHE NEEDS TO BE ESCAPED!
}
#######################################################################
# TRY TO ELIMINATE EXTRA SPACES, WHICH SEEM TO CROP UP AFTER THE LAST #
# IN A SERIES OF NUMBERS THAT ARE AUTO-CONVERTED. #
#######################################################################
#print STDOUT "word=$word\n"; # AD-HOC DEBUGGING
$word =~ s/ $//g;
$word =~ s/^ //g;
#######################################################################
# REPLACE .VRT PLACEHOLDERS #
#######################################################################
if ( $vrt_format == 1 ) {
$word = replace_vrt_placeholders($word);
}
############################################################################
# OUTPUT EACH PROCESSED WORD TO FILE #
############################################################################
if ( $vertical_output == 1 ) {
print OUTPUTFILE "$word\r\n"; # NOTE New in 333: Changed "$word\n" to "$word\r\n". Otherwise, it doesn't work.
}
else { print OUTPUTFILE "$word "; }
}
############################################################################
# PROCESS PARAGRAPH BREAKS #
############################################################################
# Add longest pause symbol ("###") if this option is chosen. #
if ( $add_paragraph_breaks == 1 ) { print OUTPUTFILE "###"; }
# Add newlines at paragraph breaks if desired. #
if ( $keep_paragraphs == 1 ) { print OUTPUTFILE "\n"; }
}
#################################################################################
# #
# CLOSE UP SHOP ON STAGE 1 #
# #
#################################################################################
close(INPUTFILE);
close(OUTPUTFILE);
if ( $use_config_file == 1 ) { close(CONFIGFILE); }
#################################################################################
# #
# STAGE 2 #
# PERFORM OUTPUT FILE CLEANING IF DESIRED #
# (This should ALWAYS be activated) #
#################################################################################
# NEW IN 425: Removed clean_output_file option -- made it mandatory
#################################################################################
# Open output and temp files #
#################################################################################
# Open the output file. Input must be UTF-8. #
if ( $lang eq "es" ) {
$user_message = "ADVERTENCIA: No fue posible abrir el archivo de salida \'$output_filename\' para lectura (input) y limpieza adicional.";
}
else {
$user_message = "WARNING: The output file \'$output_filename\' could not be opened for reading and additional cleaning.";
}
open( OUTPUTFILE, '<:encoding(UTF-8)', "$output_filename" )
|| die "\n\n$user_message\n\n";
#print STDOUT "\n >>> OFC: Opened the file $output_filename to read and then clean it.\n"; # NOTE DEBUGGING
# Open temp file. Output will be UTF-8. #
if ( $lang eq "es" ) {
$user_message = "ADVERTENCIA: No fue posible crear el archivo temporal \($output_filename\).";
}
else {
$user_message = "WARNING: The temporary file \'$output_filename\' could not be opened.";
}
open( TEMPFILE, '>:encoding(UTF-8)', "$output_filename\.cleaned" )
|| die "\n\n$user_message\n\n";
#print STDOUT " >>> OFC: Opened the file cleaned-$output_filename to write cleaned text into.\n"; # NOTE DEBUGGING
# Begin processing output file #
while (<OUTPUTFILE>) {
chomp;