emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 6aac4ca: Further tweaks to the emoji segmentation


From: Lars Ingebrigtsen
Subject: master 6aac4ca: Further tweaks to the emoji segmentation
Date: Sun, 19 Dec 2021 14:21:23 -0500 (EST)

branch: master
commit 6aac4caaff7c3217b917f3a08a114ab68f082740
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Further tweaks to the emoji segmentation
    
    * lisp/international/emoji.el (emoji--parse-emoji-test): Ensure
    that we key off of the "person" variants, even if they come after
    the gendered variations (which is the case for a handful of glyphs).
---
 lisp/international/emoji.el | 51 +++++++++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 16 deletions(-)

diff --git a/lisp/international/emoji.el b/lisp/international/emoji.el
index 4375a63..205a803 100644
--- a/lisp/international/emoji.el
+++ b/lisp/international/emoji.el
@@ -305,6 +305,7 @@ the name is not known."
     (setq emoji--names (make-hash-table :test #'equal))
     (let ((derivations (make-hash-table :test #'equal))
           (case-fold-search t)
+          (glyphs nil)
           group subgroup)
       (while (not (eobp))
         (cond
@@ -318,27 +319,40 @@ the name is not known."
           (let* ((codes (match-string 1))
                  (qualification (match-string 2))
                  (name (match-string 3))
-                 (base (emoji--base-name name derivations))
                  (glyph (mapconcat
                          (lambda (code)
                            (string (string-to-number code 16)))
                          (split-string codes))))
-            ;; Special-case flags.
-            (when (equal base "flag")
-              (setq base name))
-            ;; Register all glyphs to that we can look up their names
-            ;; later.
-            (setf (gethash glyph emoji--names) name)
-            ;; For the interface, we only care about the fully qualified
-            ;; emojis.
-            (when (equal qualification "fully-qualified")
-              (when (equal base name)
-                (emoji--add-to-group group subgroup glyph))
-              ;; Create mapping from base glyph name to name of
-              ;; derived glyphs.
-              (setf (gethash base derivations)
-                    (nconc (gethash base derivations) (list glyph)))))))
+            (push (list name qualification group subgroup glyph) glyphs))))
         (forward-line 1))
+      ;; We sort the data so that the "person foo" variant comes
+      ;; first, so that that becomes the key.
+      (setq glyphs
+            (sort (nreverse glyphs)
+                  (lambda (g1 g2)
+                    (and (equal (nth 2 g1) (nth 2 g2))
+                         (equal (nth 3 g1) (nth 3 g2))
+                         (< (emoji--score (car g1))
+                            (emoji--score (car g2)))))))
+      ;; Get the derivations.
+      (cl-loop for (name qualification group subgroup glyph) in glyphs
+               for base = (emoji--base-name name derivations)
+               do
+               ;; Special-case flags.
+               (when (equal base "flag")
+                 (setq base name))
+               ;; Register all glyphs to that we can look up their names
+               ;; later.
+               (setf (gethash glyph emoji--names) name)
+               ;; For the interface, we only care about the fully qualified
+               ;; emojis.
+               (when (equal qualification "fully-qualified")
+                 (when (equal base name)
+                   (emoji--add-to-group group subgroup glyph))
+                 ;; Create mapping from base glyph name to name of
+                 ;; derived glyphs.
+                 (setf (gethash base derivations)
+                       (nconc (gethash base derivations) (list glyph)))))
       ;; Finally create the mapping from the base glyphs to derived ones.
       (setq emoji--derived (make-hash-table :test #'equal))
       (maphash (lambda (_k v)
@@ -346,6 +360,11 @@ the name is not known."
                        (cdr v)))
                derivations))))
 
+(defun emoji--score (string)
+  (if (string-match-p "person\\|people" string)
+      0
+    1))
+
 (defun emoji--add-to-group (group subgroup glyph)
   ;; "People & Body" is very large; split it up.
   (cond



reply via email to

[Prev in Thread] Current Thread [Next in Thread]