Method and device for realizing front-end keyword highlighting

By preprocessing and analyzing the input text, identifying URLs, tags and user mentions, combining keyword matching and type recognition functions, the limitations and performance problems of keyword brightening in the prior art are solved, and a more efficient, accurate and maintainable keyword brightening effect is achieved.

CN119046553BActive Publication Date: 2025-03-25ONE NETWORK INTEROPERABILITY (BEIJING) TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411533848.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-31
Publication Date
2025-03-25
Estimated Expiration
2044-10-31

AI Technical Summary

Technical Problem

The prior art has limitations of regular expressions, performance problems, lack of context awareness, difficulty in maintaining and insufficient international support in the process of front-end keyword highlighting.

Method used

By preprocessing the input text, identifying URLs, tags and user mentions using a parsing algorithm to form a first text set; then processing ordinary vocabulary, special characters and Unicode characters through a keyword matching function to form a word boundary set; interval analysis and deduplication of the boundary set based on character positions, generating a second text set, and identifying its elements through a type recognition function to set a highlight style.

Benefits of technology

Improves the accuracy of keyword recognition, can handle multilingual content, reduces the impact on performance, and the code structure is more maintainable and scalable.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119046553B_ABST
    Figure CN119046553B_ABST
Patent Text Reader

Abstract

In an embodiment of the present invention, a method, device and electronic device for implementing front-end keyword highlighting are provided, which belongs to the field of data processing technology. The method includes: after preprocessing the input text, using a parsing algorithm to identify URLs, tags and user mentions in the text to form a first text set K containing n characters; using a keyword matching function to process common words, words containing special characters and Unicode characters contained in the first text set K; based on the position of the characters, performing interval parsing on the word boundary set B to obtain an interval set of complete vocabulary; generating a second text set K' containing p elements, and using a type recognition function to identify the text type of each element in the second text set K' to obtain a type recognition vector Z; based on the type recognition vector Z, setting a corresponding highlight style for each element in the second text set K'. The present invention improves the accuracy and efficiency of front-end keyword highlighting.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a method, device and electronic device for realizing front-end keyword highlighting. Background Art

[0002] Front-end keyword highlighting usually refers to a technology that highlights specific keywords on the user interface of a web page or application. This technology can be used to improve user experience, help users quickly locate important information on the page, or to meet certain special needs, such as keyword highlighting in search results, coloring syntax elements in code editors, etc. Keyword highlighting can not only improve the aesthetics of the interface, but also enhance the readability of the content and the efficiency of user interaction.

[0003] There are many ways to implement keyword highlighting. Depending on the application scenario and technology stack, developers can choose different implementation solutions:

[0004] 1. Pure CSS method: through <mark>tag or use the CSS :contains() pseudo-class to simply mark the text. For example, use <mark>Keywords< / mark> You can make text stand out with a yellow background without changing the page layout.

[0005] 2. JavaScript implementation: For more complex scenarios, such as dynamically obtaining and processing text that needs to be highlighted, JavaScript is required. You can find the corresponding text node through DOM operations, and then replace the matched keyword with the wrapped A new node with a label and style (such as background color, font color, etc.)

[0006] 3. Regular expression assistance: When it comes to complex pattern matching, using regular expressions can help accurately locate the text to be highlighted and avoid mislabeling similar phrases in non-target areas.

[0007] 4. Third-party libraries / plugins: There are also many mature open source projects on the market that provide ready-made solutions, such as Highlight.js, which is used to distinguish the colors of keywords in different languages ​​within code blocks; Mark.js focuses on providing flexible and efficient text search and highlighting functions, etc. These tools often have better performance and more customization options.

[0008] The existing technology has the following problems in the process of front-end keyword highlighting:

[0009] 1. Limitations of regular expressions: Simple regular expressions may not be able to handle all complex text patterns, especially when dealing with multilingual content.

[0010] 2. Performance issues: For large texts, multiple traversals and replacements may result in degraded performance.

[0011] 3. Lack of context awareness: Traditional methods have difficulty handling situations that require context, such as distinguishing between the @ symbol in a URL and user mentions.

[0012] 4. Difficult to maintain: As the number of supported platforms and features increases, the code may become difficult to maintain and extend.

[0013] 5. Insufficient internationalization support: texts in different languages ​​and character sets may not be processed correctly.

[0014] The above problems become technical problems that need to be solved. Summary of the invention

