Lingua-FreeLing3
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Lingua/FreeLing3/Paragraph.pm view on Meta::CPAN
package Lingua::FreeLing3::Paragraph;
use Lingua::FreeLing3::Bindings;
use parent -norequire, 'Lingua::FreeLing3::Bindings::paragraph';
use Scalar::Util 'blessed';
use Carp;
use warnings;
use strict;
# XXX
# *empty = *Lingua::FreeLing3::Bindingsc::ListSentence_empty;
# *clear = *Lingua::FreeLing3::Bindingsc::ListSentence_clear;
our $VERSION = "0.03";
=encoding UTF-8
=head1 NAME
Lingua::FreeLing3::Paragraph - Interface to FreeLing3 Paragraph object
=head1 SYNOPSIS
use Lingua::FreeLing3::Paragraph;
=head1 DESCRIPTION
This module is a wrapper to the FreeLing3 Paragraph object.
=head2 C<new>
The constructor returns a new Paragraph object: a list of sentences
=cut
sub new {
my $class = shift;
my $self = $class->SUPER::new();
return bless $self => $class #amen
}
sub _new_from_binding {
my ($class, $paragraph) = @_;
bless $paragraph => $class #amen
}
=head2 C<push>
Adds one or more sentences to the paragraph.
=cut
sub push {
my $self = shift;
my $p;
while ($p = shift) {
if (blessed($p) && $p->isa('Lingua::FreeLing3::Bindings::sentence')) {
$self->SUPER::push($p);
} else {
carp "Ignoring push parameter: not a sentence."
}
}
return $self;
}
=head2 C<sentence>
Gets a sentence from a paragraph. Note that this method is extremely
slow, given that FreeLing paragraph is implemented as a
list. Therefore, retrieving the nth element of the list does n
iterations on a linked list.
=cut
sub sentence {
my ($self, $n) = @_;
$n >= $self->length() and return undef;
Lingua::FreeLing3::Sentence->_new_from_binding($self->SUPER::get($n));
}
=head2 C<sentences>
Returns an array of sentences from a paragraph.
=cut
sub sentences {
map { Lingua::FreeLing3::Sentence->_new_from_binding($_) } @{ $_[0]->SUPER::elements() }
}
=head2 C<length>
Returns the number of sentences in the paragraph.
=cut
sub length { $_[0]->SUPER::size }
1;
__END__
=head1 SEE ALSO
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.502 second using v1.00-cache-2.02-grep-82fe00e-cpan-3b7f77b76a6c )