Class: GrammarPolice::Sentence

Inherits:
Object
  • Object
show all
Extended by:
FFI::Library
Defined in:
lib/grammar_police/sentence.rb

Class Method Summary collapse

Class Method Details

.count_linkages(text, dictionary, options) ⇒ Object

split up the text by punctuation (make the sentence shorter ==> processing faster)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/grammar_police/sentence.rb', line 26

def self.count_linkages(text, dictionary, options)
  count = 0
  #split them up by punctuation to reduce processing time
  text.split(/[\!?,;:']+/).each do |clause|
    c = sentence_create(clause, dictionary)
    count += sentence_parse(c, options)
    sentence_delete(c)
  end
  
  #however, sometimes the split results in all incomplete clause so check one more time in those cases
  if count == 0
    sentence = sentence_create(text, dictionary)
    count = sentence_parse(sentence, options) if count == 0
    sentence_delete(sentence)
  end
  count
end