Class: ZombieWriter::MachineLearning

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMachineLearning

Returns a new instance of MachineLearning.



40
41
42
43
44
45
46
# File 'lib/zombie_writer.rb', line 40

def initialize
  @lsi = ClassifierReborn::LSI.new
  @labels = []
  @paragraph_data = Hash.new
  @plain_to_markdown = Hash.new
  @renderer = Redcarpet::Markdown.new(CustomStripDownRender)
end

Instance Attribute Details

#labelsObject (readonly)

Returns the value of attribute labels.



38
39
40
# File 'lib/zombie_writer.rb', line 38

def labels
  @labels
end

#lsiObject (readonly)

Returns the value of attribute lsi.



38
39
40
# File 'lib/zombie_writer.rb', line 38

def lsi
  @lsi
end

#paragraph_dataObject (readonly)

Returns the value of attribute paragraph_data.



38
39
40
# File 'lib/zombie_writer.rb', line 38

def paragraph_data
  @paragraph_data
end

#plain_to_markdownObject (readonly)

Returns the value of attribute plain_to_markdown.



38
39
40
# File 'lib/zombie_writer.rb', line 38

def plain_to_markdown
  @plain_to_markdown
end

#rendererObject (readonly)

Returns the value of attribute renderer.



38
39
40
# File 'lib/zombie_writer.rb', line 38

def renderer
  @renderer
end

Instance Method Details

#add_string(paragraph) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/zombie_writer.rb', line 48

def add_string(paragraph)
  content = paragraph[:content]

  stripped_down_content = renderer.render(content)

  plain_to_markdown[stripped_down_content] = content

  paragraph_data[content] = ZombieWriter.citation_constructor(paragraph)

  labels << stripped_down_content
  lsi.add_item(stripped_down_content)
end

#generate_articlesObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/zombie_writer.rb', line 61

def generate_articles
  number_of_articles = labels.length
  clusters = determine_number_of_clusters(number_of_articles)
  clusters = generate_clusters(clusters: clusters, runs: 10)
  clusters.map do |cluster|
    article_for_summarization = generate_article(cluster) do |point|
      point.label
    end

    final_article = generate_article(cluster) do |point|
      stripped_down_content = point.label
      content = plain_to_markdown[stripped_down_content]
      citation = paragraph_data[content]
      "#{content}#{citation}"
    end

    header = ZombieWriter.header(cluster.id.to_s, article_for_summarization)
    ZombieWriter.formatted_article(header, final_article)
  end
end