[0015] In view of this, the embodiments of the present invention provide a method, device and electronic device for implementing front-end keyword highlighting, which at least partially solve the problems existing in the prior art.

[0016] In a first aspect, an embodiment of the present invention provides a method for implementing front-end keyword highlighting, including:

[0017] After preprocessing the input text, a parsing algorithm is used to identify URLs, tags, and user mentions in the text to form a first text set K={K1,K2,…Kn} containing n characters;

[0018] By using a keyword matching function, common words, words containing special characters, and Unicode characters contained in the first text set K are processed to form a word boundary set B={B1, B2, …Bm} for segmenting complete words;

[0019] Based on the position of the characters, the word boundary set B is parsed to obtain a complete vocabulary interval set, and the interval set is deduplicated to obtain a deduplicated interval set Q={Q1,Q2,…Qs} containing s elements;

[0020] Based on the deduplication interval set Q={Q1,Q2,…Qs}, a second text set K'={K'1,K'2,…K'p} containing p elements is generated, and the text type of each element in the second text set K' is identified by a type identification function to obtain a type identification vector Z=[Z1,Z2,…Zp];

[0021] Based on the type recognition vector Z=[Z1, Z2, ... Zp], a corresponding highlight style is set for each element in the second text set K'={K'1, K'2, ... K'p}.

[0022] According to a specific implementation of the embodiment of the present disclosure, after setting a corresponding highlight style for each element in the second text set K'={K'1, K'2, ...K'p}, the method further includes:

[0023] Create corresponding links for identified hashtags and user mentions based on different social media platforms;

[0024] Convert the text in the second text set into a string containing HTML tags, and use span elements and predefined CSS classes to achieve highlighting effects;

[0025] Depending on the export options, either the basic text with only keyword highlighting or the fully processed text with all highlights and links is exported.

[0026] According to a specific implementation of an embodiment of the present disclosure, the method of using a parsing algorithm to identify URLs, tags, and user mentions in a text to form a first text set K={K1, K2, ...Kn} containing n characters includes:

[0027] Define a function f(T,P), where T is the preprocessed text and P is a set of patterns containing regular expressions or rules for matching URLs, tags, and user mentions;

[0028] For each match in T, record its starting position s i and end position e i , and then get the matching interval [s i ,e i ];

[0029] By matching the interval [s i ,e i ], calculate the i-th element Ki=T[s i :e i ], each element Ki corresponds to a match in T, and the length of Ki is e i -s i +1.

[0030] According to a specific implementation of an embodiment of the present disclosure, the method of using a parsing algorithm to identify URLs, tags, and user mentions in a text to form a first text set K={K1, K2, ...Kn} containing n characters also includes:

[0031] Let T = (t1, t2, …, t L ) is the preprocessed text string;

[0032] By obtaining the matching interval, we can get a series of matching intervals [s1,e1],[s2,e2],…,[s n ,e n ].

[0033] For each i (1≤i≤n), Ki is expressed as: Ki=(tj|si≤j≤ei).

[0034] According to a specific implementation of an embodiment of the present disclosure, the common words, words containing special characters, and Unicode characters contained in the first text set K are processed by a keyword matching function to form a word boundary set B={B1, B2, ...Bm} for segmenting complete words, including:

[0035] Define a keyword matching function M(K,D) for identifying words in K that match D, where D is a keyword rule set;

[0036] For each Ki∈K, M(Ki,D) returns ,in and are the starting and ending positions of the jth word in Ki respectively;

[0037] Merge all identified word boundaries into the word boundary set B: .

[0038] According to a specific implementation of the embodiment of the present disclosure, the word boundary set B is subjected to interval parsing based on the position of characters to obtain an interval set of complete vocabulary, including:

[0039] The word boundary set B is expressed as:

[0040]

[0041] Among them, s i and e i are the starting and ending positions of the i-th word respectively;

[0042] Put all intervals in B at the starting position s i Sort in ascending order, the sorted set is B':

[0043]

[0044]

[0045] Initialize an empty interval set C and traverse each interval in B' ;

[0046] If C is empty, or the starting position of the current interval is s' i Greater than the end position of the last interval in C , then directly add the current interval to C;

[0047] Otherwise, update the end position of the last interval in C for .

