[sword-devel] SCRIPT: Covert Traditional Book Names to Short Sword Names

Andrew Thule thulester at gmail.com
Mon Jul 30 18:14:01 MST 2012


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