autocorrect-rb 2.4.0-x86_64-linux → 2.5.0-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +33 -1
- data/Rakefile +22 -2
- data/ext/autocorrect/Cargo.toml +1 -1
- data/ext/autocorrect/src/lib.rs +28 -2
- data/lib/autocorrect/2.7/autocorrect.so +0 -0
- data/lib/autocorrect/3.0/autocorrect.so +0 -0
- data/lib/autocorrect/3.1/autocorrect.so +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 110c4e66b76fa87662b3559e04cc25faf990166ed5794400289c878e9ffaeddd
|
4
|
+
data.tar.gz: f7df454eddbf9ef7dc3ef14756d565ede1ab49917ebda52097e41f963d823322
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3aef070394025f3d28ec7dc583408352ffd4595869d6c145b5ae374a7ba0775c699a908558749b1ec37a319c3bee655dbe6b0c42302b29284be110d365c808fd
|
7
|
+
data.tar.gz: 01c303b2bf073416fc39c112afa6d7a4f98933ab84f2ac1cca55504592568ab482aeced5af0eb7225b737d937712a360a2a89c5149228131127e9e57b60c755a
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# AutoCorrect for Ruby
|
2
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
|
+
|
3
5
|
The Native Ruby version of [AutoCorrect](https://github.com/huacnlee/autocorrect).
|
4
6
|
|
5
7
|
- Rust - [autocorrect](https://github.com/huacnlee/autocorrect)
|
@@ -38,11 +40,24 @@ puts result
|
|
38
40
|
# ],
|
39
41
|
# error: ''
|
40
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")
|
41
56
|
```
|
42
57
|
|
43
58
|
## Benchmarks
|
44
59
|
|
45
|
-
🎊 Rust version is
|
60
|
+
🎊 Rust version is ~3.5x faster than the Ruby (pure) version.
|
46
61
|
|
47
62
|
> NOTE: In this case Rust version has more complex rules.
|
48
63
|
|
@@ -61,6 +76,10 @@ Calculating -------------------------------------
|
|
61
76
|
format_html 5.448k (± 1.5%) i/s - 27.250k in 5.002853s
|
62
77
|
```
|
63
78
|
|
79
|
+
```
|
80
|
+
1000 ms / 111904 i/s = 0.008 ms
|
81
|
+
```
|
82
|
+
|
64
83
|
### Pure [Ruby version](https://rubygems.org/gems/auto-correct/versions/1.0.0) result:
|
65
84
|
|
66
85
|
```bash
|
@@ -76,6 +95,19 @@ Calculating -------------------------------------
|
|
76
95
|
format_html 1.659k (± 1.7%) i/s - 8.300k in 5.003164s
|
77
96
|
```
|
78
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
|
+
|
79
111
|
## Know issues
|
80
112
|
|
81
113
|
Bundler install error:
|
data/Rakefile
CHANGED
@@ -55,12 +55,12 @@ task :bench do
|
|
55
55
|
end
|
56
56
|
x.report("format 100 chars") do |n|
|
57
57
|
n.times do
|
58
|
-
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)
|
58
|
+
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)“买入”评�� 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
|
59
59
|
end
|
60
60
|
end
|
61
61
|
x.report("format 400 chars") do |n|
|
62
62
|
n.times do
|
63
|
-
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,上调吉利汽车(00175)目标价12.58%,由15.9港元升至17.9港元,并维持吉汽为行业首选股,重申对其“买入”评级,坚信吉汽长远可成为行业赢家。 该行称,随着公司销量持续复苏及产品组合改善,预计今年销量可达148万辆,同比升9%,较公司原定目标销量141万辆为高。 该行又称称,上调公司今明两年每股盈利预测各13%及升毛利率0.1个百分点,以反映销量较预期高2%及产品组合改善,主要是由领克品牌带动。公司自去年8
|
63
|
+
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,上调吉利汽车(00175)目标价12.58%,由15.9港元升至17.9港元,并维持吉汽为行业首选股,重申对其“买入”评级,坚信吉汽长远可成为行业赢家。 该行称,随着公司销量持续复苏及产品组合改善,预计今年销量可达148万辆,同比升9%,较公司原定目标销量141万辆为高。 该行又称称,上调公司今明两年每股盈利预测各13%及升毛利率0.1个百分点,以反映销量较预期高2%及产品组合改善,主要是由领克品牌带动。公司自去年8月开始已持续投资领克品牌及进行市场推广,带动领克销量环比有所改变,��期今明两年领克将占整体销量的11%及14%。 该行表示,由于低端国产车品牌在欠缺新车款及科技下,行业整合度将提升。另外,公司从去年第二季到12月为止,一��都积极推动经销商去库存,这将有利公司今年利润率复苏。")
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -72,5 +72,25 @@ task :bench do
|
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
task :memory do
|
76
|
+
require "memory_profiler"
|
77
|
+
require "./lib/autocorrect-rb"
|
78
|
+
|
79
|
+
html = open("./test/fixtures/example.txt").read
|
80
|
+
|
81
|
+
report = MemoryProfiler.report do
|
82
|
+
20_000.times do
|
83
|
+
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)“买入”评�� 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
|
84
|
+
AutoCorrect.format_for(html, "text.html")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
GC.start
|
89
|
+
report.pretty_print
|
90
|
+
|
91
|
+
puts "------------------------- Result Guide -------------------------"
|
92
|
+
puts "If [Total retained] have any bytes, there will have memory leak."
|
93
|
+
end
|
94
|
+
|
75
95
|
task test: :compile
|
76
96
|
task default: %i[test]
|
data/ext/autocorrect/Cargo.toml
CHANGED
data/ext/autocorrect/src/lib.rs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
use magnus::{define_class, function, Error, Object};
|
1
|
+
use magnus::{define_class, function, method, Error, Module, Object};
|
2
2
|
|
3
3
|
#[derive(Debug, Clone)]
|
4
4
|
pub struct LineResult {
|
@@ -84,6 +84,23 @@ impl LintResult {
|
|
84
84
|
}
|
85
85
|
}
|
86
86
|
|
87
|
+
#[magnus::wrap(class = "AutoCorrect::Ignorer")]
|
88
|
+
pub struct Ignorer {
|
89
|
+
core: autocorrect::ignorer::Ignorer,
|
90
|
+
}
|
91
|
+
|
92
|
+
impl Ignorer {
|
93
|
+
pub fn new(work_dir: String) -> Self {
|
94
|
+
Ignorer {
|
95
|
+
core: autocorrect::ignorer::Ignorer::new(&work_dir),
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
fn is_ignored(&self, path: String) -> bool {
|
100
|
+
self.core.is_ignored(&path)
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
87
104
|
pub fn format(input: String) -> String {
|
88
105
|
autocorrect::format(&input)
|
89
106
|
}
|
@@ -105,7 +122,7 @@ pub fn lint_for(input: String, filename_or_ext: String) -> magnus::RHash {
|
|
105
122
|
col: l.col,
|
106
123
|
new: l.new.clone(),
|
107
124
|
old: l.old.clone(),
|
108
|
-
severity: l.severity
|
125
|
+
severity: l.severity as usize,
|
109
126
|
})
|
110
127
|
.collect::<_>(),
|
111
128
|
error: result.error,
|
@@ -114,12 +131,21 @@ pub fn lint_for(input: String, filename_or_ext: String) -> magnus::RHash {
|
|
114
131
|
.unwrap()
|
115
132
|
}
|
116
133
|
|
134
|
+
pub fn load_config(config_str: String) {
|
135
|
+
autocorrect::config::load(&config_str).unwrap();
|
136
|
+
}
|
137
|
+
|
117
138
|
#[magnus::init(name = "autocorrect")]
|
118
139
|
fn init() -> Result<(), Error> {
|
119
140
|
let class = define_class("AutoCorrect", Default::default())?;
|
120
141
|
class.define_singleton_method("format", function!(format, 1))?;
|
121
142
|
class.define_singleton_method("format_for", function!(format_for, 2))?;
|
122
143
|
class.define_singleton_method("lint_for", function!(lint_for, 2))?;
|
144
|
+
class.define_singleton_method("load_config", function!(load_config, 1))?;
|
145
|
+
|
146
|
+
let ignorer_class = class.define_class("Ignorer", Default::default())?;
|
147
|
+
ignorer_class.define_singleton_method("new", function!(Ignorer::new, 1))?;
|
148
|
+
ignorer_class.define_method("ignored?", method!(Ignorer::is_ignored, 1))?;
|
123
149
|
|
124
150
|
Ok(())
|
125
151
|
}
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: autocorrect-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: x86_64-linux
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb_sys
|