Class: ZombieWriter::MachineLearning
- Inherits:
-
Object
- Object
- ZombieWriter::MachineLearning
- Defined in:
- lib/zombie_writer.rb
Instance Attribute Summary collapse
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
-
#lsi ⇒ Object
readonly
Returns the value of attribute lsi.
-
#paragraph_data ⇒ Object
readonly
Returns the value of attribute paragraph_data.
-
#plain_to_markdown ⇒ Object
readonly
Returns the value of attribute plain_to_markdown.
-
#renderer ⇒ Object
readonly
Returns the value of attribute renderer.
Instance Method Summary collapse
- #add_string(paragraph) ⇒ Object
- #generate_articles ⇒ Object
-
#initialize ⇒ MachineLearning
constructor
A new instance of MachineLearning.
Constructor Details
#initialize ⇒ MachineLearning
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
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
38 39 40 |
# File 'lib/zombie_writer.rb', line 38 def labels @labels end |
#lsi ⇒ Object (readonly)
Returns the value of attribute lsi.
38 39 40 |
# File 'lib/zombie_writer.rb', line 38 def lsi @lsi end |
#paragraph_data ⇒ Object (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_markdown ⇒ Object (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 |
#renderer ⇒ Object (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_articles ⇒ Object
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 |