A method for quickly decomposing and typesetting mixed content of text, emoji expressions, and emoticons
Through character-by-character decomposition and Unicode category calculation, and recombining character groups with label attributes, the problem of information entropy loss in mixed content typesetting of text, emoji, and facial text is solved, and fast and effective typesetting processing is achieved.
Patent Information
- Application Number
- CN202410280250.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-12
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2044-03-12
AI Technical Summary
The prior art is difficult to effectively process the typesetting of mixed contents of text, emoji, and facial text, resulting in the loss of information entropy during the display process.
Through character decomposition, independent and inseparable character groups are formed, the character groups are traversed for Unicode category calculation and label printing, the character groups are recombined according to the label attributes, and the maximum width of the display area is typed.
It realizes rapid decomposition and layout of text, emoji and facial text mixed content, reduces calculation steps, improves processing speed, and supports multilingual and special characters processing.
Smart Images

Figure CN118211560B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to a method for quickly decomposing and typeset mixed content of text, emoji expressions, and emoticons. Background Art
[0002] When people are chatting or expressing themselves in text, they need to express their current emotions more vividly and intuitively, so they invented characters that can express emotions intuitively and vividly, which are usually called "emoticons".
[0003] Emoticons are composed of multiple Chinese and English characters that resemble facial expressions or body movements. For example, early Western emoticons represented by “:)”, “:(”, “:->”, and “:-<” need to be tilted 90 degrees to read.
[0004] With the development of the Internet, people have gradually invented more advanced emoticons such as "(@^▽^@)ノ" and "(*´д`)" with oriental characters as the main body, which are more intuitive, readable, vivid and interesting to express their emotions. This type of text combination has a big problem, that is, because the text width is uncontrollable, once it is separated into lines during the display typesetting process, it becomes completely unreadable and loses information entropy.
[0005] With the update and development of technical standards, Unicode built-in emoji expressions have emerged. It can be composed of one or more emoji expressions into a complex emoticon with a width of two bytes.
[0006] The emergence of these text types has brought great problems to text typesetting. If line breaks are displayed purely based on the number of characters, information entropy will inevitably be lost. Therefore, it is necessary to extract and typeset such texts. Summary of the invention
[0007] The purpose of the present invention is to provide a method for quickly decomposing and typeset mixed content of text, emoji expressions, and emoticons to solve the problems raised in the above-mentioned background technology.
[0008] To achieve the above object, the present invention provides the following technical solution: a method for quickly decomposing and typesetting mixed content of text, emoji expressions, and emoticons, comprising the following steps:
[0009] S1, decomposing the input text character by character to form multiple independent and inseparable character groups;
[0010] S2, traverse the character groups, and perform Unicode category calculation on the first character of each character group to determine its type;
[0011] S3, labeling each character group according to the context and characteristics of the character group;
[0012] S4, according to the maximum width of the display text area, recombining into multiple inseparable character groups according to the label attributes;
[0013] S5. Place the inseparable character group into the display area.
[0014] Preferably, the character-by-character decomposition in S1 is performed by decomposing into groups of independent and inseparable character groups in a manner of distinguishing single characters, combined characters and substitutions.
[0015] Preferably, the method for decomposing the inseparable character group is to traverse each character in the string and extract the string into single characters or emoji emoticons.
[0016] Preferably, the single character separation method is an inseparable character group, which is separated into a new inseparable character group with an English space character or an unreleased line end and no need to wrap as the first character, and then the character group that is less than or equal to the number of single-character widths that can be displayed in the text display area is taken out and placed into a line, and the others are intercepted again after the line break until all the lines are completed.
[0017] Preferably, the type of the inseparable character group is determined by traversing all character groups, calculating the Unicode category defined by the Unicode standard to which the first character of the character group belongs, and the type of the inseparable character group is text characters, emoji expressions, and other characters.
[0018] Preferably, the method for marking the label attributes for each character group in S3 is to traverse all character groups, and if it is an emoji expression, it is marked with no need to wrap, the end of the line can be released, and a double-word width label; if it is an OpenPunctuation, it is marked with no need to wrap, the end of the line cannot be released, and a single or double-word width label; if it is a ClosePunctuation, it is marked with a need to wrap, the end of the line can be released, and a single or double-word width label; if it is OtherPunctuation, it is a punctuation mark marked with a need to wrap, the end of the line can be released, and a single or double-word width label; if the character group is Chinese characters, it is marked with no need to wrap, the end of the line can be released, and a double-word width label; other types are marked with whether to wrap, the end of the line can be released, and a single-word width label.
[0019] Preferably, in the other types, if there is a previous character group that needs to be wrapped, then the current character group also needs to be wrapped.
[0020] Preferably, the method for confirming the single or double character width label is to confirm the width of a character in Chinese and English, with Chinese being double character width, English being single character width, and emoji being double character width.
[0021] Compared with the prior art, the beneficial effects of the present invention are as follows: the present method is a highly customized text typesetting method based on Unicode character classification, which can be processed according to different character types to adapt to various situations and needs. Because it is based on Unicode, the method supports the vast majority of languages, symbols and characters in the world, including special characters such as emoji expressions and emoticons, and is more extensive and flexible. The method reduces the calculation steps and directly analyzes and labels the character type, thereby improving the processing speed. The method can be processed conveniently and quickly. The character-based labeling method greatly facilitates subsequent maintenance and expansion. Users only need to modify and add labels to make adjustments. The operation is simple and convenient, and the scalability is good. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 The figure is a flow chart of the typesetting method of the present invention. DETAILED DESCRIPTION
[0023] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0024] See also Figure 1 The present invention provides a technical solution: a method for quickly decomposing and typesetting mixed content of text, emoji expressions, and emoticons, comprising the following steps:
[0025] Separate mixed text content into multiple inseparable character groups consisting of single characters and emoji emoticons;
[0026] Traverse the inseparable character groups and calculate the Unicode category defined by the Unicode standard to which the first character of the character group belongs; if it is a Surrogate, it is an emoji expression, and if it is otherwise, use a regular expression to determine whether the character group is a Chinese character;
[0027] For an inseparable character group, a label is added; if the Unicode category to which the first character of the character group belongs is emoji, the label is added with "No need to wrap, line tail can be released, double word width"; if it is OpenPunctuation, the label is added with "No need to wrap, line tail cannot be released, single (double) word width"; if it is ClosePunctuation, the label is added with "Need to wrap, line tail can be released, single (double) word width"; if it is OtherPunctuation, the label is added with "Need to wrap, line tail can be released, single (double) word width" for punctuation marks; if the character group is Chinese characters, the label is added with "No need to wrap, line tail can be released, double word width"; for other types, the label is added with "Whether to wrap is needed (if the previous character group is labeled as need to wrap, the current character group is also labeled as need to wrap), line tail can be released, and single word width".
[0028] It should be noted that the present invention obtains the text information to be typeset, obtains the text content to be typeset, and decomposes the text into multiple inseparable character groups by looping through it. These character groups are composed of single characters (including Chinese and English characters) and emoji emoticons. The above steps need to correctly handle emoji emoticons, because many emojis are composed of multiple Unicode code points (the so-called "emoji presentation sequence"); for each inseparable character group, we need to calculate the Unicode category of its first character. The Unicode standard defines a variety of character categories, such as "letters", "numbers", "punctuation marks", etc. This step can help us understand the basic properties of characters; according to the Unicode category of the character, it is labeled as follows.
[0029] The specific implementation is as follows:
[0030] If it is an emoji expression, it is marked with the label "No need to wrap, line end can be released, double word width". If the Unicode category of the first character of the character group is OpenPunctuation, it is marked with the label "No need to wrap, line end cannot be released, single (double) word width". If it is ClosePunctuation, it is marked with the label "Need to wrap, line end can be released, single (double) word width". If it is OtherPunctuation, it is a punctuation mark and is marked with the label "Need to wrap, line end can be released, single (double) word width". For other categories, regular expressions are used to determine whether the character group is a Chinese character. If so, it is marked with the label "No need to wrap, line end can be released, double word width". Otherwise, it is marked with the label "Need to wrap" (if the previous character group is judged to have a label that needs to wrap, then the current character group also needs to wrap), line end can be released, and single word width.
[0031] Then combine the labeled characters into multiple inseparable characters and add the character width attribute. Specific implementation method:
[0032] Traverse the character group. If the current character group has a line tail tag that can be released, put it into the result character group. If the current character group has a tag that needs to be wrapped, merge it into the previous result character group and recalculate the word width of the result character group. The width of a single word is 1, and the width of a double word is 2.
[0033] Traverse the result character groups and put them into the string display area one by one. Determine the character groups that can be placed according to the maximum single-word width of the string display area. If the last character group has an unplaceable end tag, start a new line until all the result character groups are completely placed in the display area.
[0034] It should be noted that, for each character group, the present invention first determines several attributes according to the Unicode category to which it belongs: whether it needs to be glued (this may refer to whether the character or character group needs to be closely connected with the previous or next character group), whether it can be placed at the end of the line, and the character width. For example, emoticons or Chinese characters are marked as not needing to be glued, can be placed at the end of the line, and are double-width; the character group whose first character is marked as an open bracket does not need to be glued, cannot be placed at the end of the line, and its width depends on the specific situation; closed brackets or other punctuation need to be glued, can be placed at the end of the line, and its width is also determined according to the specific situation. Once all character groups are marked with appropriate labels, the result character group is constructed. This is achieved by traversing the original character group. If the current character group can be placed at the end of the line, it is added to the result character group; if it needs to be glued, it is merged into the previous result character group, and the total width of the result character group is recalculated; the result character groups after label and width adjustment will be placed one by one in the specified display area. This area has a maximum single-word width, that is, how many characters can be placed at most at one time. If the last character group is marked as not being placed at the end of the line, a new line is started. This cycle continues until all resulting character groups are placed in the display area.
[0035] Specific examples:
[0036] Take this string containing text, emoji, and emoticons as an example: "I love you and I want to go to the movies with you. Would you like to (^_^)?"
[0037] Decomposing character groups
[0038] First, decompose this string into multiple inseparable character groups. Among them, there are single characters, emoji expressions and emoticon groups:
[0039] "I"
[0040] "like"
[0041] "you"
[0042] " "
[0043] " "
[0044] "Good"
[0045] "Want"
[0046] "And"
[0047] "You"
[0048] "One"
[0049] "Together"
[0050] "Go"
[0051] "Watch"
[0052] "Electric"
[0053] "Movie"
[0054] ","
[0055] "You"
[0056] "Wish"
[0057] "Mean"
[0058] "?"
[0059] "(^_^)"
[0060] "?"
[0061] Extract the category and tag
[0062] Next, view the Unicode category of the first character of each character group and tag these character groups respectively:
[0063] "I" (No need to wrap, can release the tail, double-width)
[0064] "Love" (No need to wrap, can release the tail, double-width)
[0065] "You" (No need to wrap, can release the tail, double-width)
[0066] " " (emoji, No need to wrap, can release the tail, double-width)
[0067] " " (emoji, No need to wrap, can release the tail, double-width)
[0068] "Good" (No need to wrap, can release the tail, double-width)
[0069] "Want" (No need to wrap, can release the tail, double-width)
[0070] "And" (No need to wrap, can release the tail, double-width)
[0071] "You" (No need to wrap, can release the tail, double-width)
[0072] "One" (No need to wrap, can release the tail, double-width)
[0073] "Start" (No need to wrap, can release the tail, double-width)
[0074] "Go" (No need to wrap, can release the tail, double-width)
[0075] "Watch" (No need to wrap, can release the tail, double-width)
[0076] "Electric" (No need to wrap, can release the tail, double-width)
[0077] "Movie" (No need to wrap, can release the tail, double-width)
[0078] ", " (OpenPunctuation, no need to wrap, cannot release the tail, double-width)
[0079] "You" (No need to wrap, can release the tail, double-width)
[0080] "Wish" (No need to wrap, can release the tail, double-width)
[0081] "Will" (No need to wrap, can release the tail, double-width)
[0082] "?" (No need to wrap, can release the tail, double-width)
[0083] "(^_^)" (Emoticon, no need to wrap, can release the tail, double-width)
[0084] "?" (OtherPunctuation, need to wrap, can release the tail, double-width)
[0085] Complete text typesetting
[0086] After completing the above steps, text typesetting can be carried out according to these tags. This helps to quickly arrange the text content in a suitable way on the screen, regardless of the language or symbols contained in the text.
[0087] Example: "Welcome to Beijing! Cn The weather is so nice <(_ _)>".
[0088] Decompose character groups:
[0089] First, decompose this string into multiple inseparable character groups:
[0090] "North"
[0091] "Beijing"
[0092] "Happy"
[0093] "Welcome"
[0094] "You"
[0095] "!"
[0096] "Cn"
[0097] " "
[0098] "Weather"
[0099] "Gas"
[0100] "Really"
[0101] "Good"
[0102] "<(_ _)>"
[0103] Extract the category and tag:
[0104] Next, view the Unicode category of the first character in each character group and tag these character groups respectively:
[0105] "North" (No need to wrap, can release the tail, double-width character)
[0106] "Beijing" (No need to wrap, can release the tail, double-width character)
[0107] "Happy" (No need to wrap, can release the tail, double-width character)
[0108] "Welcome" (No need to wrap, can release the tail, double-width character)
[0109] "You" (No need to wrap, can release the tail, double-width character)
[0110] "!" (OtherPunctuation, need to wrap, can release the tail, double-width character)
[0111] "Cn" (emoji, no need to wrap, can release the tail, double-width character)
[0112] " " (emoji, no need to wrap, can release the tail, double-width character)
[0113] "Weather" (No need to wrap, can release the tail, double-width character)
[0114] "Gas" (No need to wrap, can release the tail, double-width character)
[0115] "Really" (No need to wrap, can release the tail, double-width character)
[0116] "Good" (no need to touch the package, can put the end of the line, double word width)
[0117] "<(_ _)>" (emoticons, no need to wrap, can be placed at the end of the line, double word width)
[0118] Complete text layout:
[0119] Finally, typesetting is performed based on these character groups and tags. Different tags determine how the character groups are processed and displayed.
[0120] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for quickly decomposing and typesetting mixed content of text, emoji expressions, and emoticons, characterized by: The following steps are involved: S1, decomposing the input text character by character to form multiple independent and inseparable character groups; S2, traverse the character groups, and perform Unicode category calculation on the first character of each character group to determine its type; S3, labeling each character group according to the context and characteristics of the character group; S4, according to the maximum width of the display text area, recombining into multiple inseparable character groups according to the label attributes; S5, placing the inseparable character group into the display area; The method for decomposing the inseparable character group is to traverse each character in the string and extract the string into single characters or emoji emoticons; The method of separating single characters is to separate the characters into a group of inseparable characters, and to separate the characters into a group of inseparable characters with an English space character or a line ending character that cannot be placed and a non-needed package as the first character, and then to take out the character group that is less than or equal to the single character width that can be displayed in the text display area and put it into a line, and the other characters are cut off again after the line break until all the lines are completed; Confirming the type of the inseparable character group is to traverse all character groups, calculate the Unicode category defined by the Unicode standard to which the first character of the character group belongs, and the type of the inseparable character group is a text character, an emoji expression, or other characters; The method for marking each character group with label attributes in the S3 is to traverse all character groups, and if it is an emoji expression, mark it with no need to wrap, can release the end of the line, and double word width labels; if it is an OpenPunctuation, mark it with no need to wrap, cannot release the end of the line, single or double word width labels; if it is a ClosePunctuation, mark it with a need to wrap, can release the end of the line, and a single or double word width label; if it is OtherPunctuation, it is a punctuation mark and is marked with a need to wrap, can release the end of the line, and a single or double word width label; if the character group is Chinese characters, mark it with no need to wrap, can release the end of the line, and double word width labels; other types are marked with whether to wrap, can release the end of the line, and single word width labels.
2. A method for quickly decomposing and typesetting mixed content of text, emoji expressions, and emoticons according to claim 1, characterized in that: In the other types, if the previous character group has a label that needs to be wrapped, the current character group also needs to be wrapped.
3. A method for quickly decomposing and typesetting mixed content of text, emoji expressions, and emoticons according to claim 2, characterized in that: The method for confirming the single or double character width label is to confirm the width of a character in Chinese and English, Chinese is double character width, English is single character width, and emoji emoticons are double character width.
Citation Information
Patent Citations
Text processing method and device, and equipment
CN113705190A