Module: Raingrams::Helpers::Commonality

Included in:
Model
Defined in:
lib/raingrams/helpers/commonality.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/raingrams/helpers/commonality.rb', line 6

def self.included(base)
  base.module_eval { include Raingrams::Helpers::Probability }
end

Instance Method Details

#common_ngrams_from_fragment(fragment) ⇒ Object

Returns the ngrams which occur within the specified fragment and within the model.



22
23
24
# File 'lib/raingrams/helpers/commonality.rb', line 22

def common_ngrams_from_fragment(fragment)
  ngrams_from_fragment(fragment).select { |ngram| has_ngram?(ngram) }
end

#common_ngrams_from_sentence(sentence) ⇒ Object

Returns the ngrams which occur within the specified sentence and within the model.



30
31
32
# File 'lib/raingrams/helpers/commonality.rb', line 30

def common_ngrams_from_sentence(sentence)
  ngrams_from_sentence(sentence).select { |ngram| has_ngram?(ngram) }
end

#common_ngrams_from_text(text) ⇒ Object

Returns the ngrams which occur within the specified text and within the model.



38
39
40
# File 'lib/raingrams/helpers/commonality.rb', line 38

def common_ngrams_from_text(text)
  ngrams_from_text(text).select { |ngram| has_ngram?(ngram) }
end

#common_ngrams_from_words(words) ⇒ Object

Returns the ngrams which occur within the specified words and within the model.



14
15
16
# File 'lib/raingrams/helpers/commonality.rb', line 14

def common_ngrams_from_words(words)
  ngrams_from_words(words).select { |ngram| has_ngram?(ngram) }
end

#fragment_commonality(fragment) ⇒ Object

Returns the joint probability of the common ngrams between the specified fragment and the model.



46
47
48
# File 'lib/raingrams/helpers/commonality.rb', line 46

def fragment_commonality(fragment)
  probability_of_ngrams(common_ngrams_from_fragment(fragment))
end

#sentence_commonality(sentence) ⇒ Object

Returns the joint probability of the common ngrams between the specified sentence and the model.



54
55
56
# File 'lib/raingrams/helpers/commonality.rb', line 54

def sentence_commonality(sentence)
  probability_of_ngrams(common_ngrams_from_sentence(sentence))
end

#text_commonality(text) ⇒ Object

Returns the joint probability of the common ngrams between the specified sentence and the model.



62
63
64
# File 'lib/raingrams/helpers/commonality.rb', line 62

def text_commonality(text)
  probability_of_ngrams(common_ngrams_from_text(text))
end