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.
43 my ($num, $score, $size) = split;
46 my (@labels) = map { chomp; $_ } split / /, $nl;
49 $self->add_group($num, $score, $size, @labels);
51 elsif (/^UNCLUSTERED ENTITIES$/) {
52 my (@labels) = map { chomp; $_ } <$fh>;
53 $self->add_unclustered(@labels);
58 =head $oc->add_group($number, $score, $size, @labels)
60 Add information about a group.
65 my ($self, $num, $score, $size, @labels) = @_;
67 for (qw(num score size)) {
68 croak "No value for $_ passed to add_group" unless eval "defined \$$_"
71 croak "No labels passed to add_group" unless @labels;
73 $self->{__PACKAGE__."score"}{$num} = $score;
74 $self->{__PACKAGE__."size"}{$num} = $size;
75 $self->{__PACKAGE__."labels"}{$num} = [ @labels ];
78 =head2 $oc->add_unclustered(@labels)
80 Adds those entities that are unclustered.
85 my ($self, @labels) = @_;
86 $self->{__PACKAGE__."unclust"} = \@labels;
89 =head2 $oc->get_unclustered
91 Returns those unclustered entities as a list.
97 return @{$self->{__PACKAGE__."unclust"}} if defined $self->{__PACKAGE__."unclust"};
100 =head2 ($score, $size, @labels) = $oc->get_group($n);
102 Returns information about a particular group. If the group doesn't exist you get a warning message and undef.
107 my ($self, $num) = @_;
109 if (exists $self->{__PACKAGE__."score"}{$num}) {
111 $self->{__PACKAGE__."score"}{$num},
112 $self->{__PACKAGE__."size"}{$num},
113 @{ $self->{__PACKAGE__."labels"}{$num} };
116 carp "No such group '$num'";
121 croak "No value passed to get_group";
125 =head1 @info = $oc->get_groups;
127 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.
135 [ $_, $self->get_group($_) ]
136 } sort keys %{ $self->{__PACKAGE__."score"} };
144 my ($self, $file) = @_;
149 my $pid = open3(\*WRT, \*RD, \*ERR, $self->path);
154 my @output = join "\n", split "\n", <RD>;
158 check($self->path, $?) or die "OC was naughty";