lingua-it-readability 1.1.0 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 470c3c7ea7eb28b6f52bc516d9f4a161d287c1e8
4
- data.tar.gz: d5e4a825918c07682500ab93d3e64be02ea8fb53
3
+ metadata.gz: b93556194cfe9537a625a11be8b2f973c0939622
4
+ data.tar.gz: 959ea95d40475e12c0e4f3e8c4b2a3ac8d4f595f
5
5
  SHA512:
6
- metadata.gz: 9b4a7e504931bd2dac6d06dad98e41dcd992a0135b55249b099ff5d582933a652be4ef8e9c190678606f1f1a83c6186a083b3eaf86d86be25bce3bf52b5086dd
7
- data.tar.gz: 2feae4565d24deb075bac0ee79e11c9c6652a4940a8e408ad1c4896114b8370fe31ce4f5901a161fdf833d3900cd3e819a4329caf8f233119b5d2ed64255ef5c
6
+ metadata.gz: b1fa57d62d3c1dbc8ee62f58094cc92551c5186b3dcf3218337c3558ad7e68f425f6d0b82d0e1bdeefe7c7493299c680624fd12df2a3ed08597be88175bed39a
7
+ data.tar.gz: 2eaaaf25d2e5dd2e0bb58cdeaf87e17b318c18d94458fe755ce3365067b5be218435a1b38884d014cafac31496a6fc5f358b3c1444b5cc5a0982e7b3f7f394de
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ #### 1.1.5 - 2016-02-10
2
+ ###### Added
3
+ - Method analyze, accept text and optional delimiters
4
+ - Updated usage section
5
+
1
6
  #### 1.1.0 - 2016-02-09
2
7
  ###### Added
3
8
  - Optimized regex, greatly improved overall performance
data/README.md CHANGED
@@ -39,6 +39,16 @@ report.num_sentences # 3
39
39
  report.num_words # 3
40
40
  report.num_syllables # 8
41
41
  report.report # a formatted summary of statistics and measures
42
+
43
+ # It's also possible to not directly initialize the object..
44
+ text = "Lista:\n- Gennaio;\n- Febbraio;"
45
+ report = Lingua::IT::Readability.new
46
+ # ..using method analyze with optional delimiters
47
+ report.analyze(text, ':', ';')
48
+ report.num_sentences # 3
49
+ report.num_words # 3
50
+ report.num_syllables # 8
51
+ report.report # a formatted summary of statistics and measures
42
52
  ```
43
53
 
44
54
  ## Development
@@ -1,7 +1,7 @@
1
1
  module Lingua
2
2
  module It
3
3
  module Readability
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.5"
5
5
  end
6
6
  end
7
7
  end
@@ -9,42 +9,65 @@ end
9
9
  module Lingua
10
10
  module IT
11
11
  class Readability
12
- attr_reader :text
13
- attr_reader :sent
14
- attr_reader :paragraphs
15
- attr_reader :sentences
16
- attr_reader :words
17
- attr_reader :frequencies
12
+ attr_accessor :text
13
+ attr_accessor :paragraphs
14
+ attr_accessor :sentences
15
+ attr_accessor :words
16
+ attr_accessor :frequencies
17
+ attr_reader :sentence
18
+ attr_reader :paragraph
19
+ attr_reader :syllable
18
20
 
19
21
  # Initialize the sample with +text+
20
22
  def initialize(text = '', *delimiters)
21
23
 
22
- @sent = Lingua::IT::Sentence
24
+ @paragraph = Lingua::IT::Paragraph
25
+ @sentence = Lingua::IT::Sentence
26
+ @syllable = Lingua::IT::Syllable
27
+
28
+ if(!delimiters.empty?)
29
+ @sentence.delimiter(delimiters)
30
+ else
31
+ @sentence.reset_delimiter!
32
+ end
33
+
34
+ @text = text.dup
35
+ @paragraphs = @paragraph.paragraphs(self.text)
36
+ @sentences = @sentence.sentences(self.text)
37
+ @words = []
38
+ @frequencies = {}
39
+ @frequencies.default = 0
40
+ @syllables = @syllable.syllables(self.text)
41
+ count_words
42
+ end
43
+
44
+ # Analyze a text sample with optional delimiters
45
+ def analyze(text, *delimiters)
23
46
  if(!delimiters.empty?)
24
- @sent.delimiter(delimiters)
47
+ @sentence.delimiter(delimiters)
25
48
  else
26
- @sent.reset_delimiter
49
+ @sentence.reset_delimiter!
27
50
  end
28
51
 
29
52
  @text = text.dup
30
- @paragraphs = Lingua::IT::Paragraph.paragraphs(self.text)
31
- @sentences = @sent.sentences(self.text)
53
+ @paragraphs = @paragraph.paragraphs(self.text)
54
+ @sentences = @sentence.sentences(self.text)
32
55
  @words = []
33
56
  @frequencies = {}
34
57
  @frequencies.default = 0
35
- @syllables = Lingua::IT::Syllable.syllables(self.text)
58
+ @syllables = @syllable.syllables(self.text)
36
59
  count_words
37
60
  end
38
61
 
39
62
  # Reset Lingua::IT::Sentence symbols delimiter cache
40
- def reset_delimiter
41
- @sent.reset_delimiter
63
+ def reset_delimiter!
64
+ @sentence.reset_delimiter!
42
65
  end
43
66
 
44
67
  # The number of paragraphs in the sample. A paragraph is defined as a
45
68
  # newline followed by one or more empty or whitespace-only lines.
46
69
  def num_paragraphs
47
- paragraphs.length
70
+ @paragraphs.length
48
71
  end
49
72
 
50
73
  # The number of sentences in the sample. The meaning of a "sentence" is
@@ -64,7 +87,7 @@ module Lingua
64
87
  # characters, not taking account of punctuation and spaces, see private
65
88
  # method +count_words+ for additional info about a word definition
66
89
  def num_words
67
- words.length
90
+ @words.length
68
91
  end
69
92
 
70
93
  # The total number of syllables in the text sample. Syllables are defined
@@ -50,7 +50,7 @@ module Lingua
50
50
  @delimiters
51
51
  end
52
52
 
53
- def self.reset_delimiter
53
+ def self.reset_delimiter!
54
54
  @delimiters = STD
55
55
  set_delim_regex!
56
56
  @delimiters
@@ -69,12 +69,6 @@ module Lingua
69
69
  @abbr_regex = "#{@abbreviations.join('|')}"
70
70
  end
71
71
 
72
- # Utility method, chain up all delimiters constants arrays
73
- def self.initialize_delimiters!
74
- @delimiters = STD
75
- set_delim_regex!
76
- end
77
-
78
72
  # Utility method, join all elements of the delimiters arrays
79
73
  # without a separator, making suitable for a regex.
80
74
  def self.set_delim_regex!
@@ -82,7 +76,7 @@ module Lingua
82
76
  end
83
77
 
84
78
  initialize_abbreviations!
85
- initialize_delimiters!
79
+ reset_delimiter!
86
80
  end
87
81
  end
88
82
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lingua-it-readability
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Giacomo Baldan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-09 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler