Text processing method and device, electronic equipment and computer readable storage medium

By constructing a trie in text processing and using a stack to store the keyword index, the problems of long keyword matching time and poor accuracy in existing technologies are solved, and efficient and accurate keyword display is achieved.

CN114896360BActive Publication Date: 2025-11-25BEIJING DAJIA INTERNET INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210538558.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-05-18
Publication Date
2025-11-25
Estimated Expiration
2042-05-18

AI Technical Summary

Technical Problem

Existing keyword matching methods, such as regular expression matching and brute-force matching, suffer from time consumption and poor accuracy, especially when there is an inclusion relationship between sensitive words or keywords.

Method used

The system uses preset keywords to match the text to be reviewed. It constructs a trie and creates mismatch pointers through a multi-pattern matching algorithm. It uses a stack concept to store the matched keywords and indexes. The display style of the keywords is configured according to the traversal of the index and the stack, thereby improving the matching accuracy.

Benefits of technology

It improves the accuracy and efficiency of keyword matching, ensures that keywords are correctly highlighted in the text, and avoids the performance bottlenecks and errors that occur in existing methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114896360B_ABST
    Figure CN114896360B_ABST
Patent Text Reader

Abstract

The present disclosure relates to a text processing method, device, electronic equipment, computer readable storage medium and computer program product. The method comprises the following steps: obtaining a to-be-audited text and a preset keyword, performing keyword matching on the to-be-audited text by using the preset keyword to obtain a keyword matching result, and traversing the to-be-audited text from an index corresponding to the last character of the to-be-audited text. When a target index matching the traversal index exists in the keyword matching result, a keyword corresponding to the target index is obtained as a target keyword, the obtained target keyword is stored in a first stack, and the same number of target indexes as the target keyword is stored in a second stack. Finally, a display style is configured for the target keyword in the to-be-audited text according to the traversal index of the to-be-audited text, the first stack and the second stack. Since the stack concept is used to replace the style of the matched keyword in the to-be-audited text, the accuracy of the processing is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present disclosure relates to the technical field of computer, and particularly relates to a text processing method and device, electronic equipment, computer readable storage medium and computer program product. BACKGROUND

[0002] With the development of computer technology, people gradually become accustomed to publishing information on a network platform for information exchange. Generally, in order to improve the quality of the published information on the network platform and avoid the spread of bad information on the network platform, the network platform arranges auditors to audit the information published by users to combat bad information and filter high-quality content.

[0003] In the related art, an auditor accesses an audit system through a browser (Chrome) to audit a text to be audited. In order to assist the auditor to quickly audit and judge the mass information, a regular expression matching or a brute force matching manner is generally used to match sensitive words or keywords in the text to be audited, and the color of the matched sensitive words or keywords in the text is configured through a browser plug-in, so that the browser highlights the sensitive words or keywords in the page text, thereby facilitating the auditor to quickly and accurately judge the text information.

[0004] However, both the regular expression matching and the brute force matching manner have an exponential time consumption, and when there is a containing relationship between different sensitive words or keywords, it is difficult to accurately perform style processing on all the matched sensitive words or keywords, thereby affecting the matching performance and the processing accuracy of the sensitive words or keywords. SUMMARY

[0005] The present disclosure provides a text processing method, device, electronic equipment, computer readable storage medium and computer program product to at least solve the accuracy problem of keyword matching in the related art. The technical solutions of the present disclosure are as follows:

[0006] According to a first aspect of an embodiment of the present disclosure, a text processing method is provided, comprising:

[0007] obtaining a text to be audited and a preset keyword;

[0008] performing keyword matching on the text to be audited by using the preset keyword to obtain a keyword matching result, the keyword matching result comprising a matched keyword and an index corresponding to a last character of the keyword, the index being used to represent a position of the character in the text to be audited;

[0009] start from the index corresponding to the last character of the to-be-audited text, and traverse the to-be-audited text forward; when there is a target index in the keyword matching result that matches the index corresponding to the traversed character, the keyword corresponding to the target index is obtained as a target keyword;

[0010] The obtained target keyword is stored in a first stack, and the same number of target indexes as the obtained target keyword is stored in a second stack.

[0011] According to the current traversal index of the to-be-audited text, the first stack, and the second stack, the target keyword in the to-be-audited text is configured with a display style, and a to-be-audited text after the display style is configured is obtained.

[0012] In one of the embodiments, the method further comprises: when there is no target index in the keyword matching result that matches the index corresponding to the traversed character, the traversed character is concatenated before the concatenation string; and returning to execute the step of determining, according to the current traversal index, the target index at the top of the second stack, and the character length of the target keyword at the top of the first stack, that the target keyword at the top of the first stack needs to be popped, and performing pop processing on the target keyword at the top of the first stack and the target index at the top of the second stack, and concatenating a preset hypertext style tag start symbol before the concatenation string.

[0013] In one of the embodiments, the method further comprises: when there is no target index in the keyword matching result that matches the index corresponding to the traversed character, the traversed character is concatenated before the concatenation string; and returning to execute the step of determining, according to the current traversal index, the target index at the top of the second stack, and the character length of the target keyword at the top of the first stack, that the target keyword at the top of the first stack needs to be popped, and performing pop processing on the target keyword at the top of the first stack and the target index at the top of the second stack, and concatenating a preset hypertext style tag start symbol before the concatenation string.

[0014] In one of the embodiments, the method further comprises: returning to perform the step of traversing the text to be reviewed forward when it is determined that the target keyword at the top position of the first stack does not need to be popped.

[0015] In one of the embodiments, the determining that the target keyword at the top position of the first stack needs to be popped according to the current traversal index, the target index at the top position of the second stack, and the character length of the target keyword at the top position of the first stack comprises: obtaining the number of characters between the traversal index and the target index at the top position of the second stack; and determining that the target keyword at the top position of the first stack needs to be popped when the number of characters is the same as the character length of the target keyword at the top position of the first stack.

[0016] In one of the embodiments, after the obtaining the number of characters between the traversal index and the target index at the top position of the second stack, the method further comprises: determining that the target keyword at the top position of the first stack does not need to be popped when the number of characters is less than the character length of the target keyword at the top position of the first stack.

[0017] In one of the embodiments, the obtaining the number of characters between the traversal index and the target index at the top position of the second stack comprises: obtaining the difference between the target index at the top position of the second stack and the traversal index, and taking the sum of the difference and 1 as the number of characters between the traversal index and the target index at the top position of the second stack.

[0018] In one of the embodiments, the keyword matching of the text to be reviewed by using the preset keyword comprises: keyword matching of the text to be reviewed by using the preset keyword through a multi-mode matching algorithm.

[0019] In one of the embodiments, the storing the obtained target keyword in the first stack comprises: when there are multiple target keywords corresponding to the target index, obtaining the character lengths corresponding to the multiple target keywords respectively; sorting the multiple target keywords according to the character lengths from large to small, and storing the sorted multiple target keywords in the first stack in sequence.

[0020] According to a second aspect of the embodiments of the present disclosure, a text processing apparatus is provided, comprising:

[0021] a data obtaining module configured to perform obtaining a text to be reviewed and a preset keyword;

[0022] The keyword matching module is configured to perform keyword matching on the text to be audited by using the preset keyword, to obtain a keyword matching result, the keyword matching result including a matched keyword and an index corresponding to a last character of the keyword, the index being used to represent a position of the character in the text to be audited.

[0023] The traversal module is configured to perform forward traversal of the text to be audited starting from an index corresponding to a last character of the text to be audited, and when there is a target index in the keyword matching result that matches an index corresponding to a traversed character, obtain the keyword corresponding to the target index as a target keyword.

[0024] The stack processing module is configured to store the obtained target keyword in a first stack and store the same number of target indexes as the obtained target keyword in a second stack.

