style-scanner 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -29,7 +29,9 @@ module StyleScanner
29
29
 
30
30
  def self.problem_class_names_from_dir
31
31
  Dir[(File.dirname(__FILE__) + "/../sentence_scans/*.rb")].
32
- map {|filename| File.basename(filename, ".rb").split("_").map(&:capitalize).join } - ["Base"]
32
+ map {|filename| File.basename(filename, ".rb").
33
+ split("_").
34
+ map(&:capitalize).join } - ["Base"]
33
35
  end
34
36
 
35
37
  def self.dynamically_generate_problem_classes
@@ -1,8 +1,8 @@
1
+ require 'ruby-prof'
1
2
  module StyleScanner
2
3
  module ProfilingHelpers
3
4
 
4
5
  def start_profiling
5
- require 'ruby-prof'
6
6
  RubyProf.start
7
7
  end
8
8
 
@@ -28,7 +28,7 @@ module StyleScanner
28
28
  text_to_scan = text
29
29
  text_to_scan = stemmed_verbs if options[:stem_verbs]
30
30
  text_to_scan = text_to_scan.downcase if options[:strip_case]
31
- text_to_scan.match /\b#{word}\b/
31
+ text_to_scan.match(/\b#{word}\b/)
32
32
  end
33
33
 
34
34
  def user_friendly_readout
@@ -18,7 +18,9 @@ module StyleScanner
18
18
  )
19
19
 
20
20
  def scan
21
- flag_lowercase(MONTHS)
21
+ flag_lowercase(MONTHS) do |word|
22
+ word == "may" && word.verb?
23
+ end
22
24
  flag_lowercase(ACRONYMS)
23
25
  flag_lowercase(DAYS)
24
26
  flag_lowercase(NATIONALITIES)
@@ -41,14 +43,22 @@ module StyleScanner
41
43
  end
42
44
 
43
45
  def flag_uppercase(collection)
44
- collection.each do |word|
45
- create_problem(word.downcase) if sentence.contains?(word, :strip_case => false)
46
- end
46
+ flag_case_problem(collection, :downcase)
47
+ end
48
+
49
+ def flag_lowercase(collection, &skipping_conditions)
50
+ flag_case_problem(collection, :capitalize, &skipping_conditions)
47
51
  end
48
52
 
49
- def flag_lowercase(collection)
50
- collection.each do |word|
51
- create_problem(word.capitalize) if sentence.contains?(word, :strip_case => false)
53
+ def flag_case_problem(collection, problem_case, &skipping_conditions)
54
+ words.each do |word|
55
+ # skip if the proc, when called with the tagged word, evaluates to true
56
+ next if skipping_conditions && skipping_conditions.call(word)
57
+
58
+ collection.each do |capitalization_word|
59
+ create_problem(capitalization_word.send problem_case) if sentence.contains?(capitalization_word, :strip_case => false) && word == capitalization_word
60
+ end
61
+
52
62
  end
53
63
  end
54
64
 
@@ -7,7 +7,7 @@ module StyleScanner
7
7
 
8
8
  def scan
9
9
  WORD_PAIRS.keys.each do |offender|
10
- create_problem(replacement_word(offender)) if sentence.contains?(offender)
10
+ create_problem("replace #{offender} with #{replacement_word(offender)}") if sentence.contains?(offender)
11
11
  end
12
12
  end
13
13
 
@@ -8,7 +8,7 @@ module StyleScanner
8
8
 
9
9
  def stem_verbs
10
10
  strip_punctuation.split.map do |word|
11
- is_a_verb?(word) ? word.stem : word
11
+ word.verb? ? word.stem : word
12
12
  end.join(" ")
13
13
  end
14
14
 
@@ -20,14 +20,12 @@ module StyleScanner
20
20
  @stemmed_verbs
21
21
  end
22
22
 
23
- private
24
-
25
- def is_a_verb?(word)
26
- tag(word).start_with?("V")
23
+ def verb?
24
+ tag.start_with?("V")
27
25
  end
