A text segmentation and sensitive word detection method based on matrix multiplication

By constructing a two-dimensional matrix of text characters and a matching two-dimensional matrix, combined with a tree diagram of a deterministic finite state automaton, the problem of low efficiency in detecting intermittent text strings in existing technologies is solved, and efficient sensitive word detection is achieved.

CN115757721BActive Publication Date: 2026-02-17XUANCAI INTERACTIVE NETWORK SCI & TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211398636.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-11-09
Publication Date
2026-02-17
Estimated Expiration
2042-11-09

AI Technical Summary

Technical Problem

Existing sensitive word detection technologies struggle to effectively identify spaced text strings, resulting in low detection efficiency and a high susceptibility to errors.

Method used

A matrix multiplication-based method is adopted to construct a two-dimensional matrix of text characters and a matching two-dimensional matrix, and then use a deterministic finite state automaton tree diagram to detect sensitive words, supporting the detection of spaced text strings.

Benefits of technology

It improves the accuracy and efficiency of sensitive word detection, and can effectively identify sensitive words in spaced text strings.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115757721B_ABST
    Figure CN115757721B_ABST
Patent Text Reader

Abstract

A text segmentation and sensitive word detection method based on matrix multiplication, comprising the following steps: obtaining an original text string and a sensitive word library; constructing a deterministic finite state automaton tree diagram of sensitive words according to the sensitive word library; converting the original text string into a text character two-dimensional matrix and recording the length of the text character two-dimensional matrix; constructing a matching two-dimensional matrix according to a horizontal matching rule, a vertical matching rule, an oblique matching rule and an inverse oblique matching rule, the length of the matching two-dimensional matrix being the same as that of the text character two-dimensional matrix; performing dot multiplication processing on the text character two-dimensional matrix and the matching two-dimensional matrix to obtain a corresponding result matrix; generating a corresponding matching text string according to the result matrix, and matching with the deterministic finite state automaton tree diagram to determine whether there is a sensitive word. The application supports interval text character information detection, improves the sensitive word detection accuracy and detection efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of sensitive word detection, and in particular to a text segmentation and sensitive word detection method based on matrix multiplication. BACKGROUND

[0002] With the development of sensitive word detection technology, more and more users identify the text information, and detect whether the text contains sensitive words that do not conform to the regulations or have negative effects.

[0003] At present, sensitive word detection can generally only identify continuous strings in the text, and for sensitive word information in the interval text string, it is easy to miss detection. If you want to support interval string detection, you need to exhaust more interval conditions, which will result in low detection efficiency and easy detection errors. SUMMARY

[0004] In order to solve the defects of the prior art, the purpose of the present application is to provide a text segmentation and sensitive word detection method based on matrix multiplication, which can support sensitive word detection of interval text strings and improve the detection accuracy and efficiency of sensitive words in text information.

[0005] In order to achieve the above purpose, the text segmentation and sensitive word detection method based on matrix multiplication provided by the present application comprises the following steps:

[0006] Obtain the original text string and the sensitive word library;

[0007] According to the sensitive word library, a deterministic finite state automaton tree diagram of sensitive words is constructed;

[0008] The original text string is converted into a text character two-dimensional matrix, and the length of the text character two-dimensional matrix is recorded;

[0009] According to the horizontal matching rule, the vertical matching rule, the diagonal matching rule and the anti-diagonal matching rule, a matching two-dimensional matrix is constructed, and the length of the matching two-dimensional matrix is the same as that of the text character two-dimensional matrix;

[0010] The text character two-dimensional matrix and the matching two-dimensional matrix are point multiplied to obtain a corresponding result matrix;

[0011] According to the result matrix, a corresponding matching text string is generated, which is matched with the deterministic finite state automaton tree diagram to determine whether there is a sensitive word.

[0012] Further, the step of converting the original text string into a text character two-dimensional matrix comprises: splitting the text string by character to obtain a plurality of groups of text strings and constructing a text character two-dimensional matrix, wherein a one-dimensional length of the text character two-dimensional matrix is a number of rows of the text string, and a two-dimensional length of the text character two-dimensional matrix is a length of a longest row of the text string.

[0013] Further, the step of constructing a matching two-dimensional matrix according to the horizontal matching rule, the vertical matching rule, the diagonal matching rule and the anti-diagonal matching rule respectively comprises:

[0014] constructing a reference matching two-dimensional matrix with a one-dimensional length of M and a two-dimensional length of N, and initializing values in the array to 0, wherein M and N are respectively a one-dimensional length and a two-dimensional length of the text character two-dimensional matrix;

[0015] defining a two-dimensional matching matrix queue for storing all generated matching two-dimensional matrices.

[0016] Further, the horizontal matching rule is:

[0017] defining A x as a horizontal coordinate of a point A, A y as a vertical coordinate of the point A, B x as a horizontal coordinate of a point B, B y as a vertical coordinate of the point B; initializing A x = 0, A y = 0, B x = 0, B y = N-1.

[0018] repeating the following steps to generate M horizontal matching matrices:

[0019] when A x ≤ M-1, the coordinates of the point A are [A x ][A y ], the coordinates of the point B are [B x ][B y ], and the points on a straight line defined by the points A and B are assigned a value of 1 in the reference matching two-dimensional matrix to generate a horizontal matching matrix;

[0020] adding the horizontal matching matrix to the matching matrix queue, and restoring all values of 0 in the reference matching two-dimensional matrix;

[0021] A x = A x +1, B x = B x +1.

[0022] Further, the vertical matching rule is:

[0023] Define A x Let A be the x-coordinate of point A. y Let A be the ordinate of point B. x Let B be the x-coordinate of point B. y Let A be the ordinate of point B. x =0, A y =0; B x =M-1,B y =0;

[0024] Repeat the following steps to generate N vertical matching matrices:

