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