[0025] The text processing module is configured to perform display style configuration on the target keyword in the text to be audited according to a traversal index of the text to be audited, the first stack, and the second stack, to obtain the text to be audited after display style configuration, the traversal index being an index corresponding to a traversed character of the text to be audited.

[0026] In one of the embodiments, the text processing module includes a first splicing unit configured to obtain a last character of the target keyword corresponding to a top position of the first stack, splice a preset hypertext style tag end symbol before a splicing string, and the number of spliced hypertext style tag end symbols is the same as the number of target indexes corresponding to the target keyword at the top position; a second splicing unit configured to perform out-stack processing on the target keyword at the top position of the first stack and the target index at the top position of the second stack when it is determined, according to the traversal index of the current traversal, the target index at the top position of the second stack, and the character length of the target keyword at the top position of the first stack, that the target keyword at the top position of the first stack needs to be out-stacked, and splice a preset hypertext style tag start symbol before the splicing string; and an execution unit configured to return to perform the step of forward traversal of the text to be audited until the index corresponding to a first character of the text to be audited is traversed, to obtain a target splicing string, and determine the target splicing string as the text to be audited after display style configuration.

[0027] In one of the embodiments, the first concatenating unit is further configured to perform concatenating the traversed character to the concatenation string in advance when there is no target index matching the index corresponding to the traversed character in the keyword matching result; and the executing unit is further configured to perform returning to execute the step of performing the pop processing on the target keyword at the top of the first stack and the target index at the top of the second stack when it is determined that the target keyword at the top of the first stack needs to be popped according to the character length of the target keyword at the top of the first stack, the target index at the top of the second stack and the traversed index currently traversed.

[0028] In one of the embodiments, the executing unit is further configured to perform returning to execute the step of traversing the text to be audited forward when it is determined that the target keyword at the top of the first stack does not need to be popped.

[0029] In one of the embodiments, the second concatenating unit further comprises a character number obtaining sub-unit configured to perform obtaining the number of characters between the traversed index and the target index at the top of the second stack; and a pop determining sub-unit configured to perform determining that the target keyword at the top of the first stack needs to be popped when the number of characters is the same as the character length of the target keyword at the top of the first stack.

[0030] In one of the embodiments, the pop determining sub-unit is further configured to perform determining that the target keyword at the top of the first stack does not need to be popped when the number of characters is less than the character length of the target keyword at the top of the first stack.

[0031] In one of the embodiments, the character number obtaining sub-unit is further configured to perform obtaining the difference between the target index at the top of the second stack and the traversed index, and taking the sum of the difference and 1 as the number of characters between the traversed index and the target index at the top of the second stack.

[0032] In one of the embodiments, the keyword matching module is further configured to perform keyword matching on the text to be audited by using the preset keyword through a multi-mode matching algorithm.

[0033] In one of the embodiments, the stack processing module is further configured to perform obtaining the character lengths corresponding to the target keywords respectively when there are multiple target keywords corresponding to the target index when obtained; sorting the multiple target keywords according to the character lengths from large to small; and storing the sorted multiple target keywords to the first stack in sequence.

[0034] According to a third aspect of the embodiments of the present disclosure, an electronic device is provided, comprising: a processor; a memory for storing instructions executable by the processor; wherein the processor is configured to execute the instructions to implement the text processing method according to the first aspect.

[0035] According to a fourth aspect of the embodiments of the present disclosure, a computer readable storage medium is provided, when instructions in the computer readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to perform the text processing method according to the first aspect.

[0036] According to a fifth aspect of the embodiments of the present disclosure, a computer program product is provided, the computer program product comprises instructions, when the instructions are executed by a processor of an electronic device, the electronic device is enabled to perform the text processing method according to the first aspect.

[0037] The embodiments of the present disclosure provide at least the following beneficial effects: by obtaining the to-be-audited text and the preset keyword, the preset keyword is used for keyword matching on the to-be-audited text, a keyword matching result is obtained, and the to-be-audited text is traversed from an index corresponding to a last character of the to-be-audited text; when there is a target index matched with the index corresponding to the traversed character in the keyword matching result, a target keyword corresponding to the target index is obtained, the obtained target keyword corresponding to the target index is stored in a first stack, and the same number of target indexes as the obtained target keyword is stored in a second stack; finally, a display style of the target keyword in the to-be-audited text is configured according to a traversal index of the to-be-audited text, the first stack, and the second stack, and the to-be-audited text after the display style is configured is obtained. Since the stack concept is used to replace the style of the matched keyword in the to-be-audited text in the embodiment, the processing accuracy is improved.

[0038] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF DRAWINGS

[0039] The accompanying drawings, which are incorporated into and form part of the specification, illustrate embodiments consistent with the present disclosure and, together with the specification, serve to explain the principles of the present disclosure, and do not constitute an improper limitation on the present disclosure.

[0040] Figure 1 is a flowchart of a text processing method according to an exemplary embodiment.

[0041] Figure 2 is a schematic diagram of a dictionary tree according to an exemplary embodiment.

[0042] Figure 3FIG. 1 is a diagram illustrating creation of mismatch pointers in a dictionary tree according to an example embodiment.

[0043] Figure 4 FIG. 2 is a diagram illustrating a target keyword push step according to an example embodiment.

[0044] Figure 5 FIG. 3 is a diagram illustrating a text to be reviewed after a display style is configured according to an example embodiment.

[0045] Figure 6 FIG. 4 is a diagram illustrating a target keyword pop step according to an example embodiment.

[0046] Figure 7 FIG. 5 is a flowchart of a text processing method according to another example embodiment.

[0047] Figure 8 FIG. 6 is a block diagram of a text processing apparatus according to an example embodiment.

[0048] Figure 9 FIG. 7 is a block diagram of an electronic device according to an example embodiment.

[0049] Figure 10 FIG. 8 is a block diagram of an electronic device according to another example embodiment. DETAILED DESCRIPTION

[0050] In order to make the ordinary person skilled in the art better understand the technical solutions of the present disclosure, the technical solutions in the embodiments of the present disclosure will be described clearly and completely below with reference to the drawings.

[0051] It should be noted that the terms "first", "second", and the like in the specification and claims of the present disclosure and the above-described drawings are used to distinguish similar objects, and do not necessarily have to describe a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present disclosure described herein can be implemented in an order other than that illustrated or described herein. The implementation described in the following example embodiments does not represent all implementations consistent with the present disclosure. Rather, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0052] It should also be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for display, analyzed data, etc.) involved in the present disclosure are all information and data authorized by the user or authorized by all parties.

[0053] The traditional brute force matching method traverses the sensitive word list by loop, for each sensitive word P, uses brute force to find in the text string T, traverses the text string T from left to right, the index is 0 when starting to traverse, for each character C, judges whether it matches the corresponding character in P (one character by one character comparison), if it is equal and the end of P is not matched, continue to match, as long as the middle match is wrong, start from the place of T string index + 1 (index is 0 + 1) to compare one by one again, if P is matched successfully, the matched result is wrapped with HTML (Hyper Text Markup Language, Hyper Text Markup Language) custom tag, and the custom tag is added with style, and the text string T is updated. After all the matching is finished, the whole replaced text string T1 is inserted back into the DOM (Document Object Model, Document Object Model) of HTML, so as to achieve the effect of highlighting the sensitive words.

[0054] However, the brute force matching has defects of poor performance and inability to match all sensitive words. For example, assuming that the text length is m, the length of a single sensitive word is n, and the time complexity of matching a single sensitive word is O(mn), and when there are k sensitive words to be matched, the time complexity is O(mnk), that is, the time consumption is in cubic exponential level, and the larger m, n and k are, the poorer the performance is. For example: the sensitive words are "AB" and "ABC", and the text is "ABC is cultural values", the first round will find the sensitive word "AB" in the text, and replace it after matching. The text becomes: AB C is cultural values", because "ABC" is separated by the added HTML tag, it will no longer be able to match the keyword "ABC" in the subsequent matching.

