| 1 | package Treex::Block::Read::BaseSplitterRole; | ||||||||||
| 2 | 2 | $Treex::Block::Read::BaseSplitterRole::VERSION = '2.20210102'; | |||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use MooseX::SemiAffordanceAccessor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 2 | has bundles_per_doc => ( | |||||||||
| 9 | isa => 'Int', | ||||||||||
| 10 | is => 'ro', | ||||||||||
| 11 | default => 0, | ||||||||||
| 12 | documentation => 'Split the original file into more documents, each with max. N bundles. The deafult is 0 (do not split).', | ||||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | 2 | has _buffer_doc => (is=> 'rw'); | |||||||||
| 16 | |||||||||||
| 17 | 0 | ▶ | after 'BUILD' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 18 | 0 | my ($self) = @_; | |||||||||
| 19 | 0 | ▶ | if ( $self->bundles_per_doc ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | $self->set_is_one_doc_per_file(0); | |||||||||
| 21 | } | ||||||||||
| 22 | 0 | return; | |||||||||
| 23 | 2 | }; | |||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | around 'next_document' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||
| 26 | 0 | my ($orig_next_doc_method, $self, $filename) = @_; | |||||||||
| 27 | |||||||||||
| 28 | 0 | my $doc = $self->_buffer_doc; | |||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | if (!$doc) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | $doc = $self->$orig_next_doc_method($filename); | |||||||||
| 32 | 0 | ▶ | return if !$doc; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 0 | ▶ | if ($self->bundles_per_doc) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | my $bundles_ref = $doc->treeList(); | |||||||||
| 37 | 0 | ▶ | if ( @$bundles_ref > $self->bundles_per_doc) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | my $new_doc = $self->new_document(); | |||||||||
| 39 | 0 | my @moving_bundles = splice @$bundles_ref, $self->bundles_per_doc; | |||||||||
| 40 | # TODO fix references (delete coreference links) going across new doc boundaries | ||||||||||
| 41 | # or suggest to use block Util::FixInvalidIDs | ||||||||||
| 42 | 0 | push @{$new_doc->treeList()}, @moving_bundles; | |||||||||
| 43 | 0 | $self->_set_buffer_doc($new_doc); | |||||||||
| 44 | } else { | ||||||||||
| 45 | 0 | $self->_set_buffer_doc(undef); | |||||||||
| 46 | } | ||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | 0 | return $doc; | |||||||||
| 50 | 2 | }; | |||||||||
| 51 | |||||||||||
| 52 | 2 | 1; | |||||||||
| 53 | |||||||||||
| 54 | __END__ | ||||||||||