| 1 | package Lingua::EN::Semtags::LangUnit; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | # POS - part of speech tag (Lingua::EN::Tagger style) | ||
| 6 | # POSWN - part of speech tag (WordNet style) | ||
| 7 | use constant POS2POSWN => { | ||
| 8 | NN => 'n', # Noun | ||
| 9 | VB => 'v', # Verb | ||
| 10 | JJ => 'a', # Adjective | ||
| 11 | RB => 'r' # Adverb | ||
| 12 | }; | ||
| 13 | use constant TRUE => 1; | ||
| 14 | use constant FALSE => 0; | ||
| 15 | |||
| 16 | our $VERSION = '0.01'; | ||
| 17 | |||
| 18 | #============================================================ | ||
| 19 | sub new { | ||
| 20 | #============================================================ | ||
| 21 | my ($invocant, %args) = @_; | ||
| 22 | my $self = bless ({}, ref $invocant || $invocant); | ||
| 23 | $self->_init(%args); | ||
| 24 | return $self; | ||
| 25 | } | ||
| 26 | |||
| 27 | #============================================================ | ||
| 28 | sub _init { | ||
| 29 | #============================================================ | ||
| 30 | my ($self, %args) = @_; | ||
| 31 | |||
| 32 | # Initialize attributes | ||
| 33 | $self->{token} = undef; | ||
| 34 | $self->{is_word} = FALSE; | ||
| 35 | $self->{is_phrase} = FALSE; | ||
| 36 | $self->{pos} = undef; | ||
| 37 | $self->{sense} = undef; | ||
| 38 | $self->{isas} = []; | ||
| 39 | |||
| 40 | # Set the args that came from the constructor | ||
| 41 | foreach my $arg (sort keys %args) { | ||
| 42 | die "Unknown argument: $arg!" unless exists $self->{$arg}; | ||
| 43 | $self->{$arg} = $args{$arg}; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | #============================================================ | ||
| 48 | sub token { $_[0]->{token}; } | ||
| 49 | sub is_word { $_[0]->{is_word}; } | ||
| 50 | sub is_phrase { $_[0]->{is_phrase}; } | ||
| 51 | sub pos { $_[0]->{pos}; } | ||
| 52 | sub sense { defined $_[1] ? $_[0]->{sense} = $_[1] : $_[0]->{sense}; } | ||
| 53 | sub isas { @{$_[0]->{isas}}; } | ||
| 54 | sub add_isa { push @{$_[0]->{isas}}, $_[1]; } | ||
| 55 | sub poswn { $_[0]->pos =~ /^(\w\w)/ and exists POS2POSWN->{$1} ? POS2POSWN->{$1} : undef; } | ||
| 56 | #============================================================ | ||
| 57 | |||
| 58 | TRUE; | ||
| 59 | |||
| 60 | __END__ |