kaomoji 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +45 -0
- data/README.md +11 -6
- data/kaomoji.gemspec +2 -0
- data/lib/kaomoji.rb +101 -3
- data/lib/kaomoji/version.rb +1 -1
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03573bed50d415dc40056a6dcb03c4654bd9ab07a9986ce1323399179b104ec9
|
4
|
+
data.tar.gz: afa6dbd4fa5e159d59ddf1ce184301a9f8de49cf1c0a399ed092be1b6de14ab0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7841381ac945f022cfa8d8aa8f2f3a330ac7708594901e52b97a96475ef772ba74c38da3743155d7093796d4dab9b47354acf249986d4c9553688f69b75a867
|
7
|
+
data.tar.gz: 2c4b3b51093aba9945498f92cd26785fb08e84f40fc8b42ae4c0656f1fcab76bddb48e48d144bd4e5c67d60944799db72960d7df01f7ac2a5305cbfbf9682674
|
data/.gitignore
CHANGED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kaomoji (0.1.0)
|
5
|
+
unicode-x
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
minitest (5.11.3)
|
11
|
+
rake (10.5.0)
|
12
|
+
unicode-blocks (1.5.0)
|
13
|
+
unicode-categories (1.5.0)
|
14
|
+
unicode-confusable (1.6.0)
|
15
|
+
unicode-display_width (1.6.0)
|
16
|
+
unicode-emoji (2.1.0)
|
17
|
+
unicode-name (1.8.0)
|
18
|
+
unicode-types (~> 1.5)
|
19
|
+
unicode-numeric_value (1.6.0)
|
20
|
+
unicode-scripts (1.5.0)
|
21
|
+
unicode-sequence_name (1.4.0)
|
22
|
+
unicode-types (1.5.0)
|
23
|
+
unicode-x (12.1.0)
|
24
|
+
unicode-blocks (>= 1.5, < 2.0)
|
25
|
+
unicode-categories (>= 1.5, < 2.0)
|
26
|
+
unicode-confusable (>= 1.6, < 2.0)
|
27
|
+
unicode-display_width (>= 1.6, < 2.0)
|
28
|
+
unicode-emoji (>= 2.0, < 3.0)
|
29
|
+
unicode-name (>= 1.8, < 2.0)
|
30
|
+
unicode-numeric_value (>= 1.6, < 2.0)
|
31
|
+
unicode-scripts (>= 1.5, < 2.0)
|
32
|
+
unicode-sequence_name (>= 1.4, < 2.0)
|
33
|
+
unicode-types (>= 1.5, < 2.0)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bundler (~> 2.0)
|
40
|
+
kaomoji!
|
41
|
+
minitest (~> 5.0)
|
42
|
+
rake (~> 10.0)
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
2.0.1
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Kaomoji
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Kaomoji can extract some thing like kaomoji from your strings.
|
4
|
+
There are many noise so you have to filter with your hand.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -22,7 +21,13 @@ Or install it yourself as:
|
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
25
|
-
|
24
|
+
You can get kaomoji from some strings.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
Kaomoji.get_unicode_kaomojis('(・3・)\(^o^)/ぷにう')
|
28
|
+
=>(・3・)\(^o^)/
|
29
|
+
```
|
30
|
+
|
26
31
|
|
27
32
|
## Development
|
28
33
|
|
@@ -32,7 +37,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
37
|
|
33
38
|
## Contributing
|
34
39
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/colorbox/kaomoji. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
41
|
|
37
42
|
## License
|
38
43
|
|
@@ -40,4 +45,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
45
|
|
41
46
|
## Code of Conduct
|
42
47
|
|
43
|
-
Everyone interacting in the Kaomoji project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
48
|
+
Everyone interacting in the Kaomoji project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/colorbox/kaomoji/blob/master/CODE_OF_CONDUCT.md).
|
data/kaomoji.gemspec
CHANGED
@@ -33,6 +33,8 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
34
34
|
spec.require_paths = ["lib"]
|
35
35
|
|
36
|
+
spec.add_dependency 'unicode-x'
|
37
|
+
|
36
38
|
spec.add_development_dependency "bundler", "~> 2.0"
|
37
39
|
spec.add_development_dependency "rake", "~> 10.0"
|
38
40
|
spec.add_development_dependency "minitest", "~> 5.0"
|
data/lib/kaomoji.rb
CHANGED
@@ -1,6 +1,104 @@
|
|
1
|
-
require
|
1
|
+
require 'kaomoji/version'
|
2
|
+
require 'unicode/x'
|
2
3
|
|
3
4
|
module Kaomoji
|
4
|
-
class
|
5
|
-
|
5
|
+
class << self
|
6
|
+
def kaomoji_parts?(chr)
|
7
|
+
kaomoji_group_categories = %w(Pc Pd Pe Pf Pi Po Ps Sc Sk Sm So)
|
8
|
+
japanese_group = %w(Basic\ Latin Hiragana CJK\ Unified\ Ideographs Fullwidth\ ASCII\ Variants)
|
9
|
+
return !japanese_group.include?(::Unicode::Blocks.blocks(chr).first) || kaomoji_group_categories.include?(::Unicode::Categories.categories(chr).first)
|
10
|
+
end
|
11
|
+
|
12
|
+
def normal_char?(chr)
|
13
|
+
normal_char_blocks = %w(Lc Ll Lm Lo Lt Lu Nd Nl)
|
14
|
+
target_block = ::Unicode::Categories.categories(chr)
|
15
|
+
normal_char_blocks.include?(target_block.first)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_unicode_kaomojis(str)
|
19
|
+
return [] if str.chars.length.zero?
|
20
|
+
|
21
|
+
kaomojis = (0..str.chars.size-1).map{|i| get_one_unicode_kaomoji_at_index(i, str) if kaomoji_parts?(str.chars[i]) }.uniq.compact
|
22
|
+
kaomojis.select{|k|valid_kaomoji?(k)}.reject{|target|kaomojis.map{|kaomoji| (kaomoji!=target) && kaomoji.include?(target)}.any?}
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_one_unicode_kaomoji_at_index(index, str)
|
26
|
+
start = get_kaomoji_left_side(index, str)
|
27
|
+
last = get_kaomoji_right_side(index, str)
|
28
|
+
str.chars[start..last].join
|
29
|
+
end
|
30
|
+
|
31
|
+
THRESHOLD=2
|
32
|
+
|
33
|
+
def get_kaomoji_right_side(start_index, str)
|
34
|
+
return start_index if start_index==str.chars.length-1
|
35
|
+
last = start_index
|
36
|
+
count = 0
|
37
|
+
str.chars[start_index..str.length-1].each_with_index do |chr, index|
|
38
|
+
if kaomoji_parts?(chr)
|
39
|
+
count = 0
|
40
|
+
last = start_index + index
|
41
|
+
elsif normal_char?(chr)
|
42
|
+
count += 1
|
43
|
+
end
|
44
|
+
return last if count > THRESHOLD || index == str.chars[start_index..str.length-1].length - 1
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_kaomoji_left_side(start_index, str)
|
49
|
+
return 0 if start_index.zero?
|
50
|
+
first = start_index
|
51
|
+
count = 0
|
52
|
+
str.chars[0..start_index].reverse.each_with_index do |chr, index|
|
53
|
+
if kaomoji_parts?(chr)
|
54
|
+
count = 0
|
55
|
+
first = start_index - index
|
56
|
+
elsif normal_char?(chr)
|
57
|
+
count += 1
|
58
|
+
end
|
59
|
+
return first if count > THRESHOLD || index == start_index-1
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def unicode_kaomojis(threshold = 2, str)
|
64
|
+
kaomojis = []
|
65
|
+
current=[]
|
66
|
+
count=0
|
67
|
+
str.split('').each do |chr|
|
68
|
+
if kaomoji_parts?(chr)
|
69
|
+
current.push(chr)
|
70
|
+
count=0
|
71
|
+
else
|
72
|
+
count+=1
|
73
|
+
end
|
74
|
+
|
75
|
+
pp [chr,count]
|
76
|
+
if count > threshold
|
77
|
+
kaomoji = current.join
|
78
|
+
kaomojis.push(kaomoji) if valid_kaomoji?(kaomoji)
|
79
|
+
current=[]
|
80
|
+
count=0
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
if current.count > 0
|
85
|
+
kaomoji = current.join
|
86
|
+
kaomojis.push(kaomoji) if valid_kaomoji?(kaomoji)
|
87
|
+
end
|
88
|
+
|
89
|
+
kaomojis
|
90
|
+
end
|
91
|
+
|
92
|
+
def valid_kaomoji?(kaomoji)
|
93
|
+
kaomoji.length > 3 && !half_of_normal_chars(kaomoji)
|
94
|
+
end
|
95
|
+
|
96
|
+
def half_of_normal_chars(str)
|
97
|
+
normal_chars = %w(Lc Ll Lm Lo Lt Lu Nd Nl)
|
98
|
+
normal_words_count =str.split('').map{|chr|::Unicode::Categories.categories(chr).map{|block|normal_chars.include?(block)}.any? ? 1 : 0}.sum.to_f
|
99
|
+
all_count = str.length.to_f
|
100
|
+
result = (normal_words_count / all_count) > 0.5
|
101
|
+
result
|
102
|
+
end
|
103
|
+
end
|
6
104
|
end
|
data/lib/kaomoji/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaomoji
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- colorbox
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2019-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: unicode-x
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -63,6 +77,7 @@ files:
|
|
63
77
|
- ".travis.yml"
|
64
78
|
- CODE_OF_CONDUCT.md
|
65
79
|
- Gemfile
|
80
|
+
- Gemfile.lock
|
66
81
|
- LICENSE.txt
|
67
82
|
- README.md
|
68
83
|
- Rakefile
|