9 use Text::Tradition::Directory;
11 binmode( STDOUT, ':utf8' );
12 binmode( STDERR, ':utf8' );
14 my( $tfile, $sfile, $delete, $list, $dsn ) =
15 ( undef, undef, undef, 0, 'dbi:SQLite:dbname=db/traditions.db' );
18 't|tradition=s' => \$tfile,
19 's|stemma=s' => \$sfile,
21 'd|delete=s' => \$delete,
25 # Make a KiokuDB store from the traditions data we have.
27 my $kdb = Text::Tradition::Directory->new(
29 'extra_args' => { 'create' => 1 },
32 unless( $tfile || $delete || $list ) {
33 print STDERR "Please specify a tradition file, an ID to delete, or the --list option\n";
37 if( $tfile && $delete ) {
38 print STDERR "Specify deletion by UUID, not by tradition file\n";
42 my( $tradition, $stemma );
44 print STDERR "Reading tradition from $tfile\n";
45 $tradition = Text::Tradition->new(
50 if( $tradition && $sfile ) {
51 $stemma = $tradition->add_stemma( $sfile );
52 warn "Did not get stemma from $sfile\n" unless $stemma;
55 my $scope = $kdb->new_scope();
56 my $tid = $kdb->save( $tradition );
57 print STDERR "Stored tradition for " . $tradition->name . " at $tid\n";
58 print STDERR "...and associated stemma from $sfile\n" if $stemma;
62 my $scope = $kdb->new_scope();
63 if( $kdb->exists( $delete ) ) {
64 $kdb->delete( $delete );
66 print STDERR "Object $delete does not appear to be a Text::Tradition in the DB\n";
70 # Now try reading the objects from the DB.
72 foreach my $tid ( $kdb->tradition_ids ) {
73 my $scope = $kdb->new_scope();
74 my $t = $kdb->tradition( $tid );
75 print STDERR "$tid: Tradition '" . $t->name . "'\n";
76 my @wits = map { $_->sigil } $t->witnesses;
77 print STDERR "...with witnesses @wits\n";
78 my $c = $t->collation;
79 print STDERR "...collation has " . scalar( $c->readings ) . " readings\n";
80 print STDERR "...collation has " . scalar( $c->paths ) . " paths\n";
81 print STDERR "...collation has " . scalar( $c->relationships ) . " relationship links\n";
84 print STDERR "...associated stemma has graph " . $s->graph . "\n";