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/mapper/do_mapping.pl | |
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/mapper/do_mapping.pl')
-rw-r--r-- | versification/mapper/do_mapping.pl | 61 |
1 files changed, 61 insertions, 0 deletions
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 |