Skip to content

Commit 6abaf18

Browse files
committed
num_wrapped_lines needs to default to 1
1 parent dffdce9 commit 6abaf18

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

lib/boilerpipe/document/text_block.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(text, num_words = 0, num_words_in_anchor_text = 0, num_words_in_w
2525
end
2626

2727
def self.empty_start
28-
new('', 0, 0, 0, 0, -1)
28+
new('', 0, 0, 0, 1, -1)
2929
end
3030

3131
def set_tag_level(level)
@@ -98,7 +98,6 @@ def clone
9898
def init_densities
9999
if @num_words_in_wrapped_lines == 0
100100
@num_words_in_wrapped_lines = @num_words
101-
@num_wrapped_lines = 1
102101
end
103102
@text_density = @num_words_in_wrapped_lines / @num_wrapped_lines.to_f
104103
@link_density = @num_words == 0 ? 0.0 : @num_words_in_anchor_text / @num_words.to_f

spec/document/text_block_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ module Boilerpipe
9999
expect(block.text_density).to eq 4.0
100100
expect(block.link_density).to eq 0.5
101101
end
102+
103+
it 'resets wrapped lines' do
104+
block = Document::TextBlock.new('one', 10)
105+
another_block = Document::TextBlock.new('two', 10)
106+
107+
block.merge_next(another_block)
108+
109+
expect(block.num_words_in_wrapped_lines).to eq 20
110+
expect(block.num_wrapped_lines).to eq 2
111+
end
102112
end
103113

104114
describe '#add_label' do

spec/filters/simple_block_fusion_processor_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ module Boilerpipe::Filters
66
let!(:doc) { Boilerpipe::Document::TextDocument.new('', text_blocks) }
77

88
context 'where blocks have same text density' do
9-
let(:text_block1) { Boilerpipe::Document::TextBlock.new('one', 0, 0, 0, 0, 0) }
10-
let(:text_block2) { Boilerpipe::Document::TextBlock.new('two', 0, 0, 0, 0, 1) }
11-
let(:text_block3) { Boilerpipe::Document::TextBlock.new('three', 0, 0, 0, 0, 2) }
12-
let(:text_block4) { Boilerpipe::Document::TextBlock.new('four', 0, 0, 0, 0, 3) }
9+
let(:text_block1) { Boilerpipe::Document::TextBlock.new('one', 0, 0, 0, 1, 0) }
10+
let(:text_block2) { Boilerpipe::Document::TextBlock.new('two', 0, 0, 0, 1, 1) }
11+
let(:text_block3) { Boilerpipe::Document::TextBlock.new('three', 0, 0, 0, 1, 2) }
12+
let(:text_block4) { Boilerpipe::Document::TextBlock.new('four', 0, 0, 0, 1, 3) }
1313
it 'the blocks are merged' do
1414
expect(doc.text_blocks.size).to eq 4
1515
SimpleBlockFusionProcessor.process(doc)

0 commit comments

Comments
 (0)