[0055] The traditional regular expression matching method traverses the sensitive word list by loop, for each sensitive word P, uses regular expression to match P in the text string T, gets all the subscript positions of P in T (because it may appear more than once), according to the subscript result obtained by the regular expression, wraps the matching result with HTML custom tag (such as span or Web Components), adds style to the custom tag, and updates the text string T. After all the matching is finished, the whole replaced text string T1 is inserted back into the DOM of HTML, so as to achieve the highlighting effect.

[0056] However, regular expression matching also has its limitations, including the inability to match all sensitive words, mediocre performance, and the possibility of matching errors. For example, assuming the text length is m, the length of a single sensitive word is n, and the alphabet length is k, the time complexity of matching a single sensitive word using a regular expression based on a finite automaton is O(nk) + O(m). When j sensitive words need to be matched, the time complexity becomes O((nk+m)*j), which is also exponential. However, generally, the alphabet length is fixed, and the time complexity of regular expressions is approximately quadratic exponential, compared to the cubic exponential of a brute-force loop. Furthermore, when the sensitive word is exactly the text to be replaced, matching errors can occur, leading to a messy generated HTML structure. For example, if the sensitive words are "AB" and "span", and the text is "ABC is cultural values", after the first round of matching, the text becomes: AB "C represents cultural values." During the second round of matching, because "span" is a sensitive word, the resulting text is: "< span >AB < / span >C represents cultural values, but this erroneous text violates the open / closed structure of HTML tags, and will cause display errors and layout problems when inserted into the DOM.

[0057] Based on this, this disclosure provides a text processing method. This embodiment illustrates the method by applying it to a server. It is understood that this method can also be applied to a terminal, and further to a system including both a terminal and a server, and is implemented through interaction between the terminal and the server. In this embodiment, as... Figure 1 As shown, the method includes the following steps:

[0058] In step S110, the text to be reviewed and preset keywords are obtained.

[0059] In this context, "text to be reviewed" refers to text that needs to be reviewed. Specifically, it can be text content published by users through a network platform. Typically, the network platform reviews user-published content, and only content that passes the review is publicly released. "Preset keywords" are keywords or sensitive words that are pre-set for review based on review requirements. In this embodiment, when review is required, the server first obtains the text to be reviewed and the pre-set keywords to check whether the text to be reviewed contains the preset keywords.

[0060] In step S120, preset keywords are used to perform keyword matching on the text to be reviewed, and keyword matching results are obtained.

[0061] The keyword matching result includes a matched keyword and an index corresponding to the last character of the keyword. Specifically, the index is used to represent the position of the character in the text to be audited and is a pointer to the corresponding character in the text to be audited. The index functions as a table of contents of a book and can be used to quickly find the required content. In a text, the index generally starts from 0, for example, the index of the first character of the text to be audited starts from 0 and increases one by one. The matched keyword is a keyword found in the text to be audited based on the preset keyword, that is, a keyword contained in the text to be audited.

[0062] In this embodiment, the keyword matching result is obtained by performing keyword matching on the text to be audited based on the preset keyword. For example, taking the text to be audited T as "ahishers" and the preset keyword as ['he','she', 'hers', 'his'], the keyword matching result obtained by keyword matching is as follows:

[0063] [3, ['his']],

[0064] [5, ['she', 'he']],

[0065] [7, ['hers']],

[0066] This means that in the text T, the keyword "his" can be found at the index 3, the keywords "she" and "he" can be found at the index 5, and the keyword "hers" can be found at the index 7. The "his", "she", "he", and "hers" found are the matched keywords, the index 3 is the index of the last character "s" in the matched keyword "his" in the text to be audited, the index 5 is the index of the last character "e" in the matched keywords "she" and "he" in the text to be audited, and the index 7 is the index of the last character "s" in the matched keyword "hers" in the text to be audited.

[0067] In step S130, the text to be audited is traversed from the index corresponding to the last character of the text to be audited, and when a target index matching the index corresponding to the traversed character exists in the keyword matching result, a target keyword corresponding to the target index is obtained.

[0068] The traversed character refers to the character in the text to be audited that is currently being traversed. For example, if the last character of the text to be audited is currently being traversed, the traversed character is the last character of the text to be audited, and if the first character of the text to be audited is currently being traversed, the traversed character is the first character of the text to be audited.

[0069] In the embodiment, the to-be-audited text is traversed from back to front based on the indexes, that is, the to-be-audited text is traversed from the index corresponding to the last character of the to-be-audited text to the front. For each index corresponding to a traversed character, when there is a target index matching the index in the keyword matching result, the keyword corresponding to the target index is obtained as a target keyword. The target index refers to an index matching the index corresponding to the traversed character in the keyword matching result. For example, if the index corresponding to the current traversed character is "7", and there is an index "7" in the keyword matching result, there is an index "7" matching the index corresponding to the traversed character in the keyword matching result, so the index "7" is the target index, and then the keyword corresponding to the index "7" is obtained from the keyword matching result as the target keyword.

[0070] In step S140, the obtained target keyword is stored in the first stack, and the same number of target indexes as the obtained target keyword is stored in the second stack.

[0071] The first stack and the second stack both refer to stacks. Inserting a new element into a stack is also called stacking, stacking or pushing. It is to place a new element above the top element of the stack to become the new top element. Deleting an element from a stack is also called out of stack or stack. It is to delete the top element, and its adjacent element becomes the new top element. Specifically, the first stack is a stack for storing target keywords, and the second stack is a stack for storing target indexes corresponding to the target keywords. The elements (target keywords) stored in the corresponding positions in the first stack have a corresponding relationship with the elements (target indexes) stored in the same positions in the second stack.

[0072] Since there are cases where the same index corresponds to multiple target keywords, when multiple target keywords corresponding to the target index are obtained, the multiple target keywords are sequentially stacked (that is, sequentially stored in the first stack), and the same number of target indexes as the obtained target keywords is stored in the second stack, so that the elements in the corresponding positions in the first stack correspond one by one with the elements in the same positions in the second stack. For example, the above index 5 corresponds to two target keywords, she and he. Therefore, she and he are sequentially stacked in the first stack, and index 5 is stacked in the second stack twice, so that the elements in the same positions in the two stacks correspond one by one.

[0073] In step S150, the target keyword in the to-be-audited text is configured with a display style according to the traversal index of the current traversed to-be-audited text, the first stack and the second stack, and the to-be-audited text after the display style is configured is obtained.

[0074] Wherein, the traversal index is an index corresponding to a traversal character currently traversing the text to be audited. In this embodiment, based on the target keywords and the corresponding target indexes respectively stored in the first stack and the second stack, and according to the traversal index of the text to be audited currently being traversed, the target keywords in the text to be audited are configured with display styles, so as to obtain the text to be audited configured with display styles, that is, the text to be audited is replaced, and the replaced text is inserted back into the DOM of the HTML, so as to achieve the highlighting effect.

[0075] In the above text processing method, by obtaining the text to be audited and the preset keywords, the preset keywords are used for keyword matching on the text to be audited to obtain a keyword matching result, and the text to be audited is traversed from the index corresponding to the last character of the text to be audited, when there is a target index matching the index corresponding to the traversal character in the keyword matching result, the target keyword corresponding to the target index is obtained, the obtained target keyword is stored in the first stack, and the target index same as the number of the obtained target keyword is stored in the second stack. Finally, according to the traversal index of the text to be audited currently being traversed, the first stack and the second stack, the target keywords in the text to be audited are configured with display styles, and the text to be audited configured with display styles is obtained. Since the stack concept is used in this embodiment to replace the style of the matched keywords in the text to be audited, the accuracy of processing is improved.

[0076] In an exemplary embodiment, in step S120, the preset keywords are used for keyword matching on the text to be audited, specifically including: using the preset keywords to perform keyword matching on the text to be audited by a multi-mode matching algorithm.