28
26
 
29
- def tag(word)
30
- Tagger.new(self).tagged_words.find {|tagged_word| tagged_word.word == word}.tag
27
+ def tag
28
+ Tagger.new(self).tagged_words.find {|tagged_word| tagged_word.word == self }.tag
31
29
  rescue NoMethodError
32
30
  "Unknown"
33
31
  end
@@ -13,6 +13,10 @@ module StyleScanner
13
13
  @word = word
14
14
  end
15
15
 
16
+ def ==(string)
17
+ word == string
18
+ end
19
+
16
20
  def tokenized
17
21
  word.downcase.gsub(/\W/, "")
18
22
  end
@@ -46,7 +50,8 @@ module StyleScanner
46
50
  end
47
51
 
48
52
  def verb?
49
- tag.start_with?("V")
53
+ # account for modal verbs like may
54
+ tag.start_with?("V") || tag == "MD"
50
55
  end
51
56
 
52
57
  # Gerund verb = ING verb
@@ -19,6 +19,7 @@ module StyleScanner
19
19
  def parts_of_speech_tagger
20
20
  @eng_tagger ||= EngTagger.new
21
21
  end
22
+
22
23
  end
23
24
 
24
25
  end
@@ -1,3 +1,3 @@
1
1
  module StyleScanner
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -1,6 +1,6 @@
1
- h1. Style
1
+ h1. Style-Scanner
2
2
 
