negarmoji 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -87,7 +87,8 @@ module Emoji # :nodoc:
87
87
  if custom?
88
88
  "#{name}.#{extension}"
89
89
  else
90
- "#{hex_inspect}.#{extension}"
90
+ hex_name = hex_inspect.gsub(%r{-(fe0f|200d)\b}, "")
91
+ "#{hex_name}.#{extension}"
91
92
  end
92
93
  end
93
94
  end
@@ -134,5 +134,5 @@ module Emoji # :nodoc:
134
134
  end
135
135
  end
136
136
 
137
- # Preload negarmoji into memory
137
+ # Preload negarmoji into memory.
138
138
  Emoji.all
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Emoji
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.8"
5
5
  end
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # path variables.
4
+ VENDORDIR="${PWD%/*}"/vendor
5
+ TEMPDIR="temp"
6
+
7
+ # create temporary directory for files.
8
+ mkdir -p $TEMPDIR
9
+
10
+ # download gemoji and openmoji json files.
11
+ curl -L https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/data/openmoji.json --output $TEMPDIR/openmoji.json
12
+ curl -L https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json --output $TEMPDIR/gemoji.json
13
+
14
+ # download latest unicode emoji test from gemoji.
15
+ curl -L https://raw.githubusercontent.com/github/gemoji/master/vendor/unicode-emoji-test.txt --output "$VENDORDIR"/unicode-emoji-test.txt
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "negarmoji"
5
+ require "json"
6
+
7
+ file_names = Emoji.all.map(&:image_filename).flatten
8
+
9
+ File.open(ARGV[0], "w") do |file|
10
+ file.write(JSON.pretty_generate(file_names))
11
+ end
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Python Standard Library
4
+ import json
5
+ import codecs
6
+ import copy
7
+
8
+ def handle_alias_special_case(alias):
9
+ # special aliases causing duplication problems.
10
+ special_cases = [
11
+ "pretzel",
12
+ "sunglasses",
13
+ "pouting_face",
14
+ "kiss",
15
+ "horse",
16
+ "camel",
17
+ "post_office",
18
+ "satellite",
19
+ "umbrella",
20
+ "snowman",
21
+ "calendar"
22
+ ]
23
+
24
+ if alias in special_cases:
25
+ alias = list(alias)
26
+ alias.append("2")
27
+ alias = "".join(alias)
28
+ return alias
29
+ elif alias == "flag_åland_islands":
30
+ return "flag_aland_islands"
31
+ else:
32
+ return alias
33
+
34
+ def create_alias(annotation, category):
35
+ """Create alias from annotation."""
36
+ # clean annotation from bad characters.
37
+ alias = annotation.strip()
38
+ alias = alias.replace("&", "")
39
+ alias = alias.replace("!", "")
40
+ alias = alias.replace("(", "")
41
+ alias = alias.replace(")", "")
42
+ alias = alias.replace("“", "")
43
+ alias = alias.replace("”", "")
44
+ alias = alias.replace("’", "")
45
+ alias = alias.replace("#", "hashtag")
46
+ alias = alias.replace("*", "astrix")
47
+ alias = alias.replace("ä", "a")
48
+ alias = alias.replace("ã", "a")
49
+ # doesn't remove flag_åland_islands :|
50
+ alias = alias.replace("å", "a")
51
+ alias = alias.replace("ç", "c")
52
+ alias = alias.replace("é", "e")
53
+ alias = alias.replace("ô", "o")
54
+ alias = alias.replace("í", "i")
55
+ alias = alias.replace("ñ", "n")
56
+ alias = alias.replace("ü", "u")
57
+ alias = alias.replace(" ", "_")
58
+ alias = alias.replace("-", "_")
59
+ alias = alias.replace(".", "_")
60
+ alias = alias.replace(":", "_")
61
+ alias = alias.replace(",", "_")
62
+ alias = alias.replace("__", "_")
63
+ # handle openmoji extra emojis.
64
+ if category == "Extras & Openmoji":
65
+ alias = list(alias)
66
+ alias.append("-extra")
67
+ alias = "".join(alias)
68
+ # lowercase characters.
69
+ alias = alias.lower()
70
+ return handle_alias_special_case(alias)
71
+
72
+ def create_new_emoji(emoji, description, category, aliases, tags, unicode_version):
73
+ """base structure for a emoji dictionary."""
74
+ new_dict = {
75
+ "emoji": emoji
76
+ , "description": description
77
+ , "category": category
78
+ , "aliases": [
79
+ aliases
80
+ ]
81
+ , "tags": [
82
+ tags
83
+ ]
84
+ , "unicode_version": f"{unicode_version}.0" if unicode_version is not None else ""
85
+ , "ios_version": f"{unicode_version}.0" if unicode_version is not None else ""
86
+ }
87
+ return new_dict
88
+
89
+ def generate_negarmoji_json(gemoji_json_file, openmoji_json_file, output_file_path):
90
+ """Generate negarmoji json from combining openmoji json and gemoji json."""
91
+
92
+ # read in gemoji and openmoji json files.
93
+ with open(gemoji_json_file, "rb") as read_file:
94
+ gemoji = json.load(read_file)
95
+ with open(openmoji_json_file, "rb") as read_file:
96
+ openmoji = json.load(read_file)
97
+
98
+ # collect emojis from emoji dictionaries.
99
+ gemoji_emojis = set([emoji_dict["emoji"] for emoji_dict in gemoji])
100
+ openmoji_emojis = set([emoji_dict["emoji"] for emoji_dict in openmoji])
101
+
102
+ # some emojis are same in both gemoji and openmoji emojis but they differ in
103
+ # the end sequence, openmoji usually have an extra \ufe0f character, so in
104
+ # this part of code I'm trying to normalize gemoji dictionary by appending
105
+ # \ufe0f to the end of some emojis which results in a same emoji in
106
+ # the openmoji dictionary.
107
+
108
+ # find emojis in gemoji which will be same with an emoji in openmoji if we
109
+ # add \ufe0f at the end of it.
110
+ difference = [
111
+ (emoji.replace("\ufe0f", ""), emoji)
112
+ for emoji in openmoji_emojis
113
+ if emoji.replace("\ufe0f", "") in gemoji_emojis
114
+ ]
115
+
116
+ # normalize gemoji dictionary by replacing emojis.
117
+ for emoji_dict in gemoji:
118
+ for diff in difference:
119
+ if emoji_dict["emoji"] == diff[0]:
120
+ emoji_dict["emoji"] = diff[1]
121
+ break
122
+
123
+ # re-create gemoji emojis from normalized gemoji dictionary.
124
+ gemoji_emojis = set([emoji_dict["emoji"] for emoji_dict in gemoji])
125
+
126
+ # find difference between openmoji and gemoji. since we have normalized
127
+ # gemoji, in this stage only unique new emojis from openmoji will show up
128
+ # and not the same emojis with and extra \ufe0f at the end of it.
129
+ difference = openmoji_emojis - gemoji_emojis
130
+
131
+ # create base negarmoji dictionary from gemoji.
132
+ negarmoji = copy.deepcopy(gemoji)
133
+
134
+ # convert new unique emojis from openmoji dictionary type to negarmoji dictionary
135
+ for emoji_dict in openmoji:
136
+ if emoji_dict["emoji"] in difference:
137
+ # filter properties.
138
+ emoji = emoji_dict["emoji"]
139
+ description = emoji_dict["annotation"]
140
+ category = emoji_dict["group"].replace("-", " & ").title()
141
+ aliases = create_alias(emoji_dict["annotation"], category)
142
+ tags = emoji_dict["tags"]
143
+ unicode_version = emoji_dict["unicode"]
144
+ # create emoji dictionary.
145
+ new_emoji_dict = create_new_emoji(emoji, description, category, aliases, tags, unicode_version)
146
+ # add new dictionary to negarmoji dictionary.
147
+ negarmoji.append(new_emoji_dict)
148
+
149
+ # add extra aliases for emojis from openmoji annotations.
150
+ for emoji_dict in negarmoji:
151
+ for emoji_dict_2 in openmoji:
152
+ if emoji_dict["emoji"] == emoji_dict_2["emoji"]:
153
+ new_alias = create_alias(emoji_dict_2["annotation"], emoji_dict_2["group"].replace("-", " & ").title())
154
+ if new_alias not in emoji_dict["aliases"]:
155
+ check_duplicate = list(new_alias)
156
+ check_duplicate.append("2")
157
+ check_duplicate = "".join(check_duplicate)
158
+ if check_duplicate not in emoji_dict["aliases"]:
159
+ emoji_dict["aliases"].append(new_alias)
160
+ break
161
+
162
+ with codecs.open(output_file_path, "w", encoding="utf8") as write_file:
163
+ json.dump(negarmoji, write_file, ensure_ascii=False, indent=4)
@@ -8,5 +8,5 @@
8
8
  # -x Print commands and their arguments as they are executed.
9
9
  set -ex
10
10
 
11
- script/test_style.sh
12
- script/test_module.sh
11
+ script/test_style.sh || ./test_style.sh
12
+ script/test_module.sh || ./test_module.sh
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env python3
2
+
3
+ # Python Standard Library
4
+ import os
5
+ import glob
6
+ import subprocess
7
+
8
+ # Custom modules
9
+ from json_generator import generate_negarmoji_json
10
+
11
+ # configure path variables.
12
+ file_path = os.path.abspath(os.path.dirname(__file__))
13
+ base_path = os.path.abspath(os.path.dirname(file_path))
14
+ temp_path = os.path.join(file_path, "temp")
15
+ gemoji_json_file = os.path.join(temp_path, "gemoji.json")
16
+ openmoji_json_file = os.path.join(temp_path, "openmoji.json")
17
+ negarmoji_json_file = os.path.join(base_path, "db", "negarmoji.json")
18
+ filenames_json_file = os.path.join(base_path, "db", "filenames.json")
19
+
20
+ # download latest files from gemoji and openmoji repositories.
21
+ process = subprocess.run(["./downloader.sh"], stdout=subprocess.PIPE)
22
+
23
+ # generate negarmoji json.
24
+ generate_negarmoji_json(gemoji_json_file, openmoji_json_file, negarmoji_json_file)
25
+
26
+ # generate emoji filenames json.
27
+ process = subprocess.run(["./filename_generator.rb", f"{filenames_json_file}"], stdout=subprocess.PIPE)
28
+
29
+ # delete temp folder.
30
+ process = subprocess.run(["rm", "-rf", f"{temp_path}"], stdout=subprocess.PIPE)
@@ -1,8 +1,8 @@
1
- require "test_helper"
2
- require_relative "../db/emoji-test-parser"
1
+ require 'test_helper'
2
+ require_relative '../db/emoji-test-parser'
3
3
 
4
4
  class EmojiTest < TestCase
5
- test "fetching all negarmoji" do
5
+ test "fetching all emoji" do
6
6
  count = Emoji.all.size
7
7
  assert count > 845, "there were too few emojis: #{count}"
8
8
  end
@@ -13,26 +13,26 @@ class EmojiTest < TestCase
13
13
  assert count > min_size, "there were too few unicode mappings: #{count}"
14
14
  end
15
15
 
16
- test "finding negarmoji by alias" do
17
- assert_equal "smile", Emoji.find_by_alias("smile").name
16
+ test "finding emoji by alias" do
17
+ assert_equal 'smile', Emoji.find_by_alias('smile').name
18
18
  end
19
19
 
20
- test "finding nonexistent negarmoji by alias returns nil" do
21
- assert_nil Emoji.find_by_alias("$$$")
20
+ test "finding nonexistent emoji by alias returns nil" do
21
+ assert_nil Emoji.find_by_alias('$$$')
22
22
  end
23
23
 
24
- test "finding negarmoji by unicode" do
24
+ test "finding emoji by unicode" do
25
25
  emoji = Emoji.find_by_unicode("\u{1f604}") # grinning face with smiling eyes
26
26
  assert_equal "\u{1f604}", emoji.raw
27
27
  end
28
28
 