[0077] Wherein, the multi-mode matching algorithm refers to the AC automatic machine algorithm (i.e. Aho-Corasick). Specifically, first, a dictionary tree (Trie tree) is constructed according to the preset keywords, then a mismatch pointer of each node in the tree is created, and then the text to be audited is searched for keywords based on the dictionary tree to obtain a search result, i.e. a keyword matching result.

[0078] For example, taking the text to be audited T as "ahishers" and the preset keywords as ['he','she', 'hers', 'his'], the process of the AC automatic machine algorithm is as follows:

[0079] According to the preset keywords, a dictionary tree is constructed, as Figure 2As shown, the gray color indicates that the current node is the end node of a certain keyword. For the first keyword "he", first search "h" under the root. If there is no "h", create a child node "h" under the root. If there is "h", use it directly. Then continue to search the second character "e" under the "h" node. The operation is the same as above. For the second keyword "she", the operation of creating a node is also the same as above. Judge whether the first character "s" exists under the root. If it exists, use it directly. If it does not exist, create a node. Continue in this way until all preset keywords are traversed, and the corresponding dictionary tree is obtained.

[0080] Then, based on the dictionary tree created in the above steps, the mismatch pointer (i.e. fail pointer) of each node in the tree is created. The mismatch pointer indicates how to perform state transition when the current node fails to match, so as to quickly jump when the search fails. Specifically, all nodes are traversed by level, for any node N, find the parent node P of N, find the F node along the fail pointer of the parent node, judge whether the F node has other child nodes with the same value as N. If there is a child node F1, point the fail pointer of N to the child node F1. If there is no child node F1, point the fail pointer of N to the root node (the fail pointer of the root node points to itself). As shown in the following figure, Figure 3 As shown, Figure 2 The dictionary tree based on the longest suffix node can be divided into 3 layers (in the order from left to right). Take the keyword "she" in the third layer as an example. The fail pointer of the first character "s" points to the root. For the second character "h", first find the parent node s of h, find that the fail pointer of s is the root pointer and not h, then see whether the fail pointer of s, i.e. the root pointer, has a child node h. The root has a child node h (i.e. the h in the first layer), so the h in the third layer points to the h in the first layer (as shown by the dashed line in the figure). For the third character "e", e finds the fail pointer of the parent node h, i.e. the h in the first row, and sees whether the h has a child node named e. There is a child node named e, so the fail pointer of e is the found child node e, i.e. the e in the first row. The e in the third layer points to the e in the first layer. In this way, the nodes in other layers are processed in a similar way, so as to obtain the dictionary tree after the mismatch pointer is created.

[0081] Further, based on the dictionary tree shown in the following figure, the keyword matching is performed on the text string "ahishers" of the text to be audited T. The specific matching process is as follows: Figure 3 As shown,

[0082] From left to right, traverse the text string T, initially, the search pointer P in the tree points to the root node. The first character of the traversal is a, find in the dictionary tree, find that there is no a node under P, so ignore directly. The second character is h, and there is an h node under the root, then move P from the root to "h"; the third character is i, find that there is i under P, then move P to i; the fourth character is s, find that there is s under P, then move P to s, and at this time find that the s node has a gray mark, indicating that all the nodes on the path from root=>s form a keyword, and s is the last character of the keyword.

[0083] The fifth character is h, and there is no h node under P, at this time, move P to the node s pointed by its fail pointer, find that this s node has an h node, then continue to move P to point to h; the sixth character is e, find that there is an e node under h, move P to e, and at this time find that the e node has a gray mark, indicating that another keyword is found. The seventh character is r, and there is no r node under P, at this time, move P to the node e pointed by its fail pointer, and at the same time, find that the current e node has a gray mark, indicating that another keyword is found. Then, find that this e node has an r node, then continue to move P to point to r; the eighth character is s, and there is an s node under P, move P to s, and at this time find that the s node has a gray mark, indicating that another keyword is found. At this time, the matching of the last character in the text string T has been completed, therefore, the loop ends, and the following keyword matching results are obtained:

[0084] [3,['his']],

[0085] [5,['she','he']],

[0086] [7,['hers']],

[0087] The meaning is: in the text string T, at index 3, the keyword his can be found, at index 5, the two keywords she and he can be found, and at index 7, the keyword hers can be found. His, she, he and hers are the matched keywords.

[0088] In the above embodiment, the multi-mode matching algorithm is used to match the keywords in the text to be audited. Since only one traversal of the text to be audited T is needed to find all the contained keywords, the keyword matching performance is greatly improved.

[0089] In an exemplary embodiment, as shown in Figure 4 In step S140, the target keywords obtained are stored in the first stack, specifically including:

[0090] In step S142, when there are multiple target keywords corresponding to the target index, the character lengths corresponding to the multiple target keywords are obtained respectively.

[0091] Since there may be multiple keywords corresponding to the same index, when multiple target keywords are obtained that correspond to the target index, the character length of each target keyword is obtained separately. For example, for index 5 above, the target keywords include "she" and "he". Therefore, the character length of "she" is obtained as 3, and the character length of "he" is obtained as 2.

[0092] In step S144, multiple target keywords are sorted from largest to smallest according to their character length, and the sorted target keywords are stored sequentially into the first stack.

[0093] Since stacks follow the Last-In-First-Out (LIFO) principle, meaning the last element pushed onto the stack is the first to be popped, in this embodiment, to further improve the accuracy of subsequent style processing of the text to be reviewed, multiple target keywords corresponding to the same target index can be sorted according to their character length from largest to smallest. The sorted target keywords are then stored sequentially in the first stack, with the longest target keyword pushed onto the stack first and the shortest target keyword pushed last, ensuring that the shortest target keyword is popped first.

[0094] In this embodiment, when there are multiple target keywords corresponding to the target index, the character lengths of the multiple target keywords are obtained, and the multiple target keywords are sorted from largest to smallest according to their character lengths. The sorted multiple target keywords are then stored sequentially into the first stack, so that the target keyword with the longest character length can be pushed onto the stack first and popped off last, while the target keyword with the shortest character length can be pushed onto the stack last and popped off first, thereby further improving the accuracy of subsequent style processing of the text to be reviewed.

[0095] In one exemplary embodiment, such as Figure 5 As shown, in step S150, the display style of the target keywords in the text to be reviewed is configured according to the traversal index of the currently traversed text to be reviewed, the first stack, and the second stack, to obtain the text to be reviewed after configuring the display style, specifically including:

[0096] In step S152, the last character of the target keyword corresponding to the top position of the first stack is obtained, and the last character and the preset hypertext style tag end mark are concatenated to the concatenated string.

[0097] The hypertext style tag refers to an HTML custom tag, such as span or Web Components, and the like. The hypertext style tag usually appears in pairs, and each pair of hypertext style tags includes a start symbol and an end symbol. By adding a style to the HTML custom tag, the part wrapped by the start symbol and the end symbol of the HTML tag can be displayed according to the added style. The present embodiment needs to display the matched keywords in the text to be audited in a custom style, and thus the part wrapped by the start symbol and the end symbol of the HTML tag is the target keyword part in the text to be audited.

[0098] The spliced string is a string obtained by replacing the style of the text to be audited, that is, a string obtained by adding the HTML custom tag of the keyword to the text to be audited.

[0099] Since the present embodiment starts from the index corresponding to the last character of the text to be audited and traverses the text to be audited forward, when the current traversal index is the target index, it indicates that the current traversal index corresponds to the target keyword. Since the target index corresponds to the last character of the target keyword, and the top element of the stack is popped out each time, the last character of the target keyword corresponding to the top position of the first stack is obtained, the preset hypertext style tag end symbol is spliced after the last character, and the spliced string is spliced before the splicing string, so as to splice the end symbol of the HTML custom tag after the target keyword.

