| 1 | package PMLTQ::TypeMapper; | ||||||||||||||||||||||||||||||||||
| 2 | 1 | our $AUTHORITY = 'cpan:MATY'; | |||||||||||||||||||||||||||||||||
| 3 | 1 | $PMLTQ::TypeMapper::VERSION = '1.5.0'; | |||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Helper methods for PML::Schema, relations and PML::Node types | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Treex::PML::Schema; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use PMLTQ::Common (qw(uniq first)); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use PMLTQ::Relation; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use UNIVERSAL::DOES; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 1 | PMLTQ::Relation->load(); | |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||
| 18 | BEGIN { # TredMacro should work in TrEd 2.0 | ||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | eval { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.4
| |||||||||||||||||||||||||||||||||||
| 20 | 1 | require TrEd::MacroAPI::Default; | |||||||||||||||||||||||||||||||||
| 21 | 0 | TrEd::MacroAPI::Default->import; | |||||||||||||||||||||||||||||||||
| 22 | }; | ||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | sub new { | ||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my ($class,$opts)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $opts||={}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$opts ||= {}
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
| |||||||||||||||||||||||||||||||||||
| 28 | my $what = ($opts->{file}?1:0) + | ||||||||||||||||||||||||||||||||||
| 29 | ($opts->{fsfile}?1:0) + | ||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | ($opts->{filelist}?1:0); | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | croak("Neither file, fsfile, nor filelist were specified!") unless $what; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | croak("Options file, fsfile, filelist are exclusive!") if $what>1; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 33 | my $self = bless { | ||||||||||||||||||||||||||||||||||
| 34 | fsfile => $opts->{fsfile}, | ||||||||||||||||||||||||||||||||||
| 35 | file => $opts->{file}, | ||||||||||||||||||||||||||||||||||
| 36 | filelist => $opts->{filelist}, | ||||||||||||||||||||||||||||||||||
| 37 | 0 | }, $class; | |||||||||||||||||||||||||||||||||
| 38 | 0 | return $self; | |||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | sub get_schema_for_query_node { | ||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | my ($self,$node)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_schema_for_query_node: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 43 | 0 | my $decl = $self->get_type_decl_for_query_node($node); | |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | return $decl && $decl->schema; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$decl && $decl->schema
MC/DC0%0/2
$decl && $decl->schema
$decl
$decl->schema
Truth table0%0/3
A && B
A= $declB= $decl->schema
| |||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||
| 46 | sub get_schema_for_type { | ||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | my ($self,$type)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_schema_for_type: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($type eq '*') { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 49 | 0 | my @schemas = $self->get_schemas; | |||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (@schemas == 1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 51 | 0 | return $schemas[1]; | |||||||||||||||||||||||||||||||||
| 52 | } else { | ||||||||||||||||||||||||||||||||||
| 53 | 0 | return undef; | |||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||
| 55 | } elsif ($type =~ m{^(?:([^/]+):)\*$}) { | ||||||||||||||||||||||||||||||||||
| 56 | 0 | my $schema_name = $1; | |||||||||||||||||||||||||||||||||
| 57 | 0 | my ($schema) = grep { $_->get_root_name eq $schema_name } $self->get_schemas; | |||||||||||||||||||||||||||||||||
| 58 | 0 | return $schema; | |||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | 0 | my $decl = $self->get_decl_for($type); | |||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return $decl && $decl->get_schema; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$decl && $decl->get_schema
MC/DC0%0/2
$decl && $decl->get_schema
$decl
$decl->get_schema
Truth table0%0/3
A && B
A= $declB= $decl->get_schema
| |||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | sub get_schema_name_for { | ||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | my ($self,$type)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_schema_name_for: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 0 | my $schema = $self->get_schema_for_type($type); | |||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | return $schema ? $schema->get_root_name : undef; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||
| 71 | sub _get_fsfile { | ||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_get_fsfile: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||
| 73 | 0 | my $fsfile = $self->{fsfile}; | |||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return $fsfile if $fsfile; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 75 | 0 | my $file = $self->{file}; | |||||||||||||||||||||||||||||||||
| 76 | 0 | my $fl; | |||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($file) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (ref($file) and UNIVERSAL::DOES::does($file,'Treex::PML::Document')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $file and UNIVERSAL::DOES::does($file, "Treex::PML::Document")
MC/DC0%0/2
ref $file and UNIVERSAL::DOES::does($file, "Treex::PML::Document")
ref $file
UNIVERSAL::DOES::does($file, "Treex::PML::Document")
Truth table0%0/3
A and B
A= ref $fileB= UNIVERSAL::DOES::does($file, "Treex::PML::Document")
| |||||||||||||||||||||||||||||||||||
| 79 | 0 | $self->{file} = $file->filename; | |||||||||||||||||||||||||||||||||
| 80 | 0 | return $self->{fsfile} = $file; | |||||||||||||||||||||||||||||||||
| 81 | } else { | ||||||||||||||||||||||||||||||||||
| 82 | return ($self->{fsfile} = | ||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | ((first { $_->filename eq $file } TredMacro::GetOpenFiles()) | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
&first(sub {
$_->filename eq $file;
}
, TredMacro::GetOpenFiles()) || TredMacro::Open($file, {'-preload', 1})
MC/DC0%0/2
&first(sub {
$_->filename eq $file;
}
, TredMacro::GetOpenFiles()) || TredMacro::Open($file, {'-preload', 1})
&first(sub {
$_->filename eq $file;
}
, TredMacro::GetOpenFiles())
TredMacro::Open($file, {'-preload', 1})
Truth table0%0/3
A || B
A= &first(sub {
$_->filename eq $file;
}
, TredMacro::GetOpenFiles())B= TredMacro::Open($file, {'-preload', 1})
| |||||||||||||||||||||||||||||||||||
| 84 | || TredMacro::Open($file, {-preload=>1}))); | ||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||
| 86 | } elsif ($fl = TredMacro::GetFileList($self->{filelist})) { | ||||||||||||||||||||||||||||||||||
| 87 | 0 | my %fl; | |||||||||||||||||||||||||||||||||
| 88 | 0 | my @files = $fl->files; | |||||||||||||||||||||||||||||||||
| 89 | 0 | @fl{ @files } = (); | |||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | return $self->{fsfile} = ((first { exists($fl{$_->filename}) } TredMacro::GetOpenFiles())|| | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/6
&first(sub {
exists $fl{$_->filename};
}
, TredMacro::GetOpenFiles()) || $files[0] && TredMacro::Open(TredMacro::AbsolutizeFileName($files[0], $fl->filename), {'-preload', 1})
$files[0] and TredMacro::Open(TredMacro::AbsolutizeFileName($files[0], $fl->filename), {"-preload", 1})
MC/DC0%0/3
&first(sub {
exists $fl{$_->filename};
}
, TredMacro::GetOpenFiles()) || $files[0] && TredMacro::Open(TredMacro::AbsolutizeFileName($files[0], $fl->filename), {'-preload', 1})
&first(sub {
exists $fl{$_->filename};
}
, TredMacro::GetOpenFiles())
$files[0]
TredMacro::Open(TredMacro::AbsolutizeFileName($files[0], $fl->filename), {"-preload", 1})
Truth table0%0/4
A || B and C
A= &first(sub {
exists $fl{$_->filename};
}
, TredMacro::GetOpenFiles())B= $files[0]C= TredMacro::Open(TredMacro::AbsolutizeFileName($files[0], $fl->filename), {"-preload", 1})
| |||||||||||||||||||||||||||||||||||
| 91 | $files[0] && TredMacro::Open(TredMacro::AbsolutizeFileName($files[0],$fl->filename),{-preload=>1})); | ||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||
| 95 | sub get_schema { | ||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my ($self,$schema_name)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_schema: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ($schema_name) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 98 | 0 | my ($ret) = grep { $_->get_root_name eq $schema_name } $self->get_schemas; | |||||||||||||||||||||||||||||||||
| 99 | 0 | return $ret; | |||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my $fsfile = $self->_get_fsfile || return; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_get_fsfile || (return)
MC/DC0%0/1
$self->_get_fsfile || (return)
$self->_get_fsfile
Truth table0%0/2
A
A= $self->_get_fsfile
| |||||||||||||||||||||||||||||||||||
| 102 | 0 | return PML::Schema($fsfile); | |||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||
| 105 | sub get_schemas { | ||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_schemas: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | my $fsfile = $self->_get_fsfile || return; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->_get_fsfile || (return)
MC/DC0%0/1
$self->_get_fsfile || (return)
$self->_get_fsfile
Truth table0%0/2
A
A= $self->_get_fsfile
| |||||||||||||||||||||||||||||||||||
| 108 | 0 | return uniq( map PML::Schema($_), ($fsfile, TredMacro::GetSecondaryFiles($fsfile))); | |||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | sub get_schema_names { | ||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_schema_names: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 113 | 0 | return [uniq(grep { defined } map { $_->get_root_name } $self->get_schemas)]; | |||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||
| 116 | sub get_type_decl_for_query_node { | ||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my ($self,$node)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_type_decl_for_query_node: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 118 | 0 | return $self->get_decl_for(PMLTQ::Common::GetQueryNodeType($node)); | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | sub get_decl_for { | ||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | my ($self,$type)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_decl_for: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 123 | 0 | my $ret = eval { PMLTQ::Common::QueryTypeToDecl($type,$self->get_schemas) }; | |||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 125 | 0 | return $ret; | |||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||
| 128 | sub get_node_types { | ||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | my ($self,$schema_name)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_node_types: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 130 | return [sort map PMLTQ::Common::DeclToQueryType( $_ ), map $_->node_types, | ||||||||||||||||||||||||||||||||||
| 131 | 0 | ▶ | grep { $schema_name ? ($_->get_root_name eq $schema_name) : 1 } | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 132 | $self->get_schemas | ||||||||||||||||||||||||||||||||||
| 133 | ]; | ||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | sub _find_pmlrf_relations { | ||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | my ($self)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_find_pmlrf_relations: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||
| 138 | 0 | my @schemas = $self->get_schemas; | |||||||||||||||||||||||||||||||||
| 139 | 0 | my @relations=(); | |||||||||||||||||||||||||||||||||
| 140 | 0 | my %relations; | |||||||||||||||||||||||||||||||||
| 141 | 0 | for my $schema (@schemas) { | |||||||||||||||||||||||||||||||||
| 142 | 0 | for my $type ($schema->node_types) { | |||||||||||||||||||||||||||||||||
| 143 | 0 | my $type_name = PMLTQ::Common::DeclToQueryType($type); | |||||||||||||||||||||||||||||||||
| 144 | 0 | for my $path ($type->get_paths_to_atoms({ no_nodes=>1, no_childnodes => 1 })) { | |||||||||||||||||||||||||||||||||
| 145 | 0 | my $decl = $type->find($path); | |||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | $decl=$decl->get_content_decl unless $decl->is_atomic; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 147 | 0 | ▶ | if ($decl->get_decl_type == PML_CDATA_DECL and | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$decl->get_decl_type == 8 and $decl->get_format eq "PMLREF"
MC/DC0%0/2
$decl->get_decl_type == 8 and $decl->get_format eq "PMLREF"
$decl->get_decl_type == 8
$decl->get_format eq "PMLREF"
Truth table0%0/3
A and B
A= $decl->get_decl_type == 8B= $decl->get_format eq "PMLREF"
| |||||||||||||||||||||||||||||||||||
| 148 | $decl->get_format eq 'PMLREF') { | ||||||||||||||||||||||||||||||||||
| 149 | 0 | push @relations, $path; | |||||||||||||||||||||||||||||||||
| 150 | 0 | $relations{$type_name}{$path}='#any'; | |||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||
| 155 | 0 | $self->{pmlrf_relations_hash}=\%relations; | |||||||||||||||||||||||||||||||||
| 156 | 0 | return $self->{pmlrf_relations} = [sort @relations]; | |||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | sub _find_pmlrf_relations_for_type { | ||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | my ($self,$type_name)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
_find_pmlrf_relations_for_type: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||
| 161 | 0 | my @schemas = $self->get_schemas; | |||||||||||||||||||||||||||||||||
| 162 | 0 | my @relations=(); | |||||||||||||||||||||||||||||||||
| 163 | 0 | my $relations_hash = $self->get_pmlrf_relations_hash; # init | |||||||||||||||||||||||||||||||||
| 164 | 0 | my $decl = $self->get_decl_for($type_name); | |||||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | return [] unless $decl; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 166 | 0 | for my $path ($decl->get_paths_to_atoms({ no_nodes=>1, no_childnodes => 1 })) { | |||||||||||||||||||||||||||||||||
| 167 | 0 | my $mdecl = $decl->find($path); | |||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | next if $mdecl->get_role eq '#KNIT'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | unless ($mdecl->is_atomic) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 170 | 0 | $mdecl=$mdecl->get_content_decl ; | |||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | next if $mdecl->get_role eq '#KNIT'; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | if ($mdecl->get_decl_type == PML_CDATA_DECL and | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mdecl->get_decl_type == 8 and $mdecl->get_format eq "PMLREF"
MC/DC0%0/2
$mdecl->get_decl_type == 8 and $mdecl->get_format eq "PMLREF"
$mdecl->get_decl_type == 8
$mdecl->get_format eq "PMLREF"
Truth table0%0/3
A and B
A= $mdecl->get_decl_type == 8B= $mdecl->get_format eq "PMLREF"
| |||||||||||||||||||||||||||||||||||
| 174 | $mdecl->get_format eq 'PMLREF') { | ||||||||||||||||||||||||||||||||||
| 175 | 0 | push @relations, $path; | |||||||||||||||||||||||||||||||||
| 176 | 0 | $relations_hash->{$type_name}{$path}='#any'; | |||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||
| 179 | 0 | return [sort @relations]; | |||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | sub get_pmlrf_relations { | ||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | my ($self,$qnode_or_type)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_pmlrf_relations: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ($qnode_or_type) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | my $type = ref($qnode_or_type) ? PMLTQ::Common::GetQueryNodeType($qnode_or_type,$self) : $qnode_or_type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | my $rels = ref($self->{pmlrf_relations_hash}) && $self->{pmlrf_relations_hash}{$type}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
ref $self->{'pmlrf_relations_hash'} && $self->{'pmlrf_relations_hash'}{$type}
MC/DC0%0/2
ref $self->{'pmlrf_relations_hash'} && $self->{'pmlrf_relations_hash'}{$type}
ref $self->{'pmlrf_relations_hash'}
$self->{'pmlrf_relations_hash'}{$type}
Truth table0%0/3
A && B
A= ref $self->{'pmlrf_relations_hash'}B= $self->{'pmlrf_relations_hash'}{$type}
| |||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if ($rels) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 188 | 0 | return [ uniq( sort keys %$rels ) ]; | |||||||||||||||||||||||||||||||||
| 189 | } else { | ||||||||||||||||||||||||||||||||||
| 190 | 0 | return $self->_find_pmlrf_relations_for_type($type); | |||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||
| 192 | } else { | ||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | return $self->{pmlrf_relations} || $self->_find_pmlrf_relations; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'pmlrf_relations'} || $self->_find_pmlrf_relations
MC/DC0%0/2
$self->{'pmlrf_relations'} || $self->_find_pmlrf_relations
$self->{'pmlrf_relations'}
$self->_find_pmlrf_relations
Truth table0%0/3
A || B
A= $self->{'pmlrf_relations'}B= $self->_find_pmlrf_relations
| |||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||
| 197 | sub get_pmlrf_relations_hash { | ||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | my ($self,$type)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_pmlrf_relations_hash: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 199 | 0 | my $hash = $self->{pmlrf_relations_hash}; | |||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | if ($type) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $hash = $hash->{$type} if $hash; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | return $hash if $hash; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 203 | 0 | $self->_find_pmlrf_relations_for_type($type); | |||||||||||||||||||||||||||||||||
| 204 | 0 | $hash = $self->{pmlrf_relations_hash}{$type}; | |||||||||||||||||||||||||||||||||
| 205 | } elsif (!$hash) { | ||||||||||||||||||||||||||||||||||
| 206 | 0 | $self->_find_pmlrf_relations; | |||||||||||||||||||||||||||||||||
| 207 | 0 | $hash = $self->{pmlrf_relations_hash}; | |||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||
| 209 | 0 | return $hash; | |||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||
| 212 | sub get_specific_relations { | ||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | my ($self,$qnode_or_type)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_specific_relations: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 214 | return [uniq(sort( | ||||||||||||||||||||||||||||||||||
| 215 | 0 | @{$self->get_user_defined_relations($qnode_or_type)}, | |||||||||||||||||||||||||||||||||
| 216 | 0 | @{$self->get_pmlrf_relations($qnode_or_type)}))]; | |||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | sub get_user_defined_relations { | ||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | my ($self,$qnode_or_type)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_user_defined_relations: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ($qnode_or_type) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | my $type = ref($qnode_or_type) ? PMLTQ::Common::GetQueryNodeType($qnode_or_type,$self) : $qnode_or_type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 223 | 0 | my $schema_name = $self->get_schema_name_for($type); | |||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | return $schema_name ? PMLTQ::Relation->relations_for_node_type($schema_name, $type) : []; # Ignore if it doesn't have schema_name | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||
| 226 | return [ | ||||||||||||||||||||||||||||||||||
| 227 | 0 | map @{$self->get_user_defined_relations($_)}, grep $_, @{$self->get_node_types} | |||||||||||||||||||||||||||||||||
| 228 | ]; | ||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||
| 231 | 1 | my %known_pmlref_relations = ( | |||||||||||||||||||||||||||||||||
| 232 | 't-root' => { | ||||||||||||||||||||||||||||||||||
| 233 | 'a/lex.rf' => 'a-root', | ||||||||||||||||||||||||||||||||||
| 234 | }, | ||||||||||||||||||||||||||||||||||
| 235 | 't-node' => { | ||||||||||||||||||||||||||||||||||
| 236 | 'a/lex.rf' => 'a-node', | ||||||||||||||||||||||||||||||||||
| 237 | 'a/aux.rf' => 'a-node', | ||||||||||||||||||||||||||||||||||
| 238 | 'val_frame.rf' => 'v-frame', | ||||||||||||||||||||||||||||||||||
| 239 | 'coref_text.rf' => 't-node', | ||||||||||||||||||||||||||||||||||
| 240 | 'coref_gram.rf' => 't-node', | ||||||||||||||||||||||||||||||||||
| 241 | 'compl.rf' => 't-node', | ||||||||||||||||||||||||||||||||||
| 242 | }, | ||||||||||||||||||||||||||||||||||
| 243 | 'a-node' => { | ||||||||||||||||||||||||||||||||||
| 244 | 'p/terminal.rf' => 'english_p_terminal', | ||||||||||||||||||||||||||||||||||
| 245 | 'p/nonterminals.rf' => 'english_p_nonterminal', | ||||||||||||||||||||||||||||||||||
| 246 | }, | ||||||||||||||||||||||||||||||||||
| 247 | ); | ||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||
| 249 | sub get_relation_target_type { | ||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | my ($self,$node_type,$relation,$category)=@_; | ||||||||||||||||||||||||||||||||
|
Subroutine
get_relation_target_type: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 251 | 0 | my $type; | |||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if (!$category or $category eq 'pmlrf') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $category or $category eq "pmlrf"
MC/DC0%0/2
not $category or $category eq "pmlrf"
not $category
$category eq "pmlrf"
Truth table0%0/3
not(A) or B
A= not $categoryB= $category eq "pmlrf"
| |||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | $type = $known_pmlref_relations{$node_type} && $known_pmlref_relations{$node_type}{$relation}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$known_pmlref_relations{$node_type} && $known_pmlref_relations{$node_type}{$relation}
MC/DC0%0/2
$known_pmlref_relations{$node_type} && $known_pmlref_relations{$node_type}{$relation}
$known_pmlref_relations{$node_type}
$known_pmlref_relations{$node_type}{$relation}
Truth table0%0/3
A && B
A= $known_pmlref_relations{$node_type}B= $known_pmlref_relations{$node_type}{$relation}
| |||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | return $type if $type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 255 | 0 | my $pmlref_relations_hash = $self->get_pmlrf_relations_hash($node_type); | |||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | $type = $pmlref_relations_hash && $pmlref_relations_hash->{$relation}; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$pmlref_relations_hash && $pmlref_relations_hash->{$relation}
MC/DC0%0/2
$pmlref_relations_hash && $pmlref_relations_hash->{$relation}
$pmlref_relations_hash
$pmlref_relations_hash->{$relation}
Truth table0%0/3
A && B
A= $pmlref_relations_hashB= $pmlref_relations_hash->{$relation}
| |||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | return $type if $type; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if (!$category or $category eq 'implementation') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $category or $category eq "implementation"
MC/DC0%0/2
not $category or $category eq "implementation"
not $category
$category eq "implementation"
Truth table0%0/3
not(A) or B
A= not $categoryB= $category eq "implementation"
| |||||||||||||||||||||||||||||||||||
| 260 | 0 | return PMLTQ::Relation->target_type($node_type, $relation); | |||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||
| 262 | 0 | return; | |||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||
| 265 | 1 | 1; # End of PMLTQ::TypeMapper | |||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||
| 267 | __END__ | ||||||||||||||||||||||||||||||||||