[sword-svn] r65 - trunk/versification/mapper
mgruner at crosswire.org
mgruner at crosswire.org
Wed Jun 28 12:46:54 MST 2006
Author: mgruner
Date: 2006-06-28 12:42:23 -0700 (Wed, 28 Jun 2006)
New Revision: 65
Added:
trunk/versification/mapper/do_mapping.pl
trunk/versification/mapper/v11n-mapper.db
trunk/versification/mapper/v11n-schema.db
Modified:
trunk/versification/mapper/create_db.pl
Log:
mapper tool essentially complete;
added demo tool
added version info in db
Modified: trunk/versification/mapper/create_db.pl
===================================================================
--- trunk/versification/mapper/create_db.pl 2006-06-24 10:40:53 UTC (rev 64)
+++ trunk/versification/mapper/create_db.pl 2006-06-28 19:42:23 UTC (rev 65)
@@ -15,6 +15,8 @@
my (@mappings, @bible, @bible_nab, @bible_njb, @bible_org, @bible_vul, @bible_lxx);
+my $version = 0.1;
+
##########################
#LOAD DATA
##########################
@@ -34,13 +36,21 @@
my $dbh_mapper = DBI->connect("dbi:SQLite:dbname=v11n-mapper.db","","") || die "can't connect to SQLite database\n";
$dbh_mapper->{unicode} = 1;
$dbh_mapper->{AutoCommit} = 0; # enable transactions
-$dbh_mapper->{RaiseError} = 0;
+$dbh_mapper->{RaiseError} = 1;
unlink "v11n-schema.db";
my $dbh_schema = DBI->connect("dbi:SQLite:dbname=v11n-schema.db","","") || die "can't connect to SQLite database\n";
$dbh_schema->{unicode} = 1;
$dbh_schema->{AutoCommit} = 0; # enable transactions
$dbh_schema->{RaiseError} = 1;
+#store version info
+foreach my $dbh ($dbh_mapper, $dbh_schema)
+{
+ $dbh->do("CREATE TABLE version (version TEXT NOT NULL UNIQUE)") || die $!;
+ $dbh->do("INSERT INTO version VALUES ($version)") || die $!;
+ $dbh->commit();
+}
+
sub feedSchema
{
my $dbh = shift;
Added: trunk/versification/mapper/do_mapping.pl
===================================================================
--- trunk/versification/mapper/do_mapping.pl 2006-06-24 10:40:53 UTC (rev 64)
+++ trunk/versification/mapper/do_mapping.pl 2006-06-28 19:42:23 UTC (rev 65)
@@ -0,0 +1,61 @@
+#!/usr/bin/perl -w
+
+#
+# This script is supposed to demonstrate the usage of the mappings db.
+#
+# 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 $dbh_mapper = DBI->connect("dbi:SQLite:dbname=v11n-mapper.db","","") || die "can't connect to SQLite database\n";
+$dbh_mapper->{unicode} = 1;
+$dbh_mapper->{AutoCommit} = 0; # enable transactions
+$dbh_mapper->{RaiseError} = 1;
+
+my $source_osisID = shift || "";
+my $source_schema = shift || "";
+my $target_schema = shift || "";
+
+my @available_schemas = qw(bible bible_nab bible_njb bible_org bible_lxx bible_vul);
+
+sub usageInfo
+{
+ print(
+"Usage: do_mapping.pl <osisID> <source schema> <target schema>
+ Where <source schema> and <target schema> may be one of:
+ @available_schemas\n");
+ print("\n at _\n");
+ exit 1;
+}
+
+($source_osisID =~ m/\./) || &usageInfo("Please provide a valid osisID.\n");
+(grep( $_ eq $source_schema, @available_schemas)) || &usageInfo("Please provide a valid source schema");
+(grep( $_ eq $target_schema, @available_schemas)) || &usageInfo("Please provide a valid target schema");
+($target_schema ne $source_schema) || &usageInfo("Source and target are identical, no mapping done");
+
+sub do_map
+{
+ my $osisID = shift;
+ my $source = shift;
+ my $target = shift;
+
+ #print "SELECT target FROM ".$source."_to_".$target." WHERE source='".$osisID."'\n";
+ my $result = @{$dbh_mapper->selectcol_arrayref("SELECT target FROM ".$source."_to_".$target." WHERE source='".$osisID."'")}[0];
+ return ($result || $osisID);
+}
+
+my $result = "";
+if ( ($source_schema ne "bible") && ($target_schema ne "bible") ){
+ my $tmp = &do_map($source_osisID, $source_schema, "bible"); #Warning: does not handle ranges
+ $result = &do_map($tmp, "bible", $target_schema);
+}
+else
+{
+ $result = &do_map($source_osisID, $source_schema, $target_schema);
+}
+print $result."\n";
\ No newline at end of file
Added: trunk/versification/mapper/v11n-mapper.db
===================================================================
(Binary files differ)
Property changes on: trunk/versification/mapper/v11n-mapper.db
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/versification/mapper/v11n-schema.db
===================================================================
(Binary files differ)
Property changes on: trunk/versification/mapper/v11n-schema.db
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
More information about the sword-cvs
mailing list