#!/usr/bin/perl # # Yousef Rabah - April 7th, 2004 # people.pm # # Using db.pm, DisplaySpeech.pm, VEPD.pm # # getPid - for testing purposes # Simple function that gets PID number from all users with the same first name # getInfo - for testing purposes # Function that gets ALL info from people using PID and first_name # # -- getFirstChar # Searching by First Name: # Here, were selecing first_name, last_name, phone_num from people where first_name matches # any of the string needed to run through the ADB. # Here were going to use SQLselect from db.pm to connect to ADB and run through SQL statement. # The results getting back will be stored in an array, @rows and getting the status of counter # back. If status is 0, then there is no result back. If status is 1, then there is only one match # and in that case because there is only one result, it will ask whether or not # want to call that name. # If status is more than one, that means that the user might either add another string # or can pic from the list. That all will be done with a couple of options that # the user will see. # -- getLastChar # Searching by Last Name: # Here, were selecing first_name, last_name, phone_num from people where last_name matches # any of the string needed to run through the ADB. # Here were going to use SQLselect from db.pm to connect to ADB and run through SQL statement. # The results getting back will be stored in an array, @rows and getting the status of counter # back. If status is 0, then there is no result back. If status is 1, then there is only one match # and in that case because there is only one result, it will ask whether or not # want to call that name. # If status is more than one, that means that the user might either add another string # or can pic from the list. That all will be done with a couple of options that # the user will see. # -- getPhoneChar # Searching by phone number: # The SQL statemnet of provided match of string will bring back result, put in array # of @rows. # The same functionality happens here. Yet for an enhancement, if the system # can actually decode speech, user would say the numbers and the system would # try to decoded the numbers and through this function, have the option to # search by phone number. # -- getCityChar # Searching by City Name: # Here, were selecing first_name, last_name, phone_num from people where city name matches # any of the string needed to run through the ADB. # Here were going to use SQLselect from db.pm to connect to ADB and run through SQL statement. # The results getting back will be stored in an array, @rows and getting the status of counter # back. If status is 0, then there is no result back. If status is 1, then there is only one match # and in that case because there is only one result, it will ask whether or not # want to call that name. # If status is more than one, that means that the user might either add another string # or can pic from the list. That all will be done with a couple of options that # the user will see. # XXX this function could be added as an enhancement to work through speech. For now, this only # works manually. # -- insert_to_ADB # Insert to ADB: ( for adding users) # First of all, the user would enter ID number. The ID is checked through # ADB, and if it exisits, means that there is a user. If it doesnt, means that # the ID is avaliable. In turn, this is when the uaer can add all the information # needed to provide. # After the user enters the information needed, each value will be stored in # a variable, that in turn would then be used to insert into the ADB this # information. # XXX As an enhancment, the adding of users could be done via speech. # -- view_ADB # Viewing all content of ADB: # It will display all the database to user # so that person would know what is last PID, # and also for the look, would be run as an option to # view current people in ADB ############################################################ package people; require Exporter; @ISA = qw(Exporter); @EXPORT = qw( getPid getInfo getFirstChar getLastChar getPhoneChar getCityChar insert_to_ADB view_ADB ); use strict; use db; use VEPD; use DisplaySpeech; #Function that gets PID number from all users with same first name sub getPid($){ my $first_name = $_[0]; my $sql; my @result; my $result; $sql = "SELECT pid from people WHERE first_name='$first_name'"; my ($status, @rows) = SQLselect($sql); push @result, "RESULTS|$status\n\n"; my $pid; if ($status >= 1) { for (my $i=0; $i < $status; $i++) { $pid = $rows[$i][0]; push @result, "$pid\n"; } } return(@result); } #Function that gets ALL info from people using PID and first_name sub getInfo($$){ my $pid = $_[0]; my $first_name = $_[1]; my $sql; #my $status; #my @rows; my @result; $sql = "SELECT * FROM people WHERE pid='$pid' and first_name='$first_name'"; my ($status, @rows) = SQLselect($sql); push @result, "RESULTS|$status\n\n"; my ($last_name, $phone_num, $city); if ($status >= 1) { for (my $i=0; $i < $status; $i++) { $pid = $rows[$i][0]; $first_name = $rows[$i][1]; $last_name = $rows[$i][2]; $phone_num = $rows[$i][3]; $city = $rows[$i][4]; push @result, "$pid|$first_name|$last_name|$phone_num|$city\n"; } } return(@result); } # Searching by First Name: # Here, were selecing first_name, last_name, phone_num from people where first_name matches # any of the string needed to run through the ADB. # Here were going to use SQLselect from db.pm to connect to ADB and run through SQL statement. # The results getting back will be stored in an array, @rows and getting the status of counter # back. If status is 0, then there is no result back. If status is 1, then there is only one match # and in that case because there is only one result, it will ask whether or not # want to call that name. # If status is more than one, that means that the user might either add another string # or can pic from the list. That all will be done with a couple of options that # the user will see. sub getFirstChar($){ my $name = $_[0]; my @new_result; my $sql; my @result; my $result; my $wav_files_directory = "/usr/local/share/sphinx3/model/lm/an4/wav_files"; my $raw_files_directory = "/usr/local/share/sphinx3/model/lm/an4/raw_files"; my ($a, $b); my $call; # Select what is needed to get back from ADB, with match of whatever string the user spoke # and was decoded. $sql = "SELECT first_name, last_name, phone_num from people where first_name ~ '^$name' "; my ($status, @rows) = SQLselect($sql); # for array result, were putting that Results has status of 0, 1, or more push @result, "RESULTS|$status\n\n"; my ($first_name,$last_name, $phone_num); #If status is 0, then there is no result back. if ($status == 0){ print "\nNo Matching Record of that name found !\n\n"; if ("$wav_files_directory/record*"){ system ("rm $wav_files_directory/record*"); } if ("$raw_files_directory/record*"){ system ("rm $raw_files_directory/record*"); } #main_menu(); } # if status is one, there is one result it will ask user whether or not # there user wants to call the name and number provided back by DB elsif ($status == 1) { for (my $i=0; $i < $status; $i++) { $first_name = $rows[$i][0]; $last_name = $rows[$i][1]; $phone_num = $rows[$i][2]; push @result, "$first_name|$last_name|$phone_num\n"; } print @result; print ": Do you want to call $first_name $last_name? [Y or N]"; $a = ; if ($a =~ /^[Yy]/){ print "Calling $phone_num ... \n\n\n"; sleep(4); main_menu(); } elsif($a =~ /^[Nn]/){ #take back to main file, probably VEPD (to main menu) print "\n"; if ("$wav_files_directory/record*"){ system ("rm $wav_files_directory/record*"); } if ("$raw_files_directory/record*"){ system ("rm $raw_files_directory/record*"); } main_menu(); } } # If status is more than one, that means that the user might either add another string # or can pic from the list. That all will be done with a couple of options that # the user will see. elsif ($status >= 2){ for (my $i=0; $i < $status; $i++) { $first_name = $rows[$i][0]; $last_name = $rows[$i][1]; $phone_num = $rows[$i][2]; $b = $i+1; push @result, "$b $first_name|$last_name|$phone_num\n"; } print @result; print "\n: DO you want to: \n"; print ": (A) Add to string ? \n"; print ": (B) Go back to main menu ?\n"; print ": (#) Which do you want to call [ex. 1]? \n"; print ": Press A, B or a #: "; $call = ; if ($call =~ /^[Aa]/){ print "Adding string ...\n"; #displaySpeech(); display_speech(); } elsif ($call =~ /^[bB]/){ # Going to main menu, need to make sure that there #is no record of wave or raw files if ("$wav_files_directory/record*"){ system ("rm $wav_files_directory/record*"); } if ("$raw_files_directory/record*"){ system ("rm $raw_files_directory/record*"); } #take back to main file, probably VEPD (to main menu) print "\n"; main_menu(); } if ($call =~ /[0-9]/){ my $c = $call -1; # This only takes the row that calls the phone number of # the correct person. #print "\nCalling $rows[$c][2]\n"; # If you want to print all result, which includes First, #Last name + Phone number print "\n Calling @result[$call] \n\n\n"; #gives time for system to call. sleep(4); main_menu(); } else { exit(0); } } } # Searching by Last Name: # Here, were selecing first_name, last_name, phone_num from people where last_name matches # any of the string needed to run through the ADB. # Here were going to use SQLselect from db.pm to connect to ADB and run through SQL statement. # The results getting back will be stored in an array, @rows and getting the status of counter # back. If status is 0, then there is no result back. If status is 1, then there is only one match # and in that case because there is only one result, it will ask whether or not # want to call that name. # If status is more than one, that means that the user might either add another string # or can pic from the list. That all will be done with a couple of options that # the user will see. sub getLastChar($){ my $name = $_[0]; my $wav_files_directory = "/usr/local/share/sphinx3/model/lm/an4/wav_files"; my $raw_files_directory = "/usr/local/share/sphinx3/model/lm/an4/raw_files"; my $sql; my @result; my $result; my $call; $sql = "SELECT last_name,first_name, phone_num from people where last_name ~ '^$name' "; my ($status, @rows) = SQLselect($sql); push @result, "RESULTS|$status\n\n"; my ($first_name,$last_name, $phone_num); if ($status == 1) { for (my $i=0; $i < $status; $i++) { $last_name = $rows[$i][1]; $first_name = $rows[$i][0]; $phone_num = $rows[$i][2]; push @result, "$last_name|$first_name|$phone_num\n"; } print @result; print "\n:Do you want to call $last_name, $first_name? [Y or N]"; $a = ; if ($a =~ /^[Yy]/){ print "\nCalling $phone_num ... \n\n\n"; sleep(4); } elsif($a =~ /^[Nn]/){ #take back to main file, probably VEPD (to main menu) print "\n"; main_menu(); } } #Result option if more than one return elsif ($status >= 2){ for (my $i=0; $i < $status; $i++) { $first_name = $rows[$i][0]; $last_name = $rows[$i][1]; $phone_num = $rows[$i][2]; $b = $i+1; push @result, "($b) $first_name|$last_name|$phone_num\n"; } print @result; print "\n: DO you want to: \n"; print ": (A) Add to string ? \n"; print ": (B) Go back to main menu ?\n"; print ": (#) Which do you want to call [ex. 1]? \n"; print ": Press A, B or a #: "; $call = ; if ($call =~ /^[Aa]/){ print "Adding string ...\n"; displaySpeech(); #display_speech(); } elsif ($call =~ /^[bB]/){ # Going to main menu, need to make sure that there #is no record of wave or raw files if ("$wav_files_directory/record*"){ system ("rm $wav_files_directory/record*"); } if ("$raw_files_directory/record*"){ system ("rm $raw_files_directory/record*"); } #take back to main file, probably VEPD (to main menu) print "\n"; main_menu(); } if ($call =~ /[0-9]/){ my $c = $call -1; # This only takes the row that calls the phone number of # the correct person. #print "\nCalling $rows[$c][2]\n"; # If you want to print all result, which includes First, #Last name + Phone number print "\n Calling @result[$call] \n\n\n"; #gives time for system to call. sleep(4); main_menu(); } else { exit(0); } } } # Searching by phone number: # The SQL statemnet of provided match of string will bring back result, put in array # of @rows. # The same functionality happens here. Yet for an enhancement, if the system # can actually decode speech, user would say the numbers and the system would # try to decoded the numbers and through this function, have the option to # search by phone number. sub getPhoneChar($){ my $name = $_[0]; my $wav_files_directory = "/usr/local/share/sphinx3/model/lm/an4/wav_files"; my $raw_files_directory = "/usr/local/share/sphinx3/model/lm/an4/raw_files"; my $sql; my @result; my $result; my ($a, $b); my $call; $sql = "SELECT last_name,first_name, phone_num from people where phone_num ~ '^$name' "; my ($status, @rows) = SQLselect($sql); push @result, "RESULTS|$status\n\n"; my ($first_name,$last_name, $phone_num); if ($status == 0){ print "\nNo Matching Record of that name found !\n\n"; } # Result for only one name back elsif ($status == 1) { for (my $i=0; $i < $status; $i++) { $first_name = $rows[$i][0]; $last_name = $rows[$i][1]; $phone_num = $rows[$i][2]; push @result, "$first_name|$last_name|$phone_num\n"; } print @result; print ": Do you want to call $first_name $last_name? [Y or N]"; $a = ; if ($a =~ /^[Yy]/){ print "\nCalling $phone_num ... \n\n\n"; sleep(4); } elsif($a =~ /^[Nn]/){ #take back to main file, probably VEPD (to main menu) print "\n"; main_menu(); } } #Result option if more than one return elsif ($status >= 2){ for (my $i=0; $i < $status; $i++) { $first_name = $rows[$i][0]; $last_name = $rows[$i][1]; $phone_num = $rows[$i][2]; $b = $i+1; push @result, "($b) $first_name|$last_name|$phone_num\n"; } print @result; print "\n: DO you want to: \n"; print ": (A) Add to string ? \n"; print ": (B) Go back to main menu ?\n"; print ": (#) Which do you want to call [ex. 1]? \n"; print ": Press A, B or a #: "; $call = ; if ($call =~ /^[Aa]/){ display_speech(); } elsif ($call =~ /^[bB]/){ # Going to main menu, need to make sure that there #is no record of wave or raw files if ("$wav_files_directory/record*"){ system ("rm $wav_files_directory/record*"); } if ("$raw_files_directory/record*"){ system ("rm $raw_files_directory/record*"); } #take back to main file, probably VEPD (to main menu) print "\n"; main_menu(); } if ($call =~ /[0-9]/){ my $c = $call -1; # This only takes the row that calls the phone number of # the correct person. #print "\nCalling $rows[$c][2]\n"; # If you want to print all result, which includes First, #Last name + Phone number print "\n Calling @result[$call] \n\n\n"; #gives time for system to call. sleep(4); main_menu(); } else { exit(0); } } } # Searching by City Name: # Here, were selecing first_name, last_name, phone_num from people where city name matches # any of the string needed to run through the ADB. # Here were going to use SQLselect from db.pm to connect to ADB and run through SQL statement. # The results getting back will be stored in an array, @rows and getting the status of counter # back. If status is 0, then there is no result back. If status is 1, then there is only one match # and in that case because there is only one result, it will ask whether or not # want to call that name. # If status is more than one, that means that the user might either add another string # or can pic from the list. That all will be done with a couple of options that # the user will see. # XXX this function could be added as an enhancement to work through speech. For now, this only # works manually. sub getCityChar($){ my $wav_files_directory = "/usr/local/share/sphinx3/model/lm/an4/wav_files"; my $raw_files_directory = "/usr/local/share/sphinx3/model/lm/an4/raw_files"; my $name = $_[0]; my $sql; my @result; my $result; my ($a, $b); my $call; $sql = "SELECT last_name,first_name, phone_num from people where city ~ '^$name' "; my ($status, @rows) = SQLselect($sql); push @result, "RESULTS|$status\n\n"; my ($first_name,$last_name, $phone_num); if ($status == 0){ print "\nNo Matching Record of that name found !\n\n"; } # Result for only one name back elsif ($status == 1) { for (my $i=0; $i < $status; $i++) { $first_name = $rows[$i][0]; $last_name = $rows[$i][1]; $phone_num = $rows[$i][2]; push @result, "$first_name|$last_name|$phone_num\n"; } print @result; print ": Do you want to call $first_name $last_name? [Y or N]"; $a = ; if ($a =~ /^[Yy]/){ print "Calling $phone_num ... \n\n\n"; sleep(4); } elsif($a =~ /^[Nn]/){ #take back to main file, probably VEPD (to main menu) print "\n"; main_menu(); } } #Result option if more than one return elsif ($status >= 2){ for (my $i=0; $i < $status; $i++) { $first_name = $rows[$i][0]; $last_name = $rows[$i][1]; $phone_num = $rows[$i][2]; $b = $i+1; push @result, "($b) $first_name|$last_name|$phone_num\n"; } print @result; print "\n: Do you want to: \n"; print ": (A) Add to string ? \n"; print ": (B) Go back to main menu ?\n"; print ": (#) Which do you want to call [ex. 1]? \n"; print ": Press A, B or a #: "; $call = ; if ($call =~ /^[Aa]/){ display_speech(); } elsif ($call =~ /^[bB]/){ # Going to main menu, need to make sure that there #is no record of wave or raw files if ("$wav_files_directory/record*"){ system ("rm $wav_files_directory/record*"); } if ("$raw_files_directory/record*"){ system ("rm $raw_files_directory/record*"); } #take back to main file, probably VEPD (to main menu) print "\n"; main_menu(); } if ($call =~ /[0-9]/){ my $c = $call -1; # This only takes the row that calls the phone number of # the correct person. #print "\nCalling $rows[$c][2]\n"; # If you want to print all result, which includes First, #Last name + Phone number print "\n Calling @result[$call] \n\n\n"; #gives time for system to call. sleep(4); main_menu(); } else { exit(0); } } } # Insert to ADB: ( for adding users) # First of all, the user would enter ID number. The ID is checked through # ADB, and if it exisits, means that there is a user. If it doesnt, means that # the ID is avaliable. In turn, this is when the uaer can add all the information # needed to provide. # After the user enters the information needed, each value will be stored in # a variable, that in turn would then be used to insert into the ADB this # information. # XXX As an enhancment, the adding of users could be done via speech. sub insert_to_ADB($){ #XXx need to look at how to put the personal ID # maybe when user puts a number, to check whether its there or not my $pid = $_[0]; my ($sql_select, $sql_insert); my (@s_result, @i_result, @result); my ($s_result, $i_result, $f_name, $l_name, $p_name, $city); $sql_select = "SELECT pid from people where pid = $pid"; my ($s_status, @s_rows) = SQLselect($sql_select); push @s_result, "$s_status\n\n"; if ($s_status == 0){ print "\n: Your People ID is avaliable: $pid\n"; print "\n: Enter First name: "; $f_name = ; chomp($f_name); $f_name =~ tr/a-z/A-Z/; print "\n: Enter Last name: "; $l_name = ; chomp($l_name); $l_name =~ tr/a-z/A-Z/; print "\n: Enter Phone number (usage: 000-000-0000): "; $p_name = ; chomp($p_name); print "\n: Enter city: "; $city = ; chomp($city); $city =~ tr/a-z/A-Z/; print "\n"; print ": This info will be inserted to ADB:\n|$pid\n|$f_name\n|$l_name\n|$p_name\n|$city\n"; $sql_insert = "INSERT INTO people (pid, first_name, last_name, phone_num ,city) VALUES ($pid, '$f_name', '$l_name', '$p_name', '$city')"; my $i_status = SQLinsert($sql_insert); } elsif ($s_status == 1){ for (my $i=0; $i < $s_status; $i++) { $pid = $s_rows[$i][0]; push @result, "\n: The PID $pid has already been taken.\n"; } print @result; add_user(); } } # Viewing all content of ADB: # It will display all the database to user # so that person would know what is last PID, # and also for the look, would be run as an option to # view current people in ADB sub view_ADB(){ my $sql; my ($pid, $first_name,$last_name, $phone_num, $city); my @result; $sql = "SELECT pid, first_name, last_name, phone_num, city from people"; my ($status, @rows) = SQLselect($sql); if ($status >= 1){ for (my $i=0; $i < $status; $i++) { $pid = $rows[$i][0]; $first_name = $rows[$i][1]; $last_name = $rows[$i][2]; $phone_num = $rows[$i][3]; $city = $rows[$i][4]; push @result, "\n: $pid | $first_name | $last_name | $phone_num | $city\n"; } print @result; } }