harmonious_check 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/.rspec +1 -0
- data/.travis.yml +4 -0
- data/CHANGELOG +3 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +84 -0
- data/Rakefile +8 -0
- data/benchmark/benchmark.rb +43 -0
- data/benchmark/text_test_100.txt +4 -0
- data/benchmark/text_test_1000.txt +25 -0
- data/benchmark/text_test_10000.txt +219 -0
- data/bin/harmonious_rseg +11 -0
- data/bin/harmonious_server +63 -0
- data/harmonious_dictionary.gemspec +22 -0
- data/lib/generators/harmonious_dictionary/setup/setup_generator.rb +16 -0
- data/lib/generators/harmonious_dictionary/setup/templates/chinese_dictionary.txt +0 -0
- data/lib/generators/harmonious_dictionary/setup/templates/english_dictionary.txt +0 -0
- data/lib/generators/harmonious_dictionary/setup/templates/remote_server.yml +8 -0
- data/lib/harmonious_dictionary/app.rb +18 -0
- data/lib/harmonious_dictionary/engines/dict.rb +51 -0
- data/lib/harmonious_dictionary/engines/engine.rb +21 -0
- data/lib/harmonious_dictionary/engines/english.rb +29 -0
- data/lib/harmonious_dictionary/filters/conjunction.rb +13 -0
- data/lib/harmonious_dictionary/filters/fullwidth.rb +21 -0
- data/lib/harmonious_dictionary/filters/symbol.rb +18 -0
- data/lib/harmonious_dictionary/model_additions.rb +20 -0
- data/lib/harmonious_dictionary/railtie.rb +23 -0
- data/lib/harmonious_dictionary/rseg.rb +185 -0
- data/lib/harmonious_dictionary/version.rb +3 -0
- data/lib/harmonious_dictionary.rb +48 -0
- data/lib/tasks/generate_dictionary.rake +63 -0
- data/spec/harmonious_dictionary_spec.rb +61 -0
- data/spec/model_additions_spec.rb +57 -0
- data/spec/spec_helper.rb +21 -0
- metadata +109 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
|
5
|
+
|
|
6
|
+
ActiveRecord::Schema.define(:version => 1) do
|
|
7
|
+
create_table :posts do |t|
|
|
8
|
+
t.string :title
|
|
9
|
+
t.text :body
|
|
10
|
+
t.text :note
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Post < ActiveRecord::Base
|
|
15
|
+
extend HarmoniousDictionary::ModelAdditions
|
|
16
|
+
validate_harmonious_of [:title,:body], model: :post
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe HarmoniousDictionary::ModelAdditions do
|
|
20
|
+
let(:post) { @post = Post.create title:'戴秉国在中国',body:'戴秉国在中国',note:'戴秉国在中国' }
|
|
21
|
+
|
|
22
|
+
describe 'use local' do
|
|
23
|
+
it 'should validate for harmonious' do
|
|
24
|
+
post.errors[:title].should == ['不能含有敏感词']
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'should have error on title' do
|
|
28
|
+
post.errors[:body].should == ['不能含有敏感词']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'should allow empty input value' do
|
|
32
|
+
p = Post.create body:'戴秉国在中国',note:'戴秉国在中国'
|
|
33
|
+
post.errors[:body].should == ['不能含有敏感词']
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it 'should filter! any harmonious words' do
|
|
37
|
+
HarmoniousDictionary.clean(post.body).should == '***在中国'
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# 以后再开放
|
|
42
|
+
# describe 'use remote' do
|
|
43
|
+
# before(:each) do
|
|
44
|
+
# configuration = double("configuration")
|
|
45
|
+
# @double_harmonious_dictionary = double('harmonious_dictionary')
|
|
46
|
+
# configuration.stub(:harmonious_dictionary){ @double_harmonious_dictionary }
|
|
47
|
+
# @double_harmonious_dictionary.stub(:use_remote_server){ true }
|
|
48
|
+
# Rails.stub(:configuration){configuration}
|
|
49
|
+
# end
|
|
50
|
+
|
|
51
|
+
# it 'should validate for harmonious' do
|
|
52
|
+
# HarmoniousDictionary.should_receive(:clean_by_remote?)
|
|
53
|
+
# post.errors[:title].should == ['不能含有敏感词']
|
|
54
|
+
# end
|
|
55
|
+
# end
|
|
56
|
+
end
|
|
57
|
+
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
require 'rails'
|
|
4
|
+
require 'active_model'
|
|
5
|
+
require 'active_record'
|
|
6
|
+
require 'harmonious_dictionary'
|
|
7
|
+
|
|
8
|
+
RSpec.configure do |config|
|
|
9
|
+
config.color_enabled = true
|
|
10
|
+
config.formatter = 'documentation'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module Rails
|
|
14
|
+
def self.root
|
|
15
|
+
File.join File.dirname(__FILE__),'../'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.env
|
|
19
|
+
'test'
|
|
20
|
+
end
|
|
21
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: harmonious_check
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- amelia9f
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-02-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rake
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
description: 和谐宝典用于检查输入是否包含中文或英文敏感词,并可替换为特殊字符。速度比常规的正则匹配要快10倍以上。生活在天朝,和谐宝典必须人手必备。
|
|
42
|
+
email:
|
|
43
|
+
- amelia9fpyjo@gmx.com
|
|
44
|
+
executables:
|
|
45
|
+
- harmonious_rseg
|
|
46
|
+
- harmonious_server
|
|
47
|
+
extensions: []
|
|
48
|
+
extra_rdoc_files: []
|
|
49
|
+
files:
|
|
50
|
+
- ".gitignore"
|
|
51
|
+
- ".rspec"
|
|
52
|
+
- ".travis.yml"
|
|
53
|
+
- CHANGELOG
|
|
54
|
+
- MIT-LICENSE
|
|
55
|
+
- README.markdown
|
|
56
|
+
- Rakefile
|
|
57
|
+
- benchmark/benchmark.rb
|
|
58
|
+
- benchmark/text_test_100.txt
|
|
59
|
+
- benchmark/text_test_1000.txt
|
|
60
|
+
- benchmark/text_test_10000.txt
|
|
61
|
+
- bin/harmonious_rseg
|
|
62
|
+
- bin/harmonious_server
|
|
63
|
+
- harmonious_dictionary.gemspec
|
|
64
|
+
- lib/generators/harmonious_dictionary/setup/setup_generator.rb
|
|
65
|
+
- lib/generators/harmonious_dictionary/setup/templates/chinese_dictionary.txt
|
|
66
|
+
- lib/generators/harmonious_dictionary/setup/templates/english_dictionary.txt
|
|
67
|
+
- lib/generators/harmonious_dictionary/setup/templates/remote_server.yml
|
|
68
|
+
- lib/harmonious_dictionary.rb
|
|
69
|
+
- lib/harmonious_dictionary/app.rb
|
|
70
|
+
- lib/harmonious_dictionary/engines/dict.rb
|
|
71
|
+
- lib/harmonious_dictionary/engines/engine.rb
|
|
72
|
+
- lib/harmonious_dictionary/engines/english.rb
|
|
73
|
+
- lib/harmonious_dictionary/filters/conjunction.rb
|
|
74
|
+
- lib/harmonious_dictionary/filters/fullwidth.rb
|
|
75
|
+
- lib/harmonious_dictionary/filters/symbol.rb
|
|
76
|
+
- lib/harmonious_dictionary/model_additions.rb
|
|
77
|
+
- lib/harmonious_dictionary/railtie.rb
|
|
78
|
+
- lib/harmonious_dictionary/rseg.rb
|
|
79
|
+
- lib/harmonious_dictionary/version.rb
|
|
80
|
+
- lib/tasks/generate_dictionary.rake
|
|
81
|
+
- spec/harmonious_dictionary_spec.rb
|
|
82
|
+
- spec/model_additions_spec.rb
|
|
83
|
+
- spec/spec_helper.rb
|
|
84
|
+
homepage: https://github.com/amelia9f/harmonious_check
|
|
85
|
+
licenses: []
|
|
86
|
+
metadata: {}
|
|
87
|
+
post_install_message:
|
|
88
|
+
rdoc_options: []
|
|
89
|
+
require_paths:
|
|
90
|
+
- lib
|
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
|
+
requirements:
|
|
98
|
+
- - ">="
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
version: '0'
|
|
101
|
+
requirements: []
|
|
102
|
+
rubygems_version: 3.0.8
|
|
103
|
+
signing_key:
|
|
104
|
+
specification_version: 4
|
|
105
|
+
summary: filter any words that need to be harmonized
|
|
106
|
+
test_files:
|
|
107
|
+
- spec/harmonious_dictionary_spec.rb
|
|
108
|
+
- spec/model_additions_spec.rb
|
|
109
|
+
- spec/spec_helper.rb
|