diff options
author | Martin Gruner <mg.pub@gmx.net> | 2006-06-28 19:42:23 +0000 |
---|---|---|
committer | Martin Gruner <mg.pub@gmx.net> | 2006-06-28 19:42:23 +0000 |
commit | 517691bb4bcd2c1ec80cd16bf87b42b803617e73 (patch) | |
tree | b479ae943c37535569b46a61e74ab01d25893fb8 /versification | |
parent | b915d9846b5d575e4f91923434559c2f9e1956bc (diff) | |
download | sword-tools-517691bb4bcd2c1ec80cd16bf87b42b803617e73.tar.gz |
mapper tool essentially complete;
added demo tool
added version info in db
git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@65 07627401-56e2-0310-80f4-f8cd0041bdcd
Diffstat (limited to 'versification')
-rw-r--r-- | versification/mapper/create_db.pl | 12 | ||||
-rw-r--r-- | versification/mapper/do_mapping.pl | 61 | ||||
-rw-r--r-- | versification/mapper/v11n-mapper.db | bin | 0 -> 1943552 bytes | |||
-rw-r--r-- | versification/mapper/v11n-schema.db | bin | 0 -> 8028160 bytes |
4 files changed, 72 insertions, 1 deletions
diff --git a/versification/mapper/create_db.pl b/versification/mapper/create_db.pl index 8f22f9d..1456402 100644 --- a/versification/mapper/create_db.pl +++ b/versification/mapper/create_db.pl @@ -15,6 +15,8 @@ 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); +my $version = 0.1; + ########################## #LOAD DATA ########################## @@ -34,13 +36,21 @@ unlink "v11n-mapper.db"; 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; diff --git a/versification/mapper/do_mapping.pl b/versification/mapper/do_mapping.pl new file mode 100644 index 0000000..379fe16 --- /dev/null +++ b/versification/mapper/do_mapping.pl @@ -0,0 +1,61 @@ +#!/usr/bin/perl -w + +# +# This script is supposed to demonstrate the usage of the mappings db. +# +# Author: Martin Gruner, mgruner@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@_\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 diff --git a/versification/mapper/v11n-mapper.db b/versification/mapper/v11n-mapper.db Binary files differnew file mode 100644 index 0000000..9746d56 --- /dev/null +++ b/versification/mapper/v11n-mapper.db diff --git a/versification/mapper/v11n-schema.db b/versification/mapper/v11n-schema.db Binary files differnew file mode 100644 index 0000000..d3bf615 --- /dev/null +++ b/versification/mapper/v11n-schema.db |