summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--modules/perlconverters/imp2osis.pl241
1 files changed, 241 insertions, 0 deletions
diff --git a/modules/perlconverters/imp2osis.pl b/modules/perlconverters/imp2osis.pl
new file mode 100644
index 0000000..3062ca2
--- /dev/null
+++ b/modules/perlconverters/imp2osis.pl
@@ -0,0 +1,241 @@
+#!/usr/bin/perl
+
+## IMPort format to OSIS (2.1.1) converter (for Bibles only)
+
+## Licensed under the standard (3-clause) BSD license:
+
+# Copyright (c) 2008 CrossWire Bible Society <http://www.crosswire.org/>
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in
+# the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of the CrossWire Bible Society nor the names of
+# its contributors may be used to endorse or promote products
+# derived from this software without specific prior written
+# permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
+# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+## For general inquiries, comments, suggestions, bug reports, etc. email:
+## sword-support@crosswire.org
+
+#########################################################################
+
+$version = "1.0";
+$date = "2008-06-18";
+$osisVersion = "2.1.1";
+
+@OSISbook = (
+#OT
+ "Gen", "Exod", "Lev", "Num", "Deut", "Josh", "Judg", "Ruth", "1Sam", "2Sam", "1Kgs", "2Kgs", "1Chr", "2Chr", "Ezra", "Neh", "Esth", "Job", "Ps", "Prov", "Eccl", "Song", "Isa", "Jer", "Lam", "Ezek", "Dan", "Hos", "Joel", "Amos", "Obad", "Jonah", "Mic", "Nah", "Hab", "Zeph", "Hag", "Zech", "Mal",
+
+#NT
+"Matt", "Mark", "Luke", "John", "Acts", "Rom", "1Cor", "2Cor", "Gal", "Eph", "Phil", "Col", "1Thess", "2Thess", "1Tim", "2Tim", "Titus", "Phlm", "Heb", "Jas", "1Pet", "2Pet", "1John", "2John", "3John", "Jude", "Rev",
+);
+
+%OSISbook = (
+ "Genesis" => "Gen",
+ "Exodus" => "Exod",
+ "Leviticus" => "Lev",
+ "Numbers" => "Num",
+ "Deuteronomy" => "Deut",
+ "Joshua" => "Josh",
+ "Judges" => "Judg",
+ "Ruth" => "Ruth",
+ "I Samuel" => "1Sam",
+ "II Samuel" => "2Sam",
+ "I Kings" => "1Kgs",
+ "II Kings" => "2Kgs",
+ "I Chronicles" => "1Chr",
+ "II Chronicles" => "2Chr",
+ "Ezra" => "Ezra",
+ "Nehemiah" => "Neh",
+ "Esther" => "Esth",
+ "Job" => "Job",
+ "Psalms" => "Ps",
+ "Proverbs" => "Prov",
+ "Ecclesiastes" => "Eccl",
+ "Song of Solomon" => "Song",
+ "Isaiah" => "Isa",
+ "Jeremiah" => "Jer",
+ "Lamentations" => "Lam",
+ "Ezekiel" => "Ezek",
+ "Daniel" => "Dan",
+ "Hosea" => "Hos",
+ "Joel" => "Joel",
+ "Amos" => "Amos",
+ "Obadiah" => "Obad",
+ "Jonah" => "Jonah",
+ "Micah" => "Mic",
+ "Nahum" => "Nah",
+ "Habakkuk" => "Hab",
+ "Zephaniah" => "Zeph",
+ "Haggai" => "Hag",
+ "Zechariah" => "Zech",
+ "Malachi" => "Mal",
+ "Matthew" => "Matt",
+ "Mark" => "Mark",
+ "Luke" => "Luke",
+ "John" => "John",
+ "Acts" => "Acts",
+ "Romans" => "Rom",
+ "I Corinthians" => "1Cor",
+ "II Corinthians" => "2Cor",
+ "Galatians" => "Gal",
+ "Ephesians" => "Eph",
+ "Philippians" => "Phil",
+ "Colossians" => "Col",
+ "I Thessalonians" => "1Thess",
+ "II Thessalonians" => "2Thess",
+ "I Timothy" => "1Tim",
+ "II Timothy" => "2Tim",
+ "Titus" => "Titus",
+ "Philemon" => "Phlm",
+ "Hebrews" => "Heb",
+ "James" => "Jas",
+ "I Peter" => "1Pet",
+ "II Peter" => "2Pet",
+ "I John" => "1John",
+ "II John" => "2John",
+ "III John" => "3John",
+ "Jude" => "Jude",
+ "Revelation of John" => "Rev"
+ );
+
+
+
+if (scalar(@ARGV) < 2) {
+ print "imp2osis.pl -- IMP (Sword Import) format to OSIS $osisVersion converter version $version ($date)\nSyntax: imp2osis.pl <osisWork> <input filename> [-o OSIS-file] [-m]\n\nThe -m option will produce milestoned <verse\/> elements, which are more likely to produce valid OSIS from Bibles with OSIS markup internally.\n\nNo attempt is made to convert markup present in the verse entries themselves, so this tool is appropriate for converting Bibles that already contain OSIS markup or plaintext markup.\n\nThis tool is ONLY intended for VersKey-type Sword texts, namely Bibles and commentaries.\n";
+ exit (-1);
+}
+
+$osisWork = $ARGV[0];
+
+$nextarg = 2;
+
+if ($ARGV[$nextarg] eq "-o") {
+ $outputFilename = "$ARGV[$nextarg+1]";
+ $nextarg += 2;
+}
+else {
+ $outputFilename = "$osisWork.osis.xml";
+}
+
+$milestone = 0;
+if ($ARGV[$nextarg] eq "-m") {
+ $milestone = 1;
+}
+
+open (OUTF, ">$outputFilename") or die "Could not open file $ARGV[2] for writing.";
+
+print OUTF "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<osis xmlns=\"http://www.bibletechnologies.net/2003/OSIS/namespace\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.bibletechnologies.net/2003/OSIS/namespace http://www.bibletechnologies.net/osisCore.$osisVersion.xsd\">\n<osisText osisRefWork=\"Bible\" xml:lang=\"en\" osisIDWork=\"$osisWork\">\n<header>\n<work osisWork=\"$osisWork\"\/>\n<\/header>\n";
+
+open (INF, $ARGV[1]);
+
+$book = "";
+$chap = 0;
+$vers = 0;
+
+sub closeVerse {
+ if ($milestone == 0) {
+ print OUTF "<\/verse>\n";
+ }
+ else {
+ print OUTF "<verse eID=\"$lastosisID\"\/>\n";
+ }
+}
+
+while (<INF>) {
+ $line = $_;
+
+ $line =~ s/[\n\t\r ]+$//;
+
+ if ($line =~ /^\$\$\$(.+)/) {
+ $key = $1;
+ $line = "";
+ $lastosisID = $osisID;
+ $osisID = "";
+
+ if ($key =~ /^(.+?) (\d+):(\d+)/) {
+ $book = $OSISbook{$1};
+ $chap = $2;
+ $vers = $3;
+ if ($vers > 0) {
+ $osisID = "$book.$chap.$vers";
+ }
+
+ if ($chap == 0) {
+ if ($book ne "Gen" && $book ne "Matt") {
+ closeVerse();
+ print OUTF "<\/chapter>\n";
+ print OUTF "<\/div>\n";
+ }
+ print OUTF "<div type=\"book\" osisID=\"$book\">\n";
+ }
+ elsif ($vers == 0) {
+ if ($chap != 1) {
+ closeVerse();
+ print OUTF "<\/chapter>\n";
+ }
+ print OUTF "<chapter osisID=\"$book\.$chap\">\n";
+ }
+ else {
+ if ($vers != 1) {
+ closeVerse();
+ }
+ if ($milestone == 0) {
+ print OUTF "<verse osisID=\"$osisID\">\n";
+ }
+ else {
+ print OUTF "<verse osisID=\"$osisID\" sID=\"$osisID\"\/>\n";
+ }
+ }
+
+ }
+ elsif ($key eq "\[ Module Heading \]") {
+ #do nothing
+ }
+ elsif ($key eq "\[ Testament 1 Heading \]") {
+ print OUTF "<div type=\"bookGroup\">\n";
+ }
+ elsif ($key eq "\[ Testament 2 Heading \]") {
+ closeVerse();
+ print OUTF "<\/chapter>\n";
+ print OUTF "<\/div>\n"; # close book
+ print OUTF "<\/div>\n"; # close OT (bookGroup)
+ print OUTF "<div type=\"bookGroup\">\n";
+ }
+
+ }
+ elsif ($line !~ /^\s*$/) {
+ print OUTF "$line\n";
+ }
+}
+
+closeVerse();
+print OUTF "<\/chapter>\n";
+print OUTF "<\/div>\n"; # close book
+print OUTF "<\/div>\n"; # close NT (bookGroup)
+print OUTF "<\/osisText>\n";
+print OUTF "<\/osis>\n";
+
+close (OUTF);
+close (INF);