lib/attentive.rb in attentive-0.2.0 vs lib/attentive.rb in attentive-0.3.0

- old
+ new

@@ -1,8 +1,9 @@ require "attentive/version" require "attentive/config" + module Attentive extend Attentive::Config # Default configuration self.invocations = ["@me".freeze] @@ -11,9 +12,34 @@ # a message to be heard in. self.default_required_contexts = %i{conversation} # Default contexts in which listeners will ignore messages. self.default_prohibited_contexts = %i{quotation} + + + + # Recognizes entities in a phrase + def self.abstract(message) + message = Attentive::Message.new(message) + entities = Attentive::Entity.entities.map { |entity| Attentive::Phrase.new([entity.new]) } + i = 0 + while i < message.tokens.length + entities.each do |entity| + match = Attentive::Matcher.new(entity, Cursor.new(message, i)).match! + next unless match + + i = match.replace_with(entity) + break + end + i += 1 + end + message.tokens.to_s + end + + # Shorthand for tokenizer + def self.tokenize(message, options={}) + Attentive::Tokenizer.tokenize(message, options) + end # Attentive DSL