File: LevelPrediction.pm

package info (click to toggle)
rtax 0.984-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 316 kB
  • sloc: perl: 1,123; sh: 203; makefile: 2
file content (71 lines) | stat: -rw-r--r-- 1,708 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package LevelPrediction;

use strict;
use warnings;

sub new {
	my ($this) = @_;
    my $class = ref($this) || $this;
    my $self = {};

    bless $self, $class;

    return $self;
}

for my $field (
    qw(label numChildren count localMinProportion localMaxProportion globalMinProportion globalMaxProportion alternateLocalProportion alternateGlobalProportion)
    )
{
    my $slot = __PACKAGE__ . "::$field";
    no strict "refs";    # So symbolic ref to typeglob works.

    *$field = sub {
        my $self = shift;
        $self->{$slot} = shift if @_;
        return $self->{$slot};
    };
}

sub print_tab_delimited {
    my $self = shift;
    for my $field (
        qw(label numChildren count localMinProportion localMaxProportion globalMinProportion globalMaxProportion alternateLocalProportion alternateGlobalProportion)
        )
    {
        my $slot = __PACKAGE__ . "::$field";
        print "\t" . ( $self->{$slot} ? $self->{$slot} : "undef" );
    }
}

sub toString {
    my $self = shift;
	my $result = "";
	
	for my $field (
        qw(label)
        )
    {
        my $slot = __PACKAGE__ . "::$field";
        $result .=  ( $self->{$slot} ? $self->{$slot} : "" );
    }
	
	for my $field (
        qw(numChildren count)
        )
    {
        my $slot = __PACKAGE__ . "::$field";
        $result .= ";" . ( $self->{$slot} ? $self->{$slot} : "" );
    }
	
    for my $fieldb (
        qw(localMinProportion localMaxProportion globalMinProportion globalMaxProportion alternateLocalProportion alternateGlobalProportion)
        )
    {
        my $slot = __PACKAGE__ . "::$fieldb";
        $result .=  $self->{$slot} ? (sprintf ";%.2f", $self->{$slot}) : ";" ;
    }
	return $result;
}

1;