-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge_descs
88 lines (56 loc) · 1.85 KB
/
merge_descs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/local/bin/perl
use strict;
use warnings;
use Morsulus::Ordinary::Classic;
use Morsulus::Ordinary::Legacy;
use Getopt::Euclid;
my $ord = Morsulus::Ordinary::Classic->new(dbname => $ARGV{-db});
open my $descs, '<', $ARGV{-i};
while (my $record = <$descs>)
{
print STDERR $record if $ARGV{-verbose};
$record =~ s/\r?\n$//;
my $entry = Morsulus::Ordinary::Legacy->from_string($record);
next unless $entry->has_blazon;
next unless $entry->split_descs or $ARGV{-nulls};
print STDERR "finding blazon" if $ARGV{-verbose};
my ($blazon) = $ord->add_blazon($entry->text);
#$ord->Blazon->search({ blazon => $entry->text } );
print STDERR "got blazon ", $blazon->blazon if $ARGV{-verbose};
$ord->drop_descs($blazon) unless $ARGV{-merge};
print STDERR "old descs dropped" if $ARGV{-verbose} && !$ARGV{-merge};
$ord->add_desc($_, $blazon) for $entry->split_descs;
}
__END__
=head1 NAME
merge_descs - update descriptions in database from legacy format flat file
=head1 SYNOPSIS
merge_descs -db oanda.db -i descs.db
Update blazons in oanda.db from descs.db. Additional options specify
whether to replace or merge with existing descriptions and how to handle
input records with no descriptions.
The default behavior is to replace existing descriptions.
=head1 REQUIRED
=over
=item -db <file>
SQLite database file to be created or updated with Ordinary entries.
=for Euclid:
file.type: writable
=item -i <file>
Legacy format file with descriptions.
=for Euclid:
file.type: readable
=back
=head1 OPTIONS
=over
=item -replace
Replace existing descriptions with descriptions in input file.
=item -merge
Add descriptions in input file to descriptions in database.
=item -[no]nulls
Accept/ignore input records with no descriptions.
=for Euclid:
false: nonulls
=item -verbose
Emit generous output on the fly.
=back