Class: Topical::Labelers::TermBased

Inherits:
Base
  • Object
show all
Defined in:
lib/topical/labelers/term_based.rb

Overview

Fast term-based labeling using top distinctive terms

Instance Method Summary collapse

Instance Method Details

#generate_label(topic) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/topical/labelers/term_based.rb', line 7

def generate_label(topic)
  terms = topic.terms
  return "Topic #{topic.id}" if terms.empty?
  
  # Take top distinctive terms
  label_terms = terms.first(3).select { |t| t.length > 3 }
  
  if label_terms.length >= 2
    "#{capitalize_phrase(label_terms[0])} & #{capitalize_phrase(label_terms[1])}"
  else
    capitalize_phrase(label_terms.first || terms.first)
  end
end