autocorrect-rb 2.1.2-x86_64-darwin → 2.2.0-x86_64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +56 -2
- data/Rakefile +42 -6
- data/ext/autocorrect/Cargo.toml +13 -0
- data/ext/autocorrect/extconf.rb +4 -0
- data/ext/autocorrect/src/lib.rs +125 -0
- data/lib/autocorrect/2.7/autocorrect.bundle +0 -0
- data/lib/autocorrect/3.0/autocorrect.bundle +0 -0
- data/lib/autocorrect/3.1/autocorrect.bundle +0 -0
- data/lib/autocorrect-rb.rb +0 -5
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0ec060a8fe207e43dc3885963bd225b5ffdc5ef4b624e3bea0758f53c7ee579
|
4
|
+
data.tar.gz: 2c635f8ce87b8f31d366c087a4d27221b8d88d02416fac13a16a67d7013245aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c41437d796c6c25eadb86e2ae971a3d209cf7ce51f4ba98133aa320acd6985cbb087b16a7f658d2b478e8a3e9a882575351a6b69eb7baf518395f00d1f049159
|
7
|
+
data.tar.gz: 6f8539d02b45841faa316287ffdfde30f3a48b068cea11b1f224bd6602a3523e480946c3ccdaa60ec3be59eb0213e0a610c07ede9649574f98a97a22080cdffd
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ $ bundle add autocorrect-rb
|
|
18
18
|
## Usage
|
19
19
|
|
20
20
|
```rb
|
21
|
-
require('autocorrect-rb')
|
21
|
+
require('autocorrect-rb')
|
22
22
|
|
23
23
|
out = AutoCorrect.format('Hello你好.')
|
24
24
|
puts out
|
@@ -28,7 +28,7 @@ out = AutoCorrect.format_for("title = 'Hello你好。'", 'rb')
|
|
28
28
|
puts out
|
29
29
|
# title = 'Hello 你好。'
|
30
30
|
|
31
|
-
result = AutoCorrect.
|
31
|
+
result = AutoCorrect.lint_for("title = 'Hello你好。'", 'rb')
|
32
32
|
puts result
|
33
33
|
# {
|
34
34
|
# filepath: 'rb',
|
@@ -38,3 +38,57 @@ puts result
|
|
38
38
|
# error: ''
|
39
39
|
# }
|
40
40
|
```
|
41
|
+
|
42
|
+
## Benchmarks
|
43
|
+
|
44
|
+
🎊 Rust version is 3x faster than the Ruby (pure) version.
|
45
|
+
|
46
|
+
> NOTE: In this case Rust version has more complex rules.
|
47
|
+
|
48
|
+
### Rust version
|
49
|
+
|
50
|
+
```bash
|
51
|
+
Warming up --------------------------------------
|
52
|
+
format 50 chars 11.348k i/100ms
|
53
|
+
format 100 chars 6.033k i/100ms
|
54
|
+
format 400 chars 1.772k i/100ms
|
55
|
+
format_html 545.000 i/100ms
|
56
|
+
Calculating -------------------------------------
|
57
|
+
format 50 chars 111.904k (± 3.1%) i/s - 567.400k in 5.075674s
|
58
|
+
format 100 chars 58.684k (± 2.1%) i/s - 295.617k in 5.039837s
|
59
|
+
format 400 chars 17.266k (± 2.9%) i/s - 86.828k in 5.033234s
|
60
|
+
format_html 5.448k (± 1.5%) i/s - 27.250k in 5.002853s
|
61
|
+
```
|
62
|
+
|
63
|
+
### Pure [Ruby version](https://rubygems.org/gems/auto-correct/versions/1.0.0) result:
|
64
|
+
|
65
|
+
```bash
|
66
|
+
Warming up --------------------------------------
|
67
|
+
format 50 chars 3.167k i/100ms
|
68
|
+
format 100 chars 1.588k i/100ms
|
69
|
+
format 400 chars 496.000 i/100ms
|
70
|
+
format_html 166.000 i/100ms
|
71
|
+
Calculating -------------------------------------
|
72
|
+
format 50 chars 31.589k (± 2.5%) i/s - 158.350k in 5.016131s
|
73
|
+
format 100 chars 16.122k (± 1.2%) i/s - 80.988k in 5.024082s
|
74
|
+
format 400 chars 4.946k (± 2.6%) i/s - 24.800k in 5.017711s
|
75
|
+
format_html 1.659k (± 1.7%) i/s - 8.300k in 5.003164s
|
76
|
+
```
|
77
|
+
|
78
|
+
## Know issues
|
79
|
+
|
80
|
+
Bundler install error:
|
81
|
+
|
82
|
+
```
|
83
|
+
Could not find gem 'autocorrect-rb' with platform 'ruby' in rubygems repository https://rubygems.org/ or installed locally.
|
84
|
+
```
|
85
|
+
|
86
|
+
To fix this you can run:
|
87
|
+
|
88
|
+
```bash
|
89
|
+
$ bundle lock --remove-platform ruby
|
90
|
+
```
|
91
|
+
|
92
|
+
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`
|
93
|
+
|
94
|
+
|
data/Rakefile
CHANGED
@@ -7,6 +7,7 @@ rescue LoadError
|
|
7
7
|
end
|
8
8
|
|
9
9
|
require "bundler/gem_tasks"
|
10
|
+
require "rubygems/package_task"
|
10
11
|
require "rake/testtask"
|
11
12
|
require "rake/extensiontask"
|
12
13
|
require "bundler"
|
@@ -19,22 +20,57 @@ CROSS_PLATFORMS = %w[
|
|
19
20
|
x86_64-linux
|
20
21
|
]
|
21
22
|
|
22
|
-
spec = Bundler.load_gemspec("autocorrect-rb.gemspec")
|
23
|
-
|
24
23
|
Rake::TestTask.new(:test) do |t|
|
25
24
|
t.libs << "test"
|
26
25
|
t.libs << "lib"
|
27
26
|
t.test_files = FileList["test/**/*_test.rb"]
|
28
27
|
end
|
29
28
|
|
30
|
-
|
31
|
-
|
29
|
+
spec = Bundler.load_gemspec("autocorrect-rb.gemspec")
|
30
|
+
|
31
|
+
# Make a autocorrect-rb-0.0.0.gem
|
32
|
+
# Disable release gem for platform: ruby, because autocorrect rust source build is complex.
|
33
|
+
# Gem::PackageTask.new(spec).define
|
34
|
+
|
35
|
+
# Make a native gem, eg. autocorrect-rb-0.0.0-x86_64-linux.gem
|
36
|
+
Rake::ExtensionTask.new("autocorrect", spec) do |ext|
|
37
|
+
# Compile output autocorrect.so into lib/autocorrect/autocorrect.so
|
32
38
|
ext.lib_dir = "lib/autocorrect"
|
33
39
|
ext.source_pattern = "*.{rs,toml}"
|
34
40
|
ext.cross_compile = true
|
35
41
|
ext.cross_platform = CROSS_PLATFORMS
|
36
42
|
end
|
37
43
|
|
38
|
-
task
|
44
|
+
task :bench do
|
45
|
+
require "benchmark/ips"
|
46
|
+
require "./lib/autocorrect-rb"
|
47
|
+
|
48
|
+
html = open("./test/fixtures/example.txt").read
|
49
|
+
|
50
|
+
Benchmark.ips do |x|
|
51
|
+
x.report("format 50 chars") do |n|
|
52
|
+
n.times do
|
53
|
+
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
x.report("format 100 chars") do |n|
|
57
|
+
n.times do
|
58
|
+
AutoCorrect.format("【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称,【野村:重申吉利汽车(00175)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
x.report("format 400 chars") do |n|
|
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月开始已持续投资领克品牌及进行市场推广,带动领克销量环比有所改变,预期今明两年领克将占整体销量的11%及14%。 该行表示,由于低端国产车品牌在欠缺新车款及科技下,行业整合度将提升。另外,公司从去年第二季到12月为止,一直都积极推动经销商去库存,这将有利公司今年利润率复苏。")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
x.report("format_html") do |n|
|
68
|
+
n.times do
|
69
|
+
AutoCorrect.format_for(html, "text.html")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
39
75
|
task test: :compile
|
40
|
-
task default: %i[
|
76
|
+
task default: %i[test]
|
@@ -0,0 +1,13 @@
|
|
1
|
+
[package]
|
2
|
+
edition = "2021"
|
3
|
+
name = "autocorrect-rb"
|
4
|
+
version = "2.1.1"
|
5
|
+
|
6
|
+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
7
|
+
[lib]
|
8
|
+
crate-type = ["cdylib"]
|
9
|
+
name = "autocorrect"
|
10
|
+
|
11
|
+
[dependencies]
|
12
|
+
autocorrect = {path = "../../../autocorrect", version = ">=1.0.0"}
|
13
|
+
magnus = "0.3"
|
@@ -0,0 +1,125 @@
|
|
1
|
+
use magnus::{define_class, function, Error, Object};
|
2
|
+
|
3
|
+
#[derive(Debug, Clone)]
|
4
|
+
pub struct LineResult {
|
5
|
+
line: usize,
|
6
|
+
col: usize,
|
7
|
+
new: String,
|
8
|
+
old: String,
|
9
|
+
severity: usize,
|
10
|
+
}
|
11
|
+
|
12
|
+
impl LineResult {
|
13
|
+
pub fn line(&self) -> usize {
|
14
|
+
self.line
|
15
|
+
}
|
16
|
+
|
17
|
+
pub fn col(&self) -> usize {
|
18
|
+
self.col
|
19
|
+
}
|
20
|
+
|
21
|
+
pub fn get_new(&self) -> String {
|
22
|
+
self.new.clone()
|
23
|
+
}
|
24
|
+
|
25
|
+
pub fn old(&self) -> String {
|
26
|
+
self.old.clone()
|
27
|
+
}
|
28
|
+
|
29
|
+
pub fn severity(&self) -> usize {
|
30
|
+
self.severity
|
31
|
+
}
|
32
|
+
|
33
|
+
pub fn inspect(&self) -> String {
|
34
|
+
format!("{:?}", self)
|
35
|
+
}
|
36
|
+
|
37
|
+
pub fn to_hash(&self) -> Result<magnus::RHash, Error> {
|
38
|
+
let hash = magnus::RHash::new();
|
39
|
+
hash.aset("line", self.line())?;
|
40
|
+
hash.aset("col", self.col())?;
|
41
|
+
hash.aset("new", self.get_new())?;
|
42
|
+
hash.aset("old", self.old())?;
|
43
|
+
hash.aset("severity", self.severity())?;
|
44
|
+
Ok(hash)
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
#[derive(Debug, Clone)]
|
49
|
+
pub struct LintResult {
|
50
|
+
pub filepath: String,
|
51
|
+
pub lines: Vec<LineResult>,
|
52
|
+
pub error: String,
|
53
|
+
}
|
54
|
+
|
55
|
+
impl LintResult {
|
56
|
+
pub fn filepath(&self) -> String {
|
57
|
+
self.filepath.clone()
|
58
|
+
}
|
59
|
+
|
60
|
+
pub fn lines(&self) -> Vec<LineResult> {
|
61
|
+
self.lines.clone()
|
62
|
+
}
|
63
|
+
|
64
|
+
pub fn error(&self) -> String {
|
65
|
+
self.error.clone()
|
66
|
+
}
|
67
|
+
|
68
|
+
pub fn inspect(&self) -> String {
|
69
|
+
format!("{:?}", self)
|
70
|
+
}
|
71
|
+
|
72
|
+
pub fn to_hash(&self) -> Result<magnus::RHash, Error> {
|
73
|
+
let hash = magnus::RHash::new();
|
74
|
+
hash.aset("filepath", self.filepath())?;
|
75
|
+
hash.aset(
|
76
|
+
"lines",
|
77
|
+
self.lines()
|
78
|
+
.iter()
|
79
|
+
.map(|l| l.to_hash().unwrap())
|
80
|
+
.collect::<Vec<magnus::RHash>>(),
|
81
|
+
)?;
|
82
|
+
hash.aset("error", self.error())?;
|
83
|
+
Ok(hash)
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
pub fn format(input: String) -> String {
|
88
|
+
autocorrect::format(&input)
|
89
|
+
}
|
90
|
+
|
91
|
+
pub fn format_for(input: String, filename_or_ext: String) -> String {
|
92
|
+
autocorrect::format_for(&input, &filename_or_ext).out
|
93
|
+
}
|
94
|
+
|
95
|
+
pub fn lint_for(input: String, filename_or_ext: String) -> magnus::RHash {
|
96
|
+
let result = autocorrect::lint_for(&input, &filename_or_ext);
|
97
|
+
|
98
|
+
LintResult {
|
99
|
+
filepath: filename_or_ext,
|
100
|
+
lines: result
|
101
|
+
.lines
|
102
|
+
.iter()
|
103
|
+
.map(|l| LineResult {
|
104
|
+
line: l.line,
|
105
|
+
col: l.col,
|
106
|
+
new: l.new.clone(),
|
107
|
+
old: l.old.clone(),
|
108
|
+
severity: l.severity.clone() as usize,
|
109
|
+
})
|
110
|
+
.collect::<_>(),
|
111
|
+
error: result.error,
|
112
|
+
}
|
113
|
+
.to_hash()
|
114
|
+
.unwrap()
|
115
|
+
}
|
116
|
+
|
117
|
+
#[magnus::init(name = "autocorrect")]
|
118
|
+
fn init() -> Result<(), Error> {
|
119
|
+
let class = define_class("AutoCorrect", Default::default())?;
|
120
|
+
class.define_singleton_method("format", function!(format, 1))?;
|
121
|
+
class.define_singleton_method("format_for", function!(format_for, 2))?;
|
122
|
+
class.define_singleton_method("lint_for", function!(lint_for, 2))?;
|
123
|
+
|
124
|
+
Ok(())
|
125
|
+
}
|
Binary file
|
Binary file
|
Binary file
|
data/lib/autocorrect-rb.rb
CHANGED
@@ -3,10 +3,5 @@ begin
|
|
3
3
|
ruby_version = /(\d+\.\d+)/.match(::RUBY_VERSION)
|
4
4
|
require_relative "autocorrect/#{ruby_version}/autocorrect"
|
5
5
|
rescue LoadError
|
6
|
-
# fall back to the extension compiled upon installation.
|
7
|
-
# use "require" instead of "require_relative" because non-native gems will place C extension files
|
8
|
-
# in Gem::BasicSpecification#extension_dir after compilation (during normal installation), which
|
9
|
-
# is in $LOAD_PATH but not necessarily relative to this file
|
10
|
-
# (see https://github.com/sparklemotion/nokogiri/issues/2300 for more)
|
11
6
|
require "autocorrect/autocorrect"
|
12
7
|
end
|
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.2.0
|
5
5
|
platform: x86_64-darwin
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rb_sys
|
@@ -34,6 +34,9 @@ extra_rdoc_files: []
|
|
34
34
|
files:
|
35
35
|
- README.md
|
36
36
|
- Rakefile
|
37
|
+
- ext/autocorrect/Cargo.toml
|
38
|
+
- ext/autocorrect/extconf.rb
|
39
|
+
- ext/autocorrect/src/lib.rs
|
37
40
|
- lib/autocorrect-rb.rb
|
38
41
|
- lib/autocorrect/2.7/autocorrect.bundle
|
39
42
|
- lib/autocorrect/3.0/autocorrect.bundle
|