Class: UtteranceParser::Example
- Defined in:
- lib/utterance_parser/example.rb
Overview
An example utterance for training the parser. Can be labeled with entities via XML tags: ‘Play some <category>rap</category>`.
Constant Summary
Constants inherited from Utterance
Instance Attribute Summary collapse
-
#intent ⇒ Object
readonly
Returns the value of attribute intent.
-
#labeled_text ⇒ Object
readonly
Returns the value of attribute labeled_text.
Attributes inherited from Utterance
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(labeled_text, intent) ⇒ Example
constructor
A new instance of Example.
- #labeled_tokens ⇒ Object
Methods inherited from Utterance
Constructor Details
Instance Attribute Details
#intent ⇒ Object (readonly)
Returns the value of attribute intent.
5 6 7 |
# File 'lib/utterance_parser/example.rb', line 5 def intent @intent end |
#labeled_text ⇒ Object (readonly)
Returns the value of attribute labeled_text.
5 6 7 |
# File 'lib/utterance_parser/example.rb', line 5 def labeled_text @labeled_text end |
Instance Method Details
#==(other) ⇒ Object
13 14 15 |
# File 'lib/utterance_parser/example.rb', line 13 def ==(other) other.class == self.class && other.labeled_text == @labeled_text end |
#labeled_tokens ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/utterance_parser/example.rb', line 17 def labeled_tokens labels = (@labeled_text) (PosTagger.(@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 |