| 1 | package Treex::Tool::Parser::MSTperl; | ||
| 2 | { | ||
| 3 | 1 | $Treex::Tool::Parser::MSTperl::VERSION = '0.11949'; | |
| 4 | } | ||
| 5 | |||
| 6 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use File::Spec; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | |||
| 9 | 1 | ▶ | use Treex::Tool::Parser::MSTperl::Config; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use Treex::Tool::Parser::MSTperl::Node; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 1 | ▶ | use Treex::Tool::Parser::MSTperl::Sentence; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | 1 | ▶ | use Treex::Tool::Parser::MSTperl::Parser; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 1 | ▶ | use Treex::Tool::Parser::MSTperl::Labeller; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | |||
| 15 | 1 | has 'model_name' => ( | |
| 16 | is => 'ro', | ||
| 17 | isa => 'Str', | ||
| 18 | required => '1', | ||
| 19 | ); | ||
| 20 | |||
| 21 | 1 | has 'model_dir' => ( | |
| 22 | is => 'ro', | ||
| 23 | isa => 'Str', | ||
| 24 | default => '.', | ||
| 25 | ); | ||
| 26 | |||
| 27 | 1 | has 'base_name' => ( | |
| 28 | is => 'ro', | ||
| 29 | isa => 'Str', | ||
| 30 | lazy => '1', | ||
| 31 | builder => 'build_base_name', | ||
| 32 | ); | ||
| 33 | |||
| 34 | 0 | ▶ | sub build_base_name { |
|
Subroutine
build_base_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 35 | 0 | my ($self) = @_; | |
| 36 | |||
| 37 | 0 | my $base_name = File::Spec->catfile( $self->model_dir, $self->model_name ); | |
| 38 | |||
| 39 | 0 | return $base_name; | |
| 40 | } | ||
| 41 | |||
| 42 | 1 | has 'config' => ( | |
| 43 | is => 'rw', | ||
| 44 | isa => 'Treex::Tool::Parser::MSTperl::Config', | ||
| 45 | lazy => '1', | ||
| 46 | builder => 'build_config', | ||
| 47 | ); | ||
| 48 | |||
| 49 | 0 | ▶ | sub build_config { |
|
Subroutine
build_config: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 50 | 0 | my ($self) = @_; | |
| 51 | |||
| 52 | 0 | my $config = Treex::Tool::Parser::MSTperl::Config->new( | |
| 53 | config_file => $self->base_name . '.config' | ||
| 54 | ); | ||
| 55 | |||
| 56 | 0 | return $config; | |
| 57 | } | ||
| 58 | |||
| 59 | 1 | has 'parser' => ( | |
| 60 | is => 'ro', | ||
| 61 | isa => 'Treex::Tool::Parser::MSTperl::Parser', | ||
| 62 | lazy => '1', | ||
| 63 | builder => 'build_parser', | ||
| 64 | ); | ||
| 65 | |||
| 66 | 0 | ▶ | sub build_parser { |
|
Subroutine
build_parser: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 67 | 0 | my ($self) = @_; | |
| 68 | |||
| 69 | # Initialize the parser | ||
| 70 | 0 | my $parser = Treex::Tool::Parser::MSTperl::Parser->new( | |
| 71 | config => $self->config | ||
| 72 | ); | ||
| 73 | |||
| 74 | # Load the unlabelled parsing model | ||
| 75 | 0 | $parser->load_model( $self->base_name . '.model' ); | |
| 76 | |||
| 77 | 0 | return $parser; | |
| 78 | } | ||
| 79 | |||
| 80 | 1 | has 'labeller' => ( | |
| 81 | is => 'ro', | ||
| 82 | isa => 'Treex::Tool::Parser::MSTperl::Labeller', | ||
| 83 | lazy => '1', | ||
| 84 | builder => 'build_labeller', | ||
| 85 | ); | ||
| 86 | |||
| 87 | 0 | ▶ | sub build_labeller { |
|
Subroutine
build_labeller: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 88 | 0 | my ($self) = @_; | |
| 89 | |||
| 90 | # Initialize the labeller | ||
| 91 | 0 | my $labeller = Treex::Tool::Parser::MSTperl::Labeller->new( | |
| 92 | config => $self->config | ||
| 93 | ); | ||
| 94 | |||
| 95 | # Load the labelling model | ||
| 96 | 0 | $labeller->load_model( $self->base_name . '.lmodel' ); | |
| 97 | |||
| 98 | 0 | return $labeller; | |
| 99 | } | ||
| 100 | |||
| 101 | 0 | ▶ | sub BUILD { |
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||
| 102 | 0 | my ($self) = @_; | |
| 103 | |||
| 104 | # Build the config | ||
| 105 | 0 | $self->config; | |
| 106 | |||
| 107 | 0 | return; | |
| 108 | } | ||
| 109 | |||
| 110 | 0 | ▶ | sub parse_labelled { |
|
Subroutine
parse_labelled: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 111 | 0 | my ( $self, $words ) = @_; | |
| 112 | |||
| 113 | 0 | my $sentence = $self->_create_sentence($words); | |
| 114 | 0 | my $sentence_parsed = $self->_parse_sentence($sentence); | |
| 115 | 0 | my $sentence_labelled = $self->_label_sentence($sentence_parsed); | |
| 116 | |||
| 117 | 0 | my $parents = $sentence_parsed->toParentOrdsArray(); | |
| 118 | 0 | my $labels = $sentence_labelled->toLabelsArray(); | |
| 119 | |||
| 120 | 0 | return ( $parents, $labels ); | |
| 121 | } | ||
| 122 | |||
| 123 | 0 | ▶ | sub parse_unlabelled { |
|
Subroutine
parse_unlabelled: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 124 | 0 | my ( $self, $words ) = @_; | |
| 125 | |||
| 126 | 0 | my $sentence = $self->_create_sentence($words); | |
| 127 | 0 | my $sentence_parsed = $self->_parse_sentence($sentence); | |
| 128 | |||
| 129 | 0 | my $parents = $sentence_parsed->toParentOrdsArray(); | |
| 130 | |||
| 131 | 0 | return $parents; | |
| 132 | } | ||
| 133 | |||
| 134 | # TODO: parse_tsv | ||
| 135 | |||
| 136 | # Each word is represented by | ||
| 137 | # (a ref to) an array of its fields (form, pos tag, lemma...) | ||
| 138 | 0 | ▶ | sub _create_sentence { |
|
Subroutine
_create_sentence: not called CC=2 SCAR=17.9
| |||
| 139 | |||
| 140 | # ArrayRef[ArrayRef[Str]] | ||
| 141 | 0 | my ( $self, $words ) = @_; | |
| 142 | |||
| 143 | # Create the Node objects representing the individual words | ||
| 144 | 0 | my @nodes; | |
| 145 | 0 | foreach my $fields (@$words) { | |
| 146 | 0 | my $node = Treex::Tool::Parser::MSTperl::Node->new( | |
| 147 | config => $self->config, | ||
| 148 | fields => $fields | ||
| 149 | ); | ||
| 150 | 0 | push @nodes, $node; | |
| 151 | } | ||
| 152 | |||
| 153 | # Create the Sentence object representing the whole sentence | ||
| 154 | 0 | my $sentence = Treex::Tool::Parser::MSTperl::Sentence->new( | |
| 155 | config => $self->config, | ||
| 156 | nodes => \@nodes | ||
| 157 | ); | ||
| 158 | |||
| 159 | 0 | return $sentence; | |
| 160 | } | ||
| 161 | |||
| 162 | 0 | ▶ | sub _parse_sentence { |
|
Subroutine
_parse_sentence: not called CC=1 SCAR=6.9
| |||
| 163 | 0 | my ( $self, $sentence ) = @_; | |
| 164 | |||
| 165 | 0 | my $sentence_parsed = $self->parser->parse_sentence_internal($sentence); | |
| 166 | |||
| 167 | 0 | return $sentence_parsed; | |
| 168 | } | ||
| 169 | |||
| 170 | 0 | ▶ | sub _label_sentence { |
|
Subroutine
_label_sentence: not called CC=1 SCAR=6.9
| |||
| 171 | 0 | my ( $self, $sentence ) = @_; | |
| 172 | |||
| 173 | 0 | my $sentence_labelled = $self->labeller->label_sentence_internal($sentence); | |
| 174 | |||
| 175 | 0 | return $sentence_labelled; | |
| 176 | } | ||
| 177 | |||
| 178 | 1 | 1; | |
| 179 | |||
| 180 | __END__ | ||