[0100] Since the same index corresponds to multiple target keywords, and different styles can be set for different target keywords, the corresponding HTML custom tag needs to be added for each target keyword. Therefore, the above splicing of the hypertext style tag end symbol can be based on the number of target indexes corresponding to the target keyword at the top position of the stack. For example, when the number of target indexes corresponding to the target keyword at the top position of the stack is multiple, it indicates that the target index corresponds to multiple keywords, and thus multiple hypertext style tag end symbols need to be spliced.

[0101] For example, for the traversal index 5, since the corresponding target keyword includes she and he, she is first entered into the first stack, he is later entered into the first stack, and the index 5 is stored into the second stack twice. For the target keyword he at the top position of the first stack, the last character e of he is spliced with two HTML custom tag end symbols. If the HTML custom tag end symbol is, the spliced string is “e”, and the spliced string is spliced before the splicing string. It can be understood that if it is the first time to traverse, the splicing string is the initialized string, that is, an empty string, and if it is not the first time to traverse, the splicing string is the string obtained after the last traversal.

[0102] In step S154, when it is determined that the target keyword at the top position of the first stack needs to be popped, the target keyword at the top position of the first stack and the target index at the top position of the second stack are popped, and the preset hypertext style label start symbol is spliced before the string is spliced.

[0103] Wherein, whether the pop is needed is determined by whether the complete target keyword is matched, when the complete target keyword is matched, the target keyword needs to be popped, and when the complete target keyword is not matched, the target keyword does not need to be popped.

[0104] Specifically, when it is determined that the target keyword at the top position of the first stack needs to be popped, the target keyword at the top position of the first stack and the target index at the top position of the second stack are popped, and the preset hypertext style label start symbol is spliced before the string is spliced. Wherein, the pop process can be the process of deleting elements from the corresponding stack. Since the stack is based on the principle of pop, and the elements at the same position in the first stack and the second stack are one-to-one corresponding, and each time the processing starts from the top element, when the complete target keyword is matched, i.e. when it is determined that the target keyword at the top position of the first stack needs to be popped, the target keyword at the top position of the first stack is deleted, and the target index at the top position of the second stack is also deleted, and the preset hypertext style label start symbol is spliced before the string is spliced. Since the hypertext style label end symbol has been spliced in the previous step, after the hypertext style label start symbol is spliced in this step, the target keyword at the top position of the first stack is wrapped by the hypertext style label start symbol and the end symbol.

[0105] In step S156, the step of traversing the text to be audited forward is returned to execute until the index corresponding to the first character of the text to be audited is traversed, and the target spliced string is obtained. The target spliced string is determined as the text to be audited after the display style is configured.

[0106] That is, the step of traversing the text to be audited forward in step S130 is returned to execute until the index corresponding to the first character of the text to be audited is traversed, i.e. the traversal of all characters of the text to be audited is completed, the target spliced string is obtained, and the target spliced string is determined as the text to be audited after the display style is configured.

[0107] In the above embodiment, by acquiring the last character of the target keyword corresponding to the top position of the first stack, the last character and the preset hypertext style label end symbol are spliced before the splicing string, when it is determined that the target keyword at the top position of the first stack needs to be popped, the target keyword at the top position of the first stack and the target index at the top position of the second stack are popped, and the preset hypertext style label start symbol is spliced before the splicing string, the step of executing the forward traversal of the to-be-audited text is returned until the index corresponding to the first character of the to-be-audited text is traversed, the target splicing string is obtained, and the target splicing string is determined as the to-be-audited text after the display style is configured. Since the first stack and the second stack are used to store the matched target keywords and the corresponding target indexes respectively in the embodiment, the corresponding elements in the stack are popped based on the last-in first-out principle, and the HTML custom label is added to the matched target keywords, so that accurate and efficient style processing of the keywords in the to-be-audited text is realized.

[0108] In an example embodiment, as shown in FIG. 15B, in step S154, it is determined that the target keyword at the top position of the first stack needs to be popped, which can include the following steps: Figure 6

[0109] In step S610, the number of characters between the traversal index and the target index at the top position of the second stack is acquired.

[0110] Specifically, the number of characters between the index corresponding to the current traversal character, i.e., the traversal index and the target index at the top position of the second stack, is acquired. In the embodiment, the characters at the two endpoints should be included when calculating the number of characters. For example, if the current traversal index is 4 and the target index at the top position of the second stack is 5, the number of characters between the traversal index 4 and the target index 5 at the top position of the second stack is 2, i.e., the count of all characters in the closed interval composed of the traversal index 4 and the target index 5.

[0111] In step S620, when the number of characters is the same as the character length of the target keyword at the top position of the first stack, it is determined that the target keyword at the top position of the first stack needs to be popped.

[0112] Since the target index 5 at the top position of the second stack corresponds to two target keywords she and he, and the number of characters of the target keyword she is greater than that of he, she will be first entered into the first stack and he will be later entered into the first stack, i.e., he is the top element of the first stack.

[0113] ​In the embodiment, the character length of the target keyword at the top of the first stack is obtained, and when the character number is the same as the character length of the target keyword at the top of the first stack, it is determined that the target keyword at the top of the first stack is matched, and it is determined that the target keyword at the top of the first stack needs to be popped. For example, the character length of the target keyword he at the top of the first stack is 2, and the character number between the traversal index 4 and the target index 5 at the top of the second stack obtained in the above step is also 2. Since the two are the same, it is determined that the target keyword he at the top of the first stack needs to be popped.

[0114] In the above embodiment, the character number between the traversal index and the target index at the top of the second stack is obtained, and when the character number is the same as the character length of the target keyword at the top of the first stack, it is determined that the target keyword at the top of the first stack needs to be popped. Since the target keyword at the top of the first stack corresponds to the target index at the top of the second stack, whether the target keyword at the top of the first stack is matched is determined by the relationship between the character number between the current traversal index and the target index at the top of the second stack and the character length of the target keyword at the top of the first stack, and when the target keyword at the top of the first stack is matched, it is determined that the target keyword at the top of the first stack needs to be popped, thereby improving the accuracy of keyword matching.

[0115] In an exemplary embodiment, when the character number is less than the character length of the target keyword at the top of the first stack, it is determined that the target keyword at the top of the first stack does not need to be popped. Specifically, when the character number between the traversal index and the target index at the top of the second stack is less than the character length of the target keyword at the top of the first stack, it is determined that the target keyword is not matched, and therefore it is determined that the target keyword at the top of the first stack does not need to be popped. In this embodiment, whether the target keyword at the top of the first stack is matched is determined by the relationship between the character number between the current traversal index and the target index at the top of the second stack and the character length of the target keyword at the top of the first stack, and when the target keyword at the top of the first stack is not matched, it is determined that the target keyword at the top of the first stack does not need to be popped, thereby improving the accuracy of keyword matching.

[0116] In an example embodiment, when it is determined that the target keyword at the top position of the first stack does not need to be popped, the step of traversing the text to be audited is returned to be executed. Specifically, when it is determined that the target keyword at the top position of the first stack does not need to be popped, the step of traversing the text to be audited in step S130 is returned to be executed until the index corresponding to the first character of the text to be audited is traversed, that is, the traversal of all characters of the text to be audited is completed, the target splicing string is obtained, the target splicing string is determined as the text to be audited after the display style is configured, thereby realizing the matching and replacing of all keywords in the text to be audited, and only one traversal of the text to be audited is needed, which greatly improves the matching performance.

[0117] In an example embodiment, in step S610, the number of characters between the traversal index and the target index at the top position of the second stack is obtained, which can specifically include: obtaining the difference between the target index at the top position of the second stack and the traversal index, and taking the sum of the difference and 1 as the number of characters between the traversal index and the target index at the top position of the second stack.

[0118] Since the characters at both endpoints need to be included when calculating the number of characters, when calculating the number of characters between the traversal index and the target index at the top position of the second stack, the difference between the two endpoints (i.e. the traversal index and the target index at the top position of the second stack) is calculated and a 1 operation is performed, and the final result is taken as the number of characters between the traversal index and the target index at the top position of the second stack, so that the final number of characters can include the endpoints, thereby improving the accuracy of keyword matching.