3
- Style, written by Jack Kinsella ("blog":http://www.jackkinsella.ie), helps you improve your English language writing. Based on stylistic advice given by authors such as Skunk and White, Bill Bryson and George Orwell, Style scans your text and markup files then lists issues found. Currently it spots the following problems:
3
+ Style-Scanner, written by Jack Kinsella ("blog":http://www.jackkinsella.ie), helps you improve your English language writing. Based on stylistic advice given by authors such as Skrunk and White, Bill Bryson and George Orwell, Style-Scanner scans your text and markup files then lists issues found. Currently it spots the following problems:
4
4
 
5
5
  * *Use of 600 different clichés*
6
6
  He pushed the envelope
@@ -24,28 +24,31 @@ addd
24
24
  We went to the the shopping centre.
25
25
  * *Excess white space*
26
26
  We went to the shopping centre.
27
+ * *Capitalization Problems*
28
+ On monday we will have an exam.
27
29
 
28
- _Linguistic analysis is a hard problem, so you cannot expect perfect results. Think of Style as guidelines to steer you in the right direction._
30
+ _Linguistic analysis is a hard problem, so you cannot expect perfect results. Think of Style-Scanner as guidelines to alert you of
31
+ possible faults. *Remember at best prescriptive stylistic guides can bring you up to a B minus standard of writing. * Anything more is beyond the scope of this tool._
29
32
 
30
33
  h2. Installation
31
34
 
32
- Install Style using Ruby gems:
35
+ Install Style-Scanner using Ruby gems:
33
36
 
34
37
  @gem install style-scanner@
35
38
 
36
- Next install Hunspell, an open source spell-checker that Style depends upon.
39
+ Next install Hunspell, an open source spell-checker that Style-Scanner depends upon.
37
40
 
38
41
  @brew install hunspell@
39
42
 
40
43
  h2. Usage
41
44
 
42
- Style is command line only. Cd into the directory with the files you'd like to scan, then type
45
+ Style-Scanner is command line only. Cd into the directory with the files you'd like to scan, then type
43
46
 
44
47
  @style-scanner filename@
45
48
 
46
- After a few seconds Style will print a list problems it finds.
49
+ After a few seconds Style-Scanner will print a list problems it finds.
47
50
 
48
- Style is pipe friendly.
51
+ Style-Scanner is pipe friendly.
49
52
 
50
53
  @cat filename | style-scanner@
51
54
 
@@ -76,6 +79,12 @@ Formats terminal output in red,green and other colours.
76
79
  "entagger":http://engtagger.rubyforge.org/
77
80
  Assigns parts of speech tags to English text based on a lookup dictionary and a set of probability values.
78
81
 
82
+ "RedCloth":http://redcloth.org/
83
+ Converts Textile to HTML
84
+
85
+ "Sanitize":https://github.com/rgrove/sanitize
86
+ Converts HTML to plain text
87
+
79
88
  h3. Other
80
89
 
81
90
  "Hunspell":http://hunspell.sourceforge.net/
@@ -87,51 +96,51 @@ Contribution is welcomed and encouraged, although no modifications will be accep
87
96
 
88
97
  h3. Parts of Speech
89
98
 
90
- | Tag | Part Of Speech | Examples |
91
- |CC | Conjunction, coordinating | and, or |
92
- | CD | Adjective, cardinal number | 3, fifteen |
93
- | DET | Determiner | this, each, some |
94
- EX Pronoun, existential there there
95
- FW Foreign words
96
- IN Preposition / Conjunction for, of, although, that
97
- JJ Adjective happy, bad
98
- JJR Adjective, comparative happier, worse
99
- JJS Adjective, superlative happiest, worst
100
- LS Symbol, list item A, A.
101
- MD Verb, modal can, could, 'll
102
- NN Noun aircraft, data
103
- NNP Noun, proper London, Michael
104
- NNPS Noun, proper, plural Australians, Methodists
105
- NNS Noun, plural women, books
106
- PDT Determiner, prequalifier quite, all, half
107
- POS Possessive 's, '
108
- PRP Determiner, possessive second mine, yours
109
- PRPS Determiner, possessive their, your
110
- RB Adverb often, not, very, here
111
- RBR Adverb, comparative faster
112
- RBS Adverb, superlative fastest
113
- RP Adverb, particle up, off, out
114
- SYM Symbol *
115
- TO Preposition to
116
- UH Interjection oh, yes, mmm
117
- VB Verb, infinitive take, live
118
- VBD Verb, past tense took, lived
119
- VBG Verb, gerund taking, living
120
- VBN Verb, past/passive participle taken, lived
121
- VBP Verb, base present form take, live
122
- VBZ Verb, present 3SG -s form takes, lives
123
- WDT Determiner, question which, whatever
124
- WP Pronoun, question who, whoever
125
- WPS Determiner, possessive & question whose
126
- WRB Adverb, question when, how, however
127
- PP Punctuation, sentence ender ., !, ?
128
- PPC Punctuation, comma ,
129
- PPD Punctuation, dollar sign $
130
- PPL Punctuation, quotation mark left ``
131
- PPR Punctuation, quotation mark right ''
132
- PPS Punctuation, colon, semicolon, elipsis :, ..., -
133
- LRB Punctuation, left bracket (, {, [
134
- RRB Punctuation, right bracket ), }, ]
99
+ | Tag | Part Of Speech | Examples |
100
+ |CC | Conjunction, coordinating | and, or |
101
+ | CD | Adjective, cardinal number | 3, fifteen |
102
+ | DET | Determiner | this, each, some |
103
+ |EX| Pronoun, existential there |there |
104
+ |FW| Foreign words ||
105
+ |IN| Preposition / Conjunction |for, of, although, that |
106
+ |JJ| Adjective |happy, bad |
107
+ |JJR| Adjective, comparative | happier, worse |
108
+ |JJS| Adjective, superlative | happiest, worst |
109
+ |LS| Symbol, list item |A, A. |
110
+ |MD| Verb, modal |can, could, 'll |
111
+ |NN| Noun |aircraft, data |
112
+ |NNP| Noun, proper | London, Michael |
113
+ |NNPS| Noun, proper, plural | Australians, Methodists |
114
+ |NNS| Noun, plural | women, books |
115
+ |PDT| Determiner, prequalifier | quite, all, half |
116
+ |POS| Possessive | 's, ' |
117
+ |PRP| Determiner, possessive second | mine, yours |
118
+ |PRPS| Determiner, possessive | their, your |
119
+ |RB| Adverb |often, not, very, here |
120
+ |RBR| Adverb, comparative | faster |
121
+ |RBS| Adverb, superlative | fastest |
122
+ |RP| Adverb, particle |up, off, out |
123
+ |SYM| Symbol | * |
124
+ |TO| Preposition |to |
125
+ |UH| Interjection |oh, yes, mmm |
126
+ |VB| Verb, infinitive |take, live |
127
+ |VBD| Verb, past tense | took, lived |
128
+ |VBG| Verb, gerund | taking, living |
129
+ |VBN| Verb, past/passive participle | taken, lived |
130
+ |VBP| Verb, base present form | take, live |
131
+ |VBZ| Verb, present 3SG -s form | takes, lives |
132
+ |WDT| Determiner, question | which, whatever |
133
+ |WP| Pronoun, question |who, whoever |
134
+ |WPS| Determiner, possessive & question | whose |
135
+ |WRB| Adverb, question | when, how, however |
136
+ |PP| Punctuation, sentence ender |., !, ? |
137
+ |PPC| Punctuation, comma | , |
138
+ |PPD| Punctuation, dollar sign | $ |
139
+ |PPL| Punctuation, quotation mark left | `` |
140
+ |PPR| Punctuation, quotation mark right | '' |
141
+ |PPS| Punctuation, colon, semicolon, elipsis| :, ..., - |
142
+ |LRB| Punctuation, left bracket | (, {, [ |
143
+ |RRB| Punctuation, right bracket | ), }, ] |
135
144
 
136
145
  h2. Roadmap
137
146
 
@@ -142,9 +151,13 @@ h2. Roadmap
142
151
  8 Tense switches
143
152
  9 Improve tests by:
144
153
  a Creating a sentence helper
145
- b Making a better Rspec match (more informative erros)
154
+ b Making a better Rspec matcher (more informative erros)
146
155
  c Automatically detecting the correct problem
147
- 11 Performance tests
156
+ 10 Desktop app
157
+ 11 Globalize spell check
158
+ 12 Most overused words
159
+ 13 Suggestions for synonyms
160
+ 14 Code overview screencast
148
161
 
149
162
  h2. Contributors
150
163
 
@@ -153,5 +166,5 @@ Robert Dooley, developer in Galway Western, Ireland
153
166
 
154
167
  h2. Licence
155
168
 
156
- Style is released under the "MIT license":www.opensource.org/licenses/MIT
169
+ Style-Scanner is released under the "MIT license":www.opensource.org/licenses/MIT
157
170
  Copyright "Jack Kinsella":www.jackkinsella.ie
@@ -1,2 +1,18 @@
1
- Making a cliché scanner is easier said than done. The devil is really in
2
- the details. We worked balls to the wall to get this working.
1
+ Many people think that working on your language style is unimporant.
2
+ I disagree. I prefer to use language instead of utilizing it.
3
+
4
+ Good communication is easier said than done. An important point in good English language usuage is using English instead of Latin or French. E.g. Outside of academic contexts where space is in short supply it sounds pretentious to write e.g. instead of for example.
5
+
6
+ I commonly make writing errors which can be spotted mechanically. For instance I have too much whitespace. I might might repeat a word
7
+ twice in a row, by accident. I may use a fantastic adjective twice in the same fanstastic sentence without knowing it. I might make mistakes
8
+ with capitalization, especially when I'm tired on a monday.
9
+
10
+ Sometimes I use words that add very little to a sentence. And sometimes sentences are written in a passive tense, robbing them of their verbal punch and concission.
11
+
12
+ Style-Scanner is my solution. It's far from finished, but I'd invite any
13
+ interested language hackers to participate.
14
+
15
+ Jack Kinsella
16
+ Founder Bolivian Express
17
+ Founder Oxbridge Notes
18
+ Twitter @jackkinsella
@@ -16,7 +16,7 @@ module StyleScanner
16
16
  end
17
17
 
18
18
  it "calls the scanner when cmd line called with a file" do
19
- %x(style '#{file}').should match "cliché"
19
+ %x(style-scanner '#{file}').should match "cliché"
20
20
  end
21
21
 
22
22
  it "works with HTML input" do
@@ -9,6 +9,8 @@ module StyleScanner
9
9
  let(:season) {Sentence.new("We travelled to England in the Summer.")}
10
10
  let(:month) {Sentence.new("We travelled to England in march.")}
11
11
  let(:uppercase_month) {Sentence.new("We travelled to England in March.")}
12
+ let(:may_month) {Sentence.new("Reaching deals with Indian bureaucrats and Chinese mandarins set to defend the interests and the data of their countries rapidly growing online firms may be downright impossible.")}
13
+ let(:may_verb) {Sentence.new "Reaching deals may be impossible."}
12
14
  let(:day) {Sentence.new "We arrive on wednesday"}
13
15
 
14
16
  it "catches lowercase months" do
@@ -26,6 +28,12 @@ module StyleScanner
26
28
  it "flags wrongly capitalized seasons" do
27
29
  should_problem season, Problems::Capitalization
28
30
  end
31
+ it "flags may month lowercase" do
32
+ should_problem may_month, Problems::Capitalization
33
+ end
34
+ it "does not flay may the verb" do
35
+ should_not_problem may_verb, Problems::Capitalization
36
+ end
29
37
  it "catches nationalities and languages" do
30
38
  should_problem nationality, Problems::Capitalization
31
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: style-scanner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-01 00:00:00.000000000 +01:00
13
- default_executable:
12
+ date: 2012-02-28 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: punkt-segmenter
17
- requirement: &2152642100 !ruby/object:Gem::Requirement
16
+ requirement: &2156771100 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2152642100
24
+ version_requirements: *2156771100
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: engtagger
28
- requirement: &2152641680 !ruby/object:Gem::Requirement
27
+ requirement: &2156724140 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: '0'
34
33
  type: :runtime
35
34
  prerelease: false
36
- version_requirements: *2152641680
35
+ version_requirements: *2156724140
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: colorize
39
- requirement: &2152641260 !ruby/object:Gem::Requirement
38
+ requirement: &2156722600 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: '0'
45
44
  type: :runtime
46
45
  prerelease: false
47
- version_requirements: *2152641260
46
+ version_requirements: *2156722600
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: sanitize
50
- requirement: &2152640780 !ruby/object:Gem::Requirement
49
+ requirement: &2156720920 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ! '>='
@@ -55,10 +54,10 @@ dependencies:
55
54
  version: '0'
56
55
  type: :runtime
57
56
  prerelease: false
58
- version_requirements: *2152640780
57
+ version_requirements: *2156720920
59
58
  - !ruby/object:Gem::Dependency
60
59
  name: trollop
61
- requirement: &2152640240 !ruby/object:Gem::Requirement
60
+ requirement: &2156720000 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
63
  - - ! '>='
@@ -66,10 +65,10 @@ dependencies:
66
65
  version: '0'
67
66
  type: :runtime
68
67
  prerelease: false
69
- version_requirements: *2152640240
68
+ version_requirements: *2156720000
70
69
  - !ruby/object:Gem::Dependency
71
70
  name: RedCloth
72
- requirement: &2152639800 !ruby/object:Gem::Requirement
71
+ requirement: &2156718700 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
74
  - - ! '>='
@@ -77,10 +76,10 @@ dependencies:
77
76
  version: '0'
78
77
  type: :runtime
79
78
  prerelease: false
80
- version_requirements: *2152639800
79
+ version_requirements: *2156718700
81
80
  - !ruby/object:Gem::Dependency
82
81
  name: rspec
83
- requirement: &2152639380 !ruby/object:Gem::Requirement
82
+ requirement: &2156717720 !ruby/object:Gem::Requirement
84
83
  none: false
85
84
  requirements:
86
85
  - - ! '>='
@@ -88,10 +87,10 @@ dependencies:
88
87
  version: '0'
89
88
  type: :development
90
89
  prerelease: false
91
- version_requirements: *2152639380
90
+ version_requirements: *2156717720
92
91
  - !ruby/object:Gem::Dependency
93
92
  name: rake
94
- requirement: &2152638940 !ruby/object:Gem::Requirement
93
+ requirement: &2156716680 !ruby/object:Gem::Requirement
95
94
  none: false
96
95
  requirements:
97
96
  - - ! '>='
@@ -99,10 +98,10 @@ dependencies:
99
98
  version: '0'
100
99
  type: :development
101
100
  prerelease: false
102
- version_requirements: *2152638940
101
+ version_requirements: *2156716680
103
102
  - !ruby/object:Gem::Dependency
104
103
  name: ruby-debug19
105
- requirement: &2152638480 !ruby/object:Gem::Requirement
104
+ requirement: &2156682120 !ruby/object:Gem::Requirement
106
105
  none: false
107
106
  requirements:
108
107
  - - ! '>='
@@ -110,10 +109,10 @@ dependencies:
110
109
  version: '0'
111
110
  type: :development
112
111
  prerelease: false
113
- version_requirements: *2152638480
112
+ version_requirements: *2156682120
114
113
  - !ruby/object:Gem::Dependency
115
114
  name: looksee
116
- requirement: &2152638060 !ruby/object:Gem::Requirement
115
+ requirement: &2156680820 !ruby/object:Gem::Requirement
117
116
  none: false
118
117
  requirements:
119
118
  - - ! '>='
@@ -121,10 +120,10 @@ dependencies:
121
120
  version: '0'
122
121
  type: :development
123
122
  prerelease: false
124
- version_requirements: *2152638060
123
+ version_requirements: *2156680820
125
124
  - !ruby/object:Gem::Dependency
126
125
  name: ruby-prof
127
- requirement: &2152637620 !ruby/object:Gem::Requirement
126
+ requirement: &2156680040 !ruby/object:Gem::Requirement
128
127
  none: false
129
128
  requirements:
130
129
  - - ! '>='
@@ -132,7 +131,7 @@ dependencies:
132
131
  version: '0'
133
132
  type: :development
134
133
  prerelease: false
135
- version_requirements: *2152637620
134
+ version_requirements: *2156680040
136
135
  description: Flag errors with your writing Style
137
136
  email:
138
137
  - jack.kinsella@gmail.com
@@ -208,7 +207,6 @@ files:
208
207
  - spec/tagged_word_spec.rb
209
208
  - spec/tagger_spec.rb
210
209
  - style-scanner.gemspec
211
- has_rdoc: true
212
210
  homepage: http://www.jackkinsella.ie
213
211
  licenses: []
214
212
  post_install_message:
@@ -221,15 +219,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
219
  - - ! '>='
222
220
  - !ruby/object:Gem::Version
223
221
  version: '0'
222
+ segments:
223
+ - 0
224
+ hash: 3022405515345769719
224
225
  required_rubygems_version: !ruby/object:Gem::Requirement
225
226
  none: false
226
227
  requirements:
227
228
  - - ! '>='
228
229
  - !ruby/object:Gem::Version
229
230
  version: '0'
231
+ segments:
232
+ - 0
233
+ hash: 3022405515345769719
230
234
  requirements: []
231
235
  rubyforge_project:
232
- rubygems_version: 1.6.2
236
+ rubygems_version: 1.8.15
233
237
  signing_key:
234
238
  specification_version: 3
235
239
  summary: ! 'Formal English Style Guide: Write more effectively'