[0048] According to a specific implementation of an embodiment of the present disclosure, the second text set K'={K'1, K'2, ...K'p} containing p elements is generated based on the deduplication interval set Q={Q1, Q2, ...Qs}, and the text type of each element in the second text set K' is identified by a type identification function to obtain a type identification vector Z=[Z1, Z2, ...Zp], including:

[0049] The interval set Q after deduplication is expressed as:

[0050]

[0051] in, and are the starting and ending positions of the i-th interval respectively;

[0052] For each interval , extract the corresponding substring from the text T' of the first text set:

[0053]

[0054] Finally, the second text set K' is formed:

[0055] ;

[0056] Define type identification function , the type recognition function receives a text fragment And return its text type;

[0057] For each , apply the R function to identify its text type and store the result in the type identification vector Z:

[0058] .

[0059] According to a specific implementation of the embodiment of the present disclosure, the step of setting a corresponding highlight style for each element in the second text set K'={K'1, K'2, ...K'p} based on the type recognition vector Z=[Z1, Z2, ...Zp] includes:

[0060] Define the highlight style mapping table S as the highlight style mapping table:

[0061]

[0062]

[0063]

[0064] For each and the corresponding , perform highlight style conversion through highlight function H():

[0065]

[0066] Thus forming the final highlighted text set H':

[0067] .

[0068] In a second aspect, an embodiment of the present invention provides a device for implementing front-end keyword highlighting, including:

[0069] The parsing module, after preprocessing the input text, uses a parsing algorithm to identify URLs, tags, and user mentions in the text to form a first text set K={K1,K2,…Kn} containing n characters;

[0070] A matching module, which processes common words, words containing special characters, and Unicode characters contained in the first text set K through a keyword matching function to form a word boundary set B={B1, B2, ...Bm} for segmenting complete words;

[0071] A deduplication module performs interval analysis on the word boundary set B based on the position of characters to obtain a complete vocabulary interval set, performs a deduplication operation on the interval set, and obtains a deduplication interval set Q={Q1,Q2,…Qs} containing s elements;

[0072] A recognition module generates a second text set K'={K'1, K'2, ...K'p} containing p elements based on the deduplication interval set Q={Q1, Q2, ...Qs}, and identifies the text type of each element in the second text set K' through a type recognition function to obtain a type recognition vector Z=[Z1, Z2, ...Zp];

[0073] A highlight module sets a corresponding highlight style for each element in the second text set K'={K'1, K'2, ...K'p} based on the type recognition vector Z=[Z1, Z2, ...Zp].

[0074] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:

[0075] at least one processor; and,

[0076] a memory communicatively connected to the at least one processor; wherein,

[0077] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the implementation method of front-end keyword highlighting in any of the first aspects or any implementation methods of the first aspect.

[0078] In a fourth aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the implementation method of front-end keyword highlighting in the aforementioned first aspect or any implementation method of the first aspect.

[0079] In the fifth aspect, an embodiment of the present invention further provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer executes the implementation method of front-end keyword highlighting in the aforementioned first aspect or any implementation method of the first aspect.

[0080] The implementation scheme of front-end keyword highlighting in the embodiment of the present invention includes: after preprocessing the input text, using a parsing algorithm to identify URLs, tags and user mentions in the text to form a first text set K={K1, K2, ...Kn} containing n characters; using a keyword matching function, processing common words, words containing special characters and Unicode characters contained in the first text set K to form a word boundary set B={B1, B2, ...Bm} for segmenting complete words; performing interval parsing on the word boundary set B based on the position of the characters to obtain an interval set of complete words, and segmenting the interval set Perform a deduplication operation to obtain a deduplication interval set Q={Q1,Q2,…Qs} containing s elements; generate a second text set K'={K'1,K'2,…K'p} containing p elements based on the deduplication interval set Q={Q1,Q2,…Qs}, and identify the text type of each element in the second text set K' through a type recognition function to obtain a type recognition vector Z=[Z1,Z2,…Zp]; based on the type recognition vector Z=[Z1,Z2,…Zp], set a corresponding highlight style for each element in the second text set K'={K'1,K'2,…K'p}. The solution of the present application is different from the traditional string replacement method. It recognizes and marks keywords, tags, mentions and URLs based on the precise position of characters in the text. While improving the accuracy of keyword recognition, it can also perform precise matching for multi-language situations. BRIEF DESCRIPTION OF THE DRAWINGS

[0081] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0082] Figure 1 A schematic diagram of a method for implementing front-end keyword highlighting provided by an embodiment of the present invention;

