| 1 | package Lingua::FeatureMatrix::FeatureClass; | ||
| 2 | |||
| 3 | use 5.006; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | our $VERSION = '0.01'; | ||
| 7 | use Carp; | ||
| 8 | ################################################################## | ||
| 9 | use Class::MethodMaker | ||
| 10 | new_with_init => 'new', | ||
| 11 | get_set => 'name', | ||
| 12 | hash => 'features'; | ||
| 13 | ################################################################## | ||
| 14 | sub init { | ||
| 15 | my $self = shift; | ||
| 16 | my %args = @_; | ||
| 17 | |||
| 18 | $self->name( $args{name} ); | ||
| 19 | if (not defined $self->name()) { | ||
| 20 | croak "Could not initialize ", ref($self), ":", | ||
| 21 | " missing 'name' parameter"; | ||
| 22 | } | ||
| 23 | |||
| 24 | if (not defined $args{features}) { | ||
| 25 | croak "can't initialize ", ref($self), ":", | ||
| 26 | " missing 'features' parameter!"; | ||
| 27 | } | ||
| 28 | if (ref($args{features} ne 'HASH') ) { | ||
| 29 | croak "'features' parameter value not a hashref"; | ||
| 30 | } | ||
| 31 | $self->features(%{$args{features}}); | ||
| 32 | } | ||
| 33 | ################################################################## | ||
| 34 | sub matches { | ||
| 35 | my $self = shift; | ||
| 36 | my $eme = shift; | ||
| 37 | |||
| 38 | foreach my $feature ($self->features_keys) { | ||
| 39 | if (not $eme->isSpecified($feature)) { | ||
| 40 | warn "feature $feature not specified for " . $eme->name; | ||
| 41 | return 0; | ||
| 42 | } | ||
| 43 | if (not defined $eme->$feature) { | ||
| 44 | return 0; # underspecified -- must be okay | ||
| 45 | } | ||
| 46 | if ($eme->$feature ne $self->features($feature)) { | ||
| 47 | return 0; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | return 1; | ||
| 51 | } | ||
| 52 | ################################################################## | ||
| 53 | sub dumpToText { | ||
| 54 | my $self = shift; | ||
| 55 | my $fh = shift; | ||
| 56 | } | ||
| 57 | sub dumpToC { | ||
| 58 | my $self = shift; | ||
| 59 | my $fh = shift; | ||
| 60 | } | ||
| 61 | sub dumpToBinary { | ||
| 62 | my $self = shift; | ||
| 63 | my $fh = shift; | ||
| 64 | } | ||
| 65 | ################################################################## | ||
| 66 | 1; | ||
| 67 | __END__ |