[sword-svn] r63 - trunk/versification/mapper
mgruner at crosswire.org
mgruner at crosswire.org
Fri Jun 23 13:45:55 MST 2006
Author: mgruner
Date: 2006-06-23 13:45:46 -0700 (Fri, 23 Jun 2006)
New Revision: 63
Added:
trunk/versification/mapper/create_db.pl
Log:
initial version of the mapping db creator script
written in perl
frontends can access the sqlite db file with their own language specific
routines
Added: trunk/versification/mapper/create_db.pl
===================================================================
--- trunk/versification/mapper/create_db.pl 2006-06-23 19:33:59 UTC (rev 62)
+++ trunk/versification/mapper/create_db.pl 2006-06-23 20:45:46 UTC (rev 63)
@@ -0,0 +1,75 @@
+#!/usr/bin/perl -w
+
+#
+# This script is supposed to generate a database with OSIS scheme information
+# as well as mapping data from CCEL/SIL/OSIS.
+#
+# Author: Martin Gruner, mgruner at crosswire.org
+# License: GPL
+#
+
+use strict;
+use utf8;
+use DBI;
+use DBD::SQLite; #make sure it is installed, we won't use it directly
+
+my (@mappings, @bible, @bible_nab, @bible_njb, @bible_org, @bible_vul, @bible_lxx);
+
+##########################
+#LOAD DATA
+##########################
+sub loadFromFile
+{
+ my $filename = shift;
+ my $arrayref = shift;
+ open(FH, $filename) or die "can't open $filename\n";
+ @{$arrayref} = <FH>;
+ close(FH);
+}
+
+loadFromFile( "data/refsysmap.unl", \@mappings );
+loadFromFile( "data/Bible.xml", \@bible );
+loadFromFile( "data/Bible.NAB.xml", \@bible_nab );
+loadFromFile( "data/Bible.NJB.xml", \@bible_njb );
+loadFromFile( "data/Bible.ORG.xml", \@bible_org );
+loadFromFile( "data/Bible.Vul.xml", \@bible_vul );
+loadFromFile( "data/Bible.LXX.xml", \@bible_lxx );
+
+##########################
+#INIT DB
+##########################
+unlink "v11n-mapper.db";
+my $dbh = DBI->connect("dbi:SQLite:dbname=v11n-mapper.db","","") || die "can't connect to SQLite database\n";
+$dbh->{unicode} = 1;
+$dbh->{AutoCommit} = 0; # enable transactions
+$dbh->{RaiseError} = 1;
+
+sub feedScheme
+{
+ my $dbh = shift;
+ my $table_name = shift;
+ my $array_ref = shift;
+
+ $dbh->do("CREATE TABLE $table_name (osisID TEXT NOT NULL)") || die $!;
+ #TODO: ADD INDEX!!
+
+ foreach my $osisID_line (grep(m/<osisID code/, @{$array_ref}))
+ {
+ my ($osisID) = $osisID_line =~ m/code="(.+)"/;
+ $dbh->do("INSERT INTO $table_name VALUES (\'$osisID\')") || die $!;
+ }
+ $dbh->commit();
+}
+
+&feedScheme($dbh, "scheme_bible", \@bible);
+&feedScheme($dbh, "scheme_bible_nab", \@bible_nab);
+&feedScheme($dbh, "scheme_bible_njb", \@bible_njb);
+&feedScheme($dbh, "scheme_bible_org", \@bible_org);
+&feedScheme($dbh, "scheme_bible_vul", \@bible_vul);
+&feedScheme($dbh, "scheme_bible_lxx", \@bible_lxx);
+
+#print @{$dbh->selectcol_arrayref("SELECT osisID FROM scheme_bible")};
+
+$dbh->disconnect();
+
+print "Done.\n"
\ No newline at end of file
More information about the sword-cvs
mailing list