| 1 | package Treex::Core::Node::InClause; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 38 | $Treex::Core::Node::InClause::VERSION = '2.20210102'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 38 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | # with Moose >= 2.00, this must be present also in roles | ||||||||||||||||||||||||||||||||||||||||||
| 6 | 38 | ▶ | use MooseX::SemiAffordanceAccessor; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 38 | ▶ | use Treex::Core::Log; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 38 | ▶ | use List::Util qw(first); # TODO: this wouldn't be needed if there was Treex::Core::Common for roles | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 38 | has clause_number => ( | |||||||||||||||||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | isa => 'Maybe[Int]', | ||||||||||||||||||||||||||||||||||||||||||
| 13 | documentation => 'ordinal number that is shared by all nodes of a clause', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 38 | has is_clause_head => ( | |||||||||||||||||||||||||||||||||||||||||
| 17 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 18 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||||||
| 19 | documentation => 'Is this node a head of a finite clause?', | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub get_clause_root { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_clause_root: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | log_fatal 'Incorrect number of arguments' if @_ != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $my_number = $self->clause_number; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | log_warn( 'Attribute clause_number not defined in ' . $self->id ) if !defined $my_number; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return $self if !$my_number; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my $highest = $self; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $parent = $self->get_parent(); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | while ( $parent && ( $parent->clause_number || 0 ) == $my_number ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$parent and ($parent->clause_number || 0) == $my_number
$parent->clause_number || 0
MC/DC0%0/2
$parent and ($parent->clause_number || 0) == $my_number
$parent
$parent->clause_number
Truth table0%0/3
A and B
A= $parentB= $parent->clause_number
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $highest = $parent; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $parent = $parent->get_parent(); | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ( $parent && !$highest->is_member && $parent->is_coap_root() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$parent and not $highest->is_member and $parent->is_coap_root
$parent and not $highest->is_member
MC/DC0%0/3
$parent and not $highest->is_member and $parent->is_coap_root
$parent
not $highest->is_member
$parent->is_coap_root
Truth table0%0/4
A and not(B) and C
A= $parentB= not $highest->is_memberC= $parent->is_coap_root
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $eff_parent = first { $_->is_member && ( $_->clause_number || 0 ) == $my_number } $parent->get_children(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
Branch: 1 branch
Condition0%0/2
$_->clause_number || 0
MC/DC0%0/1
$_->clause_number || 0
$_->clause_number
Truth table0%0/2
A
A= $_->clause_number
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | return $eff_parent if $eff_parent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return $highest; | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # Clauses may by split in more subtrees ("Peter eats and drinks.") | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub get_clause_nodes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_clause_nodes: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | log_fatal 'Incorrect number of arguments' if @_ != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $root = $self->get_root(); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my @descendants = $root->get_descendants( { ordered => 1 } ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $my_number = $self->clause_number; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return grep { ( $_->clause_number || '' ) eq $my_number } @descendants; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_->clause_number || ''
MC/DC0%0/1
$_->clause_number || ''
$_->clause_number
Truth table0%0/2
A
A= $_->clause_number
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # TODO: same purpose as get_clause_root but instead of clause_number uses is_clause_head | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub get_clause_head { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_clause_head: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | log_fatal 'Incorrect number of arguments' if @_ != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $node = $self; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | while ( !$node->is_clause_head && $node->get_parent() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $node->is_clause_head and $node->get_parent
MC/DC0%0/2
not $node->is_clause_head and $node->get_parent
not $node->is_clause_head
$node->get_parent
Truth table0%0/3
not(A) and B
A= not $node->is_clause_headB= $node->get_parent
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $node = $node->get_parent(); | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return $node; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub get_clause_ehead { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_clause_ehead: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | log_fatal 'Incorrect number of arguments' if @_ != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | return $self if $self->is_clause_head; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | my ($node) = $self->get_eparents( { or_topological => 1 } ); | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | while ( !$node->is_clause_head && $node->get_parent() ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $node->is_clause_head and $node->get_parent
MC/DC0%0/2
not $node->is_clause_head and $node->get_parent
not $node->is_clause_head
$node->get_parent
Truth table0%0/3
not(A) and B
A= not $node->is_clause_headB= $node->get_parent
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $node = $node->get_parent(); | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return $node; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | # Alternative API could be: $node->get_descendants({within_clause=>1}); | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub get_clause_descendants { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_clause_descendants: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | log_fatal 'Incorrect number of arguments' if @_ != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my @clause_children = grep { !$_->is_clause_head } $self->get_children(); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | return ( @clause_children, map { $_->get_clause_descendants() } @clause_children ); | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | # A variant of the previous, using effective children instead of children. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub get_clause_edescendants { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_clause_edescendants: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | log_fatal 'Incorrect number of arguments' if @_ != 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my @clause_children = grep { !$_->is_clause_head } $self->get_echildren({or_topological=>1}); | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | # we can use normal get_clause_descendants here, using echildren would no longer make any difference | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | return ( @clause_children, map { $_->get_clause_descendants() } @clause_children ); | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 38 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | __END__ | ||||||||||||||||||||||||||||||||||||||||||