29
- test "finding nonexistent negarmoji by unicode returns nil" do
29
+ test "finding nonexistent emoji by unicode returns nil" do
30
30
  assert_nil Emoji.find_by_unicode("\u{1234}")
31
31
  end
32
32
 
33
33
  test "unicode_aliases" do
34
34
  emoji = Emoji.find_by_unicode("\u{2728}") # sparkles
35
- assert_equal %w[2728 2728-fe0f], emoji.unicode_aliases.map { |u| Emoji::Character.hex_inspect(u) }
35
+ assert_equal ["2728", "2728-fe0f"], emoji.unicode_aliases.map { |u| Emoji::Character.hex_inspect(u) }
36
36
  end
37
37
 
38
38
  test "unicode_aliases doesn't necessarily include form without VARIATION_SELECTOR_16" do
@@ -41,22 +41,21 @@ class EmojiTest < TestCase
41
41
  end
42
42
 
43
43
  test "emojis have tags" do
44
- emoji = Emoji.find_by_alias("smile")
45
- assert emoji.tags.include?("happy")
46
- assert emoji.tags.include?("joy")
47
- assert emoji.tags.include?("pleased")
44
+ emoji = Emoji.find_by_alias('smile')
45
+ assert emoji.tags.include?('happy')
46
+ assert emoji.tags.include?('joy')
47
+ assert emoji.tags.include?('pleased')
48
48
  end
49
49
 
50
50
  GENDER_EXCEPTIONS = [
51
- "man_with_gua_pi_mao",
52
- "woman_with_headscarf",
53
- "man_in_tuxedo",
54
- "pregnant_woman",
55
- "isle_of_man",
56
- "blonde_woman",
57
- %r{^couple(kiss)?_},
58
- %r{^family_}
59
- ].freeze
51
+ "man_with_gua_pi_mao",
52
+ "woman_with_headscarf",
53
+ "pregnant_woman",
54
+ "isle_of_man",
55
+ "blonde_woman",
56
+ /^couple(kiss)?_/,
57
+ /^family_/,
58
+ ]
60
59
 
61
60
  test "emojis have valid names" do
62
61
  aliases = Emoji.all.flat_map(&:aliases)
@@ -65,58 +64,81 @@ class EmojiTest < TestCase
65
64
  alias_count = Hash.new(0)
66
65
  aliases.each do |name|
67
66
  alias_count[name] += 1
68
- invalid << name if name !~ %r{\A[\w+-]+\Z}
67
+ invalid << name if name !~ /\A[\w+-]+\Z/
69
68
  end
70
69
 
71
70
  duplicates = alias_count.select { |_, count| count > 1 }.keys
72
71
 
73
- assert_equal [], invalid, "some negarmoji have invalid names"
74
- assert_equal [], duplicates, "some negarmoji aliases have duplicates"
72
+ assert_equal [], invalid, "some emoji have invalid names"
73
+ assert_equal [], duplicates, "some emoji aliases have duplicates"
74
+ end
75
+
76
+ test "missing or incorrect unicodes" do
77
+ emoji_map, _ = EmojiTestParser.parse(File.expand_path("../../vendor/unicode-emoji-test.txt", __FILE__))
78
+ source_unicode_emoji = emoji_map.values
79
+ supported_sequences = Emoji.all.flat_map(&:unicode_aliases)
80
+ text_glyphs = Emoji.const_get(:TEXT_GLYPHS)
81
+
82
+ missing = 0
83
+ message = "Missing or incorrect unicodes:\n"
84
+ source_unicode_emoji.each do |emoji|
85
+ emoji[:sequences].each do |raw|
86
+ next if text_glyphs.include?(raw) || Emoji.find_by_unicode(raw)
87
+ message << "%s (%s)" % [Emoji::Character.hex_inspect(raw), emoji[:description]]
88
+ if found = Emoji.find_by_unicode(raw.gsub("\u{fe0f}", ""))
89
+ message << " - could be %s (:%s:)" % [found.hex_inspect, found.name]
90
+ end
91
+ message << "\n"
92
+ missing += 1
93
+ end
94
+ end
95
+
96
+ assert_equal 0, missing, message
75
97
  end