[0083] Figure 2 A schematic flow chart of another method for implementing front-end keyword highlighting provided by an embodiment of the present invention;

[0084] Figure 3 A schematic diagram of the structure of a device for implementing front-end keyword highlighting provided by an embodiment of the present invention;

[0085] Figure 4 A schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0086] The embodiments of the present invention are described in detail below with reference to the accompanying drawings.

[0087] The following describes the embodiments of the present disclosure through specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. The present disclosure can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present disclosure. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present disclosure.

[0088] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein may be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present disclosure, it should be understood by those skilled in the art that an aspect described herein may be implemented independently of any other aspect, and two or more of these aspects may be combined in various ways. For example, any number of aspects described herein may be used to implement the device and / or practice the method. In addition, other structures and / or functionalities other than one or more of the aspects described herein may be used to implement this device and / or practice this method.

[0089] It should also be noted that the illustrations provided in the following embodiments are only schematic illustrations of the basic concept of the present disclosure. The drawings only show components related to the present disclosure rather than being drawn according to the number, shape and size of components in actual implementation. In actual implementation, the type, quantity and proportion of each component may be changed arbitrarily, and the component layout may also be more complicated.

[0090] Additionally, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, it will be understood by those skilled in the art that the aspects described may be practiced without these specific details.

[0091] The embodiment of the present disclosure provides a method for implementing front-end keyword highlighting. The method for implementing front-end keyword highlighting provided in this embodiment can be executed by a computing device, which can be implemented as software, or as a combination of software and hardware, and the computing device can be integrated in a server, terminal device, etc.

[0092] See also Figure 1 and Figure 2 The embodiment of the present disclosure provides a method for implementing front-end keyword highlighting, including:

[0093] S101, after preprocessing the input text, use a parsing algorithm to identify URLs, tags and user mentions in the text to form a first text set K={K1, K2, ...Kn} containing n characters.

[0094] For text preprocessing, you can remove unnecessary spaces, tabs, and line breaks from the text. For example, replace multiple consecutive spaces with a single space. You can also remove punctuation or other non-text characters as needed. For example, remove periods, commas, exclamation marks, etc., which usually do not appear in URLs, tags, or user mentions. Finally, convert the text to a unified format, such as all lowercase or all uppercase, to improve the consistency of subsequent processing. This helps ignore differences in uppercase and lowercase when matching.

[0095] Parsing algorithms can be used to identify URLs, tags, and user mentions, which can be done by defining parsing rules.

[0096] URL: Defines patterns for identifying URLs. Typically, a URL starts with http: / / or https: / / , followed by the domain name and path. You can use regular expressions to match these patterns.

[0097] Hashtags: Define patterns for identifying tags. Hashtags usually start with , followed by letters, numbers, or underscores. You can use regular expressions to match these patterns.

[0098] Mentions: Define patterns for identifying user mentions. Mentions usually start with @ followed by letters, numbers, or underscores. You can use regular expressions to match these patterns.

[0099] For each defined pattern (URL, tag, user mention), traverse the preprocessed text and look for substrings that match the pattern. Record the start and end positions of each match. This position information will be used to extract the corresponding substring from the text.

[0100] According to the recorded starting position and ending position, corresponding substrings are extracted from the preprocessed text, and these substrings are stored in a list to form a first text set K.

[0101] S102, using a keyword matching function, processing common words, words containing special characters, and Unicode characters contained in the first text set K to form a word boundary set B={B1, B2, ...Bm} for segmenting complete words.

[0102] A keyword matching function can be defined to identify specific words in the text through the keyword matching function. For example, this function needs to be able to handle the following types of words:

[0103] Common words: such as "apple", "banana", etc.

[0104] Words containing special characters: such as "hello-world", "C++", etc.

[0105] Unicode characters: such as the Chinese word "苹果" (píngguǒ), the Japanese word "りんご" (ringo), etc.

[0106] During the process of applying the keyword matching function, the word boundary set can be initialized, and an empty set B can be created to store all the identified word boundaries.

[0107] For each element Ki ∈ K, apply the keyword matching function to find all the matching words and their positions in Ki. For each matching word, record its starting position s and ending position e.

[0108] If two or more words overlap, choose the longest word or merge them according to specific requirements. If two words are adjacent and there is no gap, they can be regarded as a whole word. The starting position and ending position of each identified word are added to the set B as a tuple (s, e).

