Skip to content

Instantly share code, notes, and snippets.

@simonwistow
Created March 18, 2012 16:57
Show Gist options
  • Save simonwistow/2077513 to your computer and use it in GitHub Desktop.
Save simonwistow/2077513 to your computer and use it in GitHub Desktop.
Infobot.pm.diff
--- Infobot.pm.orig 2012-03-18 09:13:26.000000000 -0700
+++ Infobot.pm 2012-03-18 09:29:08.000000000 -0700
@@ -14,6 +14,58 @@
eval { require XML::Feed };
our $HAS_XML_FEED = $@ ? 0 : 1;
+our %AUXILLARY_VERBS = (
+ "am" => { tense => 'present' },
+ "are" => { tense => 'present' },
+ "aren't" => { tense => 'present', negative_of => "are" },
+ "ain't" => { tense => 'present', negative_of => "are" },
+ "can" => { tense => 'present' },
+ "can't" => { tense => 'present', negative_of => "can" },
+ "could" => { tense => 'past' },
+ "couldn't" => { tense => 'past', negative_of => "could" },
+ "dare" => { tense => 'present' },
+ "did" => { tense => 'past' },
+ "didn't" => { tense => 'past', negative_of => "did" },
+ "do" => { tense => 'future' },
+ "don't" => { tense => 'future', negative_of => "do" },
+ "does" => { tense => 'present' },
+ "doesn't" => { tense => 'present', negative_of => "does" },
+ "had" => { tense => 'past' },
+ "hadn't" => { tense => 'past', negative_of => "had" },
+ "has" => { tense => 'present' },
+ "hasn't" => { tense => 'present', negative_of => "has" },
+ "have" => { tense => 'past' },
+ "haven't" => { tense => 'past', negative_of => "have" },
+ "is" => { tense => 'present' },
+ "isn't" => { tense => 'present', negative_of => "is" },
+ "may" => { tense => 'future' },
+ "mayn't" => { tense => 'future', negative_of => "may" },
+ "might" => { tense => 'future' },
+ "mightn't" => { tense => 'future', negative_of => "might" },
+ "must" => { tense => 'future' },
+ "mustn't" => { tense => 'future', negative_of => "must" },
+ "need" => { tense => 'future' },
+ "needn't" => { tense => 'future', negative_of => "need" },
+ "ought" => { tense => 'future' },
+ "oughtn't" => { tense => 'future', negative_of => "ought" },
+ "shall" => { tense => 'future' },
+ "shan't" => { tense => 'future', negative_of => "shall" },
+ "should" => { tense => 'future' },
+ "shouldn't" => { tense => 'future', negative_of => "should" },
+ "used to" => { tense => 'past' },
+ "was" => { tense => 'past' },
+ "wasn't" => { tense => 'past', negative_of => "was" },
+ "were" => { tense => 'past' },
+ "weren't" => { tense => 'past', negative_of => "were" },
+ "will" => { tense => 'future' },
+ "won't" => { tense => 'future', negative_of => "will" },
+ "would" => { tense => 'future' },
+ "wouldn't" => { tense => 'future', negative_of => "would" },
+);
+
+our $VERB_RE = "(".join("|", keys %AUXILLARY_VERBS).")"
+
+
sub init {
my $self = shift;
$self->config(
@@ -106,8 +158,8 @@
# <word> (is|are)
# and then removes if if <word> is a stopword
# this means that we treat "what is foo?" as "foo?"
- if ( $body =~ /^(.*?)\s+(is|are)\s+(.*)$/i ) {
- $body =~ s/^(.*?)\s+(is|are)\s+//i if $stopwords{$1};
+ if ( $body =~ /^(.*?)\s+($VERB_RE)\s+(.*)$/i ) {
+ $body =~ s/^(.*?)\s+($VERB_RE)\s+//i if $stopwords{$1};
}
# answer a factoid. this is a crazy check which ensures we will ONLY answer
@@ -170,8 +222,7 @@
# does it even look like a factoid?
return unless ( $mess->{address} or $self->get("user_passive_learn") );
return
- unless ( $body =~ /^(.*?)\s+(is)\s+(.*)$/i
- or $body =~ /^(.*?)\s+(are)\s+(.*)$/i );
+ unless ( $body =~ /^(.*?)\s+($VERB_RE)\s+(.*)$/i
my ( $object, $is_are, $description ) = ( $1, $2, $3 );
my $literal = ( $object =~ s!^literal\s+!! );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment