Class: NLP::Text

Inherits:
Object
  • Object
show all
Defined in:
lib/tagger/text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeText

Returns a new instance of Text.



5
6
7
# File 'lib/tagger/text.rb', line 5

def initialize
  @sentences = []
end

Instance Attribute Details

#sentencesObject (readonly)

Returns the value of attribute sentences.



3
4
5
# File 'lib/tagger/text.rb', line 3

def sentences
  @sentences
end

Instance Method Details

#<<(sentence) ⇒ Object



9
10
11
# File 'lib/tagger/text.rb', line 9

def << sentence
  @sentences.push sentence
end

#flattenObject



17
18
19
20
21
# File 'lib/tagger/text.rb', line 17

def flatten
  flattened = []
  @sentences.each{ |s| s.tokens.each{|t| flattened.push t } }
  flattened
end

#words_per_sentenceObject



13
14
15
# File 'lib/tagger/text.rb', line 13

def words_per_sentence
  @sentences.collect{|s| s.words_number}.mean
end