[sword-devel] SCRIPT: Covert Traditional Book Names to Short Sword Names
Andrew Thule
thulester at gmail.com
Mon Jul 30 19:16:05 MST 2012
Opps. The .php one works (though doesn't handle names of the form
1John). I didn't mean to send that one though. This one is shorter
using awk not php slightly more elegant and handles books of the form
1 John and 1John:
-=-=-=- convert-long-2-short-names.awk Script -=-=-=-
#!/usr/bin/awk -f
BEG1N {
#FS=OFS="=";
}
{
gsub(/Genesis/,"Gen");
gsub(/Exodus/,"Ex");
gsub(/Leviticus/,"Lev");
gsub(/Numbers/,"Num");
gsub(/Deuteronomy/,"Deut");
gsub(/Joshua/,"Josh");
gsub(/Judges/,"Judg");
gsub(/Ruth/,"Ruth");
gsub(/1Samuel/,"1Sam");
gsub(/1\ Samuel/,"1Sam");
gsub(/2Samuel/,"2Sam");
gsub(/2\ Samuel/,"2Sam");
gsub(/1Kings/,"1Kgs");
gsub(/1\ Kings/,"1Kgs");
gsub(/2Kings/,"2Kgs");
gsub(/2\ Kings/,"2Kgs");
gsub(/1Chronicles/,"1Chr");
gsub(/1\ Chronicles/,"1Chr");
gsub(/2Chronicles/,"2Chr");
gsub(/2\ Chronicles/,"2Chr");
gsub(/Ezra/,"Ezra");
gsub(/Nehemiah/,"Neh");
gsub(/Esther/,"Esth");
gsub(/Job/,"Job");
gsub(/Psalms/,"Pss");
gsub(/Proverbs/,"Prov");
gsub(/Ecclesiastes/,"Eccl");
gsub(/Song/,"Song");
gsub(/Isaiah/,"Isa");
gsub(/Jeremiah/,"Jer");
gsub(/Lamentations/,"Lam");
gsub(/Ezekiel/,"Eze");
gsub(/Daniel/,"Dan");
gsub(/Hosea/,"Hos");
gsub(/Joel/,"Joel");
gsub(/Amos/,"Amos");
gsub(/Obadiah/,"Ob");
gsub(/Jonah/,"Jonah");
gsub(/Micah/,"Mic");
gsub(/Nahum/,"Nah");
gsub(/Habakkuk/,"Hab");
gsub(/Zephaniah/,"Zeph");
gsub(/Haggai/,"Hag");
gsub(/Zechariah/,"Zech");
gsub(/Malachi/,"Mal");
gsub(/Matthew/,"Mt");
gsub(/Mark/,"Mk");
gsub(/Luke/,"Lk");
gsub(/Acts/,"Acts");
gsub(/Romans/,"Rom");
gsub(/1Corinthians/,"1Cor");
gsub(/1\ Corinthians/,"1Cor");
gsub(/2Corinthians/,"2Cor");
gsub(/2\ Corinthians/,"2Cor");
gsub(/Galatians/,"Gal");
gsub(/Ephesians/,"Eph");
gsub(/Philippians/,"Php");
gsub(/Colossians/,"Col");
gsub(/1Thessalonians/,"1Thes");
gsub(/1\ Thessalonians/,"1Thes");
gsub(/2Thessalonians/,"2Thes");
gsub(/2\ Thessalonians/,"2Thes");
gsub(/1Timothy/,"1Tim");
gsub(/1\ Timothy/,"1Tim");
gsub(/2Timothy/,"2Tim");
gsub(/2\ Timothy/,"2Tim");
gsub(/Titus/,"Tit");
gsub(/Philemon/,"Phm");
gsub(/Hebrews/,"Heb");
gsub(/James/,"Jas");
gsub(/1Peter/,"1Pet");
gsub(/1\ Peter/,"1Pet");
gsub(/2Peter/,"2Pet");
gsub(/2\ Peter/,"2Pet");
gsub(/1John/,"1Jn");
gsub(/1\ John/,"1Jn");
gsub(/2John/,"2Jn");
gsub(/2\ John/,"2Jn");
gsub(/3John/,"3Jn");
gsub(/3\ John/,"3Jn");
gsub(/John/,"Jn");
gsub(/Jude/,"Jude");
gsub(/Revelation/,"Rev");
print;
}
END {
}
-=-=-=- end script -=-=-=-
Use is the same.
On Mon, Jul 30, 2012 at 9:14 PM, Andrew Thule <thulester at gmail.com> wrote:
> The sword lib contains a file abbr.conf which contains mapping from
> traditional book names to short sword module names as follows:
> [Text]
> Genesis=Gen
> Exodus=Ex
> Leviticus=Lev
> Numbers=Num
> Deuteronomy=Deut
> Joshua=Josh
> Judges=Judg
> Ruth=Ruth
> I Samuel=1Sam
> ...
>
> I've grown too lazy to continue converting the names on the left in
> that file to their sword equivalent on the right, so I've written a
> script to do it. So that I could test the attached script which
> translates traditional book names to short sword names, I generated
> two text files from this abbr.conf file using the following:
>
> % cat abbr.conf | awk -F"=" '{print $1}' > long.txt
> % cat abbr.conf | awk -F"=" '{print $2}' > short.txt
>
> For long.txt I converted Roman numerals to Arabic numerals (I to 1, II
> to 2, III to 3) since the following script does not recognize Roman
> numerals.
>
> The following script will translate traditional book names to short
> sword names as follows:
>
> % cat long.txt | ./convert-long-2-short-names.php
>
>
> -=-=-= convert-long-2-short-names.php Script -=-=-=-
>
> #!/usr/bin/php -q
> <?php
>
> //
> // Last modified: 20/07/2012
> //
> // This filter is for changing tradition book names to SWORD Module names
>
> function book_names($out) {
>
> $from = array(
> "/(\W)([Gg])enesis(\W)/",
> "/(\W)([Ee])xodus(\W)/",
> "/(\W)([Ll])eviticus(\W)/",
> "/(\W)([Nn])umbers(\W)/",
> "/(\W)([Dd])euteronomy(\W)/",
> "/(\W)([Jj])oshua(\W)/",
> "/(\W)([Jj])udges(\W)/",
> "/(\W)([Rr])uth(\W)/",
> "/(\W)([12])\s([Ss])amuel(\W)/",
> "/(\W)([12])\s([Ss])amuel(\W)/",
> "/(\W)([12])\s([Kk])ings(\W)/",
> "/(\W)([12])\s([Kk])ings(\W)/",
> "/(\W)([12])\s([Cc])hronicles(\W)/",
> "/(\W)([12])\s([Cc])hronicles(\W)/",
> "/(\W)([Ee])zra(\W)/",
> "/(\W)([Nn])ehemiah(\W)/",
> "/(\W)([Ee])sther(\W)/",
> "/(\W)([Jj])ob(\W)/",
> "/(\W)([Pp])salms(\W)/",
> "/(\W)([Pp])roverbs(\W)/",
> "/(\W)([Ee])cclesiastes(\W)/",
> "/(\W)([Ss])ong(\W)/",
> "/(\W)([I1])saiah(\W)/",
> "/(\W)([Jj])eremiah(\W)/",
> "/(\W)([Ll])amentations(\W)/",
> "/(\W)([Ee])zekiel(\W)/",
> "/(\W)([Dd])aniel(\W)/",
> "/(\W)([Hh])osea(\W)/",
> "/(\W)([Jj])oel(\W)/",
> "/(\W)([Aa])mos(\W)/",
> "/(\W)([Oo])badiah(\W)/",
> "/(\W)([Jj])onah(\W)/",
> "/(\W)([Mm])icah(\W)/",
> "/(\W)([Nn])ahum(\W)/",
> "/(\W)([Hh])abakkuk(\W)/",
> "/(\W)([Zz])ephaniah(\W)/",
> "/(\W)([Hh])aggai(\W)/",
> "/(\W)([Zz])echariah(\W)/",
> "/(\W)([Mm])alachi(\W)/",
> "/(\W)([Mm])atthew(\W)/",
> "/(\W)([Mm])ark(\W)/",
> "/(\W)([Ll])uke(\W)/",
> "/(\W)([123])\s([Jj])ohn(\W)/",
> "/(\W)([123])\s([Jj])ohn(\W)/",
> "/(\W)([123])\s([Jj])ohn(\W)/",
> "/(\W)([Jj])ohn(\W)/",
> "/(\W)([Aa])cts(\W)/",
> "/(\W)([Rr])omans(\W)/",
> "/(\W)([12])\s([Cc])orinthians(\W)/",
> "/(\W)([12])\s([Cc])orinthians(\W)/",
> "/(\W)([Gg])alatians(\W)/",
> "/(\W)([Ee])phesians(\W)/",
> "/(\W)([Pp])hilippians(\W)/",
> "/(\W)([Cc])olossians(\W)/",
> "/(\W)([12])\s([Tt])hessalonians(\W)/",
> "/(\W)([12])\s([Tt])hessalonians(\W)/",
> "/(\W)([12])\s([Tt])imothy(\W)/",
> "/(\W)([12])\s([Tt])imothy(\W)/",
> "/(\W)([Tt])itus(\W)/",
> "/(\W)([Pp])hilemon(\W)/",
> "/(\W)([Hh])ebrews(\W)/",
> "/(\W)([Jj])ames(\W)/",
> "/(\W)([12])\s([Pp])eter(\W)/",
> "/(\W)([12])\s([Pp])eter(\W)/",
> "/(\W)([Jj])ude(\W)/",
> "/(\W)([Rr])evelation(\W)/",
> );
>
> $to = array(
> "$1$2en$3",
> "$1$2x$3",
> "$1$2ev$3",
> "$1$2um$3",
> "$1$2eut$3",
> "$1$2osh$3",
> "$1$2udg$3",
> "$1$2uth$3",
> "$1$2$3am$4",
> "$1$2$3am$4",
> "$1$2$3gs$4",
> "$1$2$3gs$4",
> "$1$2$3hr$4",
> "$1$2$3hr$4",
> "$1$2zra$3",
> "$1$2eh$3",
> "$1$2sth$3",
> "$1$2ob$3",
> "$1$2ss$3",
> "$1$2rov$3",
> "$1$2ccl$3",
> "$1$2ong$3",
> "$1$2sa$3",
> "$1$2er$3",
> "$1$2am$3",
> "$1$2ze$3",
> "$1$2an$3",
> "$1$2os$3",
> "$1$2oel$3",
> "$1$2mos$3",
> "$1$2b$3",
> "$1$2onah$3",
> "$1$2ic$3",
> "$1$2ah$3",
> "$1$2ab$3",
> "$1$2eph$3",
> "$1$2ag$3",
> "$1$2ech$3",
> "$1$2al$3",
> "$1$2t$3",
> "$1$2k$3",
> "$1$2k$3",
> "$1$2$3n$4",
> "$1$2$3n$4",
> "$1$2$3n$4",
> "$1$2n$3",
> "$1$2cts$3",
> "$1$2om$3",
> "$1$2$3or$4",
> "$1$2$3or$4",
> "$1$2al$3",
> "$1$2ph$3",
> "$1$2hp$3",
> "$1$2ol$3",
> "$1$2$3hes$4",
> "$1$2$3hes$4",
> "$1$2$3im$4",
> "$1$2$3im$4",
> "$1$2it$3",
> "$1$2hm$3",
> "$1$2eb$3",
> "$1$2as$3",
> "$1$2$3et$4",
> "$1$2$3et$4",
> "$1$2ude$3",
> "$1$2ev$3",
> );
>
> return preg_replace($from, $to, $out);
> }
>
>
> $file = file_get_contents("php://stdin", "r");
> $file2 = book_names($file);
> echo $file2;
>
> ?>
>
> -=-=-=- script -=-=-=-
>
> Feel free to use.
>
> ~A
More information about the sword-devel
mailing list