AI-Fuzzy

 view release on metacpan or  search on metacpan

lib/AI/Fuzzy/Axis.pm  view on Meta::CPAN

package AI::Fuzzy::Axis;

use AI::Fuzzy::Label;
## Container for Fuzzy Labels #### 

sub new {

    my ($class) = @_;
    my $self = {};

    $self->{labels} = {};

    bless $self, $class;
    return $self;
}

sub addlabel {
    # adds a label for a range of values..
    my ($self, $label, $low, $mid, $high) = @_;

    if ($label->can("name") ) {
	$self->{labels}->{$label->name} = $label;
    } else {
	$self->{labels}->{$label} = new AI::Fuzzy::Label($label, $low, $mid, $high);
    }

    return $self->{labels}->{$label};
}


sub applicability {
    # this function should be called something else..
    # calculates to what degree $label applies to a $value

    my ($self, $value, $label) = @_;
    my $membership = 0;

    return $label->applicability($value) if ($label->can("applicability"));
    return undef unless ( exists $self->{labels}->{$label} );
    return $self->{labels}->{$label}->applicability($value);
}

sub label {
    # returns a label associated with this text
    my ($self, $name) = @_;

    return $self->{labels}->{$name};
}

sub labelvalue {
    # returns a label associated with this value
    my ($self, $value) = @_;
    my $label;
    my %weight;
    my $total_weight = 0;
    my @range = $self->range();


    # first, find out the applicability of each label
    # and weight the labels accordingly.
    foreach $label (@range) {
        my $labelname ;
	my $w;

	if ($label->can("name")) {
	    $labelname = $label->name;
	    $w = $label->applicability($value);
	} else {
	    $labelname = $label;
	    $w = $self->applicability($value, $label);
	}

	next unless $w > 0;



( run in 0.732 second using v1.01-cache-2.11-cpan-6aa56a78535 )