From 010020d4a48c722d12b00cade0295c7f7766da35 Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Tue, 17 Oct 2017 19:44:46 +0100 Subject: prettify and comment process.pl --- process.pl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/process.pl b/process.pl index fb2bb60..55e7988 100755 --- a/process.pl +++ b/process.pl @@ -6,12 +6,16 @@ use JSON::MaybeXS; use File::Slurp; use Data::Dumper; -our $found; +my $found; my $json_input = read_file( "./jaroutput.txt" ) ; $json_input =~ s/.+//; + +# Quit if there is not text rurned from google api if($json_input eq "\n"){ system "./tts.sh 'Excuse me?'; exit;";} + my $data_structure = decode_json($json_input); +# Unpack the JSON my %data=%{$data_structure}; my $in=$data{'result'}; my @data2=@{$in}; @@ -21,16 +25,20 @@ my @data3=@{$in2}; my %transcript; my $i=0; -foreach(@data3){ -my %temp=%{$data3[$i]}; -if(!$found){ - check($temp{transcript}); #magic line -} -$i++; +# For each result check regex until a match is found +foreach(@data3){ + my %temp=%{$data3[$i]}; + + if(!$found){ + check($temp{transcript}); #magic line + } + + $i++; } +# If no match is found ask Wolfram alpha for help if(!$found){my %temp=%{$data3[0]}; $temp{transcript}=~s/\s/+/g; $temp{transcript}=~s/'/%27/g; system "firefox \"https://www.wolframalpha.com/input/?i=$temp{transcript}\" &"; system "./wolfram/api.sh \"$temp{transcript}\""; -- cgit v1.2.3