CWB-CQP-More

 view release on metacpan or  search on metacpan

lib/CWB/CQP/More/Parallel.pm  view on Meta::CPAN

package CWB::CQP::More::Parallel;
$CWB::CQP::More::Parallel::VERSION = '0.08';
use 5.006;
use strict;
use warnings;

use base 'CWB::CQP::More';
use Try::Tiny;

=encoding utf-8

=head1 NAME

CWB::CQP::More::Parallel - CWP::CQP::More tweaked for parallel corpora

=head1 SYNOPSIS

   use CWB::CQP::More::Parallel;

   my $cwb = CWB::CQP::More::Parallel->new( { utf8 => 1} );


=head1 DESCRIPTION

CWB::CQP::More prepared for parallel corpora.

=cut

sub new {
    shift; # class
    my $ops = ref $_[0] eq "HASH" ? shift : {};
    $ops->{parallel} = 1;
    __PACKAGE__->SUPER::new($ops, @_);
}

=head2 change_corpus

Change current active parallel corpus. Pass the corpus name as the
first argument, and the target corpus as second argument. If this one
is ommited, the target language will be automatically selected (can
misbehave for multilanguage corpora).

=cut

sub change_corpus {
    my ($self, $cname, $tname) = @_;

    my $details = $self->corpora_details($cname);
    die "Can not find details for corpus $cname." unless defined $details;

    my $target;
    if (defined($tname)) {
        if (exists($details->{attribute}{a}{lc $tname})) {
            $target = lc $tname;
        } elsif (exists($details->{attribute}{a}{uc $tname})) {
            $target = uc $tname;
        } else {
            die "Can't find an aligned corpus named $tname";
        }
    } else {
        ($target) = keys %{ $details->{attribute}{a} };
    }

    die "This does not seems a parallel corpus." unless defined $target;

    $cname = uc $cname;
    $self->exec("$cname;");
    $self->annotation_show($target);



( run in 1.590 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )