use vars qw/ @EXPORT_OK $VERSION /;
@EXPORT_OK = qw/ run_analysis group_variants analyze_variant_location wit_stringify /;
-$VERSION = "1.0";
+$VERSION = "1.1";
my $SOLVER_URL = 'http://byzantini.st/cgi-bin/graphcalc.cgi';
'name' => 'this is a text',
'input' => 'TEI',
'file' => '/path/to/tei_parallel_seg_file.xml' );
- $t->enable_stemmata;
$t->add_stemma( 'dotfile' => $stemmafile );
my $variant_data = run_analysis( $tradition );
my $tradition = Text::Tradition->new( 'input' => 'TEI',
'name' => 'test0',
'file' => $datafile );
-$tradition->enable_stemmata;
my $s = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
is( ref( $s ), 'Text::Tradition::Stemma', "Added stemma to tradition" );
my $tradition = Text::Tradition->new( 'input' => 'TEI',
'name' => 'flortest',
'file' => $datafile );
-$tradition->enable_stemmata;
my $s = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
my $sets = [ [ qw/ D Q / ], [ qw/ F H / ], [ qw/ A B C P S T / ] ];
'input' => 'Tabular',
'file' => 't/data/simple.txt',
);
-$t->enable_stemmata;
is( $t->stemma_count, 0, "No stemmas added yet" );
my $s;
ok( $s = $t->add_stemma( dotfile => 't/data/simple.dot' ), "Added a simple stemma" );
return @wits;
}
-=head2 root_graph( $root_vertex ) {
+=head2 root_graph( $root_vertex )
If the stemma graph is undirected, make it directed with $root_vertex at the root.
If it is directed, re-root it.
my $tradition = Text::Tradition->new(
'input' => 'Self',
'file' => 't/data/besoin.xml' );
-$tradition->enable_stemmata;
$tradition->add_stemma( 'dotfile' => 't/data/besoin.dot' );
# Run the analysis of the tradition
$c->add_relationship( 'n12', 'n13', { 'type' => 'spelling' } );
$c->calculate_ranks();
-$tradition->enable_stemmata;
my $stemma = $tradition->add_stemma( dotfile => 't/data/simple.dot' );
# Test for object creation
my $tradition = Text::Tradition->new( 'input' => 'TEI',
'name' => 'test0',
'file' => $datafile );
-$tradition->enable_stemmata;
my $s = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
is( ref( $s ), 'Text::Tradition::Stemma', "Added stemma to tradition" );
my $tradition = Text::Tradition->new( 'input' => 'TEI',
'name' => 'flortest',
'file' => $datafile );
-$tradition->enable_stemmata;
my $s = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
my $sets = [ [ qw/ D Q / ], [ qw/ F H / ], [ qw/ A B C P S T / ] ];
'input' => 'Tabular',
'file' => 't/data/simple.txt',
);
-$t->enable_stemmata;
is( $t->stemma_count, 0, "No stemmas added yet" );
my $s;
ok( $s = $t->add_stemma( dotfile => 't/data/simple.dot' ), "Added a simple stemma" );
use TryCatch;
use vars qw( $VERSION );
-$VERSION = "1.0";
+$VERSION = "1.1";
+
+# Enable plugin(s) if available
+eval { with 'Text::Tradition::HasStemma'; };
+if( $@ ) {
+ warn "Text::Tradition::Analysis not found. Disabling stemma analysis functionality";
+};
has 'collation' => (
is => 'ro',
}
}
-=head1 PLUGIN HOOKS
-
-=head2 enable_stemmata
-
-If the tradition in question does not have the HasStemma role, make it so. Throws
-an error if the role (ergo, if the Analysis package) is not installed.
-
-=cut
-
-sub enable_stemmata {
- my $self = shift;
- my $rolename = 'Text::Tradition::HasStemma';
- return 1 if does_role( $self, $rolename );
- try {
- apply_all_roles( $self, $rolename );
- } catch {
- throw( "Cannot apply role to enable stemmata; is the Analysis extension installed?" );
- }
- return 1;
-}
-
-=head2 enable_morphology
-
-If the tradition in question has readings that do not include the Morphology
-role, apply the role to them. Throws an error if the role (ergo, if the
-Morphology package) is not installed.
-
-=cut
-
-sub enable_morphology {
- my $self = shift;
- my $rolename = 'Text::Tradition::Morphology';
- try {
- load( $rolename );
- } catch {
- throw( "Cannot apply role to enable morphology; is the extension installed?" );
- }
- foreach my $r ( $self->collation->readings ) {
- apply_all_roles( $r, $rolename )
- unless does_role( $r, $rolename );
- }
- return 1;
-}
-
=head2 lemmatize
Calls the appropriate lemmatization function for the language of the
-tradition. Implicitly applies the Morphology role where appropriate (and
-throws an error if the package is not installed.)
+tradition. Will throw an error if the Morphology package is not installed.
=cut
warn "Please set a language to lemmatize a tradition";
return;
}
- $self->enable_morphology;
my $mod = "Text::Tradition::Language::" . $self->language;
load( $mod );
$mod->can( 'lemmatize' )->( $self );
is( scalar $st->collation->relationships, 3, "Reparsed collation has new relationships" );
# Now add a stemma, write to GraphML, and look at the output.
-my $SKIP_STEMMA;
-try {
- $tradition->enable_stemmata;
-} catch {
- $SKIP_STEMMA = 1;
-}
SKIP: {
- skip "Analysis module not present", 3 if $SKIP_STEMMA;
+ skip "Analysis module not present", 3 unless $tradition->can( 'add_stemma' );
my $stemma = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
is( ref( $stemma ), 'Text::Tradition::Stemma', "Parsed dotfile into stemma" );
is( $tradition->stemmata, 1, "Tradition now has the stemma" );
no Moose::Util::TypeConstraints;
+# Enable plugin(s) if available
+eval { with 'Text::Tradition::Morphology'; };
+# Morphology package is not on CPAN, so don't warn of its absence
+# if( $@ ) {
+# warn "Text::Tradition::Morphology not found: $@. Disabling lexeme functionality";
+# };
+
=head1 NAME
Text::Tradition::Collation::Reading - represents a reading (usually a word)
sub BUILD {
my( $self, $args ) = @_;
if( exists $args->{'lexemes'} ) {
- unless( does_role( $self, 'Text::Tradition::Morphology' ) ) {
- eval { apply_all_roles( $self, 'Text::Tradition::Morphology' ) };
- if( $@ ) {
- warn "No morphology package installed; DROPPING lexemes";
- return;
- }
+ unless( $self->can( '_deserialize_lexemes' ) ) {
+ warn "No morphology package installed; DROPPING lexemes";
+ return;
}
$self->_deserialize_lexemes( $args->{'lexemes'} );
}
);
my $tradition = Text::Tradition->new( @args );
- $tradition->enable_stemmata;
- my $stemma = $tradition->add_stemma( dotfile => $dotfile );
+ my $stemma = $tradition->add_stemma( dotfile => $dotfile ); # if Analysis module installed
$d->save_tradition( $tradition );
foreach my $id ( $d->traditions ) {
'input' => 'Tabular',
'file' => 't/data/simple.txt',
);
-my $stemma_enabled;
-eval { $stemma_enabled = $t->enable_stemmata; };
+my $stemma_enabled = $t->can( 'add_stemma' );
{
my $d = Text::Tradition::Directory->new( 'dsn' => $dsn,
# TODO add a relationship, add a stemma, write graphml, reparse it, check that
# the new data is there
$t->language('Greek');
-my $stemma_enabled;
-try {
- $stemma_enabled = $t->enable_stemmata;
-} catch {
- ok( 1, "Skipping stemma tests without Analysis module" );
-}
+my $stemma_enabled = $t->can('add_stemma');
if( $stemma_enabled ) {
$t->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
}
$use_version = $val;
} elsif( $gkey eq 'stemmata' ) {
# Make sure we can handle stemmata
- my $stemma_enabled;
- try {
- $stemma_enabled = $tradition->enable_stemmata;
- } catch {
- warn "Analysis module not installed; DROPPING stemmata";
- }
# Parse the stemmata into objects
- if( $stemma_enabled ) {
+ if( $tradition->can('add_stemma') ) {
foreach my $dotstr ( split( /\n/, $val ) ) {
$tradition->add_stemma( 'dot' => $dotstr );
}
+ } else {
+ warn "Analysis module not installed; DROPPING stemmata";
}
} elsif( $gkey eq 'user' ) {
# Assign the tradition to the user if we can
my %namechange = ( '#START#' => '__START__', '#END#' => '__END__' );
# print STDERR "Adding collation readings\n";
- my $need_morphology;
foreach my $n ( @{$graph_data->{'nodes'}} ) {
# If it is the start or end node, we already have one, so
# grab the rank and go.
$collation->end->rank( $n->{'rank'} );
next;
}
- # HACKY but no better way yet
- # If $n has a 'lexemes' property then we will need the morphology for
- # the whole tradition.
- $need_morphology = 1 if exists $n->{'lexemes'};
my $gnode = $collation->add_reading( $n );
if( $gnode->id ne $n->{'id'} ) {
$namechange{$n->{'id'}} = $gnode->id;
}
}
- # HACK continued - if any of the readings had morphology info, we
- # must enable it for the whole tradition. Just eval it, as we will
- # have already been warned if the morphology extension isn't installed.
- if( $need_morphology ) {
- eval { $tradition->enable_morphology };
- }
# Now add the edges.
# print STDERR "Adding collation path edges\n";
is( scalar $st->collation->relationships, 3, "Reparsed collation has new relationships" );
# Now add a stemma, write to GraphML, and look at the output.
-my $SKIP_STEMMA;
-try {
- $tradition->enable_stemmata;
-} catch {
- $SKIP_STEMMA = 1;
-}
SKIP: {
- skip "Analysis module not present", 3 if $SKIP_STEMMA;
+ skip "Analysis module not present", 3 unless $tradition->can( 'add_stemma' );
my $stemma = $tradition->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
is( ref( $stemma ), 'Text::Tradition::Stemma', "Parsed dotfile into stemma" );
is( $tradition->stemmata, 1, "Tradition now has the stemma" );
'input' => 'Tabular',
'file' => 't/data/simple.txt',
);
-my $stemma_enabled;
-eval { $stemma_enabled = $t->enable_stemmata; };
+my $stemma_enabled = $t->can( 'add_stemma' );
{
my $d = Text::Tradition::Directory->new( 'dsn' => $dsn,
# TODO add a relationship, add a stemma, write graphml, reparse it, check that
# the new data is there
$t->language('Greek');
-my $stemma_enabled;
-try {
- $stemma_enabled = $t->enable_stemmata;
-} catch {
- ok( 1, "Skipping stemma tests without Analysis module" );
-}
+my $stemma_enabled = $t->can('add_stemma');
if( $stemma_enabled ) {
$t->add_stemma( 'dotfile' => 't/data/florilegium.dot' );
}