shiner 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module Shiner
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/shiner.rb CHANGED
@@ -15,10 +15,11 @@ module Shiner
15
15
 
16
16
  def self.string_to_best_sentences(string, options={})
17
17
  sentences = string_to_scored_sentences(string)
18
- options[:max_sentences]||=sentences.size
19
18
  batches = []
20
19
  sentences.each_index{|index|
21
- batch={:sentences => sentences[index, options[:max_sentences]]}
20
+ batch={:sentences => sentences[index, options[:max_sentences] || sentences.size]}
21
+ next if options[:max_length] && batch[:sentences].collect{|sentence| sentence[:sentence]}.join(' ').length < options[:max_length] && batches.size > 0 #don't take last few sentences if they do not meet max_length
22
+ next if options[:max_sentences] && batch[:sentences].size < options[:max_sentences] && batches.size > 0 #don't take last few sentences if they do not meet max_sentences
22
23
  batch[:sentences].pop while options[:max_length] && batch[:sentences].collect{|sentence| sentence[:sentence]}.join(' ').length > options[:max_length]
23
24
  batch[:score] = batch[:sentences].collect{|sentence| sentence[:score]}.sum.to_f / batch[:sentences].size
24
25
  batches << batch
data/test/test_shiner.rb CHANGED
@@ -43,15 +43,15 @@ Recent reports suggested that Facebook is to launch its own smartphone by next y
43
43
  EOF
44
44
  result = Shiner.shine(doc, :max_length => 388)
45
45
  pp [result, result.size]
46
- assert result.size > 100
46
+ assert result.size > 200
47
47
  assert result.size < 388
48
48
  result = Shiner.shine(doc, :max_length => 888)
49
49
  pp [result, result.size]
50
- assert result.size > 100
50
+ assert result.size > 400
51
51
  assert result.size < 888
52
52
  result = Shiner.shine(doc, :max_length => 1888)
53
53
  pp [result, result.size]
54
- assert result.size > 100
54
+ assert result.size > 1000
55
55
  assert result.size < 1888
56
56
  result = Shiner.shine(doc, :max_sentences => 1)
57
57
  pp [result, result.size]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shiner
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Ling Xiaowei