[0109] Through the above steps, the words in the first text set K can be systematically processed, and the word boundary set B for splitting the complete words can be formed. This method ensures that each word is accurately identified and split.

[0110] S103. Based on the character positions, perform interval parsing on the word boundary set B to obtain the interval set of complete words, and perform a deduplication operation on the interval set to obtain a deduplicated interval set Q = {Q1, Q2, … Qs} containing s elements.

[0111] Performing interval parsing on the word boundary set B based on the character positions to obtain the interval set of complete words, and performing a deduplication operation on the interval set, and finally obtaining a deduplicated interval set Q = {Q1, Q2, … Qs} containing s elements may include the following steps:

[0112] Create an empty list C to store the parsed complete word intervals. For each tuple (s i , e i ) ∈ B, check whether there is already an interval in C that is the same as the current interval (s i , e i ) overlapping or adjacent intervals. If there are overlapping or adjacent intervals, merge these intervals. Otherwise, merge the current interval (s i ,e i ) is added to C.

[0113] Put all intervals in B at the starting position s i Sort in ascending order to obtain the sorted set B'. For each interval (s i ,e i )∈B': If C is empty, or the starting position of the current interval is s i Greater than the end position e of the last interval in C last , then directly add the current interval to C. Otherwise, update the end position e of the last interval in C last is max(e last ,e i ).

[0114] Check whether there are repeated intervals in C. If there are repeated intervals, remove the duplicates to obtain the deduplicated interval set Q.

[0115] Through the above steps, the word boundary set B can be systematically parsed to obtain a set of intervals of a complete vocabulary, and a deduplication operation is performed to ensure that each interval is unique and does not overlap.

[0116] S104, based on the deduplicated interval set Q={Q1,Q2,…Qs}, generate a second text set K'={K'1,K'2,…K'p} containing p elements, and identify the text type of each element in the second text set K' through a type identification function to obtain a type identification vector Z=[Z1,Z2,…Zp].

[0117] Specifically, we can create an empty list K', for each interval Qi=(s i ,e i )∈Q, extract substring K'i from the original text T, where K'i=T[s i :e i +1], add the extracted substring K'i to K'.

