in reply to minimal response program code problem
This may not be exactly what you are looking for (I didn't account for words in brackets...what ever that meant); but it should clarify how things should run. This version will count the number of times a male or female said the word, and count the total times the word was uttered. You could make your %goodwords a hash or hash (HoH) and have a separate count for each word for male and female. Like:
%Goodwords =( 'well' =>{ 'm' =>0, 'f' => 0, }, ..... .... );
But look at this to see how to make it run:
#!/usr/bin/perl use warnings; use strict; my %minresgen; my %speakersex; my $speakerID; my $langline; my $male = 0; my $female = 0; my %Goodwords = ("mhm" => 0, "right" => 0, "well" => 0, "yeah" => 0, "sure" => 0, "good" => 0, "ah" => 0, "okay" => 0, "yep" => 0, "hm" => 0, "definitely" => 0, "alright" => 0, "'m'm" => 0, "oh" => 0, "my" => 0, "god" => 0, "wow" => 0, "uhuh" => 0, "exactly" => 0, "yup" => 0, "mkay" => 0, "i see" => 0, "ooh" => 0, "cool" => 0, "uh" => 0, "fine" => 0, "true" => 0, "hm'm" => 0, "hmm" => 0, "yes" => 0, "absolutely" => 0, "great" => 0, "um" => 0, "so" => 0, "mm" => 0, "weird" => 0, "ye-" => 0, "i mean" => 0, "i know" => 0, "i think so" => 0, "huh" => 0, "yay" => 0, "maybe" => 0, "eh" => 0, "obviously" => 0, "correct" => 0, "awesome" => 0, "really" => 0, "interesting" => 0,); my @words = keys %Goodwords; while(<DATA>){ $langline = 1; #reset for each line # this detects a speaker-id-line and adds the id if(/<strong>(S[\w]+)<\/strong>:.*Gender:\s+(Male|Female)/i){ $speakerID = $1; $speakersex{$1}=$2; # print $1," ",$2,"\n"; $langline = 0; # don't process these lines for keywords $minresgen{$speakersex{$speakerID}}++; # print $minresgen{$speakersex{$speakerID}},"\n"; } # this detects a speaker(with id) line and process the keywords if($langline){ #print "langline\n"; $_=~ /.*(S[\w]+):(.*)/i; my $minres = $2; $speakerID = $1; $minres =~ s/<.*?>//g; $minres = lc($minres); while($minres =~ /(\w+)/g) { my $word = $1; if( grep{qr/$word/} @words ){ if( $speakersex{$speakerID} =~ /Male/i ){ $male++; $Goodwords{$word}++; } if( $speakersex{$speakerID} =~ /Female/i ){ $female++; $Goodwords{$word}++; } } } } } #Report: print "Male: $male\n"; print "Female: $female\n\n"; foreach my $key(keys %Goodwords){ print "$key -> $Goodwords{$key}\n"; } __DATA__ <strong>S1</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Senior Undergraduate; Gender: Male; Age: 17-23 +; Restriction: None<br> <strong>S2</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Researcher; Gender: Male; Age: 31-50; Restrict +ion: Cite<br> <strong>S3</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Junior Undergraduate; Gender: Female; Age: 17- +23; Restriction: None<br> <strong>S4</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Senior Undergraduate; Gender: Female; Age: 17- +23; Restriction: None<br> <strong>S5</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Junior Undergraduate; Gender: Female; Age: 17- +23; Restriction: None<br> <strong>SS</strong>: Native-Speaker Status: Native speaker, American E +nglish; Academic Role: Unknown; Gender: Male; Age: Unknown; Restricti +on: None<br> <p><b>S1: </b> it was presented to them by Chuck D and Public Enemy. +<font color="#ff6600"><b> [S2: </b> mhm <b> ] </b></font> and the re +st of th- Public Enemy and you know and and Chuck D's f- publicly get +s up and says you know they were with us from the beginning and, <fo +nt color="#ff6600"><b> [S2: </b> <font color="#3333ff"> mhm </font> +<b> ] </b></font> <font color="#3333ff"> all that </font> now wheth- +whether or not you know that he was reading a TelePrompTer, <font co +lor="#ff6600"><b> [S2: </b> mhm <b> ] </b></font> or or not i i thin +k is uh </p> <p><b>S2: </b> or if he was trying to make nice because of the fact th +at Public Enemy hasn't sold records lately, <font color="#ff6600"><b +> [S1: </b> right <b> ] </b></font> and he doesn't wanna look like s +ome kinda old sourpuss </p>
|
|---|