[0119] In an example embodiment, the above method can further include: when there is no target index matching the index corresponding to the traversal character in the keyword matching result, the traversal character is spliced before the splicing string, and step S154 is returned to be executed, that is, the step of popping the target keyword at the top position of the first stack and the target index at the top position of the second stack when it is determined that the target keyword at the top position of the first stack needs to be popped is returned to be executed, and the preset hypertext style label start symbol is spliced before the splicing string.

[0120] Specifically, when there is no target index matching the index corresponding to the traversal character in the keyword matching result, it indicates that the current traversal character is not the last character of the target keyword, so the current traversal character is directly spliced before the splicing string, and then the step of determining that the target keyword at the top position of the first stack needs to be popped is returned to be executed, thereby realizing accurate and efficient processing of other characters in the text to be audited which are not the last characters of the keywords.

[0121] In an example embodiment, as Figure 7As shown, the above text processing method is further illustrated below through one specific embodiment, specifically including the following steps:

[0122] In step S702, the text to be audited and the preset keyword are acquired.

[0123] In step S704, the text to be audited is matched with the preset keyword through a multi-mode matching algorithm, and a keyword matching result is obtained.

[0124] The keyword matching result includes the matched keyword and the index of the last character of the matched keyword in the text to be audited. Specifically, in the embodiment, the keyword matching result can also be preprocessed, i.e., converted into an object form for storage, i.e., taking the index of the last character of the matched keyword in the text to be audited as the key and the corresponding matched keyword as the value, so as to facilitate index query and thus speed up the search process.

[0125] In step S706, the stack and the splicing string results are initialized.

[0126] That is, the first stack and the second stack are created and initialized, and the splicing string results is also initialized, wherein the splicing string results is the final result, i.e., the text to be audited after the display style is configured, and in this step, results is an empty string.

[0127] In step S708, the text to be audited is traversed from the index corresponding to the last character of the text to be audited.

[0128] Specifically, if the character length of the text to be audited is text.length, and assuming that the index corresponding to the first character starts from 0, the index (i.e., the traversal index) of the first traversed character is i = text.length-1.

[0129] In step S710, it is determined whether the traversal index i is greater than or equal to 0 each time the text is traversed.

[0130] When i is greater than or equal to 0, step S712 is executed, and when i is less than 0, step S730 is executed.

[0131] In step S712, it is determined whether there is a target index matching the traversal index i in the keyword matching result.

[0132] When there is, step S714 is executed, and when there is not, step S728 is executed.

[0133] In step S714, the keyword corresponding to the traversal index i is acquired as the target keyword and stored in the first stack.

[0134] The specific push-in process can refer to the above-mentioned embodiments as shown in Figure 4 In the embodiments, the above-mentioned process will not be repeated.

[0135] In step S716, the traversal index i is stored in the second stack.

[0136] Specifically, the number of times of push-in of the traversal index i is the same as the number of target keywords corresponding to the traversal index i.

[0137] In step S718, the element corresponding to the top position of the first stack, i.e., the target keyword corresponding to the top position, is obtained.

[0138] In step S720, the last character of the top element and the preset hypertext style tag end symbol are spliced before the splicing string results.

[0139] Specifically, the number of hypertext style tag end symbols spliced here is the same as the number of target indexes corresponding to the element. After the splicing string results is spliced, the updated splicing string results is obtained.

[0140] In step S722, it is determined whether the stack needs to be popped out.

[0141] When the stack needs to be popped out, step S724 is executed, and when the stack does not need to be popped out, step S726 is executed.

[0142] In step S724, when the stack needs to be popped out, the element at the top position of the first stack and the element at the top position of the second stack are popped out, and the preset hypertext style tag start symbol is spliced before the results.

[0143] In step S726, the traversal index i is decremented, i.e., i-- is executed, and the step S710 is returned.

[0144] In step S728, the character corresponding to the traversal index i is spliced before the splicing string results, and the step S722 is returned.

[0145] In step S730, the final splicing string results is obtained and the process is ended.

[0146] In the above-mentioned embodiments, the multi-mode matching algorithm is used to match the keywords in the text to be audited. Since only one traversal of the text to be audited T is needed to find all the contained keywords, the matching performance of the keywords is greatly improved. By using the stack concept to replace the matched keywords in the text to be audited with the style, the processing accuracy is further improved.

[0147] It should be understood that, although Figures 1-7The steps in the flowchart are shown in sequence according to the arrows, but the steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, the steps are not strictly limited in sequence, and the steps can be executed in other sequences. Moreover, Figures 1-7 At least one of the steps in the flowchart can include multiple steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution sequence of the steps or stages is not necessarily sequential, but can be alternately executed with other steps or steps or stages in other steps.

[0148] It can be understood that the same / similar parts between the above-mentioned methods in the specification can be referred to each other, and each embodiment focuses on the differences from other embodiments, and the related parts can be referred to the description of other method embodiments.

[0149] Figure 8 is a block diagram of a text processing device according to an exemplary embodiment. Referring to Figure 8 The device includes a data acquisition module 802, a keyword matching module 804, a traversal module 806, a stack processing module 808, and a text processing module 810.

[0150] The data acquisition module 802 is configured to perform acquiring a to-be-audited text and a preset keyword;

[0151] The keyword matching module 804 is configured to perform keyword matching on the to-be-audited text using the preset keyword to obtain a keyword matching result, the keyword matching result including a matched keyword and an index corresponding to a last character of the keyword, the index being used to represent a position of the character in the to-be-audited text;

[0152] The traversal module 806 is configured to perform traversing the to-be-audited text from the index corresponding to the last character of the to-be-audited text, and when there is a target index in the keyword matching result that matches an index corresponding to a traversed character, obtaining a keyword corresponding to the target index as a target keyword;

[0153] The stack processing module 808 is configured to store the obtained target keyword in a first stack and store a target index corresponding to the obtained target keyword in a second stack;

[0154] The text processing module 810 is configured to perform display style configuration on a target keyword in the text to be audited according to a current traversal index of the text to be audited, the first stack, and the second stack, to obtain the text to be audited after display style configuration, and the traversal index is an index corresponding to a traversal character of the text to be audited in the current traversal.

[0155] In an example embodiment, the text processing module comprises: a first splicing unit configured to perform the following: obtaining a last character of a target keyword corresponding to a top position of the first stack, and splicing a preset hypertext style tag end symbol to a splicing string before the last character, and the number of splicing hypertext style tag end symbols is the same as the number of target indexes corresponding to the target keyword at the top position of the stack; a second splicing unit configured to perform the following: when it is determined, according to a current traversal index, a target index at a top position of the second stack, and a character length of a target keyword at a top position of the first stack, that the target keyword at the top position of the first stack needs to be popped, performing pop processing on the target keyword at the top position of the first stack and the target index at the top position of the second stack, and splicing a preset hypertext style tag start symbol before the splicing string; and an execution unit configured to perform the following: returning to perform the step of traversing the text to be audited forward until an index corresponding to a first character of the text to be audited is traversed, to obtain a target splicing string, and determining the target splicing string as the text to be audited after display style configuration.

[0156] In an example embodiment, the first splicing unit is further configured to perform the following: when there is no target index matching the index corresponding to the traversal character in the keyword matching result, splicing the traversal character to the splicing string; and the execution unit is further configured to perform the following: returning to perform the step of, when it is determined, according to a current traversal index, a target index at a top position of the second stack, and a character length of a target keyword at a top position of the first stack, that the target keyword at the top position of the first stack needs to be popped, performing pop processing on the target keyword at the top position of the first stack and the target index at the top position of the second stack.

[0157] In an example embodiment, the execution unit is further configured to perform the following: when it is determined that the target keyword at the top position of the first stack does not need to be popped, returning to perform the step of traversing the text to be audited forward.

