8 use base qw(Root Read Common);
18 $oc->read_file($path);
20 $oc->get_group(1); # Returns information about cluster 1
21 $oc->get_groups; # Returns all the groups
25 This is a module to read OC output.
27 =head1 $oc->read($fh);
29 Reads an OC file from a filehandle.
34 my ( $self, $fh ) = @_;
43 my ( $num, $score, $size ) = split;
46 my (@labels) = map { chomp; $_ } split / /, $nl;
49 $self->add_group( $num, $score, $size, @labels );
50 } elsif (/^UNCLUSTERED ENTITIES$/) {
51 my (@labels) = map { chomp; $_ } <$fh>;
52 $self->add_unclustered(@labels);
57 =head $oc->add_group($number, $score, $size, @labels)
59 Add information about a group.
64 my ( $self, $num, $score, $size, @labels ) = @_;
66 for (qw(num score size)) {
67 croak "No value for $_ passed to add_group" unless eval "defined \$$_";
70 croak "No labels passed to add_group" unless @labels;
72 $self->{ __PACKAGE__ . "score" }{$num} = $score;
73 $self->{ __PACKAGE__ . "size" }{$num} = $size;
74 $self->{ __PACKAGE__ . "labels" }{$num} = [@labels];
77 =head2 $oc->add_unclustered(@labels)
79 Adds those entities that are unclustered.
84 my ( $self, @labels ) = @_;
85 $self->{ __PACKAGE__ . "unclust" } = \@labels;
88 =head2 $oc->get_unclustered
90 Returns those unclustered entities as a list.
96 return @{ $self->{ __PACKAGE__ . "unclust" } } if defined $self->{ __PACKAGE__ . "unclust" };
99 =head2 ($score, $size, @labels) = $oc->get_group($n);
101 Returns information about a particular group. If the group doesn't exist you get a warning message and undef.
106 my ( $self, $num ) = @_;
107 if ( defined $num ) {
108 if ( exists $self->{ __PACKAGE__ . "score" }{$num} ) {
110 $self->{ __PACKAGE__ . "score" }{$num},
111 $self->{ __PACKAGE__ . "size" }{$num},
112 @{ $self->{ __PACKAGE__ . "labels" }{$num} };
114 carp "No such group '$num'";
118 croak "No value passed to get_group";
122 =head1 @info = $oc->get_groups;
124 Returns information about all of the groups. This is an array of arrays, the second array holds group id and then the information returned by the get_group method.
131 map { [ $_, $self->get_group($_) ] } sort keys %{ $self->{ __PACKAGE__ . "score" } };
139 my ( $self, $file ) = @_;
144 my $pid = open3( \*WRT, \*RD, \*ERR, $self->path );
149 my @output = join "\n", split "\n", <RD>;
153 check( $self->path, $? ) or die "OC was naughty";