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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 845856b16663aa450d919e2c4009e177ff8f54ccc1151b58bcae56e827541bac
4
- data.tar.gz: 2a97cbcd96ba7b4be9447ef0fd69c91cca9331c6a1d847d70f52c33392648542
3
+ metadata.gz: 110c4e66b76fa87662b3559e04cc25faf990166ed5794400289c878e9ffaeddd
4
+ data.tar.gz: f7df454eddbf9ef7dc3ef14756d565ede1ab49917ebda52097e41f963d823322
5
5
  SHA512:
6
- metadata.gz: 52ce1bb30d1e920543fab77028ee91acdec1b8b1573b28a2dddb809ac95226059b260f8bf01190c49ec4ade44f5504784e5bb24f7dfe0b4f514d66557735bb2c
7
- data.tar.gz: 2121884d734869fcd2bda8110a6961199a1ff76f56a9e89207ffaf812284f570f2ee1e4ad5acccd5b3652b08231d9f216ce240ce9f1a7892732e60d3b52075bc
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 3x faster than the Ruby (pure) version.
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)“买入”评级 上调目标价至17.9港元】智通财经APP获悉,野村发布报告称")
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月开始已持续投资领克品牌及进行市场推广,带动领克销量环比有所改变,预期今明两年领克将占整体销量的11%及14%。 该行表示,由于低端国产车品牌在欠缺新车款及科技下,行业整合度将提升。另外,公司从去年第二季到12月为止,一直都积极推动经销商去库存,这将有利公司今年利润率复苏。")
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]
@@ -1,7 +1,7 @@
1
1
  [package]
2
2
  edition = "2021"
3
3
  name = "autocorrect-rb"
4
- version = "2.4.0"
4
+ version = "2.5.0"
5
5
 
6
6
  # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7
7
  [lib]
@@ -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.clone() as usize,
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.0
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-10-27 00:00:00.000000000 Z
11
+ date: 2022-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rb_sys