style-scanner 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +19 -0
  2. data/.rspec +0 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/Rakefile +16 -0
  6. data/bin/style +11 -0
  7. data/lib/dictionaries/acronyms.txt +5 -0
  8. data/lib/dictionaries/cliches.txt +680 -0
  9. data/lib/dictionaries/nationalities.txt +185 -0
  10. data/lib/style_scanner/problems/base.rb +45 -0
  11. data/lib/style_scanner/scanner.rb +67 -0
  12. data/lib/style_scanner/sentence.rb +61 -0
  13. data/lib/style_scanner/sentence_scans/adverb.rb +19 -0
  14. data/lib/style_scanner/sentence_scans/base.rb +70 -0
  15. data/lib/style_scanner/sentence_scans/broken_link.rb +27 -0
  16. data/lib/style_scanner/sentence_scans/capitalization.rb +57 -0
  17. data/lib/style_scanner/sentence_scans/cliche.rb +21 -0
  18. data/lib/style_scanner/sentence_scans/consecutively_repeated_word.rb +22 -0
  19. data/lib/style_scanner/sentence_scans/excess_white_space.rb +22 -0
  20. data/lib/style_scanner/sentence_scans/inappropriate_contraction.rb +20 -0
  21. data/lib/style_scanner/sentence_scans/latin_abbreviation.rb +38 -0
  22. data/lib/style_scanner/sentence_scans/passive_tense.rb +32 -0
  23. data/lib/style_scanner/sentence_scans/speaking_in_generalities.rb +17 -0
  24. data/lib/style_scanner/sentence_scans/spelling.rb +22 -0
  25. data/lib/style_scanner/sentence_scans/ugly_word.rb +17 -0
  26. data/lib/style_scanner/sentence_scans/used_word_already_in_sentence.rb +29 -0
  27. data/lib/style_scanner/sentence_scans/useless_word.rb +17 -0
  28. data/lib/style_scanner/string.rb +33 -0
  29. data/lib/style_scanner/tagged_word.rb +58 -0
  30. data/lib/style_scanner/tagger.rb +25 -0
  31. data/lib/style_scanner/version.rb +3 -0
  32. data/lib/style_scanner.rb +17 -0
  33. data/readme.textile +157 -0
  34. data/spec/fixtures/sample_text.txt +2 -0
  35. data/spec/fixtures/stylish/economist/economist-1.txt +29 -0
  36. data/spec/fixtures/stylish/economist/economist-2.txt +21 -0
  37. data/spec/fixtures/stylish/economist/economist-3.txt +9 -0
  38. data/spec/fixtures/stylish/economist/economist-4.txt +23 -0
  39. data/spec/fixtures/stylish/economist/economist-5.txt +15 -0
  40. data/spec/fixtures/stylish/economist/economist-6.txt +37 -0
  41. data/spec/integrations/command_line_spec.rb +41 -0
  42. data/spec/problems/base_spec.rb +38 -0
  43. data/spec/scanner_spec.rb +41 -0
  44. data/spec/sentence_scans/adverb_spec.rb +13 -0
  45. data/spec/sentence_scans/base_spec.rb +18 -0
  46. data/spec/sentence_scans/broken_link_spec.rb +18 -0
  47. data/spec/sentence_scans/capitalization_spec.rb +44 -0
  48. data/spec/sentence_scans/cliche_spec.rb +35 -0
  49. data/spec/sentence_scans/consecutively_repeated_word_spec.rb +26 -0
  50. data/spec/sentence_scans/excess_white_space_spec.rb +22 -0
  51. data/spec/sentence_scans/inappropriate_contraction_spec.rb +21 -0
  52. data/spec/sentence_scans/latin_abbreviation_spec.rb +34 -0
  53. data/spec/sentence_scans/passive_tense_spec.rb +138 -0
  54. data/spec/sentence_scans/speaking_in_generalities_spec.rb +15 -0
  55. data/spec/sentence_scans/spelling_spec.rb +16 -0
  56. data/spec/sentence_scans/ugly_word_spec.rb +29 -0
  57. data/spec/sentence_scans/used_word_already_in_sentence.rb +21 -0
  58. data/spec/sentence_scans/useless_word_spec.rb +14 -0
  59. data/spec/sentence_spec.rb +76 -0
  60. data/spec/spec_helper.rb +26 -0
  61. data/spec/string_spec.rb +30 -0
  62. data/spec/tagged_word_spec.rb +35 -0
  63. data/spec/tagger_spec.rb +14 -0
  64. data/style-scanner.gemspec +30 -0
  65. metadata +263 -0
