[sword-svn] r158 - trunk/versification

chrislit at crosswire.org chrislit at crosswire.org
Tue Mar 10 04:12:22 MST 2009


Author: chrislit
Date: 2009-03-10 04:12:22 -0700 (Tue, 10 Mar 2009)
New Revision: 158

Modified:
   trunk/versification/v11nsys.pl
Log:
finished a big chunk of the conversion script (constructs the vm[] array)

Modified: trunk/versification/v11nsys.pl
===================================================================
--- trunk/versification/v11nsys.pl	2009-03-10 11:08:52 UTC (rev 157)
+++ trunk/versification/v11nsys.pl	2009-03-10 11:12:22 UTC (rev 158)
@@ -1,5 +1,55 @@
 #!/usr/bin/perl
 
+sub cleanupLine {
+    # here we'll do some cleanup of our input, mostly to regularlize input
+    $ret = @_[0];
+
+    $ret =~ s/1Kgdms/1Kgs/g;
+    $ret =~ s/2Kgdms/2Kgs/g;
+    $ret =~ s/3Kgdms/1Sam/g;
+    $ret =~ s/4Kgdms/2Sam/g;
+    $ret =~ s/>Pss\./>Ps\//g;
+
+    return $ret;
+}
+
+# @canons will contain this list of files, these are in a basic XML format.
+# Each file lists osisIDs along with the English names associated with the
+# osisID. These aren't exhaustive, and may or may not overlap (but hopefully
+# don't). We are only using these to load mappings from osisIDs.
+ at canons = (
+    "bible.xml",      # the Bible, broadly defined
+    "otp.xml",        # OT pseudepigrapha
+    "nta.xml",        # NT apocrpha
+    "lds.xml",        # Mormon books
+    "naghammadi.xml", # Nag Hammadi codices
+    "qumran.xml",     # Qumran mss
+    "classical.xml",  # intended for classical works, currently just Josephus
+);
+
+foreach $mapfile (@canons) {
+    open MAP, "$mapfile";
+    while (<MAP>) {
+	$line = $_;
+
+	if ($line =~ /<id>(.+?)<\/id>/) {
+	    $id = $1;
+	}
+	elsif ($line =~ /<name>(.+?)<\/name>/) {
+	    $name = $1;
+
+	    if ($idmap{$id} eq "") {
+		$idmap{$id} = $name;
+	    }
+	    else {
+		# Duplicates most likely indicate alternate names, so ignore them.
+#		print "ERROR: Duplicate mapping from $id found in $mapfile.\n"
+	    }
+	}
+    }
+    close (MAP);
+}
+
 opendir (DIR, ".");
 @srcfiles = grep /Bible\.[^\.]+\.xml$/, readdir DIR;
 closedir(DIR);
@@ -16,18 +66,45 @@
     print OUTF "/******************************************************************************\n * $outfile.h - Versification data for the $v11n system\n *\n * Copyright 1998-2005 CrossWire Bible Society (http://www.crosswire.org)\n *	CrossWire Bible Society\n *	P. O. Box 2528\n *	Tempe, AZ  85280-2528\n *\n * This program is free software; you can redistribute it and/or modify it\n * under the terms of the GNU General Public License as published by the\n * Free Software Foundation version 2.\n *\n * This program is distributed in the hope that it will be useful, but\n * WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * General Public License for more details.\n *\n */\n";
     print OUTF "\n#ifndef V11N" . uc($v11n) . "_H\n#define V11N" . uc($v11n) . "_H\n\nSWORD_NAMESPACE_START\n\n";
 
+    $thisBook = "";
+    $thisChap = "";
+    $thisVers = "";
+
+    $vm = "/******************************************************************************\n *	Maximum verses per chapter\n */\n\nint vm$v11n\[\] = {";
+
     while (<INF>) {
 	$line = $_;
 
+	$line = cleanupLine($line);
+
 	if ($line =~ /<osisID.+?code=\"(.+?)\"\/>/) {
-	    print OUTF "$1\n";
+	    $osisID = $1;
+	    
+	    $lastBook = $thisBook;
+	    $lastChap = $thisChap;
+	    $lastVers = $thisVers;
+
+	    $osisID =~ /([^\.]+)\.(\d+)\.(\d+)/;
+
+	    $thisBook = $1;
+	    $thisChap = $2;
+	    $thisVers = $3;
+
+	    if ((($thisBook ne $lastBook) ||($thisChap ne $lastChap)) && $lastVers ne "") {
+		$vm .= "$lastVers, ";
+	    }
+
+	    if ($thisBook ne $lastBook) {
+		$vm .= "\n\t// $idmap{$thisBook}\n\t";
+	    }
 	}
     }
+    $vm .= "$thisVers\n};\n";
 
+    print OUTF "$vm";
+
     print OUTF "\nSWORD_NAMESPACE_END\n\n#endif\n";
 
     close (INF);
     close (OUTF);
 }
-
-




More information about the sword-cvs mailing list