[0025] When A y When ≤N-1, the coordinates of point A are [A x [A] y The coordinates of point B are [B x [B] y Points A and B define a straight line. Points on this line are assigned a value of 1 in the baseline matching two-dimensional matrix, generating a vertical matching matrix.

[0026] Add the vertical matching matrix to the matching matrix queue, and restore all values ​​of 0 in the baseline matching two-dimensional matrix;

[0027] A y =A y +1, B y =B y +1.

[0028] Furthermore, the oblique matching rule is as follows:

[0029] Define A x Let A be the x-coordinate of point A. y Let A be the ordinate of point B. x Let B be the x-coordinate of point B. y Let A be the ordinate of point B. x =0, A y =1; B x =1, B y =0;

[0030] Repeat the following steps to generate Max(M,N) diagonal matching matrices:

[0031] When A x ! = B x &&A y ! = B y &&A x ≤M-1&&A y ≤N-1&&B x ≤M-1, the coordinates of point A are [A x [A] y The coordinates of point B are [Bx [B] y Points A and B define a straight line. Points on this line are assigned a value of 1 in the baseline matching two-dimensional matrix, generating a diagonal matching matrix.

[0032] Add the oblique matching matrix to the matching matrix queue, and restore all values ​​of 0 in the baseline matching two-dimensional matrix;

[0033] If(A y ==N-1){a X =A X +1}else{A y =A y +1};If(B x ==M-1){B y =B y +1}else{B x =B x +1}.

[0034] Furthermore, the reverse oblique matching rule is as follows:

[0035] Define A x Let A be the x-coordinate of point A. y Let A be the ordinate of point B. x Let B be the x-coordinate of point B. y Let A be the ordinate of point B. x =M-2,A y =0; B x =M-1,B y =1;

[0036] Repeat the following steps to generate Max(M,N) anti-diffraction matching matrices:

[0037] When A x !=B x &&A y ! = B y &&A x ≥0&&B x ≥0&&B y ≥N-1, the coordinates of point A are [A x [A] y The coordinates of point B are [B x [B] y Points A and B define a straight line. Points on this line are assigned a value of 1 in the baseline matching two-dimensional matrix, generating a reverse oblique matching matrix.

[0038] Add the reverse oblique matching matrix to the matching matrix queue, and restore all values ​​of 0 in the baseline matching two-dimensional matrix;

[0039] If(Ax == 0) { A y = A y + 1) else { A x = A x - 1); If (B y == N-1) { B x = B x - 1) else { B y = B y + 1).

[0040] Further, the step of point multiplying the text character two-dimensional matrix with the matching two-dimensional matrix comprises: multiplying positions with same row coordinates and column coordinates in the matching two-dimensional matrix and the text character two-dimensional matrix, when a value of a certain row and a certain column in the matching two-dimensional matrix is 0, then a coordinate position in the result matrix is an empty string; when the value of the certain row and the certain column in the matching two-dimensional matrix is 1, then the coordinate position in the result matrix is a character value of the position in the text character two-dimensional matrix.

[0041] To achieve the above object, the present application further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor is configured to execute the computer program stored in the memory to implement the text segmentation and sensitive word detection method based on matrix multiplication.

[0042] To achieve the above object, the present application further provides a computer readable storage medium, wherein the storage medium stores at least one instruction, and the instruction is loaded and executed by a processor to implement the text segmentation and sensitive word detection method based on matrix multiplication.

[0043] Compared with the prior art, the text segmentation and sensitive word detection method based on matrix multiplication provided by the present application has the following beneficial effects:

[0044] By splitting the to-be-detected text string information according to characters, a text character two-dimensional matrix is constructed, and a corresponding matching two-dimensional matrix is constructed, and the matching two-dimensional matrix is assigned with 1 at positions of text characters to be intercepted, after point multiplication processing of the text character two-dimensional matrix and the matching two-dimensional matrix, a text string containing interval text information is obtained, and then the sensitive word is matched by using a deterministic finite state automaton and a tree diagram, to determine whether the sensitive word exists in the to-be-detected text string, so that the method of the present application supports interval text string detection, and improves the detection accuracy and efficiency of sensitive words in text information.

[0045] Other features and advantages of the present application will be described in the following description, and become apparent from the description, or be learned from the practice of the present application. BRIEF DESCRIPTION OF DRAWINGS

[0046] The accompanying drawings are included to provide a further understanding of the present application, and are incorporated in and constitute a part of this specification, illustrate embodiments of the present application and serve to explain the principles of the present application, and should not be taken as limiting of the present application. In the drawings:

[0047] Figure 1 A flow chart of a text segmentation and sensitive word detection method based on matrix multiplication according to an embodiment of the present application;

[0048] Figure 2 A sensitive word DFA tree diagram according to an embodiment of the present application;

[0049] Figure 3 A text character two-dimensional matrix diagram according to an embodiment of the present application;

[0050] Figure 4 A vertical matching matrix diagram according to an embodiment of the present application;

[0051] Figure 5 A diagonal matching matrix diagram according to an embodiment of the present application;

[0052] Figure 6 A vertical result matrix diagram according to an embodiment of the present application;

[0053] Figure 7 A diagonal result matrix diagram according to an embodiment of the present application;

[0054] Figure 8 An electronic device structure diagram according to an embodiment of the present application. DETAILED DESCRIPTION

[0055] The preferred embodiments of the present application will be described herein below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are merely intended to illustrate and explain the present application, and should not be construed as limiting the present application. The preferred embodiments of the present application are provided for the purpose of more thoroughly and completely understanding the present application.

[0056] Embodiments of the present application will be described in more detail by referring to the accompanying drawings. Although certain embodiments of the present application are shown in the drawings, it should be understood that the present application can be implemented in various forms, and should not be construed as being limited to the embodiments set forth herein, but rather the embodiments are provided for a more thorough and complete understanding of the present application. It should be understood that the drawings and embodiments of the present application are for illustrative purposes only, and should not be construed as limiting the scope of the present application.

[0057] As used herein, the term "includes" and its variants are to be read as open-ended terms that mean "includes, but is not limited to." The term "based on" is to be cab interpreted as "based, at least in part, on." The term "one embodiment" does not preclude the existence of another embodiment. Likewise, the term "another embodiment" means "at least one other embodiment." The term "some embodiments" means "at least some embodiments." Related terms will be interpreted accordingly.

[0058] It should be noted that the terms "first", "second", and the like in the present application can be used to distinguish different apparatuses, components or parts, but not to limit the order or interdependence of the functions performed by these apparatuses, components or parts.

[0059] It should be noted that the modification of "one" or "multiple" mentioned in the present application is illustrative but not restrictive, and those skilled in the art should understand that "one or more" should be understood unless otherwise explicitly indicated in the context. "Multiple" should be understood as two or more.

[0060] In the following, embodiments of the present application will be described in detail with reference to the accompanying drawings.

[0061] Embodiment 1

[0062] In step 101, an original text string and a sensitive word library are acquired.

[0063] In the embodiments of the present application, the acquisition of the original text string to be detected can be through the input of the text string information by the user in the terminal, or the acquisition of the pre-stored text string information; the sensitive word library contains a plurality of preset sensitive words. In general, in the sensitive word detection technology, the sensitive word detection is performed on the text information to be detected based on the sensitive word library.

[0064] In step 102, a deterministic finite state automaton tree diagram of the sensitive word is constructed according to the sensitive word library.

[0065] The finite state automaton is a mathematical model of output output system, which has a finite number of internal states. The system can determine the next behavior of the system according to the current state and the input character faced, and the current state summarizes the information of the past input processing. The deterministic finite state machine (Deterministic Finite Automaton, DFA) is also called deterministic finite automaton. The next state is obtained through the past and current state. In the current DFA algorithm for implementing sensitive word filtering, DFA almost does not involve calculation, but only state conversion, which meets the demand of reducing operation, so DFA algorithm is a better implementation algorithm.

[0066] The sensitive word database contains many sensitive words. Generating a Descriptive Factorial (DFA) tree diagram from these words—essentially constructing the database as a tree with branches—significantly reduces the search scope when determining if a word is sensitive, thus improving detection efficiency. For example, the DFA tree diagram for the sensitive words "paper writing service" and "exam taking service" would look like this: Figure 2 As shown.

[0067] In step 103, the original text string is converted into a two-dimensional matrix of text characters, and the length of the two-dimensional matrix of text characters is recorded.

[0068] In this embodiment, the original text string is split according to characters to obtain multiple text strings, and these text strings are generated into a two-dimensional text character matrix. The one-dimensional length (vertical) of this two-dimensional text character matrix is ​​the number of rows of the corresponding string, and the two-dimensional length (horizontal) is the length of the longest row of the corresponding string. For example, the following text: "This is a bright day; is a good person. One by one, it becomes a substitute. Strip by strip, it becomes a test. Substitute for substitute. Test becomes test. Become becomes become advertisement." is split according to characters into text strings such as "This is a bright day;" and "is a good person.", and these strings are generated into a two-dimensional text character matrix, such as... Figure 3 As shown. The first dimension of this two-dimensional matrix of text characters has a length of 8, and the second dimension has a length of 9. These two length values ​​are recorded for later use in constructing a matching two-dimensional matrix with the same length as the text character matrix.

[0069] In step 104, a two-dimensional matching matrix is ​​constructed according to the horizontal matching rule, the vertical matching rule, and the diagonal matching rule. The length of the two-dimensional matching matrix is ​​the same as the length of the two-dimensional text character matrix.

[0070] In this embodiment of the application, a set of matching two-dimensional matrices is constructed according to the length of the two-dimensional matrix of text characters, following horizontal matching rules, vertical matching rules, diagonal matching rules, and anti-diagonal matching rules. The one-dimensional length of each matching two-dimensional matrix is ​​equal to the one-dimensional length of the two-dimensional matrix of text characters, and the two-dimensional length of the matching two-dimensional matrix is ​​equal to the two-dimensional length of the two-dimensional matrix of text characters. The position of the text character to be extracted in the matching two-dimensional matrix is ​​assigned a value of 1.

[0071] Specifically, let the length of the first dimension of the above two-dimensional matrix of text characters be M, and the length of the second dimension be N.

[0072] First, construct a baseline matching two-dimensional matrix with a one-dimensional length of M and a two-dimensional length of N, and initialize all values ​​in the baseline matching two-dimensional matrix to 0; in addition, define a two-dimensional matching matrix queue to store all generated two-dimensional matching matrices.

[0073] The process for generating the horizontal matching matrix is ​​as follows:

[0074] Define A x Let A be the x-coordinate of point A. y Let A be the ordinate of point B. x Let B be the x-coordinate of point B. y Let A be the ordinate of point B. Initialize A. x =0, A y =0; B x =0, B y =N-1;

[0075] Repeat the following steps to generate M horizontal matching matrices:

[0076] When A x When M ≤ M-1, the coordinates of point A are [A x [A] y The coordinates of point B are [B x [B] y Points A and B define a straight line. Points on this line are assigned a value of 1 in the baseline matching two-dimensional matrix, generating a horizontal matching matrix.

[0077] Add the generated horizontal matching matrix to the matching matrix queue, and restore all values ​​of 0 in the baseline matching two-dimensional matrix;

[0078] A x =A x +1, B x =B x +1.

[0079] The process for generating the vertical matching matrix is ​​as follows:

[0080] Define A x Let A be the x-coordinate of point A. y Let A be the ordinate of point B. x Let B be the x-coordinate of point B. y Let A be the ordinate of point B. Initialize A. x =0, A y =0; B x =M-1,B y =0;

[0081] Repeat the following steps to generate N vertical matching matrices:

[0082] When A y When ≤N-1, the coordinates of point A are [Ax [A] y The coordinates of point B are [B x [B] y Points A and B define a straight line. Points on this line are assigned a value of 1 in the baseline matching two-dimensional matrix, generating a vertical matching matrix.

[0083] Add the generated vertical matching matrix to the matching matrix queue, and restore all values ​​of 0 in the baseline matching two-dimensional matrix;

[0084] A y =A y +1, B y =B y +1.

[0085] The process for generating the oblique matching matrix is ​​as follows:

[0086] Define A x Let A be the x-coordinate of point A. y Let A be the ordinate of point B. x Let B be the x-coordinate of point B. y Let A be the ordinate of point B. Initialize A. x =0, A y =1; B x =1, B y =0;

[0087] Repeating the following steps will generate Max(M,N) diagonal matching matrices:

[0088] When A x ! = B x &&Ay! =B y &&A x ≤M-1&&A y ≤N-1&&B x ≤M-1, the coordinates of point A are [A x [A] y The coordinates of point B are [B x [B] y Points A and B define a straight line. Points on this line are assigned a value of 1 in the baseline matching two-dimensional matrix, generating a diagonal matching matrix.

[0089] Add the generated diagonal matching matrix to the matching matrix queue, and restore all values ​​of 0 in the baseline matching two-dimensional matrix;

[0090] If(A y ==N-1){A x =A x +1}else{A y =A y +1};If(Bx ==M-1){B y =B y 1}else{B x =B x +1}。

[0091] The generation process of the anti-oblique matching matrix is as follows:

[0092] Define A x as the horizontal coordinate of point A, A y as the vertical coordinate of point A, B x as the horizontal coordinate of point B, B y as the vertical coordinate of point B. Initialize A x =M-2, A y =0; B x =M-1, B y =1;

[0093] Repeat the following steps to generate Max(M, N) anti-oblique matching matrices.

[0094] When A x ! = B x && A y ! = B y && A x ≥ 0 && B x ≥ 0 && B y ≥ N-1, the coordinates of point A are [A x ][A y ], and the coordinates of point B are [B x ][B y ], and the two points A and B confirm a straight line, the content of the point on the straight line in the reference matching two-dimensional matrix is assigned as 1, and an anti-oblique matching matrix is generated;

[0095] Add the generated matching matrix to the matching matrix queue, and restore all values to 0 in the reference matching two-dimensional matrix;

[0096] If(A x == 0){A y = A y + 1} else{A x = A x - 1}; If(B y == N-1){B x = B x - 1} else{B y = B y + 1}.

[0097] In the embodiment of the application, the matching two-dimensional matrix is constructed according to the above rules for the one-dimensional text character two-dimensional matrix with a length of 8 and the two-dimensional text character two-dimensional matrix with a length of 9, and a generated vertical matching matrix is as followsFigure 4 As shown, a generated diagonal matching matrix is as shown in Figure 5 .

[0098] It is easy to see that when the one-dimensional length of the two-dimensional matrix of text characters is 1 or the two-dimensional length is 1, then the diagonal matching matrix and the anti-diagonal matching matrix do not need to be constructed.

[0099] In step 105, the two-dimensional matrix of text characters is dot-multiplied with the matching two-dimensional matrix to obtain a corresponding result matrix.

[0100] The dot-multiplication algorithm rule is:

[0101] The positions of the same row coordinates and column coordinates in the matching two-dimensional matrix and the two-dimensional matrix of text characters are multiplied, if the value of a certain row and a certain column of the matching two-dimensional matrix is 0, then the coordinate position in the result matrix is assigned as an empty string; if the value of a certain row and a certain column of the matching two-dimensional matrix is 1, then the coordinate position in the result matrix is assigned as the character value of the position in the two-dimensional matrix of text characters. For example, the above-mentioned vertical matching two-dimensional matrix (see Figure 4 ), diagonal matching matrix (see Figure 5 ) are respectively dot-multiplied with the two-dimensional matrix of text characters (see Figure 2 ) to obtain the vertical result matrix as shown in Figure 6 and the diagonal result matrix as shown in Figure 7 .

[0102] The two-dimensional matrix of text characters is dot-multiplied with the corresponding matching two-dimensional matrix, the purpose is to intercept the text character content of a certain part of the two-dimensional matrix of text characters through the matching two-dimensional matrix, the intercepted text character content includes continuous, interval, or contains non-text symbol text string. For example, through the dot-multiplication of the horizontal matching matrix and the two-dimensional matrix of text characters, the continuous text string is intercepted; and through the dot-multiplication of the vertical matching matrix, the diagonal matching matrix or the anti-diagonal matching matrix and the two-dimensional matrix of text characters, the discontinuous text character content is intercepted. Therefore, when the sensitive word matching detection is performed on the text string in the subsequent, even if the interval sensitive word, it can also be detected.

[0103] In step 106, the corresponding matching text string is generated according to the result matrix, and is matched with the determined finite state automaton tree diagram of the sensitive word to judge whether there is a sensitive word.

[0104] In the embodiment of the present application, the text characters in the above longitudinal result matrix and oblique result matrix are respectively generated into matching text strings, that is, "this is a make-up test" and "this is a make-up advertisement" are obtained, and then are matched with the deterministic finite automaton tree diagram of sensitive words, so that the sensitive words "make-up" and "make-up" in the text string can be detected in the case that the sensitive word library includes "make-up" or "make-up".

[0105] In the embodiment of the present application, the text characters in the above longitudinal result matrix and oblique result matrix are respectively generated into matching text strings, that is, "this is a make-up test" and "this is a make-up advertisement" are obtained, and then are matched with the deterministic finite automaton tree diagram of sensitive words, so that the sensitive words "make-up" and "make-up" in the text string can be detected in the case that the sensitive word library includes "make-up" or "make-up".

[0106] Embodiment 2

[0107] In the embodiment of the present application, an electronic device is further provided, Figure 8 As shown in the structural schematic diagram of the electronic device according to the embodiment of the present application, Figure 8 The electronic device according to the embodiment of the present application includes a processor 201 and a memory 202, wherein,

[0108] The memory 202 stores a computer program, and the computer program, when read and executed by the processor 201, performs the steps in the above-mentioned text segmentation and sensitive word detection method based on matrix multiplication.

[0109] Embodiment 3

[0110] In the embodiment of the present application, a computer readable storage medium is further provided, and the computer readable storage medium stores a computer program, wherein the computer program is set to execute the steps in the above-mentioned text segmentation and sensitive word detection method based on matrix multiplication when running.

[0111] In the embodiment, the above-mentioned computer readable storage medium can include but is not limited to: a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store computer programs.

[0112] Those skilled in the art can understand that the above are only the preferred embodiments of the present application, and are not used to limit the present application, and although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions recorded in the foregoing embodiments, or make equivalent replacements to some of the technical features. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A method for text segmentation and sensitive word detection based on matrix multiplication, comprising the following steps: obtaining an original text string and a sensitive word library; constructing a deterministic finite automaton tree diagram of sensitive words according to the sensitive word library; converting the original text string into a two-dimensional matrix of text characters and recording the length of the two-dimensional matrix of text characters; constructing a matching two-dimensional matrix with the same dimension as the two-dimensional matrix of text characters according to a horizontal matching rule, a vertical matching rule, a diagonal matching rule and an anti-diagonal matching rule; in the matching two-dimensional matrix, the element value of the position of the text character to be intercepted is 1, and the element value of the other positions is 0; performing dot multiplication processing on the two-dimensional matrix of text characters and the matching two-dimensional matrix to obtain a corresponding result matrix; generating a corresponding matching text string according to the result matrix, and matching the deterministic finite automaton tree diagram to determine whether there is a sensitive word; the step of performing dot multiplication processing on the two-dimensional matrix of text characters and the matching two-dimensional matrix comprises multiplying the positions with the same row and column coordinates in the matching two-dimensional matrix and the two-dimensional matrix of text characters; when the value of a certain row and column in the matching two-dimensional matrix is 0, the coordinate position in the result matrix is an empty character; when the value of a certain row and column in the matching two-dimensional matrix is 1, the coordinate position in the result matrix is the character value of the position in the two-dimensional matrix of text characters. 2.The method of claim 1, wherein, the step of converting the original text string into a two-dimensional matrix of text characters comprises splitting the text string by characters to obtain multiple groups of text strings and constructing a two-dimensional matrix of text characters; the one-dimensional length of the two-dimensional matrix of text characters is the number of rows of the string, and the two-dimensional length is the length of the longest row of string in the string. 3.The method of claim 1, wherein, the step of constructing a matching two-dimensional matrix according to a horizontal matching rule, a vertical matching rule, a diagonal matching rule and an anti-diagonal matching rule further comprises: constructing a reference matching two-dimensional matrix with a one-dimensional length of M and a two-dimensional length of N, and initializing the values in the array to 0, wherein M and N are the one-dimensional length and the two-dimensional length of the two-dimensional matrix of text characters, respectively; defining a two-dimensional matching matrix queue for storing all generated matching two-dimensional matrices.

4. The matrix multiplication based text segmentation and sensitive word detection method according to claim 3, characterized in that, the horizontal matching rule is: Definitions is the x-coordinate of point A, is the y-coordinate of point A, is the x-coordinate of point B, is the y-coordinate of point B; initialization , , , ; repeating the following steps to generate M horizontal matching matrices: When , the coordinates of point A are , the coordinates of point B are , and points on the straight line passing through points A and B are assigned a value of 1 in the content of the reference matching two-dimensional matrix to generate a horizontal matching matrix. adding the horizontal matching matrix to the matching matrix queue, and restoring all values to 0 in the reference matching two-dimensional matrix; , 。 5.The method of claim 3, wherein, the vertical matching rule is: Definitions is the x-coordinate of point A, is the y-coordinate of point A, is the x-coordinate of point B, is the y-coordinate of point B, initialize , ; , ; repeating the following steps to generate N vertical matching matrices: When , the coordinates of point A are , the coordinates of point B are , and points on the straight line passing through points A and B are assigned a value of 1 in the content of the reference matching two-dimensional matrix to generate a vertical matching matrix. adding the vertical matching matrix to the matching matrix queue, and restoring all values to 0 in the reference matching two-dimensional matrix; , 。 6.The method of claim 3, wherein, the diagonal matching rule is: Definitions is the x-coordinate of point A, is the y-coordinate of point A, is the x-coordinate of point B, is the y-coordinate of point B, initialize , ; , ; repeating the following steps to generate Max(M, N) diagonal matching matrices: When , the coordinates of point A are , the coordinates of point B are , points on a straight line determined by points A and B are assigned a value of 1 according to the content of the reference matching two-dimensional matrix, and a diagonal matching matrix is generated; adding the diagonal matching matrix to the matching matrix queue, and restoring all values to 0 in the reference matching two-dimensional matrix; else ; else . 7.The method of claim 3, wherein, the anti-diagonal matching rule is: Definitions is the x-coordinate of point A, is the y-coordinate of point A, is the x-coordinate of point B, is the y-coordinate of point B, initialize , ; , ; repeating the following steps to generate Max(M, N) anti-diagonal matching matrices: When , the coordinates of point A are , the coordinates of point B are , points on a straight line passing through points A and B are assigned a value of 1 in the content of the reference matching two-dimensional matrix, and a matching matrix in an inverse oblique direction is generated. adding the anti-diagonal matching matrix to the matching matrix queue, and restoring all values to 0 in the reference matching two-dimensional matrix; else ; else .

8. An electronic device comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, characterized in that, The processor is configured to execute a computer program stored in the memory, and implement the matrix multiplication based text segmentation and sensitive word detection method in any one of claims 1-7.

9. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction, which is loaded and executed by the processor to implement the matrix multiplication based text segmentation and sensitive word detection method in any one of claims 1-7.

Citation Information

Patent Citations

  • Sensitive word detection filtering method and device and electronic equipment

    CN110457428A

  • Sensitive word filtering method based on DFA algorithm and system thereof

    CN113157904A