@@ -0,0 +1,17 @@
1
+ module StyleScanner
2
+ module SentenceScans
3
+ class SpeakingInGeneralities < Base
4
+
5
+ GENERAL_WORDS = ["many", "various", "mostly", "largely",
6
+ "huge", "a number", "significantly", "substantially",
7
+ "vast", "relatively", "completely"]
8
+
9
+ def scan
10
+ GENERAL_WORDS.each do |useless_word|
11
+ create_problem(useless_word) if sentence.contains?(useless_word)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,22 @@
1
+ module StyleScanner
2
+ module SentenceScans
3
+ class Spelling < Base
4
+ # notice the way you don't give hunspell any specific file so much
5
+ # as the name both the aff and dic file use
6
+ DICTIONARY = File.expand_path("../../../dictionaries/en_US", __FILE__)
7
+
8
+ def scan
9
+ mispellings.each do |mispelled_word|
10
+ create_problem(mispelled_word)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def mispellings
17
+ `echo '#{sentence.text}' | hunspell -l -d #{DICTIONARY}`.split("\n")
18
+ end
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,17 @@
1
+ module StyleScanner
2
+ module SentenceScans
3
+ class UglyWord < Base
4
+
5
+ WORD_PAIRS= {"utilize" => "use", "necessitate" => "require", "leverage" => "use", "aforementioned" => "previous",
6
+ "transpire" => "happen", "thusly" => "thus", "whilst" => "while", "tackle" => "solve"}
7
+
8
+ def scan
9
+ WORD_PAIRS.keys.each do |offender|
10
+ create_problem(replacement_word(offender)) if sentence.contains?(offender)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,29 @@
1
+ module StyleScanner
2
+ module SentenceScans
3
+ class UsedWordAlreadyInSentence < Base
4
+
5
+ def scan
6
+ repeated_words.each do |repeated_word|
7
+ create_problem(repeated_word.word)
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def repeated_words
14
+ words.select do |word|
15
+ appears_more_than_twice(word) && word.non_structural? && appears_non_consecutively(word.tokenized)
16
+ end.uniq
17
+ end
18
+
19
+ def appears_more_than_twice(word)
20
+ tokenized_words.count(word.tokenized) >= 2
21
+ end
22
+
23
+ def appears_non_consecutively(word)
24
+ tokenized_words[tokenized_words.index(word) + 1] != word
25
+ end
26
+
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ module StyleScanner
2
+ module SentenceScans
3
+ class UselessWord < Base
4
+
5
+ USELESS_WORDS = ["extremely", "exceedingly", "quite",
6
+ "remarkably", "surprisingly", "interestingly", "clearly",
7
+ "very", "pretty" "fairly", "really"]
8
+
9
+ def scan
10
+ USELESS_WORDS.each do |useless_word|
11
+ create_problem(useless_word) if sentence.contains?(useless_word)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,33 @@
1
+ module StyleScanner
2
+ # Module is used to help people trace where the monkey patched methods came from http://olabini.com/blog/2011/01/safeer-monkey-patching/
3
+ module StringExtensions
4
+
5
+ def strip_punctuation
6
+ gsub(/[^a-zA-Z0-9\-\s]/, "").gsub(/\s{2,}/, " ")
7
+ end
8
+
9
+ def stem_verbs
10
+ strip_punctuation.split.map do |word|
11
+ is_a_verb?(word) ? word.stem : word
12
+ end.join(" ")
13
+ end
14
+
15
+ def titlecase
16
+ scan(/[A-Z][a-z]*/).join(" ")
17
+ end
18
+
19
+ private
20
+
21
+ def is_a_verb?(word)
22
+ tag(word).start_with?("V")
23
+ end
24
+
25
+ def tag(word)
26
+ Tagger.new(self).tagged_words.find {|tagged_word| tagged_word.word == word}.tag
27
+ rescue NoMethodError
28
+ "Unknown"
29
+ end
30
+
31
+ end
32
+ ::String.send :include, StringExtensions
33
+ end
@@ -0,0 +1,58 @@
1
+ module StyleScanner
2
+ class TaggedWord
3
+ #TODO add tests for all the new methods added here.
4
+
5
+ STRUCTURAL_TAGS = %{
6
+ WRB WPS WP WDT UH TO SYM PRPS CC DET EX IN LS PDT POS PRP PRPS
7
+ }
8
+
9
+ attr_reader :tag, :word
10
+
11
+ def initialize(tag, word)
12
+ @tag = tag.upcase
13
+ @word = word
14
+ end
15
+
16
+ def tokenized
17
+ word.downcase.gsub(/\W/, "")
18
+ end
19
+
20
+ def adverb?
21
+ tag.start_with?("RB")
22
+ end
23
+
24
+ def preposition?
25
+ tag.start_with?("IN")
26
+ end
27
+
28
+ def determiner?
29
+ tag.start_with?("DET")
30
+ end
31
+
32
+ def non_structural?
33
+ ! STRUCTURAL_TAGS.include?(tag)
34
+ end
35
+
36
+ def possessive?
37
+ ["POS", "PRP", "PRPS"].include?(tag)
38
+ end
39
+
40
+ def noun?
41
+ tag.start_with?("NN")
42
+ end
43
+
44
+ def be_verb?
45
+ verb? && ["is", "was", "been", "be"].include?(tokenized)
46
+ end
47
+
48
+ def verb?
49
+ tag.start_with?("V")
50
+ end
51
+
52
+ # Gerund verb = ING verb
53
+ def gerund_verb?
54
+ tag == "VBG" && tokenized != "being"
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ module StyleScanner
2
+ class Tagger
3
+
4
+ attr_reader :input_text
5
+
6
+ def initialize(input_text)
7
+ @input_text = input_text
8
+ end
9
+
10
+ def tagged_words
11
+ Tagger.parts_of_speech_tagger.
12
+ add_tags(input_text).
13
+ scan(/\<(?<tag>\w+)>(?<text>[^(<\)]+)</).
14
+ map {|tag, word| TaggedWord.new(tag,word)}
15
+ end
16
+
17
+ class << self
18
+ # load once since there is a high initialization cost
19
+ def parts_of_speech_tagger
20
+ @eng_tagger ||= EngTagger.new
21
+ end
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module StyleScanner
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,17 @@
1
+ # Ruby core dependencies
2
+ require "net/http"
3
+ require "forwardable"
4
+
5
+ # External dependencies
6
+ require "punkt-segmenter"
7
+ require 'colorize'
8
+ require "engtagger"
9
+ require "sanitize"
10
+ require 'redcloth'
11
+ require 'trollop'
12
+
13
+ require "style/problems/base"
14
+ require "style/sentence_scans/base"
15
+ Dir[File.dirname(__FILE__) + '/**/*.rb'].each do |file|
16
+ require file
17
+ end
data/readme.textile ADDED
@@ -0,0 +1,157 @@
1
+ h1. Style
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:
4
+
5
+ * *Use of 600 different clichés*
6
+ He pushed the envelope
7
+ * *Use of 11 different forms of passive tense.*
8
+ The letter was sent
9
+ * *Broken links*
10
+ http://www.thiswebsite404s.com
11
+ * *Ugly words*
12
+ The government utilized the resources.
13
+ * *Speaking in generalities*
14
+ Many people think that
15
+ * *Useless words*
16
+ It was a very fast app.
17
+ * *Repeating the same non structural word within a sentence*
18
+ Trask makes an excellent point, forcefully and with taste, in his excellent work 'Mind The Gaffe'
19
+ * *Using latin abbreviations within your text*
20
+ E.g.
21
+ * *Spelling mistakes*
22
+ addd
23
+ * *Repeating the same word consecutively*
24
+ We went to the the shopping centre.
25
+ * *Excess white space*
26
+ We went to the shopping centre.
27
+
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._
29
+
30
+ h2. Installation
31
+
32
+ Install Style using Ruby gems:
33
+
34
+ @gem install style@
35
+
36
+ Next install Hunspell, an open source spell-checker that Style depends upon.
37
+
38
+ @brew install hunspell@
39
+
40
+ h2. Usage
41
+
42
+ Style is command line only. Cd into the directory with the files you'd like to scan, then type
43
+
44
+ @style filename@
45
+
46
+ After a few seconds Style will print a list problems it finds.
47
+
48
+ Style is pipe friendly.
49
+
50
+ @cat filename | style@
51
+
52
+ See all command line options
53
+
54
+ @style -h@
55
+
56
+ By default some scans, such as the Adverb scan, are turned off. Use command line options to enable them.
57
+
58
+ @style -a filename@ #scan for adverbs
59
+
60
+ Scan HTML files
61
+ @style filename.html --help@
62
+
63
+ Scan Textile files
64
+ @style filename.html -t@
65
+
66
+ h2. Dependencies
67
+
68
+ h3. Gems
69
+
70
+ "punkt-segmenter":https://github.com/lfcipriani/punkt-segmenter
71
+ Splits text into sentences.
72
+
73
+ "colorize":https://github.com/fazibear/colorize
74
+ Formats terminal output in red,green and other colours.
75
+
76
+ "entagger":http://engtagger.rubyforge.org/
77
+ Assigns parts of speech tags to English text based on a lookup dictionary and a set of probability values.
78
+
79
+ h3. Other
80
+
81
+ "Hunspell":http://hunspell.sourceforge.net/
82
+ An open source spell checker used by Open Office, Mozilla Firefox and Google Chrome.
83
+
84
+ h2. Contributing
85
+
86
+ Contribution is welcomed and encouraged, although no modifications will be accepted if they are not accompanied by passing tests.
87
+
88
+ h3. Parts of Speech
89
+
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 ), }, ]
135
+
136
+ h2. Roadmap
137
+
138
+ 1 Add more acronyms
139
+ 2 Refactor the collection methods.
140
+ 4 More useless words.
141
+ 5 Troublesome words from Stunk.
142
+ 8 Tense switches
143
+ 9 Improve tests by:
144
+ a Creating a sentence helper
145
+ b Making a better Rspec match (more informative erros)
146
+ c Automatically detecting the correct problem
147
+ 11 Performance tests
148
+
149
+ h2. Contributors
150
+
151
+ Jack Kinsella
152
+ Robert Dooley, developer in Galway Western, Ireland
153
+
154
+ h2. Licence
155
+
156
+ Style is released under the "MIT license":www.opensource.org/licenses/MIT
157
+ Copyright "Jack Kinsella":www.jackkinsella.ie
@@ -0,0 +1,2 @@
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.
@@ -0,0 +1,29 @@
1
+ BY THE standards of past summits, European leaders finished early—shortly before 10pm on January 30th. And by the acrimonious standards of past gatherings, notably last month’s bust-up with Britain, this event was uneventful, even amicable. Agreement was reached on the fiscal compact, the new treaty to toughen budget rules, in record time: less than two months.
2
+
3
+ A final row between France and Poland over who gets to attend which summits was resolved with a complicated compromise. This involves variable configurations of meetings involving 17 countries (the euro zone), 23 (the largely-forgotten Euro-Plus Pact, 25 (the signatories of the fiscal compact), 27 (all EU member states, still in charge of the single market) and 28 (involving soon-to-join Croatia).
4
+
5
+ It shows that, at the very least, European leaders can negotiate rapidly when they have the political will to do so—and when the British and the Czechs decide to step aside. Whether electorates will be quite so quick to shackle themselves to Germanic fiscal rules is another matter.
6
+
7
+ But did the leaders achieve anything useful to stem the crisis in the latest of their interminable summits? Their compact—now called the “treaty on stability, co-ordination and governance in the Economic and Monetary Union”, has as its main aim the imposition of balanced-budget rules on members. This may be a useful discipline in good times. But many worry that, at a time of widespread crisis, such pro-cyclical rules risk imposing too much austerity too widely, thus darkening the spectre of recession and making it even harder to balance budgets. This may explain why leaders suddenly want to be seen talking about their plan (declaration is here in PDF) for growth and jobs, particularly in tackling the problem of youth unemployment.
8
+
9
+ Nevertheless, Angela Merkel, the German chancellor who had pushed hard for the treaty, hailed it as a great success. Many others, however, dismiss the compact with so much faint praise. “It is an important distraction”, says one diplomat. “It has gone from damaging to merely useless,” says a member of the European Parliament. Even Mario Monti, these days everybody’s favourite Italian, judged the compact little more than “a decorative songbird”.
10
+
11
+ By contrast the two issues that could affect the course of the euro-zone debt crisis in the coming weeks—the fate of Greece and the possibility of creating a bigger firewall—were for the most part ignored or relegated to side-meetings. With Greece and its private creditors still negotiating the scale of haircuts to be imposed on bondholders, this may have been too delicate a time for leaders to discuss Greece. A statement from the euro zone says little that is new.
12
+
13
+ Moreover, Mrs Merkel was keen to dampen emotions after her officials floated the idea of placing the country under a commissar with the power to reject Greek budgets. When asked about such a prospect, Mrs Merkel expressed “frustration” with Greece’s lack of compliance with its austerity-and-reform programme, but backed away from imposing such a draconian loss of sovereignty on Greece. President Nicolas Sarkozy of France, for his part, said "there is no question of placing Greece under tutelage.”
14
+
15
+ All leaders of the euro zone are insisting that forcing private creditors to take a hit on Greek bonds constitutes a “unique” event, for fear of causing contagion. But spreads on Portuguese bonds are rising to alarming levels, and the outlook for Italy and Spain is still wobbly.
16
+
17
+ “An inability to tackle a problem the size of Greece inspires little confidence in the ability of the EU to tackle Italy and Spain,” says Sony Kapoor, head of Re-Define, a financial think-tank in Brussels.
18
+
19
+ Germany parried demands, from Mr Monti and others, to enlarge the firewall by merging the existing temporary European Financial Stability Facility (EFSF) and the permanent new European Stability Mechanism (ESM). This would enlarge the fund from €500 billion ($659 billion) to €750 billion. Mrs Merkel said the matter should be discussed in March, as decided in last December’s summit.
20
+
21
+ The British have decided not to be awkward about the compact, despite the falling-out at the previous summit, where Britain threatened to veto a change to the EU’s treaties unless it were able to secure greater protection from financial-services legislation. The stalemate forced the other 26 countries to negotiate the compact outside the EU treaties (with Britain sitting in as an observer).
22
+
23
+ Mr Cameron is under pressure from Eurosceptic backbenchers to wage legal warfare to prevent signatories to the pact from using EU institutions, such as the European Commission and the European Court of Justice. “We will only take action if our national interests are threatened. And I made clear today that we will be watching this closely,” said Mr Cameron.
24
+
25
+ Nevertheless, Mr Sarkozy and Mr Cameron are still sparring. The French president’s barb in a television interview a day earlier, when he mockingly said that Britain had “no industry left”, prompted Mr Cameron to rattle off a list of great British car companies—among them Honda, Toyota and Nissan (all Japanese). He said he relished the prospect of French banks moving operations across the Channel to London if Mr Sarkozy pressed ahead with his promise to impose a tax on financial transactions unilaterally.
26
+
27
+ Perhaps the most interesting dynamic was between France and Germany ahead of the French presidential elections in April and May. Mrs Merkel said that she would campaign for the re-election of Mr Sarkozy, saying he had done the same for her in the past. But she said she would not be worried if his opponent, François Hollande, who is leading opinion polls, were to win—even though he wants to renegotiate the fiscal compact and has blocked Mr Sarkozy’s attempt to enshrine a golden rule in the constitution.
28
+
29
+ Asked if she could envisage having to take France to court for failure to adopt a balanced-budget rule, as provided for by the compact, Mrs Merkel said: “I cannot imagine taking legal action against France because I cannot imagine that France will not institute a golden rule.”
@@ -0,0 +1,21 @@
1
+ GREECE, progenitor of the euro zone’s debt drama, is back at centre-stage. The reason is a battle between the Greek government, its European and IMF rescuers, and the holders of Greek bonds over the terms of a “voluntary” reduction in its private debts. Greece’s economy is in far worse shape than when the outlines of a deal were put together last October, so there is a bigger financial hole to plug. Germany and other rescuers don’t want to offer more money, not least because Greece’s politicians have broken so many of the promises they made to reform. Bondholders don’t want to take a bigger hit.
2
+
3
+
4
+ If no deal is in place by March 20th, when a big bond payment is due, Greece will be pushed into a chaotic default, which would increase the risk that the country is forced out of the euro. That is a frightening prospect. The ensuing chaos and contagion could fell the single currency, not least because Europe’s governments have made little progress on building a “firewall” around countries like Italy and Spain.
5
+
6
+ What is the best way out of this mess? Step one is to force private bondholders to take more losses. They have been treated with kid gloves so far because European governments insist the debt deal must be voluntary, thanks in part to a misplaced fear of triggering credit-default swaps. That must change. Discard the veneer of voluntarism and Greece can be tougher on its creditors. It should pass a law that retroactively introduces collective-action clauses into all domestic-debt contracts (making it easier to impose debt deals on recalcitrant bondholders). If it does this now there is still, just, enough time to organise a big, coercive, but orderly, restructuring of Greek bonds by March 20th.
7
+
8
+ That is the route this newspaper has long advocated. A year ago it would have gone a long way towards solving Greece’s problems. Unfortunately, today it is no longer enough. The economy is in such a state, with slumping output and a still-gaping budget deficit, that there is no realistic prospect of reducing its debts to a sustainable level by hitting private bondholders alone. Debts owed to official bodies—from the bonds held by the European Central Bank to the loans from euro-zone governments—will at some point need to be reduced too.
9
+
10
+ Greece will need propping up for a long time. Virtually no progress has been made in overhauling the economy. Although wages have fallen slightly, the country remains chronically uncompetitive (see article). Greece’s rescuers bear some blame: they focused too much on raising taxes and too little on reforming the state and freeing up the economy. But the real culprit is the Greek government, which has proved singularly incapable of implementing the reforms needed to allow the economy to grow.
11
+
12
+ Explore our interactive guide to Europe's troubled economies
13
+ With so little to show for the efforts so far, would it be better for Greece and its European creditors if the country simply left the single currency? If Greece had its own currency, devaluing it would surely be part of the route to greater competitiveness. And leaving the euro might just be the shock Greece’s political system needs to galvanise reform.
14
+
15
+ Yet the costs of a Greek exit still outweigh the benefits. Recreating a currency is far harder than devaluing an existing one. Some industries, such as tourism, would eventually benefit, but in the short term jettisoning the euro would cause devastating disruption. The legal mess of broken contracts it would create would take years to sort out. Greece could face hyperinflation and become a failed state. Not surprisingly, a large majority of Greeks want to keep the euro.
16
+
17
+ Playing for time
18
+
19
+ For the rest of Europe, a Greek exit would also be dangerous: it could cause bank runs, capital flight and soaring bond yields in Portugal, Italy and beyond. But over time the balance of risks will change. Once a tough debt restructuring has been imposed on Greece’s private creditors, the country’s fate will have less impact on other bond markets. As reforms in Italy and Spain gain momentum, the distinctions between Greece and others will become clearer. And over the coming months European leaders, with luck, will agree on a permanent way to boost their rescue funds. All this would make the spectre of a Greek exit much less frightening for the rest of the euro zone.
20
+
21
+ Greece’s European rescuers should offer the country a clear choice. If it embraces tough reforms, it will get fresh funds and a gradual reduction of its official debts. But if it continues its current path of inaction, it may not be able to avoid an exit. As the costs to others of a Greek departure from the euro fall, so that threat will become more credible.
@@ -0,0 +1,9 @@
1
+ THE breezy hilltop resort of Zabadani is usually occupied by rich Syrians in second homes and Gulf tourists enjoying the picturesque mountains on the Lebanese border. But for much of January the town of some 40,000 people has been a rebel enclave. After several days of fighting by daring but lightly armed opposition forces, the army, equipped with tanks and heavy weaponry, was forced to pull back on January 18th. Residents hailed their “liberated city” and hung pictures of the dead in a tree. They waved placards and shouted slogans ridiculing the regime. Civilians guarded checkpoints usually manned by the security forces.
2
+
3
+ Zabadani is not the first place in Syria to experience a brief taste of freedom over the past ten months. Last year Mr Assad’s forces temporarily lost control to the opposition in Hama, the country’s fourth-largest city. Rastan and Tel Kalakh, two small towns close to Homs, have at times barricaded themselves in. Parts of Homs, the third-largest city, and villages near Idleb have also enjoyed a measure of autonomy.
4
+
5
+ But Zabadani is much closer to Damascus, the capital, than any of them—about 25 miles (40km). The fight for control of the country is no longer taking place far from the centre of power. Just days after Zabadani was liberated, armed clashes erupted in Douma, a suburb six miles from Damascus. Army defectors seized control of the town for a few hours.
6
+
7
+ Reports of firefights are no longer rare in what was once a peaceful capital. Two large car bombs exploded in front of a security-services’ building on December 23rd. It was followed by another one in a residential area a fortnight later. Few Syrians now dare to drive on the country’s main artery, the highway from the capital north to Aleppo, a commercial hub, fearing ambushes on the road. Military buses and oil pipelines are often hit by explosions. Who is responsible is hard to know. “There is so much going on that it gives the feeling that everything is starting to unravel,” says a Western diplomat in Damascus.
8
+
9
+ A year ago Syria could call itself the safest country in the region. But since the start of the uprising in March, the regime has presided over rising violence. It appears readier than ever now to employ heavy weapons and kill indiscriminately.
@@ -0,0 +1,23 @@
1
+ THE public has never loved the way that private-equity titans make a buck—or billions. But now that Mitt Romney’s career at Bain Capital, a buy-out firm, is fodder for his Republican rivals, it has become fashionable to demonise private equity as “vulture” capitalism and “worse than Wall Street”. Do Mr Romney and his ilk deserve such opprobrium?
2
+
3
+ Two charges are generally made against private equity. The first is that it plunders companies and slashes jobs. The other, underscored this week when Mr Romney released his tax returns, is that private-equity executives are obscenely rich in part because they do not pay enough tax.
4
+
5
+ Private-equity firms claim to make money by taking over poorly managed companies, improving their performance and selling them on. Often that involves cutting jobs. At a time when American unemployment is stuck at a worryingly high level, this has made private-equity firms a target for anger from both Republicans and Democrats.
6
+
7
+ Yet the direct employment losses that result from private-equity deals are not as large as critics claim: on average employment declines by only 1% two years after a buy-out, once the jobs created at new facilities are counted. Such shifts in employment are part of the creative destruction that invigorates the economy, and if private equity hurries the process along, that is all to the good. The evidence suggests that it does. Private-equity buy-outs tend to increase productivity—by around 2%, on average, according to one academic study. If firms become more efficient, the economy works better. Resources will be reallocated where they can better be used.
8
+
9
+ Debt in, dividends out
10
+
11
+ Critics are on stronger ground when they complain that private-equity firms burdened companies with debt, took the cash out as dividends and sometimes drove them to the wall. Bankruptcy was not the intention nor, in the great majority of cases, was it the outcome. But as the price of debt fell, that pattern became increasingly common. From 2004 to 2011 private-equity firms piled more debt onto their companies so they could take out $188 billion in dividends to pay themselves. The deals got bigger and bigger. The largest ever, in 2007, was the $44 billion purchase of TXU, an electricity company. The market worries the company will go under.
12
+
13
+ But though the private-equity people may have walked off with the loot, America’s tax code was partly to blame, because it encourages this behaviour. The tax deductibility of interest payments on debt gives private-equity executives an incentive to pile extra debt onto the companies they buy, thereby risking the health of these firms for the sake of a tax benefit and the prospect of higher returns.
14
+
15
+ There is another way in which the tax code is responsible for allowing private-equity types to walk off with vast bounties. Their profits, called “carried interest”, are taxed as capital gains, which incur a lower rate than income does. People who work in the business maintain that carried interest is investment income, but most of the capital at risk is that of investors, not their own.
16
+
17
+ Politicians in America and Britain, who have been debating this loophole since 2007, should close it. Carried interest is really a bonus and should be taxed like one.
18
+
19
+ There is a third charge against private equity, to which the industry’s critics have paid little attention. It relates to the returns the industry delivers: investors have more reason to complain about private equity than do voters.
20
+
21
+ The industry has seduced investors with the promise of outstanding returns. But there is no clear evidence that private equity outperforms public markets (see article). Once the exorbitant fees are taken into account, returns look much less impressive than the industry’s promoters claim, and than an illiquid, leveraged and long-duration investment would warrant.
22
+
23
+ Looking ahead, returns are likely to be even worse. Buy-out executives themselves admit that performance will be more ordinary in future, since debt, which powered private-equity firms’ profits, won’t quickly return to pre-crisis levels. The performance of funds which did well in the bubble era is likely to be unimpressive in tighter times. Public pensions, which provide more than a quarter of buy-out firms’ assets, should take note as they choose their future investments.
@@ -0,0 +1,15 @@
1
+ JAPAN holds the modern record for years spent with interest rates at zero; they were on the floor from 2001 to 2006. America is on track to break that record. Having cut its short-term rate to near zero in late 2008, the Federal Reserve said on January 25th it will probably stay there “at least through late 2014”, more than a year longer than its previous guidance.
2
+
3
+ On the same day the Fed for the first time published projections of the year individual members of the Federal Open Market Committee, its main policymaking body, expect the federal-funds rate to start rising and the path it would follow over the next three years. The median forecast for a rise in interest rates is 2014 (see chart) but the accompanying statement implies it will probably be later.
4
+
5
+ The Fed also took the long-awaited step of announcing an explicit inflation target—something that many other central banks adopted years ago and that the Fed chairman, Ben Bernanke, has long advocated. The central bank said it prefers inflation of 2%, also the target (or the midpoint in a target range) of the British, Canadian, Swedish and Israeli central banks.
6
+
7
+ Mr Bernanke characterised these steps as a way to make monetary policy more transparent and predictable, and therefore more effective. But the practical consideration is that the Fed needs new ways to kick-start economic growth. Promising lower rates for longer is one way to do this, because it will drive bond yields lower.
8
+
9
+ Some officials have argued that the Fed could better steer private-sector expectations with a framework that more explicitly committed it to lower unemployment or higher output. The Fed did not go that far but the inflation target (a word the Fed’s official documents didn’t use but Mr Bernanke did in a subsequent press conference) will help in two ways.
10
+
11
+ First, 2% is at the high end of the range that officials previously considered acceptable. Higher inflation implies lower, and thus more stimulative, real interest rates. Second, markets previously thought the Fed was so focused on inflation that it would tighten as soon as it topped 2%, no matter how high unemployment was. Mr Bernanke dispelled that notion by emphasising the Fed’s equal attention to unemployment. Should inflation overshoot 2% while the economy is unacceptably weak, the Fed will take its time about bringing it back down.
12
+
13
+ The increased transparency is helping. Since the Fed committed itself in August to two years of near-zero rates, the ten-year Treasury yield has fluctuated around 2% despite a run of better-than-expected economic news. The yield dropped on news of the Fed’s new projections, before rising back up again.
14
+
15
+ But this flurry of activity still may not be enough. The Fed actually lowered its projections for economic growth to between 2.2% and 2.7% in 2012; it projects growth of 2.8-3.2% in 2013. Unemployment, now 8.5%, is seen edging below 8% only by the end of 2013. Inflation, meanwhile, will be at or below the new target of 2%. With unemployment too high and inflation still weak, more monetary stimulus is easily justified. Mr Bernanke left the door open to that option. The odds are that he will walk through it.
@@ -0,0 +1,37 @@
1
+ FIRST came the yodelling, then the pain. The online entrepreneurs and venture capitalists at DLD, a geeks’ shindig this month in Munich, barely had time to recover from their traditional Bavarian entertainment before Viviane Reding, the European Union’s justice commissioner, introduced a new privacy regulation. Ms Reding termed personal data the “currency” of the digital economy. “And like any currency it needs stability and trust,” Ms Reding told the assembled digerati.
2
+
3
+ The EU’s effort (formally published on January 25th) is part of a global government crackdown on the commercial use of personal information. A White House report, out soon, is expected to advocate a consumer-privacy law. China has issued several draft guidelines on the issue and India has a privacy bill in the works. But their approaches differ dramatically. As data whizz across borders, creating workable rules for business out of varying national standards will be hard.
4
+
5
+ Europe’s new privacy regulation is one of the most sweeping. Its first goal is to build a “digital single market”. That will be a welcome change from the patchwork of rules that has grown up since the previous privacy directive in 1995. When Google’s Street View mapping service accidentally captured personal data from some open, unsecured Wi-Fi networks in the houses it photographed, some EU countries told the firm to delete the data. Others told it to hold the information indefinitely.
6
+
7
+ The Commission hopes that when the new regulation comes into effect (probably in 2016) it will clear up this mess. A firm based in, say, Ireland will be able to obey Irish law and do business across the EU, without worrying whether it is in line with other countries’ rules. A new European Data Protection Board will enforce the regime. And if a company faces judicial proceedings in two member states, the courts will be obliged to communicate. Ms Reding expects these changes to save business €2.3 billion ($3 billion) a year.
8
+
9
+ But the new regime is tougher as well as being uniform. Firms must gain proper consent (defined strictly) before using and processing data. They may collect no more information than is necessary and keep it only while they need it. Children’s data gain extra safeguards. Users must be able to move information from one service provider to another (for example, an address book between two social networks).
10
+
11
+ The EU’s 500m residents will also win a brand new right: to be forgotten. Users can not only request that a company show what data it holds on them; they can also demand that it deletes all copies. Critics say this is impractical, vague, and over-ambitious. It is hard to say where one man’s data end and another’s begin. And once something is online, it is virtually impossible to ensure that all copies are deleted. Small firms will struggle; even big ones will find the planned penalties steep.
12
+
13
+ Even more contentiously, the directive covers any firm that does business with Europeans, even if it is based outside the EU. America’s Department of Commerce sent the Commission a strong 15-page protest, saying that the directive “could hinder commercial interoperability while unintentionally diminishing consumer privacy protection”.
14
+
15
+ An ocean of data
16
+
17
+ That stance reflects differences in American and European attitudes towards data protection, and indeed to regulation in general. America has avoided overly prescriptive privacy legislation, believing that companies should generally regulate themselves. Only when firms fail at self-regulation does the Federal Trade Commission (FTC) step in. It has broad powers to tackle unfair and deceptive practices, and has not hesitated to use them. In recent rulings, Google and Facebook agreed to a biennial audit of their privacy policies and practices for the next 20 years.
18
+
19
+ European sensitivities are different. A Eurobarometer poll last year found that 62% of Europeans do not trust internet companies to protect their personal information. A big reason is history. In the 1930s Dutch officials compiled an impressive national registry. This later enabled the Nazis to identify 73% of Dutch Jews, compared with just 25% in less efficient France, notes Viktor Mayer-Schönberger of Oxford University in his book “Delete: The Virtue of Forgetting in the Digital Age”.
20
+
21
+ For the global digital economy, differences in privacy laws are a kind of trade barrier and a costly brake on innovation. In the past Europe and America reached a compromise with the “safe harbour” framework of 2000. As long as American companies adhered to certain principles based on the 1995 directive, they could do business in the EU.
22
+
23
+ The arrangement has worked well, but America now worries that when its new rules come in the EU may want to rejig the deal. America might have more bargaining power if it had its own privacy law on the statute books, some experts argue; in any case public concern about data protection is growing there. On January 24th Google triggered an outcry when it announced that from March it will share data gleaned from people logged into any of its services with all of its businesses, whether those users like it or not.
24
+
25
+ The administration is hurrying to catch up. In its report, the White House will recommend a legal framework for privacy, plus new codes of conduct. The chances of legislation passing in an election year are slim, even on what is usually a bipartisan issue. Talks among business lobbies, privacy activists and regulators may at least produce non-statutory codes, though without the imminent threat of legislation some companies may dawdle.
26
+
27
+ The FTC will also release a privacy report later this year. This will look broadly at the use of personal data being scooped up by companies on- and offline. Among other things, it is likely to applaud progress in letting internet users take steps to block tracking by tweaking their web browsers. It will probably support a tougher regime for brokers of consumer data, and an industry initiative to give web pages special icons that people can use to prevent firms from tracking their activity.
28
+
29
+ America and Europe will set the global standards. But other countries’ privacy rules matter too. China and India will soon have more people online than Europe and America have citizens. Neither Asian country has yet passed formal national legislation, but both are considering it—with every indication that their new laws will outdo even Europe in their severity.
30
+
31
+ India’s draft privacy bill will set up a data-protection authority, call for consent before personal data can be processed, and create a formal “right to privacy”. Critics say the bill is too broad and that clauses protecting an individual’s “honour and good name” could be used for censorship.
32
+
33
+ China’s draft Personal Information Protection Law was proposed in 2003, but has since languished, leading to both regional experimentation and some big ad hoc rulings from ministries. The resulting hotch-potch leaves businesses and consumers confused. But in January 2011 the Ministry of Industry and Information Technology issued draft rules on data protection that restrict the ability of organisations to transfer personal data without specific prior informed consent.
34
+
35
+ These define personal information broadly, as anything that can identify an individual either on its own, or in combination with other data. They also appear to forbid the export of personal information—even, on one reading, from one division of a company to another. That could hamper multinationals which need to send data across national borders. And it could hit outsourcers trying to deal with their customers. A further danger is that China’s regulations are often arbitrarily or selectively enforced. Some information-processing firms are said to have moved their operations to Hong Kong, which has laxer and more predictable rules.
36
+
37
+ Building a single European data-protection regime is hard enough. Harmonising it smoothly with America will be harder. 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. Welcome to the new world of data geopolitics
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ require "spec_helper"
3
+ module StyleScanner
4
+ describe "Command Line Interface" do
5
+
6
+ let(:text) {"Tom hit the dlog."}
7
+ let(:adverb_text) {"I talked quietly to the floor."}
8
+ let(:html) {"<div id='dlog'><p> Tom hit the dog. </p></div>"}
9
+ let(:textile) {"!/images/dlog.png! Tom hit the dog. "}
10
+ let(:file) {Dir.pwd + "/spec/fixtures/sample_text.txt"}
11
+ let(:scanner) {double(:scanner)}
12
+
13
+ it "calls the scanner when cmd line called with an echoed sentence" do
14
+ # mispelling error should show
15
+ %x(echo '#{text}' | style -s).should match "dlog"
16
+ end
17
+
18
+ it "calls the scanner when cmd line called with a file" do
19
+ %x(style '#{file}').should match "cliché"
20
+ end
21
+
22
+ it "works with HTML input" do
23
+ # mispelling in html should not show if stripper properly
24
+ %x(echo '#{html}' | style -h -s).should_not match "dlog"
25
+ end
26
+
27
+ it "doesn't do adverbs by default" do
28
+ %x(echo '#{adverb_text}' | style).should_not match "quietly"
29
+ end
30
+
31
+ it "can turn on adverbs as needed using command line options" do
32
+ %x(echo '#{adverb_text}' | style -a).should match "quietly"
33
+ end
34
+
35
+ it "works with Textile input" do
36
+ # this test works because the software will visit the image link if the html is not stripped
37
+ %x(echo '#{textile}' | style -t -s).should_not match "dlog"
38
+ end
39
+
40
+ end
41
+ end