]> git.donarmstrong.com Git - infobot.git/blob - src/Factoids/Norm.pl
* Fixed a bug that caused seen stats flush to crash related to sqlite not having...
[infobot.git] / src / Factoids / Norm.pl
1 #
2 #   Norm.pl: Norm.
3 #    Author: Kevin Lenzo
4 #   Version: 1997
5 #
6
7 # TODO:
8 # use strict;
9
10 sub normquery {
11     my ($in) = @_;
12
13     $in = " $in ";
14
15     for ($in) {
16         # where blah is -> where is blah
17         s/ (where|what|who)\s+(\S+)\s+(is|are) / $1 $3 $2 /i;
18
19         # where blah is -> where is blah
20         s/ (where|what|who)\s+(.*)\s+(is|are) / $1 $3 $2 /i;
21
22         s/^\s*(.*?)\s*/$1/;
23
24         s/be tellin\'?g?/tell/i;
25         s/ \'?bout/ about/i;
26
27         s/,? any(hoo?w?|ways?)/ /ig;
28         s/,?\s*(pretty )*please\??\s*$/\?/i;
29
30         # what country is ...
31         if ($in =~
32             s/wh(at|ich)\s+(add?res?s|country|place|net (suffix|domain))/wh$1 /ig) {
33             if ((length($in) == 2) && ($in !~ /^\./)) {
34                 $in = '.'.$in;
35             }
36             $in .= '?';
37         }
38
39         # profanity filters.  just delete it
40         s/th(e|at|is) (((m(o|u)th(a|er) ?)?fuck(in\'?g?)?|hell|heck|(god-?)?damn?(ed)?) ?)+//ig;
41         s/wtf/where/gi;
42         s/this (.*) thingy?/ $1/gi;
43         s/this thingy? (called )?//gi;
44         s/ha(s|ve) (an?y?|some|ne) (idea|clue|guess|seen) /know /ig;
45         s/does (any|ne|some) ?(1|one|body) know //ig;
46         s/do you know //ig;
47         s/can (you|u|((any|ne|some) ?(1|one|body)))( please)? tell (me|us|him|her)//ig;
48         s/where (\S+) can \S+ (a|an|the)?//ig;
49         s/(can|do) (i|you|one|we|he|she) (find|get)( this)?/is/i; # where can i find
50         s/(i|one|we|he|she) can (find|get)/is/gi; # where i can find
51         s/(the )?(address|url) (for|to) //i; # this should be more specific
52         s/(where is )+/where is /ig;
53         s/\s+/ /g;
54         s/^\s+//;
55         if ($in =~ s/\s*[\/?!]*\?+\s*$//) {
56             $finalQMark = 1;
57         }
58
59         s/\s+/ /g;
60         s/^\s*(.*?)\s*$/$1/;
61         s/^\s+|\s+$//g;         # why twice, see Question.pl
62     }
63
64     return $in;
65 }
66
67 # for be-verbs
68 sub switchPerson {
69     my ($in) = @_;
70
71     for ($in) {
72         # # fix genitives
73         s/(^|\W)\Q$who\Es\s+/$1${who}\'s /ig;
74         s/(^|\W)\Q$who\Es$/$1${who}\'s/ig;
75         s/(^|\W)\Q$who\E\'(\s|$)/$1${who}\'s$2/ig;
76
77         s/(^|\s)i\'m(\W|$)/$1$who is$2/ig;
78         s/(^|\s)i\'ve(\W|$)/$1$who has$2/ig;
79         s/(^|\s)i have(\W|$)/$1$who has$2/ig;
80         s/(^|\s)i haven\'?t(\W|$)/$1$who has not$2/ig;
81         s/(^|\s)i(\W|$)/$1$who$2/ig;
82         s/ am\b/ is/i;
83         s/\bam /is/i;
84         s/(^|\s)(me|myself)(\W|$)/$1$who$3/ig;
85         s/(^|\s)my(\W|$)/$1${who}\'s$2/ig; # turn 'my' into name's
86         s/(^|\W)you\'?re(\W|$)/$1you are$2/ig;
87
88         if ($addressed) {
89             my $mynick = 'UNDEF';
90             $mynick = $conn->nick() if ($conn);
91             # is it safe to remove $in from here, too?
92             $in =~ s/yourself/$mynick/i;
93             $in =~ s/(^|\W)are you(\W|$)/$1is $mynick$2/ig;
94             $in =~ s/(^|\W)you are(\W|$)/$1$mynick is$2/ig;
95             $in =~ s/(^|\W)you(\W|$)/$1$mynick$2/ig;
96             $in =~ s/(^|\W)your(\W|$)/$1$mynick\'s$2/ig;
97         }
98     }
99
100     return $in;
101 }
102
103 1;
104
105 # vim:ts=4:sw=4:expandtab:tw=80