[0158] In an example embodiment, the second splicing unit further includes a character number obtaining subunit configured to perform obtaining a character number between the traversal index and the target index of the top position of the second stack.

[0159] In an example embodiment, the outstack determining subunit is further configured to perform determining that the target keyword of the top position of the first stack does not need to be outstacked when the character number is less than the character length of the target keyword of the top position of the first stack.

[0160] In an example embodiment, the character number obtaining subunit is further configured to perform obtaining a difference value between the target index of the top position of the second stack and the traversal index, and taking a sum of the difference value and 1 as the character number between the traversal index and the target index of the top position of the second stack.

[0161] In an example embodiment, the keyword matching module is further configured to perform keyword matching on the text to be audited by using a preset keyword through a multi-mode matching algorithm.

[0162] In an example embodiment, the stack processing module is further configured to perform, when there are multiple target keywords corresponding to the target index, obtaining character lengths respectively corresponding to the multiple target keywords, sorting the multiple target keywords according to the character lengths from large to small, and storing the sorted multiple target keywords into the first stack in sequence.

[0163] As to the apparatus in the above-mentioned embodiments, the specific manners in which various modules perform operations have been described in detail in the embodiments of the method, and thus will not be described in detail here.

[0164] Figure 9 FIG. 1 is a block diagram illustrating an electronic device 100 according to an example embodiment. The electronic device 100 can be a mobile phone, a computer, a digital broadcasting terminal, a message transmitting / receiving device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, etc.

[0165] Referring to FIG. 1, Figure 9 The electronic device 100 can include one or more of the following components: a processing component 102, a memory 104, a power supply component 106, a multimedia component 108, an audio component 110, an input / output (I / O) interface 112, a sensor component 114, and a communication component 116.

[0166] The processing component 902 generally controls the overall operation of the electronic device 900 by, for example, executing instructions. The processing component 902 can include one or more processors 920 to execute instructions and to process data. Examples of processors 920 include general purpose processors, application specific processors, and logic devices. The processing component 902 can further include a memory controller 924 that controls communications between the processing component 902 and the system memory 904. The processing component 902 can include one or more modules to facilitate the interaction between the processing component 902 and other components. For example, the processing component 902 can include a multi-media module to facilitate the interaction between the multi-media component 908 and the processing component 902.

[0167] The memory 904 is configured to store various types of data to support operations of the electronic device 900. Examples of such data include instructions for any application or method operating on the electronic device 900, contact data, phonebook data, messages, pictures, videos, and so on. The memory 904 can be implemented by any type of volatile or non-volatile storage devices or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read only memory (EEPROM), erasable programmable read only memory (EPROM), programmable read only memory (PROM), read only memory (ROM), magnetic memory, flash memory, magnetic disks, optical disks, or graphene memory.

[0168] The power component 906 provides power to the various components of the electronic device 900. The power component 906 can include a power supply management system, one or more power sources, and other components associated with generating, managing and distributing power for the electronic device 900.

[0169] The multi-media component 908 includes a screen to provide an output interface between the electronic device 900 and a user. In some embodiments, the screen can include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense a touch, a slide and a gesture on the touch panel. The touch sensors can not only sense a boundary of a touch or a slide, but also detect duration and pressure related to the touch or slide operations. In some embodiments, the multi-media component 908 includes a front-facing camera and / or a rear-facing camera. The front-facing camera and / or the rear-facing camera can receive external multi-media data when the electronic device 900 is in an operation mode, such as a photographing mode or a video mode. Each of the front-facing camera and the rear-facing camera can be a fixed optical lens system or have a focal length and optical zoom capability.

[0170] The audio component Z10 is configured to output and / or input audio signals. For example, the audio component Z10 includes a microphone (MIC) that is configured to receive an external audio signal when the electronic device Z00 is in an operation mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal can be further stored in the memory Z04 or transmitted via the communication component Z16. In some embodiments, the audio component Z10 also includes a speaker for outputting an audio signal.

[0171] The I / O interface Z12 provides an interface between the processing component Z02 and peripheral interface modules, which can be a keypad, a click wheel, buttons, and the like. The buttons can include, but are not limited to, a home button, a volume button, a start button, and a lock button.

[0172] The sensor component Z14 includes one or more sensors for providing various state assessments for the electronic device Z00. For example, the sensor component Z14 can detect an open / closed position of the electronic device Z00, relative positioning of components, such as a display and a keypad of the electronic device Z00, a change in position of the electronic device Z00 or components of the electronic device Z00, presence or absence of user contact with the electronic device Z00, the device Z00 orientation or acceleration / deceleration, and a temperature change of the electronic device Z00. The sensor component Z14 can include a proximity sensor configured to detect presence of a nearby object without any physical touch. The sensor component Z14 can further include a light sensor, such as a CMOS or CCD image sensor, for use in an imaging application. In some embodiments, the sensor component Z14 can further include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.

[0173] The communication component Z16 is configured to facilitate wired or wireless communication between the electronic device Z00 and another device. The electronic device Z00 can access a wireless network based on a communication standard, such as WiFi, a cellular network standard (such as 2G, 3G, 4G, or 5G), or a combination thereof. In an example embodiment, the communication component Z16 receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel. In an example embodiment, the communication component Z16 further includes a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology, and other technology.

[0174] In example embodiments, the electronic device Z00 can be implemented with one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic elements, for performing the above-described methods.

[0175] In example embodiments, a computer-readable storage medium including instructions, such as the memory Z04 including instructions, is also provided, which can be executed by the processor Z20 of the electronic device Z00 to complete the above-described methods. For example, the computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disc, and an optical data storage device, etc.

[0176] In example embodiments, a computer program product including instructions, which can be executed by the processor Z20 of the electronic device Z00 to complete the above-described methods, is also provided.

[0177] Figure 10 is a block diagram of an electronic device S00 for text processing according to an example embodiment. For example, the electronic device S00 can be a server. Referring to Figure 10 , the electronic device S00 includes a processing component S20, which further includes one or more processors, and a memory resource represented by a memory S22, for storing instructions, such as application programs, executable by the processing component S20. The application programs stored in the memory S22 can include one or more than one module each corresponding to a set of instructions. In addition, the processing component S20 is configured to execute the instructions to perform the above-described methods.

[0178] The electronic device S00 can also include a power component S24 configured to perform power management of the electronic device S00, a wired or wireless network interface S26 configured to connect the electronic device S00 to a network, and an input output (I / O) interface S28. The electronic device S00 can operate based on an operating system stored in the memory S22, such as Windows Server, Mac OSX, Unix, Linux, FreeBSD, or the like.

[0179] In example embodiments, a computer-readable storage medium including instructions, such as the memory S22 including instructions, is also provided, which can be executed by the processor of the electronic device S00 to complete the above-described methods. The storage medium can be a computer-readable storage medium, for example, which can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disc, and an optical data storage device, etc.

[0180] In an example embodiment, there is also provided a computer program product comprising instructions executable by a processor of an electronic device S00 to perform the above method.

[0181] It should be noted that the above apparatus, electronic device, computer readable storage medium, computer program product and the like according to the description of the method embodiments can also include other implementation manners, and the specific implementation manners can be referred to the description of the related method embodiments, which will not be repeated here.

[0182] Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the concepts disclosed herein. The disclosure is intended to cover any variations, uses or adaptations of the disclosure following, in general, the principles of the disclosure and including such departures from the present disclosure as come within known or customary practice in the art to which the disclosure pertains. The specification and examples are to be regarded as illustrative only, and the true scope and spirit of the disclosure are indicated by the appended claims.

[0183] It should be understood that the present disclosure is not limited to the precise structures herein described and illustrated in the drawings, and that various modifications and changes can be made without departing from the scope thereof. The scope of the present disclosure is limited only by the claims that follow.

Claims