76
98
 
77
- test "negarmoji have category" do
99
+ test "emoji have category" do
78
100
  missing = Emoji.all.select { |e| e.category.to_s.empty? }
79
- assert_equal [], missing.map(&:name), "some negarmoji don't have a category"
101
+ assert_equal [], missing.map(&:name), "some emoji don't have a category"
80
102
 
81
- emoji = Emoji.find_by_alias("family_man_woman_girl")
82
- assert_equal "People & Body", emoji.category
103
+ emoji = Emoji.find_by_alias('family_man_woman_girl')
104
+ assert_equal 'People & Body', emoji.category
83
105
 
84
106
  categories = Emoji.all.map(&:category).uniq.compact
85
107
  assert_equal [
86
- "Smileys & Emotion",
87
- "People & Body",
88
- "Animals & Nature",
89
- "Food & Drink",
90
- "Travel & Places",
91
- "Activities",
92
- "Objects",
93
- "Symbols",
94
- "Flags",
95
- "Component",
96
- "Extras & Openmoji",
97
- "Extras & Unicode"
108
+ "Smileys & Emotion",
109
+ "People & Body",
110
+ "Animals & Nature",
111
+ "Food & Drink",
112
+ "Travel & Places",
113
+ "Activities",
114
+ "Objects",
115
+ "Symbols",
116
+ "Flags",
117
+ "Component",
118
+ "Extras & Openmoji",
119
+ "Extras & Unicode"
98
120
  ], categories
99
121
  end
100
122
 
101
- test "negarmoji have description" do
123
+ test "emoji have description" do
102
124
  missing = Emoji.all.select { |e| e.description.to_s.empty? }
103
- assert_equal [], missing.map(&:name), "some negarmoji don't have a description"
125
+ assert_equal [], missing.map(&:name), "some emoji don't have a description"
104
126
 
105
- emoji = Emoji.find_by_alias("family_man_woman_girl")
106
- assert_equal "family: man, woman, girl", emoji.description
127
+ emoji = Emoji.find_by_alias('family_man_woman_girl')
128
+ assert_equal 'family: man, woman, girl', emoji.description
107
129
  end
108
130
 
109
- test "negarmoji have Unicode version" do
110
- emoji = Emoji.find_by_alias("family_man_woman_girl")
111
- assert_equal "6.0", emoji.unicode_version
131
+ test "emoji have Unicode version" do
132
+ emoji = Emoji.find_by_alias('family_man_woman_girl')
133
+ assert_equal '6.0', emoji.unicode_version
112
134
  end
113
135
 
114
- test "negarmoji have iOS version" do
136
+ test "emoji have iOS version" do
115
137
  missing = Emoji.all.select { |e| e.ios_version.to_s.empty? }
116
- assert_equal [], missing.map(&:name), "some negarmoji don't have an iOS version"
138
+ assert_equal [], missing.map(&:name), "some emoji don't have an iOS version"
117
139
 
118
- emoji = Emoji.find_by_alias("family_man_woman_girl")
119
- assert_equal "8.3", emoji.ios_version
140
+ emoji = Emoji.find_by_alias('family_man_woman_girl')
141
+ assert_equal '8.3', emoji.ios_version
120
142
  end
121
143
 
122
144
  test "no custom emojis" do
@@ -183,11 +205,12 @@ class EmojiTest < TestCase
183
205
 
184
206
  begin
185
207
  assert_equal emoji, Emoji.find_by_alias("weary")
208
+ assert_equal emoji, Emoji.find_by_alias("weary_face")
186
209
  assert_equal emoji, Emoji.find_by_alias("whining")
187
210
  assert_equal emoji, Emoji.find_by_unicode("\u{1f629}")
188
211
  assert_equal emoji, Emoji.find_by_unicode("\u{1f629}\u{266a}")
189
212
 
190
- assert_equal %w[weary whining], emoji.aliases
213
+ assert_equal %w[weary weary_face whining], emoji.aliases
191
214
  assert_includes emoji.tags, "complaining"
192
215
  ensure
193
216
  emoji.aliases.pop