class UtteranceParser::Example
An example utterance for training the parser. Can be labeled with entities via XML tags: `Play some <category>rap</category>`.
Attributes
intent[R]
labeled_text[R]
Public Class Methods
new(labeled_text, intent)
click to toggle source
Calls superclass method
# File lib/utterance_parser/example.rb, line 7 def initialize(labeled_text, intent) super(labeled_text.gsub(TAG_RE, '\2')) @labeled_text = labeled_text @intent = intent end
Public Instance Methods
==(other)
click to toggle source
# File lib/utterance_parser/example.rb, line 13 def ==(other) other.class == self.class && other.labeled_text == @labeled_text end
labeled_tokens()
click to toggle source
# File lib/utterance_parser/example.rb, line 17 def labeled_tokens labels = tags_with_position(@labeled_text) tags_with_position(PosTagger.add_tags(@text)).map do |tag, word, word_position| label = labels.detect do |name, content, label_position| # If the word position intersect with the label's, it's a match if label_position.include? word_position.begin break name end end [word, tag.upcase, label] end end