[0118] Furthermore, a type recognition function R(K'i) can be defined, which receives a text segment K'i and returns its text type. Common text types include URLs, hashtags, user mentions, etc. For each K'i∈K', apply R(K'i) to identify its text type and store the result in the type recognition vector Z.

[0119] Through the above steps, the second text set K' can be systematically generated, and the text type of each element can be identified, and finally the type identification vector Z can be obtained. This method ensures that each word is accurately classified and processed.

[0120] S105 , based on the type recognition vector Z=[Z1, Z2, …Zp], setting a corresponding highlight style for each element in the second text set K′={K′1, K′2, …K′p}.

[0121] You can define corresponding highlight styles for different text types. For example:

[0122] URL:<spanclass="url"> ... `

[0123] Hashtags: ` <spanclass="hashtag"> ... `

[0124] User mentions:<spanclass="mention"> ...

[0125] Common vocabulary:<spanclass="normal"> ...

[0126] For each K'i∈K', use the corresponding type Z in the type identification vector Z i to select an appropriate highlighting style and wrap K'i in that style.

[0127] For example, we can create an empty list H to store the highlighted text fragments. For each K'i∈K' and the corresponding Z i ∈Z, find Z i The corresponding highlight style in style_map is used to wrap K'i, and the wrapped text fragment is added to H. All the highlighted text fragments in H are concatenated into a complete highlighted text string.

[0128] See also Figure 2 According to a specific implementation of the embodiment of the present disclosure, after setting a corresponding highlight style for each element in the second text set K'={K'1, K'2, ...K'p}, the method further includes:

[0129] S201, creating corresponding links for the identified tags and user mentions according to different social media platforms;

[0130] S202, converting the text in the second text set into a string containing HTML tags, and using span elements and predefined CSS classes to achieve a highlighting effect;

[0131] S203, according to different output options, outputting the basic text containing only the highlighted keywords, or outputting the complete processed text containing all the highlights and links.

[0132] Specifically, you can create links for tags and user mentions, including:

[0133] Define the link generation rules:

[0134] - Hashtags: Often on social media platforms, tags are converted into search links. For example, on the abc website, `awesome` becomes `https: / / abc.com / hashtag / awesome`.

[0135] - User mentions: User mentions are converted into links to the user's personal page. For example, on the abc website, `@user123` becomes `https: / / abc.com / user123`.

[0136] Apply link generation rules: For each tag and user mention, generate a corresponding link based on its type.

[0137] Next, the text in the second text set can be converted into a string containing HTML tags. Each text type can be mapped to a corresponding highlight style by creating a dictionary or mapping table.

[0138] The second text set can be traversed and the highlight style can be applied. For each K'i∈K' and corresponding Zi∈Z, the highlight style corresponding to Zi in style_map is found. If it is a tag or user mention, %s is replaced with the actual text content and a corresponding link is generated.

[0139] According to a specific implementation of an embodiment of the present disclosure, the method of using a parsing algorithm to identify URLs, tags, and user mentions in a text to form a first text set K={K1, K2, ...Kn} containing n characters includes:

[0140] Define a function f(T,P), where T is the preprocessed text and P is a set of patterns containing regular expressions or rules for matching URLs, tags, and user mentions;

[0141] For each match in T, record its starting position s i and end position e i , and then get the matching interval [s i ,e i ];

[0142] By matching the interval [s i ,e i ], calculate the i-th element Ki=T[s i :e i ], each element Ki corresponds to a match in T, and the length of Ki is e i -s i +1.

[0143] According to a specific implementation of an embodiment of the present disclosure, the method of using a parsing algorithm to identify URLs, tags, and user mentions in a text to form a first text set K={K1, K2, ...Kn} containing n characters also includes:

[0144] Let T = (t1, t2, …, t L ) is the preprocessed text string;

[0145] By obtaining the matching interval, we can get a series of matching intervals [s1,e1],[s2,e2],…,[s n ,e n ].

[0146] For each i (1≤i≤n), Ki is expressed as: Ki=(tj|si≤j≤ei).

[0147] According to a specific implementation of an embodiment of the present disclosure, the common words, words containing special characters, and Unicode characters contained in the first text set K are processed by a keyword matching function to form a word boundary set B={B1, B2, ...Bm} for segmenting complete words, including:

[0148] Define a keyword matching function M(K,D) for identifying words in K that match D, where D is a keyword rule set;

[0149] For each Ki∈K, M(Ki,D) returns ,in and are the starting and ending positions of the jth word in Ki respectively;

[0150] Merge all identified word boundaries into the word boundary set B: .

[0151] According to a specific implementation of the embodiment of the present disclosure, the word boundary set B is subjected to interval parsing based on the position of characters to obtain an interval set of complete vocabulary, including:

[0152] The word boundary set B is expressed as:

[0153]

[0154] Among them, s i and e i are the starting and ending positions of the i-th word respectively;

[0155] Put all intervals in B at the starting position s i Sort in ascending order, the sorted set is B':

[0156]

[0157]

[0158] Initialize an empty interval set C and traverse each interval in B' ;

[0159] If C is empty, or the starting position of the current interval is s' i Greater than the end position of the last interval in C , then directly add the current interval to C;

[0160] Otherwise, update the end position of the last interval in C for .

[0161] According to a specific implementation of an embodiment of the present disclosure, the second text set K'={K'1, K'2, ...K'p} containing p elements is generated based on the deduplication interval set Q={Q1, Q2, ...Qs}, and the text type of each element in the second text set K' is identified by a type identification function to obtain a type identification vector Z=[Z1, Z2, ...Zp], including:

[0162] The interval set Q after deduplication is expressed as:

[0163]

[0164] in, and are the starting and ending positions of the i-th interval respectively;

[0165] For each interval , extract the corresponding substring from the text T' of the first text set:

[0166]

[0167] Finally, the second text set K' is formed:

[0168] ;

[0169] Define type identification function , the type recognition function receives a text fragment And return its text type;

[0170] For each , apply the R function to identify its text type and store the result in the type identification vector Z:

[0171] .

[0172] According to a specific implementation of the embodiment of the present disclosure, the step of setting a corresponding highlight style for each element in the second text set K'={K'1, K'2, ...K'p} based on the type recognition vector Z=[Z1, Z2, ...Zp] includes:

[0173] Define the highlight style mapping table S as the highlight style mapping table:

[0174]

[0175]

[0176]

[0177] For each and the corresponding , perform highlight style conversion through highlight function H():

[0178]

[0179] Thus forming the final highlighted text set H':

[0180] .

[0181] Corresponding to the above method embodiment, see Figure 3 The embodiment of the present invention further discloses a front-end keyword highlighting implementation device 30, comprising:

[0182] The parsing module 301 pre-processes the input text and uses a parsing algorithm to identify URLs, tags, and user mentions in the text to form a first text set K={K1, K2, ...Kn} containing n characters;

[0183] A matching module 302 processes common words, words containing special characters, and Unicode characters contained in the first text set K through a keyword matching function to form a word boundary set B={B1, B2, ...Bm} for segmenting complete words;

[0184] The deduplication module 303 performs interval parsing on the word boundary set B based on the position of the characters to obtain a set of intervals of complete vocabulary, performs deduplication operation on the set of intervals to obtain a deduplication interval set Q={Q1,Q2,…Qs} containing s elements;

[0185] The recognition module 304 generates a second text set K'={K'1, K'2, ...K'p} containing p elements based on the deduplication interval set Q={Q1, Q2, ...Qs}, and recognizes the text type of each element in the second text set K' through a type recognition function to obtain a type recognition vector Z=[Z1, Z2, ...Zp];

[0186] The highlight module 305 sets a corresponding highlight style for each element in the second text set K'={K'1, K'2, ...K'p} based on the type recognition vector Z=[Z1, Z2, ...Zp].

[0187] See also Figure 4 The embodiment of the present invention further provides an electronic device 60, the electronic device comprising:

[0188] at least one processor; and,

[0189] a memory communicatively connected to the at least one processor; wherein,

[0190] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the implementation method of front-end keyword highlighting in the aforementioned method embodiment.

[0191] An embodiment of the present invention further provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the aforementioned method embodiment.

[0192] An embodiment of the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer executes the implementation method of front-end keyword highlighting in the aforementioned method embodiment.

[0193] Reference below Figure 4 , which shows a schematic diagram of the structure of an electronic device 60 suitable for implementing the embodiment of the present disclosure. The electronic device in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0194] like Figure 4 As shown, the electronic device 60 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the electronic device 60 are also stored. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0195] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, a gage, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device 60 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 4 The electronic device 60 is shown with various devices, but it should be understood that it is not required to implement or have all the devices shown. More or fewer devices may be implemented or have instead.

[0196] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by the processing device 601, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0197] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.< / mark>

Claims

1. A method for realizing front-end keyword highlighting, characterized in that: include: After preprocessing the input text, a parsing algorithm is used to identify URLs, tags, and user mentions in the text to form a first text set K={K1,K2,…Kn} containing n characters; By using a keyword matching function, common words, words containing special characters, and Unicode characters contained in the first text set K are processed to form a word boundary set B={B1, B2, …Bm} for segmenting complete words; Based on the position of the characters, the word boundary set B is parsed to obtain a complete vocabulary interval set, and the interval set is deduplicated to obtain a deduplicated interval set Q={Q1,Q2,…Qs} containing s elements; Based on the deduplication interval set Q={Q1,Q2,…Qs}, a second text set K'={K'1,K'2,…K'p} containing p elements is generated, and the text type of each element in the second text set K' is identified by a type identification function to obtain a type identification vector Z=[Z1,Z2,…Zp]; Based on the type recognition vector Z=[Z1, Z2, ... Zp], a corresponding highlight style is set for each element in the second text set K'={K'1, K'2, ... K'p}; wherein The method uses a parsing algorithm to identify URLs, tags, and user mentions in the text to form a first text set K={K1, K2, ...Kn} containing n characters, including: Define a function f(T,P), where T is the preprocessed text and P is a set of patterns containing regular expressions or rules for matching URLs, tags, and user mentions; For each match in T, record its starting position s i and end position e i , and then get the matching interval [s i ,e i ]; By matching the interval [s i ,e i ], calculate the i-th element Ki=T[s i :e i ], each element Ki corresponds to a match in T, and the length of Ki is e i -s i +1.

2. The method according to claim 1, characterized in that After setting a corresponding highlight style for each element in the second text set K'={K'1, K'2, ...K'p}, the method further includes: Create corresponding links for identified hashtags and user mentions based on different social media platforms; Convert the text in the second text set into a string containing HTML tags, and use span elements and predefined CSS classes to achieve highlighting effects; Depending on the export options, either the basic text with only keyword highlighting or the fully processed text with all highlights and links is exported.

3. The method according to claim 1, characterized in that The method uses a parsing algorithm to identify URLs, tags, and user mentions in the text to form a first text set K={K1, K2, ...Kn} containing n characters, and further includes: Let T = (t1, t2, …, t L ) is the preprocessed text string; By obtaining the matching interval, we can get a series of matching intervals [s1,e1],[s2,e2],…,[s n ,e n ]; For each i (1≤i≤n), Ki is expressed as: Ki=(tj|si≤j≤ei).

4. The method according to claim 3, characterized in that The method of processing common words, words containing special characters, and Unicode characters contained in the first text set K through a keyword matching function to form a word boundary set B={B1, B2, ...Bm} for segmenting complete words includes: Define a keyword matching function M(K,D) for identifying words in K that match D, where D is a keyword rule set; For each Ki∈K, M(Ki,D) returns ,in and are the starting and ending positions of the jth word in Ki respectively; Merge all identified word boundaries into the word boundary set B: .

5. The method according to claim 4, characterized in that The word boundary set B is subjected to interval parsing based on the position of the characters to obtain an interval set of complete vocabulary, including: The word boundary set B is expressed as: Among them, s i and e i are the starting and ending positions of the i-th word respectively; Put all intervals in B at the starting position s i Sort in ascending order, the sorted set is B': Initialize an empty interval set C and traverse each interval in B' ; If C is empty, or the starting position of the current interval is s' i Greater than the end position of the last interval in C , then directly add the current interval to C; Otherwise, update the end position of the last interval in C for .

6. The method according to claim 5, characterized in that The second text set K'={K'1, K'2, ...K'p} containing p elements is generated based on the deduplication interval set Q={Q1, Q2, ...Qs}, and the text type of each element in the second text set K' is identified by a type identification function to obtain a type identification vector Z=[Z1, Z2, ...Zp], including: The interval set Q after deduplication is expressed as: in, and are the starting and ending positions of the i-th interval respectively; For each interval , extract the corresponding substring from the text T' of the first text set: Finally, the second text set K' is formed: ; Define type identification function , the type recognition function receives a text fragment And return its text type; For each , apply the R function to identify its text type and store the result in the type identification vector Z: 。 7. The method according to claim 6, characterized in that The step of setting a corresponding highlight style for each element in the second text set K'={K'1, K'2, ...K'p} based on the type recognition vector Z=[Z1, Z2, ...Zp] includes: Define the highlight style mapping table S as the highlight style mapping table: For each and the corresponding , perform highlight style conversion through highlight function H(): Thus forming the final highlighted text set H': 。 8. A device for realizing front-end keyword highlighting, characterized in that: include: The parsing module, after preprocessing the input text, uses a parsing algorithm to identify URLs, tags, and user mentions in the text to form a first text set K={K1,K2,…Kn} containing n characters; A matching module, which processes common words, words containing special characters, and Unicode characters contained in the first text set K through a keyword matching function to form a word boundary set B={B1, B2, ...Bm} for segmenting complete words; A deduplication module performs interval analysis on the word boundary set B based on the position of characters to obtain a complete vocabulary interval set, performs a deduplication operation on the interval set, and obtains a deduplication interval set Q={Q1,Q2,…Qs} containing s elements; A recognition module generates a second text set K'={K'1, K'2, ...K'p} containing p elements based on the deduplication interval set Q={Q1, Q2, ...Qs}, and identifies the text type of each element in the second text set K' through a type recognition function to obtain a type recognition vector Z=[Z1, Z2, ...Zp]; A highlight module sets a corresponding highlight style for each element in the second text set K'={K'1, K'2, ...K'p} based on the type recognition vector Z=[Z1, Z2, ...Zp]; wherein The method uses a parsing algorithm to identify URLs, tags, and user mentions in the text to form a first text set K={K1, K2, ...Kn} containing n characters, including: Define a function f(T,P), where T is the preprocessed text and P is a set of patterns containing regular expressions or rules for matching URLs, tags, and user mentions; For each match in T, record its starting position s i and end position e i , and then get the matching interval [s i ,e i ]; By matching the interval [s i ,e i ], calculate the i-th element Ki=T[s i :e i ], each element Ki corresponds to a match in T, and the length of Ki is e i -s i +1.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the implementation method of front-end keyword highlighting as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Text rendering method and device and electronic equipment

    CN116341538A