From e2f9810d9154e46c6cbb5e72e3aa1c88d1c68cd4 Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Sun, 11 Feb 2018 20:44:14 -0800 Subject: [PATCH] Spinach: Improve normalization, and laxen validation --- PBot/Plugins/Spinach.pm | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/PBot/Plugins/Spinach.pm b/PBot/Plugins/Spinach.pm index 297193fd..fabc65c0 100644 --- a/PBot/Plugins/Spinach.pm +++ b/PBot/Plugins/Spinach.pm @@ -1048,29 +1048,35 @@ sub normalize_text { if ($word =~ m/^\d{4}$/ and $word >= 1700 and $word <= 2100) { $newword = year2en($word); - } elsif ($word =~ m/^\d+$/) { + } elsif ($word =~ m/^-?\d+$/) { $newword = num2en($word); if (defined $punct and $punct eq '%') { $newword .= " percent"; $punct = undef; } - } elsif ($word =~ m/^(\d+)(?:st|nd|rd|th)$/i) { + } elsif ($word =~ m/^(-?\d+)(?:st|nd|rd|th)$/i) { $newword = num2en_ordinal($1); - } elsif ($word =~ m/^\$(\d+)(\.\d+)?$/i) { - my ($dollars, $cents) = ($1, $2); - $word = num2en($dollars); - $newword = "$word " . ($dollars == 1 ? "dollar" : "dollars"); + } elsif ($word =~ m/^(-)?\$(\d+)?(\.\d+)?$/i) { + my ($neg, $dollars, $cents) = ($1, $2, $3); + $newword = ''; + $dollars = "$neg$dollars" if defined $neg and defined $dollars; + + if (defined $dollars) { + $word = num2en($dollars); + $newword = "$word " . (abs $dollars == 1 ? "dollar" : "dollars"); + } if (defined $cents) { $cents =~ s/^\.0*//; + $cents = "$neg$cents" if defined $neg and not defined $dollars; $word = num2en($cents); - $newword .= " and $word cent" if $cents == 1; - $newword .= " and $word cents" if $cents > 1; + $newword .= " and " if defined $dollars; + $newword .= (abs $cents == 1 ? "$word cent" : "$word cents"); } - } elsif ($word =~ m/^(\d+\.\d+)(?:st|nd|rd|th)?$/i) { + } elsif ($word =~ m/^(-?\d*\.\d+)(?:st|nd|rd|th)?$/i) { $newword = num2en($1); - } elsif ($word =~ m{^(\d+\s*/\s*\d+)(?:st|nd|rd|th)?$}i) { + } elsif ($word =~ m{^(-?\d+\s*/\s*-?\d+)(?:st|nd|rd|th)?$}i) { $newword = fraction2words($1); } @@ -1102,6 +1108,7 @@ sub validate_lie { return 0; } +=cut $count = 0; foreach my $word (keys %lie_words) { if (exists $truth_words{$word}) { @@ -1112,6 +1119,7 @@ sub validate_lie { if ($count == $lie_word_count) { return 0; } +=cut my $stripped_truth = $truth; $stripped_truth =~ s/(?:\s|\p{PosixPunct})+//g;