Permalink
Browse files

pull the trigger

  • Loading branch information...
1 parent 3fcd9a6 commit 865c8cba040c14e2e23e9de31a2db40b0d2400af Glen D Sanford committed Aug 15, 2012
@@ -40,9 +40,39 @@ abstract class KeywordPrefixResponder(stopWords: Set[String])
}
/**
+ * for a given list of words, will try to find each in the status text, and use as
+ * the keyword prefix. If more than once match, will prefer the one earliest in the
+ * status text.
+ */
+abstract class IndexKeywordPrefixResponder extends KeywordPrefixResponder(Set.empty) {
+ def words: Seq[String]
+
+ lazy val paddedWords = words.distinct.sorted.map { " " + _ + " " }
+
+ /**
+ * will try every extraction, but prefer the longest one
+ */
+ override def extract(statusText: String) = {
+ val earliest = paddedWords flatMap { word =>
+ val index = statusText.indexOf(word)
+ if (index > 0)
+ Some((index, word.trim))
+ else
+ None
+ } sortWith { case ((thisIndex, _), (thatIndex, _)) =>
+ thisIndex < thatIndex
+ } headOption
+
+ earliest map { case (index, word) =>
+ (word, statusText.substring(index + word.size + 1))
+ }
+ }
+}
+
+/**
* Attempts to match various "to be", "to have", and "to do" verb combinations
*/
-abstract class BeHaveDoKeywordPrefixResponder extends KeywordPrefixResponder(Set.empty) {
+abstract class BeHaveDoKeywordPrefixResponder extends IndexKeywordPrefixResponder {
val contractable =
Seq(
"could",
@@ -104,35 +134,10 @@ abstract class BeHaveDoKeywordPrefixResponder extends KeywordPrefixResponder(Set
val withAux = needsAux flatMap { word => aux.map { word + " " + _} }
- val words =
+ override lazy val words =
contractable ++ contractable.map { _ + "n't" } ++
uncontractable ++ uncontractable.map { _ + " not"} ++
withAux ++ others
-
- val paddedWords = words.distinct.sorted.map { " " + _ + " " }
-
- paddedWords.foreach(println(_))
-
- /**
- * will try every extraction, but prefer the longest one
- */
- override def extract(statusText: String) = {
- val earliest = paddedWords flatMap { word =>
- val index = statusText.indexOf(word)
- if (index > 0)
- Some((index, word.trim))
- else
- None
- } sortWith { case ((thisIndex, _), (thatIndex, _)) =>
- thisIndex < thatIndex
- } headOption
-
- earliest map { case (index, word) =>
- (word, statusText.substring(index + word.size + 1))
- }
- }
-
-
}
/**
@@ -6,17 +6,10 @@ object YourMomBot
extends FollowBackBot(
Responder.ignoreProtectedUsers(
Responder.rateLimited(
- Responder.merged(
- // experimental, so just log what would have happened
- Responder.logOnly(
- Responder.preferLongestResponse(
- Responder.simple(new YourMomBeHaveDoResponder),
- Responder.simple(new YourMomGerrundResponder),
- Responder.simple(new YourMomPastTenseResponder)
- )
- ),
- Responder.simple(new YourMomPastTenseResponder),
- Responder.simple(new YourMomGerrundResponder)
+ Responder.preferLongestResponse(
+ Responder.simple(new YourMomBeHaveDoResponder),
+ Responder.simple(new YourMomGerrundResponder),
+ Responder.simple(new YourMomPastTenseResponder)
),
RateLimiter.merged(
RateLimiter.perHour(2),

0 comments on commit 865c8cb

Please sign in to comment.