autocorrect-rb 2.5.6.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +125 -0
- data/Rakefile +97 -0
- data/ext/autocorrect/Cargo.lock +658 -0
- data/ext/autocorrect/Cargo.toml +13 -0
- data/ext/autocorrect/extconf.rb +4 -0
- data/ext/autocorrect/src/lib.rs +151 -0
- data/ext/autocorrect/target/debug/build/bindgen-2bfaec9031475734/out/tests.rs +0 -0
- data/ext/autocorrect/target/debug/build/clang-sys-989543ac26a5e988/out/common.rs +319 -0
- data/ext/autocorrect/target/debug/build/clang-sys-989543ac26a5e988/out/dynamic.rs +262 -0
- data/ext/autocorrect/target/debug/build/rb-sys-4b217af8fe7506dd/out/bindings-raw.rs +20455 -0
- data/ext/autocorrect/target/debug/build/rb-sys-4b217af8fe7506dd/out/bindings.rs +20455 -0
- data/ext/autocorrect/target/debug/build/thiserror-6f4e16a661287080/out/probe.rs +8 -0
- data/ext/autocorrect/target/debug/incremental/autocorrect-ycs7cwobmcw6/s-ggxr2dhzul-3iamp5.lock +0 -0
- data/lib/autocorrect-rb.rb +7 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cce0a1e0dd62d0ef9a97657984677104995e639e5a2c7768723d618ba489fde9
|
4
|
+
data.tar.gz: 4c64a5b4b47da9cd0f057352cace7f978270552446c0a670a9ac18acfe88d5be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6bfbdd16fcf9edb4948bf90f55eacdd19825c72520a1bb9707220100c8a64539e78acd049eea0468018cf3a0d5933155dafdb49d519cb03dd7c7b6f678f58e41
|
7
|
+
data.tar.gz: a288c7a90aa65672f28ee3aab3b047d760f969fe223607940cc99a269744c80eeabb294de9a63d2941b44a21982e302ace227405878c49c27759e354b7e041be
|
data/README.md
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# AutoCorrect for Ruby
|
2
|
+
|
3
|
+
<a href="https://rubygems.org/gems/autocorrect-rb"><img src="https://img.shields.io/gem/v/autocorrect-rb?color=1&label=Gem" alt="Gem Version"></a>
|
4
|
+
|
5
|
+
The Native Ruby version of [AutoCorrect](https://github.com/huacnlee/autocorrect).
|
6
|
+
|
7
|
+
- Rust - [autocorrect](https://github.com/huacnlee/autocorrect)
|
8
|
+
- Ruby - [autocorrect-rb](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-rb)
|
9
|
+
- Go - [autocorrect-go](https://github.com/longbridgeapp/autocorrect)
|
10
|
+
- Python - [autocorrect-py](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-py)
|
11
|
+
- Node.js - [autocorrect-node](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-node)
|
12
|
+
- JavaScript (Browser) - [autocorrect-wasm](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-wasm)
|
13
|
+
- Java - [autocorrect-java](https://github.com/huacnlee/autocorrect/tree/main/autocorrect-java)
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
```bash
|
18
|
+
$ bundle add autocorrect-rb
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```rb
|
24
|
+
require('autocorrect-rb')
|
25
|
+
|
26
|
+
out = AutoCorrect.format('Hello你好.')
|
27
|
+
puts out
|
28
|
+
# Hello 你好。
|
29
|
+
|
30
|
+
out = AutoCorrect.format_for("title = 'Hello你好。'", 'rb')
|
31
|
+
puts out
|
32
|
+
# title = 'Hello 你好。'
|
33
|
+
|
34
|
+
result = AutoCorrect.lint_for("title = 'Hello你好。'", 'rb')
|
35
|
+
puts result
|
36
|
+
# {
|
37
|
+
# filepath: 'rb',
|
38
|
+
# lines: [
|
39
|
+
# { l: 1, c: 13, new: "'Hello 你好。'", old: "'Hello你好。'", severity: 1 }
|
40
|
+
# ],
|
41
|
+
# error: ''
|
42
|
+
# }
|
43
|
+
|
44
|
+
config_str = %({ textRules: { "你好hello": 0 } })
|
45
|
+
AutoCorrect.load_config(config_str)
|
46
|
+
out = AutoCorrect.format('Hello你好.')
|
47
|
+
puts out
|
48
|
+
# Hello 你好。
|
49
|
+
out = AutoCorrect.format('你好hello')
|
50
|
+
puts out
|
51
|
+
# 你好hello
|
52
|
+
|
53
|
+
# Ignorer, if /path/to/workdir contains .autocorrectignore or .gitignore
|
54
|
+
ignorer = AutoCorrect::Ignorer.new("/path/to/")
|
55
|
+
ignorer.ignored?("README.md")
|
56
|
+
```
|
57
|
+
|
58
|
+
## Benchmarks
|
59
|
+
|
60
|
+
🎊 Rust version is ~3.5x faster than the Ruby (pure) version.
|
61
|
+
|
62
|
+
> NOTE: In this case Rust version has more complex rules.
|
63
|
+
|
64
|
+
### Rust version
|
65
|
+
|
66
|
+
```bash
|
67
|
+
Warming up --------------------------------------
|
68
|
+
format 50 chars 11.348k i/100ms
|
69
|
+
format 100 chars 6.033k i/100ms
|
70
|
+
format 400 chars 1.772k i/100ms
|
71
|
+
format_html 545.000 i/100ms
|
72
|
+
Calculating -------------------------------------
|
73
|
+
format 50 chars 111.904k (± 3.1%) i/s - 567.400k in 5.075674s
|
74
|
+
format 100 chars 58.684k (± 2.1%) i/s - 295.617k in 5.039837s
|
75
|
+
format 400 chars 17.266k (± 2.9%) i/s - 86.828k in 5.033234s
|
76
|
+
format_html 5.448k (± 1.5%) i/s - 27.250k in 5.002853s
|
77
|
+
```
|
78
|
+
|
79
|
+
```
|
80
|
+
1000 ms / 111904 i/s = 0.008 ms
|
81
|
+
```
|
82
|
+
|
83
|
+
### Pure [Ruby version](https://rubygems.org/gems/auto-correct/versions/1.0.0) result:
|
84
|
+
|
85
|
+
```bash
|
86
|
+
Warming up --------------------------------------
|
87
|
+
format 50 chars 3.167k i/100ms
|
88
|
+
format 100 chars 1.588k i/100ms
|
89
|
+
format 400 chars 496.000 i/100ms
|
90
|
+
format_html 166.000 i/100ms
|
91
|
+
Calculating -------------------------------------
|
92
|
+
format 50 chars 31.589k (± 2.5%) i/s - 158.350k in 5.016131s
|
93
|
+
format 100 chars 16.122k (± 1.2%) i/s - 80.988k in 5.024082s
|
94
|
+
format 400 chars 4.946k (± 2.6%) i/s - 24.800k in 5.017711s
|
95
|
+
format_html 1.659k (± 1.7%) i/s - 8.300k in 5.003164s
|
96
|
+
```
|
97
|
+
|
98
|
+
### Rust version VS Purge Ruby Version
|
99
|
+
|
100
|
+
| Test Case | Duration (Rust) | Duration (Pure Ruby) | Speedup |
|
101
|
+
| ----------- | --------------- | -------------------- | ------- |
|
102
|
+
| Foramt 50 | 0.008ms | 0.031ms | ~3.8x |
|
103
|
+
| Format 100 | 0.017ms | 0.062ms | ~3.6x |
|
104
|
+
| Format 400 | 0.052ms | 0.2ms | ~3.8x |
|
105
|
+
| Format HTML | 0.183ms | 0.67ms | ~3.6x |
|
106
|
+
|
107
|
+
> 🎈 Rust version about 3.5 ~ 3.8x fast then Ruby (pure version).
|
108
|
+
>
|
109
|
+
> By this result, we can see the Ruby version is also fast, but the Rust version is more better.
|
110
|
+
|
111
|
+
## Know issues
|
112
|
+
|
113
|
+
Bundler install error:
|
114
|
+
|
115
|
+
```
|
116
|
+
Could not find gem 'autocorrect-rb' with platform 'ruby' in rubygems repository https://rubygems.org/ or installed locally.
|
117
|
+
```
|
118
|
+
|
119
|
+
To fix this you can run:
|
120
|
+
|
121
|
+
```bash
|
122
|
+
$ bundle lock --remove-platform ruby
|
123
|
+
```
|
124
|
+
|
125
|
+
Because of autocorrect-rb not release the gem for `platform: ruby`, but your `Gemfile.lock` specialed that. This command will remove `ruby` platform from your `Gemfile.lock`
|
data/Rakefile
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# autocorrect: false
|
2
|
+
require "rubygems"
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "bundler/setup"
|
6
|
+
rescue LoadError
|
7
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
8
|
+
end
|
9
|
+
|
10
|
+
require "bundler/gem_tasks"
|
11
|
+
require "rubygems/package_task"
|
12
|
+
require "rake/testtask"
|
13
|
+
require "rake/extensiontask"
|
14
|
+
require "bundler"
|
15
|
+
|
16
|
+
CROSS_PLATFORMS = %w[
|
17
|
+
aarch64-linux
|
18
|
+
arm64-darwin
|
19
|
+
x64-mingw32
|
20
|
+
x86_64-darwin
|
21
|
+
x86_64-linux
|
22
|
+
]
|
23
|
+
|
24
|
+
Rake::TestTask.new(:test) do |t|
|
25
|
+
t.libs << "test"
|
26
|
+
t.libs << "lib"
|
27
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
28
|
+
end
|
29
|
+
|
30
|
+
spec = Bundler.load_gemspec("autocorrect-rb.gemspec")
|
31
|
+
|
32
|
+
# Make a autocorrect-rb-0.0.0.gem
|
33
|
+
# Disable release gem for platform: ruby, because autocorrect rust source build is complex.
|
34
|
+
# Gem::PackageTask.new(spec).define
|
35
|
+
|
36
|
+
# Make a native gem, eg. autocorrect-rb-0.0.0-x86_64-linux.gem
|
37
|
+
Rake::ExtensionTask.new("autocorrect", spec) do |ext|
|
38
|
+
# Compile output autocorrect.so into lib/autocorrect/autocorrect.so
|
39
|
+
ext.lib_dir = "lib/autocorrect"
|
40
|
+
ext.source_pattern = "*.{rs,toml}"
|
41
|
+
ext.cross_compile = true
|
42
|
+
ext.cross_platform = CROSS_PLATFORMS
|
43
|
+
end
|
44
|
+
|
45
|
+
task :bench do
|
46
|
+
require "benchmark/ips"
|
47
|
+
require "./lib/autocorrect-rb"
|
48
|
+
|
49
|
+
html = open("./test/fixtures/example.txt").read
|
50
|
+
|
51
|
+
Benchmark.ips do |x|
|
52
|
+
x.report("format 50 chars") do |n|
|
53
|
+
n.times do
|
54
|
+
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
x.report("format 100 chars") do |n|
|
58
|
+
n.times do
|
59
|
+
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)“买入”评�� 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
x.report("format 400 chars") do |n|
|
63
|
+
n.times do
|
64
|
+
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,上调吉利汽车(00175)目标价12.58%,由15.9港元升至17.9港元,并维持吉汽为行业首选股,重申对其“买入”评级,坚信吉汽长远可成为行业赢家。 该行称,随着公司销量持续复苏及产品组合改善,预计今年销量可达148万辆,同比升9%,较公司原定目标销量141万辆为高。 该行又称称,上调公司今明两年每股盈利预测各13%及升毛利率0.1个百分点,以反映销量较预期高2%及产品组合改善,主要是由领克品牌带动。公司自去年8月开始已持续投资领克品牌及进行市场推广,带动领克销量环比有所改变,��期今明两年领克将占整体销量的11%及14%。 该行表示,由于低端国产车品牌在欠缺新车款及科技下,行业整合度将提升。另外,公司从去年第二季到12月为止,一��都积极推动经销商去库存,这将有利公司今年利润率复苏。")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
x.report("format_html") do |n|
|
69
|
+
n.times do
|
70
|
+
AutoCorrect.format_for(html, "text.html")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
task :memory do
|
77
|
+
require "memory_profiler"
|
78
|
+
require "./lib/autocorrect-rb"
|
79
|
+
|
80
|
+
html = open("./test/fixtures/example.txt").read
|
81
|
+
|
82
|
+
report = MemoryProfiler.report do
|
83
|
+
20_000.times do
|
84
|
+
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)“买入”评�� 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
|
85
|
+
AutoCorrect.format_for(html, "text.html")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
GC.start
|
90
|
+
report.pretty_print
|
91
|
+
|
92
|
+
puts "------------------------- Result Guide -------------------------"
|
93
|
+
puts "If [Total retained] have any bytes, there will have memory leak."
|
94
|
+
end
|
95
|
+
|
96
|
+
task test: :compile
|
97
|
+
task default: %i[test]
|