in reply to Re^6: Best way to store/access large dataset?
in thread Best way to store/access large dataset?
Hi Speed_Freak,
This line was not correct, sorry for that: $subres{ID} = $attrs->[0] ; and should have been $subres{ID} = $attrs->[$j][0] ;. But it doesn't matter so much because that line is changed again in the next code.
I will give you some suggestions commented in the code how to require the results you described, but you'll have do some programming there yourself:
use strict ; use warnings ; use Data::Dumper ; open my $dataIn1, "<", "Attributes_ID.txt" or die "NO ID FILE: $!" ; open my $dataIn2, "<", "Attributes.txt" or die "NO ATTR FILE: $!" ; my $data = () ; my $attrs = () ; sub getdata { my ( $fileName, $type ) = split /\t/, $_[0] ; push @{$data}, $type unless !defined $fileName ; } sub getattrs { my @attrs = split /\t/, $_[0] ; push @{$attrs}, \@attrs unless !defined $attrs[0] ; } sub calcPercentages { # INPUT: Hash reference # Determine the total amount of attributes # Walk through each category: Circle, Triangle, ... # Take the hit count divided by the total amount of attributes (mu +ltiplied by 100?) # For each category add something to the hash to store the percent +age # e.g. CircleChance, TriangleChance, .... # askQuestions could potentially be called here } sub askQuestions { # INPUT: Hash reference # my $h = ... # Question 1: Does this attribute occur in Circle more than 50% of + the time, and less than 10% of the time in Triangle # if ( $h->{ CircleChance } > 50 && $h->{ TriangleChance } < 10 ) +{ # Do something here. # E.g. Store another result $h # } } while( <$dataIn1> ) { chomp ; getdata( $_ ) ; } while( <$dataIn2> ) { chomp ; getattrs( $_ ) ; } my @result; for( my $j = 0 ; $j < @{$attrs} ; ++$j ) { my %subres ; my $id = $attrs->[$j][0] ; @subres{@{$data}} = ( 0 ) x @{$attrs->[0]} ; for( my $i = 1 ; $i < @{$attrs->[$j]} ; ++$i ) { if ( $attrs->[$j][$i] == 1 ) { ++$subres{ $data->[$i-1]} ; } } ; # You could potentially start calculating hit count percentages pe +r category here: calcPercentages( \%subres ) ; push @result, { $id => \%subres } ; } print Dumper(\@result) ;
The results now look like this, but more work is needed to calculate the hit count percentages (as indicated in the code above):
$VAR1 = [ { '1' => { 'Circle' => 4, 'Rectangle' => 4, 'Square' => 4, 'Triangle' => 0 } }, { '2' => { 'Circle' => 4, 'Square' => 4, 'Rectangle' => 0, 'Triangle' => 0 } }, ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Best way to store/access large dataset?
by Speed_Freak (Sexton) on Jun 27, 2018 at 14:10 UTC | |
by poj (Abbot) on Jun 28, 2018 at 14:32 UTC | |
by Speed_Freak (Sexton) on Jun 28, 2018 at 19:53 UTC | |
by Speed_Freak (Sexton) on Aug 02, 2018 at 14:57 UTC | |
by Speed_Freak (Sexton) on Jun 27, 2018 at 16:56 UTC |