]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/factoids.rb
markov: refactor triplet learning
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / factoids.rb
index cba09b983696e4c02bbebb8eb8f21933457b180b..5b5e2b7204f7bea44d388268a80a897b21ed5411 100644 (file)
@@ -120,7 +120,7 @@ class FactoidsPlugin < Plugin
     super
 
     # TODO config
-    @dir = File.join(@bot.botclass,"factoids")
+    @dir = datafile
     @filename = "factoids.rbot"
     @factoids = FactoidList.new
     @triggers = Set.new
@@ -331,7 +331,9 @@ class FactoidsPlugin < Plugin
     # When looking for words we separate them with
     # arbitrary whitespace, not whatever they came with
     pre = words.map { |w| Regexp.escape(w)}.join("\\s+")
-    return Regexp.new("\\b#{pre}\\b", true)
+    pre << '\b' if pre.match(/\b$/)
+    pre = '\b' + pre if pre.match(/^\b/)
+    return Regexp.new(pre, true)
   end
 
   def facts(m, params)
@@ -366,7 +368,7 @@ class FactoidsPlugin < Plugin
           reply << short_fact(f)
         }
       end
-      m.reply reply.join(". "), :split_at => /\s+--\s+/
+      m.reply reply.join(". "), :split_at => /\[\d+\/\d+\] /, :purge_split => false
     end
   end
 
@@ -377,7 +379,12 @@ class FactoidsPlugin < Plugin
       return if @triggers.empty?
       query = $1.strip.downcase
       if @triggers.include?(query)
-        facts(m, :words => query.split)
+        words = query.split
+        words.instance_variable_set(:@string_value, query)
+        def words.to_s
+          @string_value
+        end
+        facts(m, :words => words)
       end
     else
       return if m.address? # we don't learn stuff directed at us which is not an explicit learn command