From: Tara L Andrews Date: Sun, 24 Jun 2012 12:37:09 +0000 (+0200) Subject: make normal_form default to ->text X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=367e901bd7644e4f197cb157380cfa7dff12ae41;p=scpubgit%2Fstemmatology.git make normal_form default to ->text --- diff --git a/lib/Text/Tradition/Collation/Reading.pm b/lib/Text/Tradition/Collation/Reading.pm index 108548b..2d4322e 100644 --- a/lib/Text/Tradition/Collation/Reading.pm +++ b/lib/Text/Tradition/Collation/Reading.pm @@ -159,7 +159,8 @@ has 'is_nonsense' => ( has 'normal_form' => ( is => 'rw', isa => 'Str', - predicate => 'has_normal_form', + predicate => '_has_normal_form', + clearer => '_clear_normal_form', ); # Holds the lexemes for the reading. @@ -236,6 +237,21 @@ sub BUILD { } } +# Make normal_form default to text, transparently. +around 'normal_form' => sub { + my $orig = shift; + my $self = shift; + my( $arg ) = @_; + if( $arg && $arg eq $self->text ) { + $self->_clear_normal_form; + return $arg; + } elsif( !$arg && !$self->_has_normal_form ) { + return $self->text; + } else { + $self->$orig( @_ ); + } +}; + =head2 is_meta A meta attribute (ha ha), which should be true if any of our 'special' diff --git a/lib/Text/Tradition/Language/Base.pm b/lib/Text/Tradition/Language/Base.pm index d0d1caf..f0fe304 100644 --- a/lib/Text/Tradition/Language/Base.pm +++ b/lib/Text/Tradition/Language/Base.pm @@ -113,8 +113,7 @@ sub _lemmatize_treetagger_sequence { warn "Ran out of readings in sequence at $lexeme"; last; } - my $curr_rdg_text = $curr_rdg->has_normal_form - ? $curr_rdg->normal_form : $curr_rdg->text; + my $curr_rdg_text = $curr_rdg->normal_form; if( $unused_rdg_part && $unused_rdg_part =~ /^\Q$lexeme\E(\s*)(.*)$/ ) { # Nth part of curr_rdg @@ -134,7 +133,7 @@ sub _lemmatize_treetagger_sequence { my @lookahead; my $matched; while( my $nr = shift @path ) { - my $nrtext = $nr->has_normal_form ? $nr->normal_form : $nr->text; + my $nrtext = $nr->normal_form; if( $nrtext =~ /^\Q$lexeme\E/ ) { $curr_rdg = $lookahead[-1] if @lookahead; $matched = 1; @@ -209,8 +208,7 @@ sub _text_from_path { unless ( $r->join_prior || !$last || $last->join_next ) { $pathtext .= ' '; } - $pathtext .= ( $normalize && $r->has_normal_form ) - ? $r->normal_form : $r->text; + $pathtext .= $normalize ? $r->normal_form : $r->text; $last = $r; } return $pathtext;