Text highlighting method, device, equipment and storage medium
By constructing a statement prefix tree and matching index information, the problem of low retrieval efficiency and non-display of information in the highlighting method is solved, and efficient text highlighting is achieved.
Patent Information
- Application Number
- CN202210255864.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-15
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2042-03-15
AI Technical Summary
The existing highlighting method is inefficient during retrieval and the highlighted information is not displayed.
By building a statement prefix tree, matching the text statements in the text to be matched and the word segments of the search statements, generating matching index information, filtering the target statements based on the index information, and adjusting the highlight position to display the matching text.
It improves the retrieval efficiency and the generation efficiency of matching index information, ensures the accurate display of highlighted information, and avoids the problem of highlighted information not being displayed when viewing text.
Smart Images

Figure CN114637839B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a text highlighting method, device, equipment and storage medium. Background Art
[0002] In a retrieval system with highlighted display, you can intuitively see how much content in the resource matches the search information, thereby helping users quickly locate the specific resources they want to view.
[0003] In current highlighting solutions, a regular matching algorithm is usually used to match information that matches the search text from the resource text for display. However, this method has problems such as long retrieval time and the highlight information not being displayed when viewing the text. Summary of the invention
[0004] In view of the above, it is necessary to provide a text highlighting method, device, equipment and storage medium, which can not only improve the retrieval efficiency, but also avoid the problem of highlight information not being displayed when viewing the text.
[0005] In one aspect, the present invention provides a text highlighting method, the text highlighting method comprising:
[0006] Get the search statement and the text to be matched;
[0007] Constructing a sentence prefix tree according to the sentence segmentation in the search sentence;
[0008] Based on the sentence prefix tree, each text sentence in the to-be-matched text is matched with the sentence segmentation to obtain a matching sentence in the to-be-matched text that matches the sentence segmentation and matching index information of the matching sentence;
[0009] Filtering a target statement from the matching statements according to the matching index information;
[0010] Adjusting the matching index information according to the text position of the target sentence in the to-be-matched text to obtain a highlighted position;
[0011] Get the display frame length of the display frame;
[0012] The target sentence is displayed according to the sentence length of the target sentence, the length of the display frame and the highlight position.
[0013] According to a preferred embodiment of the present invention, constructing a sentence prefix tree according to sentence segmentation in the search sentence includes:
[0014] Performing word segmentation processing on the search sentence based on a preset dictionary to obtain a plurality of word segments of the sentence;
[0015] Taking each grammatical participle as a node link of a root node, and taking each participle character in each grammatical participle as a child node in the node link in turn to construct an initial prefix tree;
[0016] Detecting whether there are repeated word segmentation characters in the nodes at the same level in the initial prefix tree, and determining the continuous levels containing the repeated word segmentation characters as level links;
[0017] Determine the level where the child node of the root node is located as the target level, and merge the nodes corresponding to the repeated word segmentation characters in the level link including the target level to obtain an intermediate prefix tree;
[0018] Generate a node state of each node in the intermediate prefix tree based on the sentence segmentation;
[0019] The node state is written into the intermediate prefix tree to obtain the statement prefix tree.
[0020] According to a preferred embodiment of the present invention, the matching process of each text sentence in the text to be matched with the sentence segmentation based on the sentence prefix tree to obtain the matching sentence in the text to be matched that matches the sentence segmentation and the matching index information of the matching sentence includes:
[0021] Segment the text to be matched based on preset symbols to obtain a plurality of text sentences;
[0022] Generate a character index value according to the position of each text character in the plurality of text sentences in the text to be matched;
[0023] For each text sentence, filter out the first character from the text sentence according to the character index values in ascending order, and compare the first character with each node in the sentence prefix tree;
[0024] Acquire a node state corresponding to a first matching node matching the first character from the sentence prefix tree as an initial state, and determine the text sentence as the matching sentence;
[0025] If the initial state is the first preset state, then according to the character index value, the next character of the first character in the text sentence is compared with the child node of the first matching node as the second character to obtain the target state;
[0026] If the target state is the second preset state, obtaining the next character of the second character from the text sentence according to the character index value as the third character and comparing it with each node in the sentence prefix tree;
[0027] If the third character does not match any node, the matching index information is generated according to the character index value of the first character and the character index value of the second character.
[0028] According to a preferred embodiment of the present invention, the adjusting the matching index information according to the text position of the target sentence in the to-be-matched text to obtain the highlighted position includes:
[0029] Obtaining the character index value of the first character in the target sentence as the target index value;
[0030] The difference between each information value in the matching index information corresponding to the target sentence and the target index value is calculated to obtain the highlighted position.
[0031] According to a preferred embodiment of the present invention, filtering a target statement from the matching statement according to the matching index information includes:
[0032] Counting the matching length of each matching statement according to the matching index information, and determining the matching length with the largest value as the target length;
[0033] Counting the number of matching index information in each matching statement as the number of matching fragments of each matching statement, and counting the statement length of each matching statement;
[0034] Calculating a matching score of the matching sentence according to the matching length, the target length, the number of matching segments and the sentence length;
[0035] The matching sentence with the largest matching score is determined as the target sentence.
[0036] According to a preferred embodiment of the present invention, the calculation formula of the matching score is:
[0037] matchScore=longestMatch*k1+avgMatchLength*k2+matchPercent*k3+(index.size() / t2)*k4;
[0038] longestMatch = maxLen / t1;
[0039] avgMatchLength=(matchCharSum / index.size()) / t2;
[0040] matchPercent=matchCharSum / content.length();
[0041] k1+k2+k3+k4=1;
[0042] Among them, matchScore refers to the matching score, maxLen refers to the target length, matchCharSum refers to the matching length, index.size() refers to the number of matching fragments, content.length() refers to the statement length, and k1, k2, k3, k4, t1, and t2 are constants.
[0043] According to a preferred embodiment of the present invention, displaying the target sentence according to the sentence length of the target sentence, the length of the display frame and the highlight position includes:
[0044] Comparing the length of the sentence with the length of the display frame;
[0045] If the length of the sentence is greater than or equal to the length of the display frame, display the target sentence in the display frame, and highlight the vocabulary corresponding to the highlighted position in the target sentence; or
[0046] If the sentence length is less than the display box length, the length difference between the display box length and the sentence length is calculated, an output sentence is obtained from the text to be matched based on the length difference and the target sentence, and the target sentence and the output sentence are displayed in the display box.
[0047] On the other hand, the present invention further provides a text highlighting display device, the text highlighting display device comprising:
[0048] An acquisition unit, used to acquire a search statement and a text to be matched;
[0049] A construction unit, used to construct a sentence prefix tree according to the sentence segmentation in the search sentence;
[0050] A matching unit, configured to match each text sentence in the to-be-matched text with the sentence segmentation based on the sentence prefix tree, to obtain a matching sentence in the to-be-matched text that matches the sentence segmentation and matching index information of the matching sentence;
[0051] A screening unit, configured to screen a target statement from the matching statements according to the matching index information;
[0052] An adjusting unit, configured to adjust the matching index information according to the text position of the target sentence in the to-be-matched text to obtain a highlighted position;
[0053] The obtaining unit is further used to obtain the display frame length of the display frame;
[0054] A display unit is used to display the target sentence according to the sentence length of the target sentence, the length of the display frame and the highlight position.
[0055] On the other hand, the present invention further provides an electronic device, comprising:
[0056] a memory storing computer readable instructions; and
[0057] A processor executes the computer-readable instructions stored in the memory to implement the text highlighting method.
[0058] On the other hand, the present invention further proposes a computer-readable storage medium, in which computer-readable instructions are stored. The computer-readable instructions are executed by a processor in an electronic device to implement the text highlighting method.
[0059] The present invention constructs a sentence prefix tree based on the sentence segmentation, and can store multiple sentence segmentations of different lengths containing the same character in the same node link, and then match each text sentence in the text to be matched with the sentence segmentation based on the sentence prefix tree. When the same character exists in multiple sentence segmentations of different lengths, when detecting whether the text to be matched contains a sentence segmentation of longer length, it is not necessary to re-match the same characters in the sentence segmentation of longer length, so the matching efficiency can be improved, thereby improving the generation efficiency of the matching index information. In addition, the present invention adjusts the matching index information according to the text position of the target sentence in the text to be matched, and can accurately locate the highlight position, so that the vocabulary matching the search sentence in the target sentence can be accurately highlighted, and the target sentence can be further displayed according to the sentence length of the target sentence, the length of the display box and the highlight position, so that the target sentence that best matches the search sentence can be displayed, and the problem of highlight text not being displayed when viewing the text can be avoided. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1 It is a flow chart of a preferred embodiment of the text highlighting method of the present invention.
[0061] Figure 2 It is a schematic diagram of constructing the sentence prefix tree of the present invention.
[0062] Figure 3 It is a functional module diagram of a preferred embodiment of the text highlighting display device of the present invention.
[0063] Figure 4 It is a structural schematic diagram of an electronic device of a preferred embodiment of the text highlighting method of the present invention. DETAILED DESCRIPTION
[0064] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention is described in detail below with reference to the accompanying drawings and specific embodiments.
[0065] like Figure 1 FIG. 1 is a flowchart of a preferred embodiment of the text highlighting method of the present invention. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.
[0066] The text highlighting method can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0067] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0068] The text highlighting method is applied to one or more electronic devices, which are devices that can automatically perform numerical calculations and / or information processing according to pre-set or stored computer-readable instructions, and whose hardware includes but is not limited to microprocessors, application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), digital signal processors (DSPs), embedded devices, etc.
[0069] The electronic device may be any electronic product that can perform human-computer interaction with a user, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), a smart wearable device, etc.
[0070] The electronic device may include a network device and / or a user device. The network device includes, but is not limited to, a single network electronic device, an electronic device group consisting of multiple network electronic devices, or a cloud consisting of a large number of hosts or network electronic devices based on cloud computing.
[0071] The network where the electronic device is located includes, but is not limited to: the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VPN), etc.
[0072] S10, obtaining a search statement and obtaining a text to be matched.
[0073] In at least one embodiment of the present invention, the search statement may be a statement set by a user who has a query requirement, and the search statement may be obtained from a user terminal of the user who has a query requirement.
[0074] The text to be matched may be any text in a preset text library.
[0075] S11, constructing a sentence prefix tree according to sentence segmentation in the search sentence.
[0076] In at least one embodiment of the present invention, the sentence segmentation refers to the phrases obtained after segmenting the search sentence.
[0077] The sentence prefix tree includes multiple node links and the node status in each node.
[0078] In at least one embodiment of the present invention, the electronic device constructing a sentence prefix tree according to sentence segmentation in the search sentence includes:
[0079] Performing word segmentation processing on the search sentence based on a preset dictionary to obtain a plurality of word segments of the sentence;
[0080] Taking each grammatical participle as a node link of a root node, and taking each participle character in each grammatical participle as a child node in the node link in turn to construct an initial prefix tree;
[0081] Detecting whether there are repeated word segmentation characters in the nodes at the same level in the initial prefix tree, and determining the continuous levels containing the repeated word segmentation characters as level links;
[0082] Determine the level where the child node of the root node is located as the target level, and merge the nodes corresponding to the repeated word segmentation characters in the level link including the target level to obtain an intermediate prefix tree;
[0083] Generate a node state of each node in the intermediate prefix tree based on the sentence segmentation;
[0084] Write the node state into the intermediate prefix tree to obtain the statement prefix tree.
[0085] Among them, the preset dictionary can be any pre-customized dictionary.
[0086] The number of links in the node link of the initial prefix tree is the same as the number of word segments of the multiple statement word segments.
[0087] The node state is used to indicate whether the word segment character corresponding to the node is the last character among the multiple statement word segments.
[0088] For example, after word segmentation processing, multiple statement word segments are obtained as: Who, is, the first vehicle, installed, safety glass, safety. After analyzing and constructing the multiple statement word segments, the statement prefix tree is obtained as Figure 2 shown. Since the node "Who" is the last character of the statement word segment "Who", therefore, the node state corresponding to the node "Who" is end = true; since the nodes "An" are not the last characters of the statement word segments "safety" and "safety glass", therefore, the node state corresponding to the node "An" is end = false.
[0089] By performing word segmentation processing on the search statement through the preset dictionary, the multiple statement word segments can be quickly obtained. Furthermore, the continuous levels containing repeated word segment characters are determined as level links, and the nodes corresponding to the repeated word segment characters in the level link containing the target level are merged, which can realize storing multiple statement word segments of different lengths containing the same characters in the same node link. By analyzing the node state through the statement word segments, the accuracy of the node state is improved, thereby improving the construction accuracy of the statement prefix tree.
[0090] S12. Based on the statement prefix tree, perform matching processing on each text statement in the text to be matched with the statement word segments to obtain the matching statements in the text to be matched that match the statement word segments and the matching index information of the matching statements.
[0091] In at least one embodiment of the present invention, the matching statement refers to a text statement that has a matching relationship with any statement word segment.
[0092] The matching index information includes the character index values corresponding to the text characters that have a matching relationship with any statement word segment. For example, if the text characters that have a matching relationship with any statement word segment are: safety glass, and the character index values of the text characters "safety glass" are 11, 12, 13, 14 respectively, then the matching index information can be [11, 14].
[0093] In at least one embodiment of the present invention, the electronic device matches each text sentence in the text to be matched with the sentence segmentation based on the sentence prefix tree, and obtains a matching sentence in the text to be matched that matches the sentence segmentation and matching index information of the matching sentence, including:
[0094] Segment the text to be matched based on preset symbols to obtain a plurality of text sentences;
[0095] Generate a character index value according to the position of each text character in the plurality of text sentences in the text to be matched;
[0096] For each text sentence, filter out the first character from the text sentence according to the character index values in ascending order, and compare the first character with each node in the sentence prefix tree;
[0097] Acquire a node state corresponding to a first matching node matching the first character from the sentence prefix tree as an initial state, and determine the text sentence as the matching sentence;
[0098] If the initial state is the first preset state, then according to the character index value, the next character of the first character in the text sentence is compared with the child node of the first matching node as the second character to obtain the target state;
[0099] If the target state is the second preset state, obtaining the next character of the second character from the text sentence according to the character index value as the third character and comparing it with each node in the sentence prefix tree;
[0100] If the third character does not match any node, the matching index information is generated according to the character index value of the first character and the character index value of the second character.
[0101] The preset symbols include: colon, comma, semicolon and other symbols that can separate sentences.
[0102] It is understandable that Figure 2 Corresponding to the generated statement prefix tree, the first preset state is set to true, and the second preset state is set to false.
[0103] Through the above implementation, when the same characters exist in multiple sentence segmentations of different lengths, when detecting whether the text to be matched contains a sentence segmentation of a longer length, there is no need to re-match the same characters in the sentence segmentation of a longer length. Therefore, the matching efficiency can be improved, thereby improving the efficiency of generating the matching index information.
[0104] S13: Filter a target statement from the matching statements according to the matching index information.
[0105] It should be emphasized that in order to further ensure the privacy and security of the above target statement, the above target statement can also be stored in a node of a blockchain.
[0106] In at least one embodiment of the present invention, the target sentence refers to a matching sentence that best matches the search sentence.
[0107] In at least one embodiment of the present invention, the electronic device filtering a target statement from the matching statements according to the matching index information comprises:
[0108] Counting the matching length of each matching statement according to the matching index information, and determining the matching length with the largest value as the target length;
[0109] Counting the number of matching index information in each matching statement as the number of matching fragments of each matching statement, and counting the statement length of each matching statement;
[0110] Calculating a matching score of the matching sentence according to the matching length, the target length, the number of matching segments and the sentence length;
[0111] The matching sentence with the largest matching score is determined as the target sentence.
[0112] The number of matching segments refers to the number of words in the matching sentence that match the multiple sentence segmentations.
[0113] Through the above implementation, the target sentence can be quickly determined based on the matching score.
[0114] Specifically, the calculation formula of the matching score is:
[0115] matchScore=longestMatch*k1+avgMatchLength*k2+matchPercent*k3+(index.size() / t2)*k4;
[0116] longestMatch = maxLen / t1;
[0117] avgMatchLength=(matchCharSum / index.size()) / t2;
[0118] matchPercent=matchCharSum / content.length();
[0119] k1+k2+k3+k4=1;
[0120] Among them, matchScore refers to the matching score, maxLen refers to the target length, matchCharSum refers to the matching length, index.size() refers to the number of matching fragments, content.length() refers to the statement length, and k1, k2, k3, k4, t1, and t2 are constants.
[0121] The matching score of the matching sentence can be calculated from multiple dimensions through the matching length, the target length, the number of matching fragments and the sentence length, thereby improving the accuracy of the matching score and facilitating the screening of the target sentence.
[0122] S14, adjusting the matching index information according to the text position of the target sentence in the text to be matched to obtain a highlighted position.
[0123] In at least one embodiment of the present invention, the highlighted position refers to the position of the text character in the target sentence that matches the sentence segmentation in the target sentence.
[0124] In at least one embodiment of the present invention, the electronic device adjusts the matching index information according to the text position of the target sentence in the text to be matched, and obtaining the highlighted position includes:
[0125] Obtaining the character index value of the first character in the target sentence as the target index value;
[0126] The difference between each information value in the matching index information corresponding to the target sentence and the target index value is calculated to obtain the highlighted position.
[0127] By adjusting the matching index information according to the text position of the target sentence in the text to be matched, the highlight position can be accurately located.
[0128] S15, obtaining a display frame length of the display frame.
[0129] In at least one embodiment of the present invention, the display box refers to a text box for displaying text, and the display box is usually located in the input interface of the search statement.
[0130] The display frame length refers to the specific length of the text that can be displayed in the display frame. The display frame length can be set according to actual conditions.
[0131] S16, displaying the target sentence according to the sentence length of the target sentence, the length of the display frame and the highlight position.
[0132] In at least one embodiment of the present invention, the sentence length refers to the total number of all text characters in the target sentence.
[0133] In at least one embodiment of the present invention, the electronic device displays the target sentence according to the sentence length of the target sentence, the length of the display frame, and the highlight position, including:
[0134] Comparing the length of the sentence with the length of the display frame;
[0135] If the length of the sentence is greater than or equal to the length of the display frame, display the target sentence in the display frame, and highlight the vocabulary corresponding to the highlighted position in the target sentence; or
[0136] If the sentence length is less than the display box length, the length difference between the display box length and the sentence length is calculated, an output sentence is obtained from the text to be matched based on the length difference and the target sentence, and the target sentence and the output sentence are displayed in the display box.
[0137] The highlighted position can accurately highlight the words in the target sentence that match the search sentence. By highlighting the target sentence, the target sentence that best matches the search sentence can be displayed, which can avoid the problem of highlighted text not being displayed when viewing the text.
[0138] It can be seen from the above technical scheme that the present invention constructs a sentence prefix tree based on the sentence segmentation, and can store multiple sentence segmentations of different lengths containing the same characters in the same node link, and then match each text sentence in the text to be matched with the sentence segmentation based on the sentence prefix tree. When the same characters exist in multiple sentence segmentations of different lengths, when detecting whether the text to be matched contains a sentence segmentation of longer length, it is not necessary to re-match the same characters in the sentence segmentation of longer length, so the matching efficiency can be improved, thereby improving the generation efficiency of the matching index information. In addition, the present invention adjusts the matching index information by the text position of the target sentence in the text to be matched, and can accurately locate the highlight position, so that the vocabulary matching the search sentence in the target sentence can be accurately highlighted, and the target sentence can be further displayed according to the sentence length of the target sentence, the length of the display box and the highlight position, so that the target sentence that best matches the search sentence can be displayed, and the problem of highlight text not being displayed when viewing the text can be avoided.
[0139] like Figure 3, which is a functional module diagram of a preferred embodiment of the text highlighting display device of the present invention. The text highlighting display device 11 includes an acquisition unit 110, a construction unit 111, a matching unit 112, a screening unit 113, an adjustment unit 114 and a display unit 115. The module / unit referred to in the present invention refers to a series of computer-readable instruction segments that can be acquired by the processor 13 and can perform fixed functions, which are stored in the memory 12. In this embodiment, the functions of each module / unit will be described in detail in subsequent embodiments.
[0140] The acquisition unit 110 acquires a search statement and acquires text to be matched.
[0141] In at least one embodiment of the present invention, the search statement may be a statement set by a user who has a query requirement, and the search statement may be obtained from a user terminal of the user who has a query requirement.
[0142] The text to be matched may be any text in a preset text library.
[0143] The construction unit 111 constructs a sentence prefix tree according to the sentence segmentations in the search sentence.
[0144] In at least one embodiment of the present invention, the sentence segmentation refers to the phrases obtained after segmenting the search sentence.
[0145] The sentence prefix tree includes multiple node links and the node status in each node.
[0146] In at least one embodiment of the present invention, the constructing unit 111 constructs a sentence prefix tree according to the sentence segmentation in the search sentence, including:
[0147] Performing word segmentation processing on the search sentence based on a preset dictionary to obtain a plurality of word segments of the sentence;
[0148] Taking each grammatical participle as a node link of a root node, and taking each participle character in each grammatical participle as a child node in the node link in turn to construct an initial prefix tree;
[0149] Detecting whether there are repeated word segmentation characters in the nodes at the same level in the initial prefix tree, and determining the continuous levels containing the repeated word segmentation characters as level links;
[0150] Determine the level where the child node of the root node is located as the target level, and merge the nodes corresponding to the repeated word segmentation characters in the level link including the target level to obtain an intermediate prefix tree;
[0151] Generate a node state of each node in the intermediate prefix tree based on the sentence segmentation;
[0152] Write the node state into the intermediate prefix tree to obtain the statement prefix tree.
[0153] Wherein, the preset dictionary can be any pre-customized dictionary.
[0154] The number of links in the node link of the initial prefix tree is the same as the number of word segments of the multiple statement word segments.
[0155] The node state is used to indicate whether the word segment character corresponding to the node is the last character in the multiple statement word segments.
[0156] For example, after word segment processing, the multiple statement word segments obtained are: who, is, the first vehicle, installed, safety glass, safety. After analyzing and constructing the multiple statement word segments, the statement prefix tree is obtained as Figure 2 shown. Since the node "who" is the last character of the statement word segment "who", therefore, the node state corresponding to the node "who" is end = true; since the node "an" is not the last character of the statement word segments "safety" and "safety glass", therefore, the node state corresponding to the node "an" is end = false.
[0157] By performing word segment processing on the search statement through the preset dictionary, the multiple statement word segments can be quickly obtained. Furthermore, the continuous levels containing repeated word segment characters are determined as level links, and the nodes corresponding to the repeated word segment characters in the level link containing the target level are merged, which can realize storing multiple statement word segments with different lengths and the same characters in the same node link. By analyzing the node state through the statement word segments, the accuracy of the node state is improved, thereby improving the construction accuracy of the statement prefix tree.
[0158] The matching unit 112 performs matching processing on each text statement in the text to be matched with the statement word segments based on the statement prefix tree, and obtains the matching statements in the text to be matched that match the statement word segments and the matching index information of the matching statements.
[0159] In at least one embodiment of the present invention, the matching statement refers to a text statement that has a matching relationship with any statement word segment.
[0160] The matching index information includes the character index values corresponding to the text characters that have a matching relationship with any statement word segment. For example, if the text characters that have a matching relationship with any statement word segment are: safety glass, and the character index values of the text character "safety glass" are 11, 12, 13, 14 respectively, then the matching index information can be [11, 14].
[0161] In at least one embodiment of the present invention, the matching unit 112 matches each text sentence in the to-be-matched text with the sentence segmentation based on the sentence prefix tree, and obtains a matching sentence in the to-be-matched text that matches the sentence segmentation and matching index information of the matching sentence, including:
[0162] Segment the text to be matched based on preset symbols to obtain a plurality of text sentences;
[0163] Generate a character index value according to the position of each text character in the plurality of text sentences in the text to be matched;
[0164] For each text sentence, filter out the first character from the text sentence according to the character index values in ascending order, and compare the first character with each node in the sentence prefix tree;
[0165] Acquire a node state corresponding to a first matching node matching the first character from the sentence prefix tree as an initial state, and determine the text sentence as the matching sentence;
[0166] If the initial state is the first preset state, then according to the character index value, the next character of the first character in the text sentence is compared with the child node of the first matching node as the second character to obtain the target state;
[0167] If the target state is the second preset state, obtaining the next character of the second character from the text sentence according to the character index value as the third character and comparing it with each node in the sentence prefix tree;
[0168] If the third character does not match any node, the matching index information is generated according to the character index value of the first character and the character index value of the second character.
[0169] The preset symbols include: colon, comma, semicolon and other symbols that can separate sentences.
[0170] It is understandable that Figure 2 Corresponding to the generated statement prefix tree, the first preset state is set to true, and the second preset state is set to false.
[0171] Through the above implementation, when the same characters exist in multiple sentence segmentations of different lengths, when detecting whether the text to be matched contains a sentence segmentation of a longer length, there is no need to re-match the same characters in the sentence segmentation of a longer length. Therefore, the matching efficiency can be improved, thereby improving the efficiency of generating the matching index information.
[0172] The screening unit 113 screens target sentences from the matching sentences according to the matching index information.
[0173] It should be emphasized that in order to further ensure the privacy and security of the above target statement, the above target statement can also be stored in a node of a blockchain.
[0174] In at least one embodiment of the present invention, the target sentence refers to a matching sentence that best matches the search sentence.
[0175] In at least one embodiment of the present invention, the screening unit 113 screening the target sentence from the matching sentence according to the matching index information includes:
[0176] Counting the matching length of each matching statement according to the matching index information, and determining the matching length with the largest value as the target length;
[0177] Counting the number of matching index information in each matching statement as the number of matching fragments of each matching statement, and counting the statement length of each matching statement;
[0178] Calculating a matching score of the matching sentence according to the matching length, the target length, the number of matching segments and the sentence length;
[0179] The matching sentence with the largest matching score is determined as the target sentence.
[0180] The number of matching segments refers to the number of words in the matching sentence that match the multiple sentence segmentations.
[0181] Through the above implementation, the target sentence can be quickly determined based on the matching score.
[0182] Specifically, the calculation formula of the matching score is:
[0183] matchScore=longestMatch*k1+avgMatchLength*k2+matchPercent*k3+(index.size() / t2)*k4;
[0184] longestMatch = maxLen / t1;
[0185] avgMatchLength=(matchCharSum / index.size()) / t2;
[0186] matchPercent=matchCharSum / content.length();
[0187] k1+k2+k3+k4=1;
[0188] Among them, matchScore refers to the matching score, maxLen refers to the target length, matchCharSum refers to the matching length, index.size() refers to the number of matching fragments, content.length() refers to the statement length, and k1, k2, k3, k4, t1, and t2 are constants.
[0189] The matching score of the matching sentence can be calculated from multiple dimensions through the matching length, the target length, the number of matching fragments and the sentence length, thereby improving the accuracy of the matching score and facilitating the screening of the target sentence.
[0190] The adjusting unit 114 adjusts the matching index information according to the text position of the target sentence in the to-be-matched text to obtain a highlighted position.
[0191] In at least one embodiment of the present invention, the highlighted position refers to the position of the text character in the target sentence that matches the sentence segmentation in the target sentence.
[0192] In at least one embodiment of the present invention, the adjusting unit 114 adjusts the matching index information according to the text position of the target sentence in the to-be-matched text, and the highlight position includes:
[0193] Obtaining the character index value of the first character in the target sentence as the target index value;
[0194] The difference between each information value in the matching index information corresponding to the target sentence and the target index value is calculated to obtain the highlighted position.
[0195] By adjusting the matching index information according to the text position of the target sentence in the text to be matched, the highlight position can be accurately located.
[0196] The acquiring unit 110 acquires a display frame length of the display frame.
[0197] In at least one embodiment of the present invention, the display box refers to a text box for displaying text, and the display box is usually located in the input interface of the search statement.
[0198] The display frame length refers to the specific length of the text that can be displayed in the display frame. The display frame length can be set according to actual conditions.
[0199] The display unit 115 displays the target sentence according to the sentence length of the target sentence, the length of the display frame and the highlight position.
[0200] In at least one embodiment of the present invention, the sentence length refers to the total number of all text characters in the target sentence.
[0201] In at least one embodiment of the present invention, the display unit 115 displays the target sentence according to the sentence length of the target sentence, the length of the display frame and the highlight position, including:
[0202] Comparing the length of the sentence with the length of the display frame;
[0203] If the length of the sentence is greater than or equal to the length of the display frame, display the target sentence in the display frame, and highlight the vocabulary corresponding to the highlighted position in the target sentence; or
[0204] If the sentence length is less than the display box length, the length difference between the display box length and the sentence length is calculated, an output sentence is obtained from the text to be matched based on the length difference and the target sentence, and the target sentence and the output sentence are displayed in the display box.
[0205] The highlighted position can accurately highlight the words in the target sentence that match the search sentence. By highlighting the target sentence, the target sentence that best matches the search sentence can be displayed, which can avoid the problem of highlighted text not being displayed when viewing the text.
[0206] It can be seen from the above technical scheme that the present invention constructs a sentence prefix tree based on the sentence segmentation, and can store multiple sentence segmentations of different lengths containing the same characters in the same node link, and then match each text sentence in the text to be matched with the sentence segmentation based on the sentence prefix tree. When the same characters exist in multiple sentence segmentations of different lengths, when detecting whether the text to be matched contains a sentence segmentation of longer length, it is not necessary to re-match the same characters in the sentence segmentation of longer length, so the matching efficiency can be improved, thereby improving the generation efficiency of the matching index information. In addition, the present invention adjusts the matching index information by the text position of the target sentence in the text to be matched, and can accurately locate the highlight position, so that the vocabulary matching the search sentence in the target sentence can be accurately highlighted, and the target sentence can be further displayed according to the sentence length of the target sentence, the length of the display box and the highlight position, so that the target sentence that best matches the search sentence can be displayed, and the problem of highlight text not being displayed when viewing the text can be avoided.
[0207] like Figure 4 , which is a schematic diagram of the structure of an electronic device of a preferred embodiment of the text highlighting method of the present invention.
[0208] In one embodiment of the present invention, the electronic device 1 includes, but is not limited to, a memory 12, a processor 13, and computer-readable instructions stored in the memory 12 and executable on the processor 13, such as a text highlighting program.
[0209] Those skilled in the art will understand that the schematic diagram is merely an example of the electronic device 1 and does not constitute a limitation on the electronic device 1. The electronic device 1 may include more or fewer components than shown in the diagram, or a combination of certain components, or different components. For example, the electronic device 1 may also include input and output devices, network access devices, buses, etc.
[0210] The processor 13 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc. The processor 13 is the computing core and control center of the electronic device 1, and uses various interfaces and lines to connect various parts of the entire electronic device 1, and executes the operating system of the electronic device 1 and various installed applications, program codes, etc.
[0211] Exemplarily, the computer-readable instructions may be divided into one or more modules / units, which are stored in the memory 12 and executed by the processor 13 to complete the present invention. The one or more modules / units may be a series of computer-readable instruction segments capable of completing specific functions, which are used to describe the execution process of the computer-readable instructions in the electronic device 1. For example, the computer-readable instructions may be divided into an acquisition unit 110, a construction unit 111, a matching unit 112, a screening unit 113, an adjustment unit 114, and a display unit 115.
[0212] The memory 12 can be used to store the computer-readable instructions and / or modules, and the processor 13 implements various functions of the electronic device 1 by running or executing the computer-readable instructions and / or modules stored in the memory 12, and calling the data stored in the memory 12. The memory 12 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the electronic device, etc. The memory 12 can include non-volatile and volatile memories, such as: a hard disk, a memory, a plug-in hard disk, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other storage devices.
[0213] The memory 12 may be an external memory and / or an internal memory of the electronic device 1. Furthermore, the memory 12 may be a memory in a physical form, such as a memory stick, a TF card (Trans-flash Card), and the like.
[0214] If the module / unit integrated in the electronic device 1 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also instruct the relevant hardware to complete it through computer-readable instructions. The computer-readable instructions can be stored in a computer-readable storage medium. When the computer-readable instructions are executed by the processor, the steps of the above-mentioned various method embodiments can be implemented.
[0215] The computer-readable instructions include computer-readable instruction codes, which may be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer-readable instruction code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM).
[0216] The blockchain referred to in the present invention is a new application mode of computer technologies such as distributed text highlighting, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0217] Combination Figure 1 The memory 12 in the electronic device 1 stores computer-readable instructions to implement a text highlighting method, and the processor 13 can execute the computer-readable instructions to implement:
[0218] Get the search statement and the text to be matched;
[0219] Constructing a sentence prefix tree according to the sentence segmentation in the search sentence;
[0220] Based on the sentence prefix tree, each text sentence in the to-be-matched text is matched with the sentence segmentation to obtain a matching sentence in the to-be-matched text that matches the sentence segmentation and matching index information of the matching sentence;
[0221] Filtering a target statement from the matching statements according to the matching index information;
[0222] Adjusting the matching index information according to the text position of the target sentence in the to-be-matched text to obtain a highlighted position;
[0223] Get the display frame length of the display frame;
[0224] The target sentence is displayed according to the sentence length of the target sentence, the length of the display frame and the highlight position.
[0225] Specifically, the specific implementation method of the processor 13 for the above-mentioned computer readable instructions can refer to Figure 1 The description of the relevant steps in the corresponding embodiments will not be repeated here.
[0226] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation.
[0227] The computer-readable storage medium stores computer-readable instructions, wherein the computer-readable instructions are used to implement the following steps when executed by the processor 13:
[0228] Get the search statement and the text to be matched;
[0229] Constructing a sentence prefix tree according to the sentence segmentation in the search sentence;
[0230] Based on the sentence prefix tree, each text sentence in the to-be-matched text is matched with the sentence segmentation to obtain a matching sentence in the to-be-matched text that matches the sentence segmentation and matching index information of the matching sentence;
[0231] Filtering a target statement from the matching statements according to the matching index information;
[0232] Adjusting the matching index information according to the text position of the target sentence in the to-be-matched text to obtain a highlighted position;
[0233] Get the display frame length of the display frame;
[0234] The target sentence is displayed according to the sentence length of the target sentence, the length of the display frame and the highlight position.
[0235] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0236] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0237] Therefore, no matter from which point of view, the embodiments should be regarded as illustrative and non-restrictive, and the scope of the present invention is limited by the appended claims rather than the above description, so it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any attached figure mark in the claims should not be regarded as limiting the claims involved.
[0238] In addition, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. The multiple units or devices mentioned can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
[0239] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. A text highlighting method, characterized in that: The text highlighting method comprises: Get the search statement and the text to be matched; Constructing a sentence prefix tree according to the sentence segmentation in the search sentence; Based on the sentence prefix tree, each text sentence in the to-be-matched text is matched with the sentence segmentation to obtain a matching sentence in the to-be-matched text that matches the sentence segmentation and matching index information of the matching sentence; Filtering a target sentence from the matching sentence according to the matching index information includes: counting the matching length of each matching sentence according to the matching index information, and determining the matching length with the largest value as the target length; counting the number of matching index information in each matching sentence as the number of matching fragments of each matching sentence, and counting the sentence length of each matching sentence; calculating the matching score of the matching sentence according to the matching length, the target length, the number of matching fragments and the sentence length; and determining the matching sentence with the largest matching score as the target sentence; The matching index information is adjusted according to the text position of the target sentence in the to-be-matched text to obtain a highlighted position, including: obtaining the character index value of the first character in the target sentence as the target index value; calculating the difference between each information value in the matching index information corresponding to the target sentence and the target index value to obtain the highlighted position; Get the display frame length of the display frame; The target sentence is displayed according to the sentence length of the target sentence, the length of the display frame and the highlight position.
2. The text highlighting method according to claim 1, characterized in that: The constructing a sentence prefix tree according to the sentence segmentation in the search sentence comprises: Performing word segmentation processing on the search sentence based on a preset dictionary to obtain a plurality of word segments of the sentence; Taking each grammatical participle as a node link of a root node, and taking each participle character in each grammatical participle as a child node in the node link in turn to construct an initial prefix tree; Detecting whether there are repeated word segmentation characters in the nodes at the same level in the initial prefix tree, and determining the continuous levels containing the repeated word segmentation characters as level links; Determine the level where the child node of the root node is located as the target level, and merge the nodes corresponding to the repeated word segmentation characters in the level link including the target level to obtain an intermediate prefix tree; Generate a node state of each node in the intermediate prefix tree based on the sentence segmentation; The node state is written into the intermediate prefix tree to obtain the statement prefix tree.
3. The text highlighting method according to claim 1, characterized in that: The matching process of each text sentence in the to-be-matched text with the sentence segmentation based on the sentence prefix tree to obtain a matching sentence in the to-be-matched text that matches the sentence segmentation and matching index information of the matching sentence includes: Segment the text to be matched based on preset symbols to obtain a plurality of text sentences; Generate a character index value according to the position of each text character in the plurality of text sentences in the text to be matched; For each text sentence, filter out the first character from the text sentence according to the character index values in ascending order, and compare the first character with each node in the sentence prefix tree; Acquire a node state corresponding to a first matching node matching the first character from the sentence prefix tree as an initial state, and determine the text sentence as the matching sentence; If the initial state is the first preset state, then according to the character index value, the next character of the first character in the text sentence is compared with the child node of the first matching node as the second character to obtain the target state; If the target state is the second preset state, obtaining the next character of the second character from the text sentence according to the character index value as the third character and comparing it with each node in the sentence prefix tree; If the third character does not match any node, the matching index information is generated according to the character index value of the first character and the character index value of the second character.
4. The text highlighting method according to claim 1, characterized in that: The calculation formula of the matching score is: in, refers to the matching score, is the target length, refers to the matching length, refers to the number of matching fragments, is the length of the statement, is a constant.
5. The text highlighting method according to claim 1, characterized in that: The displaying of the target sentence according to the sentence length of the target sentence, the length of the display frame and the highlight position includes: Comparing the length of the sentence with the length of the display frame; If the length of the sentence is greater than or equal to the length of the display frame, display the target sentence in the display frame, and highlight the vocabulary corresponding to the highlighted position in the target sentence; or If the sentence length is less than the display box length, the length difference between the display box length and the sentence length is calculated, an output sentence is obtained from the text to be matched based on the length difference and the target sentence, and the target sentence and the output sentence are displayed in the display box.
6. A text highlighting device, characterized in that: The text highlighting device comprises: An acquisition unit, used to acquire a search statement and a text to be matched; A construction unit, used to construct a sentence prefix tree according to the sentence segmentation in the search sentence; A matching unit, configured to match each text sentence in the to-be-matched text with the sentence segmentation based on the sentence prefix tree, to obtain a matching sentence in the to-be-matched text that matches the sentence segmentation and matching index information of the matching sentence; A screening unit is used to screen a target sentence from the matching sentence according to the matching index information, including: counting the matching length of each matching sentence according to the matching index information, and determining the matching length with the largest value as the target length; counting the number of matching index information in each matching sentence as the number of matching fragments of each matching sentence, and counting the sentence length of each matching sentence; calculating the matching score of the matching sentence according to the matching length, the target length, the number of matching fragments and the sentence length; determining the matching sentence with the largest matching score as the target sentence; An adjustment unit is used to adjust the matching index information according to the text position of the target sentence in the to-be-matched text to obtain a highlighted position, including: obtaining the character index value of the first character in the target sentence as the target index value; calculating the difference between each information value in the matching index information corresponding to the target sentence and the target index value to obtain the highlighted position; The obtaining unit is further used to obtain the display frame length of the display frame; A display unit is used to display the target sentence according to the sentence length of the target sentence, the length of the display frame and the highlight position.
7. An electronic device, characterized in that: The electronic device comprises: a memory storing computer-readable instructions; and A processor executes computer-readable instructions stored in the memory to implement the text highlighting method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions are executed by a processor in an electronic device to implement the text highlighting method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Long text enterprise name recognition algorithm based on pre-built word bank
CN110413764A
Combined title prefix and full-word content searching
US20070043714A1
Information search system and information search method using index
US20200394223A1
Method and system for dynamically processing ambiguous, reduced text search queries and highlighting results thereof
WO2007025149A2
Method and apparatus for analysis and matching of resume data information, electronic device, and medium
WO2021174919A1
