| 1 | package Treex::Block::W2A::JA::ParseJDEPP; | ||||||||||
| 2 | 2 | $Treex::Block::W2A::JA::ParseJDEPP::VERSION = '0.13095'; | |||||||||
| 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 | |||||||||||
| 6 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use Treex::Core::Common; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Treex::Tool::Parser::JDEPP; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 2 | extends 'Treex::Block::W2A::BaseChunkParser'; | |||||||||
| 11 | |||||||||||
| 12 | # we use kyoto-partial model as a default model (installed as default during jdepp installation) | ||||||||||
| 13 | # other models should be trained through jdepp itself before using them | ||||||||||
| 14 | 2 | has 'model_dir' => ( | |||||||||
| 15 | is => 'ro', | ||||||||||
| 16 | isa => 'Str', | ||||||||||
| 17 | required => 1, | ||||||||||
| 18 | default => 'data/models/parser/jdepp/kyoto-partial', | ||||||||||
| 19 | documentation => 'path to the model relative to Treex resource_path', | ||||||||||
| 20 | ); | ||||||||||
| 21 | |||||||||||
| 22 | 2 | has parser => ( is => 'rw' ); | |||||||||
| 23 | |||||||||||
| 24 | 1 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 25 | 1 | my ($self) = @_; | |||||||||
| 26 | |||||||||||
| 27 | 1 | return; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 1 | ▶ | sub process_start { | ||||||||
|
Subroutine
process_start: called CC=1 SCAR=2.6
Pod
documented
| |||||||||||
| 31 | 1 | my ($self) = @_; | |||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | #TODO: Model dir must be set outside Treex, via Jdepp itself -> fix this in the future! | ||||||||||
| 35 | 1 | my $model_dir = $self->require_files_from_share( $self->model_dir ); | |||||||||
| 36 | |||||||||||
| 37 | 0 | my $parser = Treex::Tool::Parser::JDEPP->new( model_dir => $model_dir ); | |||||||||
| 38 | 0 | $self->set_parser( $parser ); | |||||||||
| 39 | |||||||||||
| 40 | 0 | $self->SUPER::process_start(); | |||||||||
| 41 | |||||||||||
| 42 | 0 | return; | |||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub parse_chunk { | ||||||||
|
Subroutine
parse_chunk: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 46 | 0 | my ( $self, @a_nodes ) = @_; | |||||||||
| 47 | |||||||||||
| 48 | 0 | my @words = map { $_->form } @a_nodes; | |||||||||
| 49 | 0 | my @tags = map { $_->tag } @a_nodes; | |||||||||
| 50 | |||||||||||
| 51 | 0 | my ( $parents_rf ) = $self->parser->parse_sentence( \@words, \@tags ); | |||||||||
| 52 | |||||||||||
| 53 | 0 | my @roots = (); | |||||||||
| 54 | 0 | foreach my $a_node (@a_nodes) { | |||||||||
| 55 | 0 | my $parent_index = shift @$parents_rf; | |||||||||
| 56 | 0 | ▶ | if ($parent_index) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | my $parent = $a_nodes[ $parent_index - 1 ]; | |||||||||
| 58 | 0 | $a_node->set_parent($parent); | |||||||||
| 59 | } | ||||||||||
| 60 | else { | ||||||||||
| 61 | 0 | push @roots, $a_node; | |||||||||
| 62 | } | ||||||||||
| 63 | } | ||||||||||
| 64 | 0 | return @roots; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 2 | 1; | |||||||||
| 68 | |||||||||||
| 69 | __END__ | ||||||||||