| 1 | package Alvis::NLPPlatform::MyReceiver; | ||
| 2 | #use Data::Dumper; | ||
| 3 | |||
| 4 | |||
| 5 | 4 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 4 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 0 | ▶ | use XML::Parser::PerlSAX; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | # use utf8; | ||
| 10 | |||
| 11 | use Alvis::NLPPlatform::XMLEntities; | ||
| 12 | |||
| 13 | use Data::Dumper; | ||
| 14 | |||
| 15 | our $VERSION=$Alvis::NLPPlatform::VERSION; | ||
| 16 | |||
| 17 | ### | ||
| 18 | ### Package | ||
| 19 | ### | ||
| 20 | |||
| 21 | |||
| 22 | my $data; | ||
| 23 | |||
| 24 | sub start_document { | ||
| 25 | # print Dumper($tab_object); | ||
| 26 | } | ||
| 27 | |||
| 28 | sub end_document { | ||
| 29 | # print Dumper($tab_object); | ||
| 30 | } | ||
| 31 | |||
| 32 | # | ||
| 33 | # init object | ||
| 34 | # | ||
| 35 | |||
| 36 | sub new { | ||
| 37 | my $type = shift; | ||
| 38 | |||
| 39 | my @stack_elements = (); | ||
| 40 | my $tab_objet = {}; | ||
| 41 | my $is_in_ann; | ||
| 42 | # my $data; | ||
| 43 | return bless {"tab_object" => {} , "stack_elements" => \@stack_elements, "is_in_ann" => $is_in_ann, "counter_id" => 0 } , $type; | ||
| 44 | } | ||
| 45 | |||
| 46 | # | ||
| 47 | # process <..> | ||
| 48 | # | ||
| 49 | |||
| 50 | |||
| 51 | sub start_element { | ||
| 52 | my ($self,$properties) = @_; | ||
| 53 | |||
| 54 | if ($self->{"is_in_ann"}) { | ||
| 55 | if ($self->is_empty()) { # new element | ||
| 56 | my $elem = {}; | ||
| 57 | push(@{$self->{"stack_elements"}},$elem); | ||
| 58 | $elem->{'kind'} = 'simple'; | ||
| 59 | } else { | ||
| 60 | my $father = $self->top_stack(); | ||
| 61 | my $elem; | ||
| 62 | if ($properties->{'Name'} =~ /^list/) { # detects that it is a list | ||
| 63 | $elem = {}; # hashtable par défaut | ||
| 64 | $elem->{'kind'} = 'list'; | ||
| 65 | $elem->{'values'} = []; # tableau | ||
| 66 | } else { | ||
| 67 | $elem = {}; # hashtable par défaut | ||
| 68 | $elem->{'kind'} = 'simple'; | ||
| 69 | } | ||
| 70 | if ($father->{'kind'} eq 'list') { | ||
| 71 | my $tab = $father->{'values'}; | ||
| 72 | } else { # complex or simple | ||
| 73 | $father->{'kind'} = 'complex'; | ||
| 74 | $father->{$properties->{'Name'}} = $elem; | ||
| 75 | } | ||
| 76 | $elem->{'datatype'} = $properties->{'Name'}; | ||
| 77 | push(@{$self->{"stack_elements"}},$elem); | ||
| 78 | } | ||
| 79 | } else { | ||
| 80 | $self->{"is_in_ann"} = $properties->{'Name'} eq 'linguisticAnalysis'; | ||
| 81 | |||
| 82 | } | ||
| 83 | $data=''; | ||
| 84 | } | ||
| 85 | |||
| 86 | sub end_element { | ||
| 87 | my ($self,$properties) = @_; | ||
| 88 | my $field; | ||
| 89 | my $father; | ||
| 90 | if ($self->{"is_in_ann"}) { | ||
| 91 | $self->{"is_in_ann"} = $properties->{'Name'} ne 'linguisticAnalysis'; | ||
| 92 | if ($self->{"is_in_ann"}) { | ||
| 93 | my $size=$#{$self->{"stack_elements"}}; | ||
| 94 | my $elem = $self->top_stack(); | ||
| 95 | if ($size >= 1) { | ||
| 96 | if ($properties->{'Name'} eq "named_entity") { | ||
| 97 | if (!exists($elem->{'id'})) { | ||
| 98 | my $ftab = $elem->{'values'}; | ||
| 99 | push (@$ftab, "named_entity" . $self->{"counter_id"}); | ||
| 100 | $elem->{'id'} = "named_entity" . $self->{"counter_id"}; | ||
| 101 | $field = 'id'; | ||
| 102 | $data = "semantic_unit" . $self->{"counter_id"}; | ||
| 103 | $self->{"counter_id"}++; | ||
| 104 | } else { | ||
| 105 | $field = $elem->{'datatype'}; | ||
| 106 | } | ||
| 107 | $father = {'named_entity'=> $elem, 'datatype' => 'semantic_unit'}; | ||
| 108 | } else { | ||
| 109 | $field = $elem->{'datatype'}; | ||
| 110 | $father = $self->snd_stack(); | ||
| 111 | if ((exists $father->{'datatype'}) && ($father->{'datatype'} eq "named_entity") && ($field eq "id")) { | ||
| 112 | $father->{'id'} = $data; | ||
| 113 | $father = {'named_entity'=> $father, 'datatype' => 'semantic_unit'}; | ||
| 114 | $elem->{'kind'} = 'complex'; | ||
| 115 | $data =~ /([0-9]+)$/; | ||
| 116 | $data = "semantic_unit$1"; | ||
| 117 | |||
| 118 | } | ||
| 119 | } | ||
| 120 | |||
| 121 | if ((exists $father->{'kind'}) && ($father->{'kind'} eq 'list')) { | ||
| 122 | my $tab = $father->{'values'}; | ||
| 123 | if ((exists $elem->{'kind'}) && ($elem->{'kind'} eq 'simple')) { | ||
| 124 | push(@$tab,$data); | ||
| 125 | } else { | ||
| 126 | push(@$tab,$elem); | ||
| 127 | } | ||
| 128 | } else { | ||
| 129 | if ((exists $elem->{'kind'}) && ($elem->{'kind'} eq 'simple')) { | ||
| 130 | $father->{$field} = $data; # replace hashtable that has been created by default | ||
| 131 | } | ||
| 132 | } | ||
| 133 | if ($field eq 'id') { | ||
| 134 | $self->{"tab_object"}->{$data} = $father; | ||
| 135 | #print Dumper($tab_object); | ||
| 136 | } | ||
| 137 | if ($elem->{'kind'} eq 'list') { | ||
| 138 | # replace : list-xxx=>{'value'=>[...]} | ||
| 139 | # by : list-xxx=>[...] | ||
| 140 | $father->{$elem->{'datatype'}} = $elem->{'values'}; | ||
| 141 | } | ||
| 142 | } | ||
| 143 | delete($elem->{'kind'}); # kind is only used by process | ||
| 144 | #delete($elem->{'datatype'}); # optionnal | ||
| 145 | pop(@{$self->{"stack_elements"}}); | ||
| 146 | } | ||
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 | # Function "characters" corrected by Julien Deriviere | ||
| 151 | # (September 11th, 2004) | ||
| 152 | |||
| 153 | sub characters { | ||
| 154 | my ($self,$properties) = @_; | ||
| 155 | # $data = $properties->{'Data'}; | ||
| 156 | $data = $data.$properties->{'Data'}; # CORRECTION - Julien | ||
| 157 | } | ||
| 158 | |||
| 159 | sub comment { | ||
| 160 | |||
| 161 | } | ||
| 162 | |||
| 163 | sub processing_instruction { | ||
| 164 | } | ||
| 165 | |||
| 166 | # Function "entity_reference" corrected by Julien | ||
| 167 | # (September 14th, 2004) | ||
| 168 | |||
| 169 | sub entity_reference { | ||
| 170 | my($self,$event)=@_; | ||
| 171 | # Name et Value | ||
| 172 | # traduction de l'entité | ||
| 173 | my $entity={}; | ||
| 174 | my $par=$event->{Parameter}?'%':'&'; | ||
| 175 | $entity->{'Data'}=$par.$event->{Name}.";"; | ||
| 176 | |||
| 177 | $self->characters($entity); | ||
| 178 | } | ||
| 179 | |||
| 180 | sub top_stack { | ||
| 181 | my ($self) = @_; | ||
| 182 | return $self->{"stack_elements"}->[-1]; | ||
| 183 | } | ||
| 184 | |||
| 185 | sub snd_stack { | ||
| 186 | my ($self) = @_; | ||
| 187 | return $self->{"stack_elements"}->[-2]; | ||
| 188 | } | ||
| 189 | |||
| 190 | sub is_empty { | ||
| 191 | my ($self) = @_; | ||
| 192 | return $#{$self->{"stack_elements"}} == -1; | ||
| 193 | } | ||
| 194 | |||
| 195 | |||
| 196 | 1; | ||
| 197 | |||
| 198 | __END__ | ||