中英文自动加空格 auto-correct

码农软件 · 软件分类 · 常用工具包 · 2019-08-15 19:13:12

软件介绍

auto-correct 会自动给中文英文之间加入合理的空格,自动纠正中文英文混排是一些不够好的写法,纠正错误的名词大小写。

Before

[经验之谈]转行做ruby程序员的8个月, mysql 经验

After

[经验之谈] 转行做 Ruby 程序员的 8 个月, MySQL 经验

使用说明

irb> require 'auto-correct'
true
irb> "关于ssh连接的Permission denied(publickey).".auto_correct!
关于 SSH 连接的 Permission denied (publickey).
irb> "怎样追踪一个repo的新feature 和进展呢?".auto_correct!
怎样追踪一个 repo 的新 feature 和进展呢?
irb> "vps上sessions不生效,但在本地的环境是ok的,why?".auto_correct!
VPS 上 sessions 不生效,但在本地的环境是 OK 的,why?
irb> "bootstrap control-group对齐问题".auto_correct!
Bootstrap control-group 对齐问

ActiveModel 的 changed? 相关提示

由于 auto_correct 是直接修改原始变量值的,你可能会遇到由于没有引发 ActiveModel::Dirty 的相关 callback 事件而导致下面这种场景 ActiveModel 不会将相关的字段写入到数据库。

比如下面的情况:

class Topic < ActiveRecord::Base
  before_save do
    self.title.auto_correct!
  end
end

正确的方式:

class Topic < ActiveRecord::Base
  before_save do
    # 引发 ActiveModel::Dirty 的 change
    self.title_will_change!
    self.title.auto_correct!
  end
end

具体请参见 ActiveModel::Dirty 的文档

性能

详见 Rakefile

$ rake benchmark
       user     system      total        real
auto_correct!
 100 times  0.000000   0.000000   0.000000 (  0.004397)
 1000 times  0.030000   0.000000   0.030000 (  0.031084)
 10000 times  0.330000   0.010000   0.340000 (  0.335932)
auto_space!
 100 times  0.010000   0.000000   0.010000 (  0.002938)
 1000 times  0.020000   0.000000   0.020000 (  0.023121)
 10000 times  0.210000   0.000000   0.210000 (  0.221530)

TODO

  • 'Foo'的"Bar" -> 'Foo' 的 "Bar"

  • 什么,时候 -> 什么, 时候 -> 什么,时候

应用案例

  • Ruby China - 目前整站的标题都做了自动转换处理。

本文地址:https://www.codercto.com/soft/d/12441.html

Web Design for ROI

Web Design for ROI

Lance Loveday、Sandra Niehaus / New Riders Press / 2007-10-27 / USD 39.99

Your web site is a business--design it like one. Billions of dollars in spending decisions are influenced by web sites. So why aren't businesses laser-focused on designing their sites to maximize thei......一起来看看 《Web Design for ROI》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

SHA 加密
SHA 加密

SHA 加密工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具