use Moose;
use overload '""' => \&_stringify, 'fallback' => 1;
-use Text::Tradition::Collation;
=head1 NAME
required => 1,
writer => 'alter_text',
);
+
+has 'punctuation' => (
+ traits => ['Array'],
+ isa => 'ArrayRef[HashRef[Str]]',
+ default => sub { [] },
+ handles => {
+ punctuation => 'elements',
+ add_punctuation => 'push',
+ },
+ );
+
+has 'separate_punctuation' => (
+ is => 'ro',
+ isa => 'Bool',
+ default => 1,
+ );
has 'is_start' => (
is => 'ro',
# ID to match.
if( exists $args->{'is_lacuna'} && !exists $args->{'text'} ) {
- $args->{'text'} = sprintf( "#LACUNA_%s#", $args->{'id'} );
+ $args->{'text'} = '#LACUNA#';
} elsif( exists $args->{'is_start'} ) {
$args->{'id'} = '#START#'; # Change the ID to ensure we have only one
$args->{'text'} = '#START#';
$class->$orig( $args );
};
+# Post-process the given text, stripping punctuation if we are asked.
+sub BUILD {
+ my $self = shift;
+ if( $self->separate_punctuation && !$self->is_meta ) {
+ my $pos = 0;
+ my $wspunct = ''; # word sans punctuation
+ foreach my $char ( split( //, $self->text ) ) {
+ if( $char =~ /^[[:punct:]]$/ ) {
+ $self->add_punctuation( { 'char' => $char, 'pos' => $pos } );
+ } else {
+ $wspunct .= $char;
+ }
+ $pos++;
+ }
+ $self->alter_text( $wspunct );
+ }
+}
+
+sub punctuated_form {
+ my $self = shift;
+ my $word = $self->text;
+ foreach my $p ( sort { $a->{pos} <=> $b->{pos} } $self->punctuation ) {
+ substr( $word, $p->{pos}, 0, $p->{char} );
+ }
+ return $word;
+}
+
=head2 is_meta
A meta attribute (ha ha), which should be true if any of our 'special'
return $self->collation->related_readings( $self, @_ );
}
+sub predecessors {
+ my $self = shift;
+ my @pred = $self->collation->sequence->predecessors( $self->id );
+ return map { $self->collation->reading( $_ ) } @pred;
+}
+
+sub successors {
+ my $self = shift;
+ my @succ = $self->collation->sequence->successors( $self->id );
+ return map { $self->collation->reading( $_ ) } @succ;
+}
+
sub set_identical {
my( $self, $other ) = @_;
return $self->collation->add_relationship( $self, $other,