clausewitz-spelling 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.rspec_status +4 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +6 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/clausewitz-spelling.gemspec +32 -0
- data/exe/clausewitz-spellcheck +36 -0
- data/lib/clausewitz/spelling/checker.rb +184 -0
- data/lib/clausewitz/spelling/formatter.rb +36 -0
- data/lib/clausewitz/spelling/results.rb +100 -0
- data/lib/clausewitz/spelling/version.rb +5 -0
- data/lib/clausewitz/spelling.rb +7 -0
- metadata +176 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9ab21323f524077bd5d9e5b124b4884067f951bb
|
|
4
|
+
data.tar.gz: ffd995d3915893597f15559ee7b677cd14b53db6
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: dc5ade503bd38e3d6db5056936cc5c9b161d5e87707fe9574006c168c5702f72434b0d40a868013b7b47e68efa186713505c0adf99cd16a99fffc9d164a8b3af
|
|
7
|
+
data.tar.gz: 0421ec9e3211c91c2deee5febc77caa0741c8fddeef7fc86dde91123ddf35c06f9969810e94138378bda44a75bf06faf73c8bc330abe963394fbdecc1adc6bcd
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rspec_status
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at wtchappell@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
clausewitz-spelling (0.1.0)
|
|
5
|
+
colorize
|
|
6
|
+
damerau-levenshtein
|
|
7
|
+
ffi-aspell
|
|
8
|
+
optimist
|
|
9
|
+
|
|
10
|
+
GEM
|
|
11
|
+
remote: https://rubygems.org/
|
|
12
|
+
specs:
|
|
13
|
+
coderay (1.1.2)
|
|
14
|
+
colorize (0.8.1)
|
|
15
|
+
damerau-levenshtein (1.3.1)
|
|
16
|
+
diff-lcs (1.3)
|
|
17
|
+
ffi (1.9.25)
|
|
18
|
+
ffi-aspell (1.1.0)
|
|
19
|
+
ffi
|
|
20
|
+
method_source (0.9.2)
|
|
21
|
+
optimist (3.0.0)
|
|
22
|
+
pry (0.12.2)
|
|
23
|
+
coderay (~> 1.1.0)
|
|
24
|
+
method_source (~> 0.9.0)
|
|
25
|
+
rake (10.5.0)
|
|
26
|
+
rspec (3.8.0)
|
|
27
|
+
rspec-core (~> 3.8.0)
|
|
28
|
+
rspec-expectations (~> 3.8.0)
|
|
29
|
+
rspec-mocks (~> 3.8.0)
|
|
30
|
+
rspec-core (3.8.0)
|
|
31
|
+
rspec-support (~> 3.8.0)
|
|
32
|
+
rspec-expectations (3.8.2)
|
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
34
|
+
rspec-support (~> 3.8.0)
|
|
35
|
+
rspec-mocks (3.8.0)
|
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
37
|
+
rspec-support (~> 3.8.0)
|
|
38
|
+
rspec-support (3.8.0)
|
|
39
|
+
|
|
40
|
+
PLATFORMS
|
|
41
|
+
ruby
|
|
42
|
+
|
|
43
|
+
DEPENDENCIES
|
|
44
|
+
bundler (~> 1.16)
|
|
45
|
+
clausewitz-spelling!
|
|
46
|
+
pry
|
|
47
|
+
rake (~> 10.0)
|
|
48
|
+
rspec (~> 3.0)
|
|
49
|
+
|
|
50
|
+
BUNDLED WITH
|
|
51
|
+
1.16.1
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Will Chappell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Clausewitz::Spelling
|
|
2
|
+
|
|
3
|
+
Tools for performing dialect/language-aware spellchecking of Paradox
|
|
4
|
+
Interactive's Clausewitz engine localisation files, used in games like Europa
|
|
5
|
+
Universalis and Hearts of Iron IV.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Add this line to your application's Gemfile:
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'clausewitz-spelling'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
And then execute:
|
|
16
|
+
|
|
17
|
+
$ bundle
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
$ gem install clausewitz-spelling
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
> clausewitz-spellcheck --help
|
|
27
|
+
Options:
|
|
28
|
+
-c, --custom-wordlist=<s> Text file containing newline-delimited list of
|
|
29
|
+
custom words
|
|
30
|
+
-e, --english-dialect=<s> Two-letter code indicating dialect of English
|
|
31
|
+
to use
|
|
32
|
+
-s, --spanish-dialect=<s> Two-letter code indicating dialect of Spanish
|
|
33
|
+
to use
|
|
34
|
+
-u, --suggestion-count=<i> How many suggestions to display
|
|
35
|
+
-h, --help Show this message
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Development
|
|
39
|
+
|
|
40
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
41
|
+
|
|
42
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
43
|
+
|
|
44
|
+
## Contributing
|
|
45
|
+
|
|
46
|
+
Bug reports and pull requests are welcome on GitLab at https://gitlab.com/owb-dev-team/clausewitz-spelling. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
47
|
+
|
|
48
|
+
## License
|
|
49
|
+
|
|
50
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
51
|
+
|
|
52
|
+
## Code of Conduct
|
|
53
|
+
|
|
54
|
+
Everyone interacting in the Clausewitz::Spelling project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/owb-dev-team/clausewitz-spelling/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "clausewitz/spelling"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
require "pry"
|
|
11
|
+
Pry.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "clausewitz/spelling/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "clausewitz-spelling"
|
|
8
|
+
spec.version = Clausewitz::Spelling::VERSION
|
|
9
|
+
spec.authors = ["Will Chappell"]
|
|
10
|
+
spec.email = ["wtchappell@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = "Spellchecker tool for Clausewitz engine files"
|
|
13
|
+
spec.homepage = "http://github.com/wtchappell/clausewitz-spelling"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
|
18
|
+
end
|
|
19
|
+
spec.bindir = "exe"
|
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
26
|
+
spec.add_development_dependency "pry"
|
|
27
|
+
|
|
28
|
+
spec.add_dependency "ffi-aspell"
|
|
29
|
+
spec.add_dependency "optimist"
|
|
30
|
+
spec.add_dependency "colorize"
|
|
31
|
+
spec.add_dependency "damerau-levenshtein"
|
|
32
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'clausewitz/spelling/checker'
|
|
3
|
+
require 'optimist'
|
|
4
|
+
|
|
5
|
+
class Main
|
|
6
|
+
def initialize(args)
|
|
7
|
+
@opts, @args = parse_args(args)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def parse_args(args)
|
|
11
|
+
opts = Optimist::options(args) do
|
|
12
|
+
opt :custom_wordlist,
|
|
13
|
+
"Text file containing newline-delimited list of custom words",
|
|
14
|
+
type: :string
|
|
15
|
+
opt :english_dialect,
|
|
16
|
+
"Two-letter code indicating dialect of English to use",
|
|
17
|
+
type: :string
|
|
18
|
+
opt :spanish_dialect,
|
|
19
|
+
"Two-letter code indicating dialect of Spanish to use",
|
|
20
|
+
type: :string
|
|
21
|
+
opt :suggestion_count,
|
|
22
|
+
"How many suggestions to display",
|
|
23
|
+
type: :int
|
|
24
|
+
end
|
|
25
|
+
[opts, args]
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def run
|
|
29
|
+
spellchecker = Clausewitz::Spelling::Checker.new(@opts)
|
|
30
|
+
spellchecker.check_files(@args).render
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
Main.new(ARGV).run
|
|
35
|
+
|
|
36
|
+
# vim: set ft=ruby ts=2 sw=2 tw=79 :
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
require 'ffi/aspell'
|
|
2
|
+
require 'open3'
|
|
3
|
+
require 'set'
|
|
4
|
+
require 'tmpdir'
|
|
5
|
+
require 'yaml'
|
|
6
|
+
require 'damerau-levenshtein'
|
|
7
|
+
require 'clausewitz/spelling/results'
|
|
8
|
+
require 'pry'
|
|
9
|
+
|
|
10
|
+
module Clausewitz; module Spelling
|
|
11
|
+
class Checker
|
|
12
|
+
attr_accessor :dict_words
|
|
13
|
+
def initialize(opts = {})
|
|
14
|
+
|
|
15
|
+
@suggestion_count = opts[:suggestion_count] || 3
|
|
16
|
+
|
|
17
|
+
@english_dialect = opts[:english_dialect] || 'GB'
|
|
18
|
+
@english_dialect = "en_#{@english_dialect}"
|
|
19
|
+
@en_speller = FFI::Aspell::Speller.new(@english_dialect)
|
|
20
|
+
|
|
21
|
+
@spanish_dialect = opts[:spanish_dialect] || 'es'
|
|
22
|
+
@spanish_dialect = "es_#{@spanish_dialect}" if opts[:spanish_dialect]
|
|
23
|
+
@es_speller = FFI::Aspell::Speller.new(@spanish_dialect)
|
|
24
|
+
|
|
25
|
+
dict_path = opts[:custom_wordlist]
|
|
26
|
+
|
|
27
|
+
if dict_path
|
|
28
|
+
fail("No such file #{dict_path}!") unless File.exist?(dict_path)
|
|
29
|
+
@dict_words = Set.new(File.read(dict_path).lines.map(&:chomp).to_a)
|
|
30
|
+
@custom_words_filepath = generate_word_list
|
|
31
|
+
@en_speller.set('extra-dicts', @custom_words_filepath)
|
|
32
|
+
@en_speller.set('ignore-accents', true)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def check_file(file_path)
|
|
37
|
+
loc = load_file(file_path)
|
|
38
|
+
# Poorly formatted YAML files often lack proper indentation; you can
|
|
39
|
+
# easily discover this by checking to make sure all top level keys are
|
|
40
|
+
# actual language names.
|
|
41
|
+
bad_keys = loc.keys.select { |key| bad_lang_key(key) }
|
|
42
|
+
bad_keys.map! { |key| unsmudge_key(key) }
|
|
43
|
+
if !bad_keys.empty?
|
|
44
|
+
UnknownLangsFileResult.new(file_path, bad_keys)
|
|
45
|
+
else
|
|
46
|
+
results = loc.map do |lang, entries|
|
|
47
|
+
check_entries(lang, entries)
|
|
48
|
+
end
|
|
49
|
+
FileResults.new(file_path, results)
|
|
50
|
+
end
|
|
51
|
+
rescue Psych::SyntaxError
|
|
52
|
+
# If we fail to load the file it's probably busted.
|
|
53
|
+
BadFormatFileResult.new(file_path)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def check_files(file_paths)
|
|
57
|
+
results = Array(file_paths).map do |file_path|
|
|
58
|
+
check_file(file_path)
|
|
59
|
+
end
|
|
60
|
+
OverallResults.new(results)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def check_entries(lang, entries)
|
|
64
|
+
misspellings = []
|
|
65
|
+
entries.each do |key, text|
|
|
66
|
+
result = check_entry(key, text)
|
|
67
|
+
misspellings << result unless result.check_results.empty?
|
|
68
|
+
end
|
|
69
|
+
misspellings
|
|
70
|
+
LangResults.new(lang, misspellings)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def check_entry(key, text)
|
|
74
|
+
misspellings = []
|
|
75
|
+
text = preprocess_entry(text)
|
|
76
|
+
text.split(' ').each_with_index do |word, index|
|
|
77
|
+
unless check_word(word) || misspellings.any? { |ms| ms.misspelled_word == word }
|
|
78
|
+
misspellings << CheckResult.new(word, suggest_words(word))
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
KeyResults.new(unsmudge_key(key), misspellings)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
SQUIGGLE = '§'
|
|
85
|
+
def check_word(word)
|
|
86
|
+
return true if word.chars.count('.') > 1
|
|
87
|
+
word.gsub!(/^(#{SQUIGGLE}.|[[:punct:]])+/, '')
|
|
88
|
+
word.gsub!(/(#{SQUIGGLE}.|[[:punct:]])+$/, '')
|
|
89
|
+
not_word?(word) ||
|
|
90
|
+
@dict_words.include?(word) ||
|
|
91
|
+
@en_speller.correct?(word) ||
|
|
92
|
+
@es_speller.correct?(word)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def load_file(file_path)
|
|
96
|
+
f = File.read(file_path)
|
|
97
|
+
f = f.lines.map do |line|
|
|
98
|
+
smudge_key(line)
|
|
99
|
+
end.join("\n")
|
|
100
|
+
YAML.load(f)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def not_word?(word)
|
|
104
|
+
is_percentage?(word) ||
|
|
105
|
+
is_number?(word) ||
|
|
106
|
+
is_ordinal?(word) ||
|
|
107
|
+
word =~ /^£/
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
private
|
|
111
|
+
|
|
112
|
+
def bad_lang_key(key)
|
|
113
|
+
key !~ /l_.+/
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def is_ordinal?(word)
|
|
117
|
+
word =~ /[0-9]+(th|st|nd|rd)/
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def is_number?(word)
|
|
121
|
+
Float(word) != nil rescue false
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Tries to detect if a word is a percentage and can be skipped.
|
|
125
|
+
def is_percentage?(word)
|
|
126
|
+
word =~ /(-|\+)?[0-9]+(\.[0-9]+)?%/ ||
|
|
127
|
+
word =~ /%(-|\+)?[0-9]+(\.[0-9]+)?/
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# Loads our custom wordlist into a temporary Aspell dictionary.
|
|
131
|
+
# This way Aspell won't yell at us for custom words and will also
|
|
132
|
+
# potentially select from this list as suggestions for misspelled words.
|
|
133
|
+
def generate_word_list
|
|
134
|
+
dir = Dir.mktmpdir('custom-wordlist-')
|
|
135
|
+
output = File.join(dir, 'fallout_words.wlst')
|
|
136
|
+
cmd = %W[
|
|
137
|
+
aspell --lang=en --encoding=UTF-8 create master #{output}
|
|
138
|
+
]
|
|
139
|
+
value = nil
|
|
140
|
+
Open3.popen3(*cmd) do |stdin, stdout, stderr, wait_thr|
|
|
141
|
+
@dict_words.each do |word|
|
|
142
|
+
stdin.puts(word)
|
|
143
|
+
end
|
|
144
|
+
stdin.close
|
|
145
|
+
value = wait_thr.value
|
|
146
|
+
end
|
|
147
|
+
fail("Could not generate custom word list!") unless value.success?
|
|
148
|
+
output
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def preprocess_entry(entry)
|
|
152
|
+
entry.gsub(/\[.+\]/, '')
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def smudge_key(key)
|
|
156
|
+
key.sub(/\:([0-9]+) /, "!!!1: ")
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def suggest_words(word)
|
|
160
|
+
return [] if word.size < 5
|
|
161
|
+
|
|
162
|
+
suggestions = Set.new
|
|
163
|
+
|
|
164
|
+
aspell_suggestions = []
|
|
165
|
+
aspell_suggestions.concat(@en_speller.suggestions(word))
|
|
166
|
+
aspell_suggestions.concat(@es_speller.suggestions(word))
|
|
167
|
+
|
|
168
|
+
custom_suggestions = @dict_words.select do |dict_word|
|
|
169
|
+
DamerauLevenshtein.distance(word, dict_word) < word.size
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
aspell_suggestions.each { |sug| suggestions.add(sug) }
|
|
173
|
+
custom_suggestions.each { |sug| suggestions.add(sug) }
|
|
174
|
+
|
|
175
|
+
suggestions.to_a.sort_by do |sug|
|
|
176
|
+
DamerauLevenshtein.distance(sug, word)
|
|
177
|
+
end.first(@suggestion_count)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def unsmudge_key(key)
|
|
181
|
+
key.gsub(/!!!([0-9]+)$/, ":1")
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
end; end # Clausewitz::Spelling
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module Clausewitz; module Spelling
|
|
2
|
+
class Formatter
|
|
3
|
+
def render(overall_results)
|
|
4
|
+
render_overall_results(overall_results)
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
private
|
|
8
|
+
|
|
9
|
+
def render_overall_results(overall_results)
|
|
10
|
+
overall_results.files.each do |file_results|
|
|
11
|
+
render_file_results(file_results)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def render_file_results(file_results)
|
|
16
|
+
file_results.langs.each do |lang_results|
|
|
17
|
+
render_lang_results(lang_results)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def render_lang_results(lang_results)
|
|
22
|
+
lang_results.keys.each do |key_results|
|
|
23
|
+
render_key_results(key_results)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def render_key_results(key_results)
|
|
28
|
+
key_results.spellchecks.each do |spellcheck_result|
|
|
29
|
+
render_spellcheck_result(spellcheck_result)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def render_spellcheck_result(spellcheck_result)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end; end # Clausewitz::Spelling
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
require 'colorize'
|
|
2
|
+
|
|
3
|
+
module Clausewitz; module Spelling
|
|
4
|
+
# Stores the results of a run over a set of files.
|
|
5
|
+
class OverallResults
|
|
6
|
+
attr_reader :file_results
|
|
7
|
+
def initialize(file_results)
|
|
8
|
+
@file_results = file_results
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def render
|
|
12
|
+
@file_results.each(&:render)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class FileResults
|
|
17
|
+
attr_reader :file_path, :lang_results
|
|
18
|
+
def initialize(file_path, lang_results)
|
|
19
|
+
@file_path = file_path
|
|
20
|
+
@lang_results = lang_results
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def render
|
|
24
|
+
puts " #{@file_path} has #{@lang_results.size.to_s.red} langs with errors:"
|
|
25
|
+
@lang_results.each(&:render)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class BadFormatFileResult
|
|
30
|
+
attr_reader :file_path
|
|
31
|
+
def initialize(file_path)
|
|
32
|
+
@file_path = file_path
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def render
|
|
36
|
+
puts " #{@file_path} appears to be formatted incorrectly!".red
|
|
37
|
+
puts " Make sure that each loc key has *two* leading *spaces*.".yellow
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
class UnknownLangsFileResult
|
|
42
|
+
attr_reader :file_path, :bad_langs
|
|
43
|
+
def initialize(file_path, bad_langs)
|
|
44
|
+
@file_path = file_path
|
|
45
|
+
@bad_langs = bad_langs
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def render
|
|
49
|
+
langs = @bad_langs.join(', ')
|
|
50
|
+
puts " #{@file_path} has unknown languages #{langs}!".red
|
|
51
|
+
puts " Make sure that each loc key has *two* leading *spaces*.".yellow
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
class LangResults
|
|
56
|
+
attr_reader :lang, :key_results
|
|
57
|
+
def initialize(lang, key_results)
|
|
58
|
+
@lang = lang
|
|
59
|
+
@key_results = key_results
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def render
|
|
63
|
+
puts " #{@lang} has #{@key_results.size.to_s.red} keys with errors:"
|
|
64
|
+
@key_results.each(&:render)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
class KeyResults
|
|
69
|
+
attr_reader :key, :check_results
|
|
70
|
+
def initialize(key, check_results)
|
|
71
|
+
@key = key
|
|
72
|
+
@check_results = check_results
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def render
|
|
76
|
+
puts " #{@key.yellow} has #{@check_results.size.to_s.red} unrecognized words:"
|
|
77
|
+
@check_results.each(&:render)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
class CheckResult
|
|
82
|
+
attr_reader :misspelled_word, :suggestions
|
|
83
|
+
def initialize(misspelled_word, suggestions)
|
|
84
|
+
@misspelled_word = misspelled_word
|
|
85
|
+
@suggestions = suggestions
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def render
|
|
89
|
+
print " Unrecognized word '#{@misspelled_word.red}'"
|
|
90
|
+
if @suggestions.empty?
|
|
91
|
+
puts
|
|
92
|
+
else
|
|
93
|
+
puts "; did you mean:"
|
|
94
|
+
@suggestions.each do |sug|
|
|
95
|
+
puts " '#{sug.green}'"
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end; end # Clausewitz::Spelling
|
metadata
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: clausewitz-spelling
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Will Chappell
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-01-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: pry
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: ffi-aspell
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: optimist
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - ">="
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: '0'
|
|
90
|
+
type: :runtime
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - ">="
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: '0'
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: colorize
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - ">="
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: '0'
|
|
104
|
+
type: :runtime
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: damerau-levenshtein
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - ">="
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: '0'
|
|
118
|
+
type: :runtime
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - ">="
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: '0'
|
|
125
|
+
description:
|
|
126
|
+
email:
|
|
127
|
+
- wtchappell@gmail.com
|
|
128
|
+
executables:
|
|
129
|
+
- clausewitz-spellcheck
|
|
130
|
+
extensions: []
|
|
131
|
+
extra_rdoc_files: []
|
|
132
|
+
files:
|
|
133
|
+
- ".gitignore"
|
|
134
|
+
- ".rspec"
|
|
135
|
+
- ".rspec_status"
|
|
136
|
+
- ".travis.yml"
|
|
137
|
+
- CODE_OF_CONDUCT.md
|
|
138
|
+
- Gemfile
|
|
139
|
+
- Gemfile.lock
|
|
140
|
+
- LICENSE.txt
|
|
141
|
+
- README.md
|
|
142
|
+
- Rakefile
|
|
143
|
+
- bin/console
|
|
144
|
+
- bin/setup
|
|
145
|
+
- clausewitz-spelling.gemspec
|
|
146
|
+
- exe/clausewitz-spellcheck
|
|
147
|
+
- lib/clausewitz/spelling.rb
|
|
148
|
+
- lib/clausewitz/spelling/checker.rb
|
|
149
|
+
- lib/clausewitz/spelling/formatter.rb
|
|
150
|
+
- lib/clausewitz/spelling/results.rb
|
|
151
|
+
- lib/clausewitz/spelling/version.rb
|
|
152
|
+
homepage: http://github.com/wtchappell/clausewitz-spelling
|
|
153
|
+
licenses:
|
|
154
|
+
- MIT
|
|
155
|
+
metadata: {}
|
|
156
|
+
post_install_message:
|
|
157
|
+
rdoc_options: []
|
|
158
|
+
require_paths:
|
|
159
|
+
- lib
|
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
|
+
requirements:
|
|
162
|
+
- - ">="
|
|
163
|
+
- !ruby/object:Gem::Version
|
|
164
|
+
version: '0'
|
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
|
+
requirements:
|
|
167
|
+
- - ">="
|
|
168
|
+
- !ruby/object:Gem::Version
|
|
169
|
+
version: '0'
|
|
170
|
+
requirements: []
|
|
171
|
+
rubyforge_project:
|
|
172
|
+
rubygems_version: 2.5.2.1
|
|
173
|
+
signing_key:
|
|
174
|
+
specification_version: 4
|
|
175
|
+
summary: Spellchecker tool for Clausewitz engine files
|
|
176
|
+
test_files: []
|