1. A text processing method characterized by, The method comprises: acquiring a text to be audited and a preset keyword; performing keyword matching on the text to be audited by using the preset keyword to obtain a keyword matching result, wherein the keyword matching result comprises a matched keyword and an index corresponding to a last character of the keyword, and the index is used to represent a position of the character in the text to be audited; starting from the index corresponding to the last character of the text to be audited, traversing the text to be audited forward, when there is a target index in the keyword matching result that matches an index corresponding to a traversed character, acquiring the keyword corresponding to the target index as a target keyword; storing the target keyword in a first stack and storing the target index in a second stack, wherein the target index is the same as the number of the target keyword; configuring a display style for the target keyword in the text to be audited according to a current traversal index of the text to be audited, the first stack and the second stack, wherein the traversal index is an index corresponding to a traversed character of the text to be audited, and obtaining the text to be audited after the display style is configured; the method further comprises: when there is no target index in the keyword matching result that matches the index corresponding to the traversed character, concatenating the traversed character to the concatenation string in front of the concatenation string; 2. The method of claim 1, wherein, returning to execute the step of traversing the text to be audited forward until the index corresponding to the first character of the text to be audited is traversed, obtaining a target concatenation string, and determining the target concatenation string as the text to be audited after the display style is configured. The method further comprises: when there is no target index in the keyword matching result that matches the index corresponding to the traversed character, concatenating the traversed character to the concatenation string in front of the concatenation string; 3. The method of claim 2, wherein, returning to execute the step of performing out-stack processing on the target keyword at the top of the first stack and the target index at the top of the second stack when it is determined that the target keyword at the top of the first stack needs to be out-stacked. The method further comprises:

4. The method according to any one of claims 1 to 3, characterized in that, when it is determined that the target keyword at the top of the first stack does not need to be out-stacked, returning to execute the step of traversing the text to be audited forward. The method further comprises: acquiring a number of characters between the traversal index and the target index at the top of the second stack; 5. The method of claim 4, wherein, when the number of characters is the same as the length of the target keyword at the top of the first stack, determining that the target keyword at the top of the first stack needs to be out-stacked. The method further comprises: after the step of acquiring the number of characters between the traversal index and the target index at the top of the second stack, the method further comprises: When the character number is less than the character length of the target keyword at the top position of the first stack, it is determined that the target keyword at the top position of the first stack does not need to be popped.

6. The method of claim 4, wherein, The character number between the target index at the top position of the second stack and the traversal index is obtained. The difference value between the target index at the top position of the second stack and the traversal index is obtained, and the sum of the difference value and 1 is taken as the character number between the target index at the top position of the second stack and the traversal index.

7. The method according to any one of claims 1 to 3, characterized in that, The keyword matching on the to-be-audited text by using the preset keyword comprises: The keyword matching on the to-be-audited text by using the preset keyword comprises:

8. The method according to any one of claims 1 to 3, characterized in that, The target keyword obtained is stored in the first stack. When there are multiple target keywords corresponding to the target index, the character lengths of the multiple target keywords are obtained respectively. The multiple target keywords are sorted according to the character lengths from large to small, and the sorted multiple target keywords are sequentially stored in the first stack.

9. A text processing apparatus characterized by comprising: Comprise: The data acquisition module is configured to perform obtaining to-be-audited text and a preset keyword; The keyword matching module is configured to perform keyword matching on the to-be-audited text by using the preset keyword to obtain a keyword matching result, the keyword matching result comprising a matched keyword and an index corresponding to the last character of the keyword, the index being used to represent the position of the character in the to-be-audited text; The traversal module is configured to perform forward traversal of the to-be-audited text from the index corresponding to the last character of the to-be-audited text, and when there is a target index matching the index corresponding to the traversal character in the keyword matching result, the keyword corresponding to the target index is obtained as a target keyword; The stack processing module is configured to perform storing the target keyword obtained in the first stack and storing the target index corresponding to the target keyword obtained in the second stack; The text processing module is configured to perform configuring a display style for the target keyword in the to-be-audited text according to the traversal index of the to-be-audited text currently traversed, the first stack, and the second stack, to obtain the to-be-audited text after the display style is configured, the traversal index being the index corresponding to the traversal character of the to-be-audited text currently traversed; The text processing module comprises: The first splicing unit is configured to perform obtaining the last character of the target keyword corresponding to the top position of the first stack, splicing the last character and a preset hypertext style tag end symbol to a splicing string in advance, and the number of spliced hypertext style tag end symbols being the same as the number of target indexes corresponding to the target keyword at the top position. The second splicing unit is configured to perform the outstack processing on the target keyword at the top of the first stack and the target index at the top of the second stack when it is determined that the target keyword at the top of the first stack needs to be outstacked according to the current traversal index, the target index at the top of the second stack and the character length of the target keyword at the top of the first stack, and splice a preset hypertext style label start symbol before the spliced string. The execution unit is configured to perform the step of returning to execute the step of traversing the text to be audited forward until the index corresponding to the first character of the text to be audited is traversed to obtain a target spliced string, and determining the target spliced string as the text to be audited after the display style is configured.

10. The apparatus of claim 9, wherein The first splicing unit is further configured to perform the step of splicing the traversal character before the spliced string when there is no target index matching the index corresponding to the traversal character in the keyword matching result. The execution unit is further configured to perform the step of returning to execute the step of determining whether the target keyword at the top of the first stack needs to be outstacked according to the current traversal index, the target index at the top of the second stack and the character length of the target keyword at the top of the first stack.

11. The apparatus of claim 10, wherein, The execution unit is further configured to perform the step of returning to execute the step of traversing the text to be audited forward when it is determined that the target keyword at the top of the first stack does not need to be outstacked. The second splicing unit further comprises:

12. The apparatus of any one of claims 9 to 11, wherein, The character number obtaining subunit is configured to perform the step of obtaining the character number between the traversal index and the target index at the top of the second stack. The outstacking determination subunit is configured to perform the step of determining that the target keyword at the top of the first stack needs to be outstacked when the character number is the same as the character length of the target keyword at the top of the first stack. The outstacking determination subunit is further configured to perform the step of determining that the target keyword at the top of the first stack does not need to be outstacked when the character number is less than the character length of the target keyword at the top of the first stack.

13. The apparatus of claim 12, wherein, The character number obtaining subunit is further configured to perform the step of obtaining the difference between the target index at the top of the second stack and the traversal index, and taking the sum of the difference and 1 as the character number between the traversal index and the target index at the top of the second stack. The keyword matching module is further configured to perform the step of matching the text to be audited by using the preset keyword through a multi-mode matching algorithm.

14. The apparatus of claim 12, wherein, The stack processing module is further configured to perform the step of obtaining the character length corresponding to each of the target keywords when there are multiple target keywords corresponding to the target index. The stack processing module is further configured to perform the step of obtaining the character length corresponding to each of the target keywords when there are multiple target keywords corresponding to the target index.

15. The apparatus of any one of claims 9 to 11, wherein, ​ ​ 16. The apparatus of any one of claims 9 to 11, wherein, ​ ​ According to the character length from large to small, the plurality of target keywords are sorted, and the sorted plurality of target keywords are sequentially stored into the first stack.

17. An electronic device, comprising: Comprise: a processor; a memory for storing the processor-executable instructions; wherein the processor is configured to execute the instructions to implement the text processing method of any one of claims 1 to 8.

18. A computer-readable storage medium, characterized in that, When the instructions in the computer-readable storage medium are executed by the processor of the electronic device, the electronic device is enabled to perform the text processing method of any one of claims 1 to 8.

19. A computer program product, comprising instructions therein, characterised in that, The instructions are executed by the processor of the electronic device, and the electronic device is enabled to perform the text processing method of any one of claims 1 to 8.

Citation Information

Patent Citations

  • Data retrieval method and device, electronic equipment and storage medium

    CN111309970A

  • KR1022133680000B1