Sensitive word recognition method, system and computer readable storage medium
1. A sensitive word recognition method is applied to a word stock retrieval server, and comprises the following steps:
when a text to be identified is received, sending a data access request to a distributed cache server, wherein the data access request comprises a main key, and when the distributed cache server receives the data access request, acquiring a search tree corresponding to the main key from a cache node corresponding to the distributed cache server, and sending the search tree to the word stock retrieval server;
receiving the search tree corresponding to the primary key returned by the distributed cache server;
and determining a matching result of the text to be recognized and the search tree based on an AC automata algorithm, and determining sensitive words in the text to be recognized according to the matching result.
2. The sensitive word recognition method of claim 1, wherein the step of sending a data access request to a distributed cache server upon receiving the text to be recognized further comprises:
acquiring a sensitive word bank stored in a database, and establishing a search tree corresponding to the sensitive word bank based on an AC (automatic control) automaton algorithm according to the sensitive word bank;
synchronizing the search tree into the distributed cache servers for the distributed cache servers to store the search tree in corresponding cache nodes.
3. The sensitive word recognition method of claim 2, wherein the step of synchronizing the search tree into the distributed cache server comprises:
acquiring the relation information of each node corresponding to the search tree;
and synchronizing each node and the relationship information to the distributed cache server in a key-value pair mode, so that the distributed cache server generates the search tree according to each node and the relationship information and stores the search tree.
4. The sensitive word recognition method of claim 1, wherein the step of receiving the search tree corresponding to the primary key returned by the distributed cache server is preceded by:
monitoring sensitive word bank updating information, wherein the sensitive word bank updating information comprises sensitive words to be updated;
updating the sensitive word stock according to the sensitive word stock updating information to obtain an updated sensitive word stock and storing the updated sensitive word stock in a database;
and sending the sensitive word to be updated to the distributed cache server, so that the distributed cache server updates the search tree according to the sensitive word to be updated.
5. The sensitive word recognition method of claim 1, wherein the step of determining a matching result of the text to be recognized and the search tree based on an AC automaton algorithm, and determining the sensitive word in the text to be recognized according to the matching result comprises:
matching each character corresponding to the text to be recognized with each node of the search tree;
acquiring at least one sensitive word completely matched with the text to be recognized and the search tree;
and determining the sensitive words in the text to be recognized according to the matching result and the sensitive words serving as the matching result.
6. A sensitive word recognition method is applied to a distributed cache server, and the sensitive word recognition method further comprises the following steps:
when a data access request sent by the word stock retrieval server is received, searching a cache node corresponding to a main key according to the main key corresponding to the data access request;
obtaining a search tree stored in the cache node;
and returning the search tree to the word stock retrieval server so that the word stock retrieval server determines a matching result of the text to be recognized and the search tree based on an AC automaton algorithm, and determining sensitive words in the text to be recognized according to the matching result.
7. The sensitive word recognition method according to claim 6, wherein before the step of searching for the cache node corresponding to the primary key according to the primary key corresponding to the data access request when receiving the data access request sent by the thesaurus retrieval server, the method further comprises:
receiving the corresponding relation information of each node and each node of the search tree sent by the word stock retrieval server;
generating a corresponding search tree according to the corresponding relation information of each node and each node;
determining a cache node corresponding to the main key through a Hash algorithm according to the main key corresponding to the search tree;
caching the search tree in the cache node.
8. The sensitive word recognition method of claim 6, further comprising:
when receiving the sensitive words to be updated sent by the word stock retrieval server, acquiring a sequence to be updated according to the sensitive words to be updated;
and generating a new path in the search tree according to the sequence to be updated and inserting the new path into the search tree so as to update the search tree.
9. A sensitive word recognition system is characterized by comprising a word stock retrieval server, a database and a distributed cache server, wherein the database and the distributed cache server are connected with the word stock retrieval server, and the sensitive word recognition system comprises: memory, a processor and a sensitive word recognition program stored on the memory and executable on the processor, the sensitive word recognition program when executed by the processor implementing the steps of the sensitive word recognition method according to any one of claims 1 to 8.
10. A computer-readable storage medium, on which a sensitive word recognition program is stored, which when executed by a processor implements the steps of the sensitive word recognition method according to any one of claims 1 to 8.
Background
Along with the popularization of the internet, the information transmission speed is high, the range is wide, the influence is large, sensitive information inevitably appears in the information transmission process, and the adverse social influence is brought. In the prior art, sensitive words in information to be propagated are matched, searched and replaced through a sensitive word bank, but the sensitive word bank adopted in the prior art is stored in a hard disk, and when the number of the sensitive words is large, the recognition speed is slow, so that the filtering effect on the sensitive words is poor.
Disclosure of Invention
The invention mainly aims to provide a sensitive word recognition method, a sensitive word recognition system and a computer readable storage medium, and aims to solve the problem that the recognition speed is slow when a sensitive word is recognized in the prior art.
In order to achieve the above object, the present invention provides a sensitive word recognition method, which is applied to a thesaurus search server, and the sensitive word recognition method comprises the steps of:
when a text to be identified is received, sending a data access request to a distributed cache server, wherein the data access request comprises a main key, and when the distributed cache server receives the data access request, acquiring a search tree corresponding to the main key from a cache node corresponding to the distributed cache server, and sending the search tree to the word stock retrieval server;
receiving the search tree corresponding to the primary key returned by the distributed cache server;
and determining a matching result of the text to be recognized and the search tree based on an AC automata algorithm, and determining sensitive words in the text to be recognized according to the matching result.
Optionally, before the step of sending a data access request to the distributed cache server when receiving the text to be recognized, the method further includes:
acquiring a sensitive word bank stored in a database, and establishing a search tree corresponding to the sensitive word bank based on an AC (automatic control) automaton algorithm according to the sensitive word bank;
synchronizing the search tree into the distributed cache servers for the distributed cache servers to store the search tree in corresponding cache nodes.
Optionally, the step of synchronizing the search tree into the distributed cache server includes:
acquiring the relation information of each node corresponding to the search tree;
and synchronizing each node and the relationship information to the distributed storage server in a key-value pair mode, so that the distributed storage server generates the search tree according to each node and the relationship information and stores the search tree.
Optionally, before the step of receiving the search tree corresponding to the primary key returned by the distributed cache server, the method further includes:
monitoring sensitive word bank updating information, wherein the sensitive word bank updating information comprises sensitive words to be updated;
updating the sensitive word stock according to the sensitive word stock updating information to obtain an updated sensitive word stock and storing the updated sensitive word stock in a database;
and sending the sensitive word to be updated to the distributed cache server, so that the distributed cache server updates the search tree according to the sensitive word to be updated.
Optionally, the step of determining a matching result of the text to be recognized and the search tree based on the AC automata algorithm, and determining the sensitive word in the text to be recognized according to the matching result includes:
matching each character corresponding to the text to be recognized with each node of the search tree;
acquiring at least one sensitive word completely matched with the text to be recognized and the search tree;
and determining the sensitive words in the text to be recognized according to the matching result and the sensitive words serving as the matching result.
A sensitive word recognition method is applied to a distributed cache server, and comprises the following steps:
when a data access request sent by the word stock retrieval server is received, searching a cache node corresponding to a main key according to the main key corresponding to the data access request;
obtaining a search tree stored in the cache node;
and returning the search tree to the word stock retrieval server so that the word stock retrieval server determines a matching result of the text to be recognized and the search tree based on an AC automaton algorithm, and determining sensitive words in the text to be recognized according to the matching result.
Optionally, before the step of searching for the cache node corresponding to the primary key according to the primary key corresponding to the data access request when receiving the data access request sent by the thesaurus retrieval server, the method further includes:
receiving the corresponding relation information of each node and each node of the search tree sent by the word stock retrieval server;
generating a corresponding search tree according to the corresponding relation information of each node and each node;
determining a cache node corresponding to the main key through a Hash algorithm according to the main key corresponding to the search tree;
caching the search tree in the cache node.
Optionally, the sensitive word recognition method further includes:
when receiving the sensitive words to be updated sent by the word stock retrieval server, acquiring a sequence to be updated according to the sensitive words to be updated;
and generating a new path in the search tree according to the sequence to be updated and inserting the new path into the search tree so as to update the search tree.
In addition, to achieve the above object, the present invention further provides a sensitive word recognition system, where the sensitive word recognition system includes a word stock search server, a database, and a distributed cache server, and the sensitive word recognition system includes: a memory, a processor and a sensitive word recognition program stored on the memory and executable on the processor, the sensitive word recognition program when executed by the processor implementing the steps of the sensitive word recognition method as described above.
In addition, to achieve the above object, the present invention also provides a computer-readable storage medium storing a sensitive word recognition program, which when executed by a processor, implements the steps of the sensitive word recognition method as described above.
According to the sensitive word identification method, the sensitive word identification system and the computer readable storage medium, the word stock retrieval server acquires the sensitive word stock stored in the database, further constructs a search tree corresponding to the sensitive word stock based on an AC (alternating current) automaton algorithm, and synchronizes the search tree to the distributed cache server so that the distributed cache server can be located in a corresponding cache node. The word stock retrieval server sends a data access request to the distributed cache server to acquire a corresponding search tree when receiving a text to be recognized, and then determines a sensitive word in the text to be recognized according to a matching result of the search tree and the text to be recognized and the matching result, so that the database is prevented from being accessed and queried, the pressure of the database is reduced, the access speed is higher by accessing the distributed cache access server, and the recognition speed of the sensitive word recognition is further improved.
Drawings
FIG. 1 is a schematic diagram of a terminal \ structure of a hardware operating environment according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a sensitive word recognition method according to a first embodiment of the present invention;
FIG. 3 is a diagram illustrating a search tree according to a first embodiment of the sensitive word recognition method of the present invention;
fig. 4 is a flowchart illustrating a sensitive word recognition method according to a second embodiment of the present invention.
FIG. 5 is a flowchart illustrating a sensitive word recognition method according to a third embodiment of the present invention;
FIG. 6 is a flowchart illustrating a sensitive word recognition method according to a fourth embodiment of the present invention;
fig. 7 is a flowchart illustrating a sensitive word recognition method according to a fifth embodiment of the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The main solution of the embodiment of the invention is as follows: when a text to be identified is received, sending a data access request to a distributed cache server, wherein the data access request comprises a main key, and when the distributed cache server receives the data access request, acquiring a search tree corresponding to the main key from a cache node corresponding to the distributed cache server, and sending the search tree to the word stock retrieval server; receiving the search tree corresponding to the primary key returned by the distributed cache server; and determining a matching result of the text to be recognized and the search tree based on an AC automata algorithm, and determining sensitive words in the text to be recognized according to the matching result.
As shown in fig. 1, fig. 1 is a schematic terminal structure diagram of a hardware operating environment according to an embodiment of the present invention.
The sensitive word recognition method related by the embodiment of the invention is mainly applied to the terminal, and the terminal can be equipment with processing function, such as a PC, a portable computer, a mobile terminal and the like.
As shown in fig. 1, the terminal may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001.
Optionally, the terminal may further include a camera, a Radio Frequency (RF) circuit, a sensor, an audio circuit, a WiFi module, and the like. Such as light sensors, motion sensors, and other sensors. Specifically, the light sensor may include an ambient light sensor that may adjust the brightness of the display screen according to the brightness of ambient light, and a proximity sensor that may turn off the display screen and/or the backlight when the mobile terminal is moved to the ear. As one of the motion sensors, the gravity acceleration sensor can detect the magnitude of acceleration in each direction (generally, three axes), detect the magnitude and direction of gravity when the mobile terminal is stationary, and can be used for applications (such as horizontal and vertical screen switching, related games, magnetometer attitude calibration), vibration recognition related functions (such as pedometer and tapping) and the like for recognizing the attitude of the mobile terminal; of course, the mobile terminal may also be configured with other sensors such as a gyroscope, a barometer, a hygrometer, a thermometer, and an infrared sensor, which are not described herein again.
Those skilled in the art will appreciate that the terminal structure shown in fig. 1 is not intended to be limiting and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a kind of computer storage medium, may include therein an operating system, a network communication module, a user interface module, and a sensitive word recognition program.
In the terminal shown in fig. 1, the network interface 1004 is mainly used for connecting to a backend server and performing data communication with the backend server; the user interface 1003 is mainly used for connecting a client (user side) and performing data communication with the client; and the processor 1001 may be configured to invoke the sensitive word recognition program stored in the memory 1005 and perform the following operations:
when a text to be identified is received, sending a data access request to a distributed cache server, wherein the data access request comprises a main key, and when the distributed cache server receives the data access request, acquiring a search tree corresponding to the main key from a cache node corresponding to the distributed cache server, and sending the search tree to the word stock retrieval server;
receiving the search tree corresponding to the primary key returned by the distributed cache server;
and determining a matching result of the text to be recognized and the search tree based on an AC automata algorithm, and determining sensitive words in the text to be recognized according to the matching result.
Further, the processor 1001 may call the sensitive word recognition program stored in the memory 1005, and also perform the following operations:
acquiring a sensitive word bank stored in a database, and establishing a search tree corresponding to the sensitive word bank based on an AC (automatic control) automaton algorithm according to the sensitive word bank;
synchronizing the search tree into the distributed cache servers for the distributed cache servers to store the search tree in corresponding cache nodes.
Further, the processor 1001 may call the sensitive word recognition program stored in the memory 1005, and also perform the following operations:
acquiring the relation information of each node corresponding to the search tree;
and synchronizing each node and the relationship information to the distributed cache server in a key-value pair mode, so that the distributed cache server generates the search tree according to each node and the relationship information and stores the search tree.
Further, the processor 1001 may call the sensitive word recognition program stored in the memory 1005, and also perform the following operations:
monitoring sensitive word bank updating information, wherein the sensitive word bank updating information comprises sensitive words to be updated;
updating the sensitive word stock according to the sensitive word stock updating information to obtain an updated sensitive word stock and storing the updated sensitive word stock in a database;
and sending the sensitive word to be updated to the distributed cache server, so that the distributed cache server updates the search tree according to the sensitive word to be updated.
Further, the processor 1001 may call the sensitive word recognition program stored in the memory 1005, and also perform the following operations:
matching each character corresponding to the text to be recognized with each node of the search tree;
acquiring at least one sensitive word completely matched with the text to be recognized and the search tree;
and determining the sensitive words in the text to be recognized according to the matching result and the sensitive words serving as the matching result.
Further, the processor 1001 may call the sensitive word recognition program stored in the memory 1005, and also perform the following operations:
when a data access request sent by the word stock retrieval server is received, searching a cache node corresponding to a main key according to the main key corresponding to the data access request;
obtaining a search tree stored in the cache node;
and returning the search tree to the word stock retrieval server so that the word stock retrieval server determines a matching result of the text to be recognized and the search tree based on an AC automaton algorithm, and determining sensitive words in the text to be recognized according to the matching result.
Further, the processor 1001 may call the sensitive word recognition program stored in the memory 1005, and also perform the following operations:
receiving the corresponding relation information of each node and each node of the search tree sent by the word stock retrieval server;
generating a corresponding search tree according to the corresponding relation information of each node and each node;
determining a cache node corresponding to the main key through a Hash algorithm according to the main key corresponding to the search tree;
caching the search tree in the cache node.
Further, the processor 1001 may call the sensitive word recognition program stored in the memory 1005, and also perform the following operations:
when receiving the sensitive words to be updated sent by the word stock retrieval server, acquiring a sequence to be updated according to the sensitive words to be updated;
and generating a new path in the search tree according to the sequence to be updated and inserting the new path into the search tree so as to update the search tree.
In the prior art, when sensitive word recognition is performed, a sensitive word lexicon stored in a database is obtained by accessing the database, and when the data volume corresponding to the sensitive word lexicon is large, the sensitive word recognition speed is slow because the sensitive word lexicon is stored in a hard disk based on the database and the access speed is too slow.
Referring to fig. 2, a first embodiment of the sensitive word recognition method according to the present invention provides a sensitive word recognition method, including:
step S10, when receiving a text to be identified, sending a data access request to a distributed cache server, wherein the data access request comprises a primary key, and when receiving the data access request, the distributed cache server acquires a search tree corresponding to the primary key from a cache node corresponding to the distributed cache server and sends the search tree to the thesaurus retrieval server;
step S20, receiving the search tree corresponding to the primary key returned by the distributed cache server;
and step S30, determining the matching result of the text to be recognized and the search tree based on an AC automaton algorithm, and determining the sensitive words in the text to be recognized according to the matching result.
In this application embodiment, be applied to the thesaurus search server among the sensitive word recognition system, the sensitive word recognition system includes thesaurus search server and with database and distributed cache server that thesaurus search server connects, wherein, the database is mysql database, distributed cache service is redis cache server, redis cache server includes the redis cluster, the redis cluster includes at least one buffer node, distributed cache server establishes based on the memory, and the access speed based on the memory is greater than the access speed of hard disk far away, and based on this, when this application embodiment need obtain corresponding search tree, direct access distributed cache server reads the efficiency that the search tree corresponds and is greater than direct access far away the efficiency of data reading database.
Optionally, the mysql database stores a sensitive word bank, where the sensitive word bank includes a plurality of sensitive words, and the sensitive word bank adds sensitive words in the sensitive word bank, deletes the sensitive words, or modifies existing sensitive words in the sensitive word bank based on system configuration personnel.
Optionally, in order to avoid the sensitive word recognition process, in the embodiment of the present application, when the sensitive word stock is cached in the memory corresponding to the cache node of the distributed cache server, the sensitive word stock in the distributed cache server may be directly accessed in the subsequent sensitive word recognition. Optionally, when the sensitive word bank is cached in the memory corresponding to the distributed cache server, in order to improve the efficiency of sensitive word recognition, in the embodiment of the present application, the sensitive word bank stored in the mysql database is used to construct a corresponding search tree, and the search tree is further cached in the memory corresponding to the distributed cache server. Based on this, the step S10 is preceded by:
acquiring a sensitive word library stored in a database, and establishing a search tree corresponding to the sensitive word library based on an AC (automatic control) automaton algorithm according to the sensitive word library;
synchronizing the search tree into the distributed cache servers for the distributed cache servers to store the search tree in corresponding cache nodes.
Optionally, the word stock retrieval server receives the sensitive word stock stored in the mysql database, and then constructs a corresponding search tree according to the sensitive word stock.
Optionally, the method for establishing the corresponding search tree according to the sensitive word thesaurus includes establishing the search tree corresponding to the sensitive word thesaurus based on an AC automaton algorithm. In a specific implementation process, each sensitive word stored in the sensitive word thesaurus is obtained, a corresponding Trie tree is constructed based on each sensitive word, and then a corresponding failure pointer is constructed based on each node in the Trie tree, wherein the failure pointer is used for continuing downward matching according to a failure node corresponding to a current matching node when matching of the current matching node fails, and then the establishment of the search tree is completed according to the Trie tree and each failure pointer.
Optionally, after the establishment of the search tree is completed, the search tree is cached in a cache node corresponding to the distributed cache server. The distributed cache server is established based on a redis cluster, wherein the redis cluster comprises at least one cache node. Said step of synchronizing said search tree to said distribution cache server comprises:
acquiring the relation information of each node corresponding to the search tree;
and synchronizing each node and the relationship information to the distributed storage server in a key-value pair mode, so that the distributed storage server generates the search tree according to each node and the relationship information and stores the search tree.
In a specific implementation process, relationship information of each node corresponding to the search tree is obtained, the relationship information includes a parent node corresponding to each node, and then each node and the relationship information are synchronized into the distributed cache server in a key-value pair (key-value) manner. The key value pair includes a key value, the key value is used for marking the search tree, and the key value may be configured by a user, for example, the key value corresponding to the search tree is minganci. In addition, the key-value pair includes a vulue value whose data structure is an unordered set. The unordered set comprises the relationship information of each node. For example, the relationship information of one node in the unordered set corresponding to the node is { parent: root, value: red, the nodes are red, and the corresponding relationship information of the nodes is as follows: the parent node root and the child node are red. The distributed cache server receives the key value and the value, obtains a hash value corresponding to the key value based on a hash algorithm, determines a cache node corresponding to the key value according to the hash value, and caches the key value and the value in a memory corresponding to the cache node.
Optionally, after caching the key value and the value in a memory corresponding to the cache node, the distributed cache server generates a corresponding search tree based on an AC automaton algorithm according to relationship information between each node corresponding to the value and each node, and then caches the search tree in the cache node corresponding to the key value. It is understood that the search tree cached in the distributed cache server is the same as the search tree established by the thesaurus retrieval server based on the sensitive word thesaurus.
Optionally, after the search tree is synchronized to the distributed cache server, when a sensitive word recognition operation is subsequently performed, the distributed cache server may be directly accessed to obtain a corresponding search tree. In an actual operation process, after receiving a text to be identified, the thesaurus retrieval server sends a data access request to the distributed cache server, wherein the data access request comprises a main key, the main key is equivalent to a corresponding key value, so that when the distributed cache server receives the main key, the cache node corresponding to the main key is inquired in each cache node of the distributed cache server according to the main key, after the corresponding cache node is inquired, a corresponding search tree is obtained according to the main key, and then the search tree is returned to the thesaurus retrieval server.
Optionally, after receiving the search tree returned by the distributed cache server, the thesaurus retrieval server determines a matching result between the text to be recognized and the search tree based on an AC automaton algorithm.
Optionally, the step of determining a matching result of the text to be recognized and the search tree based on the AC automata algorithm includes:
matching each character corresponding to the text to be recognized with each node of the search tree;
acquiring at least one sensitive word completely matched with the text to be recognized and the search tree;
and determining the sensitive words in the text to be recognized according to the matching result and the sensitive words serving as the matching result.
Optionally, the text to be recognized is composed of a plurality of chinese characters and/or english characters, for example, the text to be recognized is "fast coming to rush to red packet", and the characters are "fast", "coming", "rush", "red", and "packet", respectively.
And after each corresponding character is obtained, matching is carried out according to each character and each node of the search tree, and at least one sensitive word of the text to be recognized and the search tree which are completely matched is further obtained. Referring to fig. 3, fig. 3 is one embodiment of the search tree, and the sensitive word based on the complete matching of the text to be recognized and the search tree is "rushing to red envelope".
Optionally, after the at least one sensitive word completely matched with the search tree is obtained, the sensitive word is used as a matching result of a current sensitive word recognition operation, and the sensitive word in the text to be recognized is determined according to the matching result, for example, the matching result is "red packet robbing", and then the sensitive word in the text to be recognized is determined to be "red packet robbing".
In the embodiment of the application, after a text to be recognized is obtained, a data access request is sent to the distributed cache server according to the text to be recognized, the distributed cache server is built in a memory to obtain a corresponding search tree, a matching result of the text to be recognized and the search tree is determined based on an AC (alternating current) automaton algorithm, and then sensitive words in the text to be recognized are determined according to the matching result. The cache server is based on direct access distribution, and a database stored in a hard disk does not need to be accessed, so that the pressure of the database is reduced, and the efficiency of sensitive word recognition is improved.
Optionally, referring to fig. 4, based on the first embodiment, the present invention provides a second embodiment of the sensitive word recognition method, where before the step S20, the method further includes:
step S40, monitoring sensitive word bank updating information, wherein the sensitive word bank updating information comprises sensitive words to be updated;
step S41, updating the sensitive word stock according to the sensitive word stock update information to obtain an updated sensitive word stock and storing the updated sensitive word stock in a database;
step S42, sending the sensitive word to be updated to the distributed cache server, so that the distributed cache server updates the search tree according to the sensitive word to be updated.
Optionally, the sensitive word is updated in real time based on the service requirement, and based on this, in order to improve the recognition capability of the sensitive word recognition, the sensitive word bank also needs to be updated dynamically.
Optionally, in an embodiment of the present application, the thesaurus retrieval server monitors sensitive thesaurus update information within a preset time interval, where the sensitive thesaurus update information includes a sensitive word to be updated, and then updates the sensitive thesaurus stored in the database according to the sensitive word to be updated to obtain an updated sensitive thesaurus, where a manner of updating the sensitive thesaurus stored in the database may be to add a new sensitive word, to delete an original sensitive word, or to modify an original sensitive word.
Optionally, after the sensitive word lexicon is updated, the search tree stored in the database is updated according to the updated sensitive word lexicon, so as to obtain an updated search tree.
Optionally, when the search tree is updated, the sensitive word to be updated is sent to the distributed cache server according to the updated search tree, so that the distributed cache server updates the search tree cached in the distributed cache server according to the sensitive word to be updated.
And updating the search tree cached in the cache server according to the sensitive words to be updated in a mode of updating the search tree based on an AC automaton incremental algorithm.
In the embodiment of the application, the sensitive word bank is dynamically updated by monitoring the update information of the sensitive word bank and updating the update information of the sensitive word bank, the corresponding search tree is updated according to the sensitive words to be updated corresponding to the updated sensitive word bank, and the search tree cached in the distributed cache server is updated at the same time, so that the real-time update of the search tree is realized, the response speed of sensitive word identification based on the updated search tree is increased, and the identification capability of the sensitive word identification is improved.
Optionally, referring to fig. 5, the present invention provides a third embodiment of a sensitive word recognition method, where the third embodiment of the sensitive word recognition method is applied to a distributed cache server in a sensitive word recognition system, and the sensitive word recognition method includes:
step S50, when receiving a data access request sent by the thesaurus retrieval server, searching a cache node corresponding to a primary key according to the primary key corresponding to the data access request;
step S60, obtaining the search tree stored in the cache node;
step S70, the search tree is returned to the thesaurus retrieval server, so that the thesaurus retrieval server determines the matching result of the text to be recognized and the search tree based on an AC automaton algorithm, and determines the sensitive words in the text to be recognized according to the matching result.
In this embodiment of the present application, in a process of performing sensitive word recognition, the thesaurus retrieval server sends a data access request to the distributed cache server, and when the distributed cache server receives the data access request, the distributed cache server searches for a cache node corresponding to the primary key according to the primary key corresponding to the access request, where a specific implementation manner of searching for a cache node corresponding to the primary key according to the primary key is to calculate a hash value corresponding to the primary key based on a hash algorithm, and then determine a cache node corresponding to the hash value according to the hash value, and then determine the cache node corresponding to the hash value as a cache node corresponding to the primary key,
optionally, after the corresponding cache node is obtained, a search tree corresponding to the primary key is further obtained according to the primary key, where the primary key and the search tree are in a one-to-one correspondence relationship.
After the corresponding search tree is obtained, the search tree is sent to the word stock retrieval server, so that the word stock retrieval server determines a matching result of the text to be recognized and the search tree based on an AC automaton algorithm, and determines sensitive words in the text to be recognized according to the matching result.
In the embodiment of the application, after receiving a data access request, the distributed cache server queries a corresponding search tree according to the data access request, and then returns the search tree to the word stock retrieval server, so that the efficiency of acquiring the corresponding search tree is improved, and the efficiency of identifying sensitive words is improved.
Optionally, referring to fig. 6, based on the foregoing embodiment, before the step S50, the method further includes:
step S80, receiving the relation information of each node and each node of the search tree sent by the thesaurus retrieval server;
step S81, generating a corresponding search tree according to the relationship information corresponding to each node;
step S82, determining a cache node corresponding to the primary key through a hash algorithm according to the primary key corresponding to the search tree;
step S83, cache the search tree in the cache node.
In this embodiment of the present application, the thesaurus retrieval server establishes a corresponding search tree according to the sensitive word thesaurus, and in order to cache the search tree in the distributed cache server, the thesaurus retrieval server sends the relationship information corresponding to each node and each node corresponding to the search tree to the distributed cache server, so that the distributed cache server establishes the same search tree according to the relationship information corresponding to each node and each node, and further caches the search tree in the corresponding node.
It can be understood that, when the thesaurus retrieval server sends the relationship information corresponding to each node to the distributed cache server, the thesaurus retrieval server simultaneously sends the primary key corresponding to the search tree to the distributed cache server, and after receiving the primary key, the distributed cache server calculates the cache node corresponding to the primary key based on a hash algorithm, so as to cache the relationship information corresponding to each node in the cache node.
Optionally, after receiving the relationship information between each node and each node, establishing a search tree corresponding to the relationship information between each node and each node based on an AC automata algorithm, and further caching the search tree in the cache node corresponding to the primary key.
In the embodiment of the application, after the relationship information, corresponding to each node, of the search tree sent by the thesaurus retrieval server is received, the search tree identical to the search tree stored in the database is constructed according to the relationship information, corresponding to each node, of each node, and meanwhile, the cache node corresponding to the main key is determined through a hash algorithm according to the main key of the search tree stored in the database, so that the relationship information, corresponding to each node, of the search tree is stored in the cache node, the search tree is returned to the thesaurus retrieval server more quickly in the sensitive word identification process, and the sensitive word identification efficiency is improved.
Optionally, referring to fig. 7, the sensitive word recognition method further includes:
step S90, when receiving the sensitive words to be updated sent by the thesaurus retrieval server, obtaining the sequence to be updated according to the sensitive words to be updated;
step S91, generating a new path in the search tree according to the sequence to be updated, and inserting the new path into the search tree to update the search tree.
In the embodiment of the application, the sensitive words stored in the sensitive word bank can be dynamically updated, and after the sensitive word bank is updated, the corresponding sensitive words to be updated are sent to the distributed cache server, so that the distributed cache server updates the corresponding search tree according to the sensitive words to be updated.
The specific implementation manner of updating the corresponding search tree by the distributed cache server according to the sensitive word to be updated is to generate a corresponding sequence to be updated according to the sensitive word to be updated, for example, the sensitive word to be updated is "coming soon" and the sequence to be updated corresponding to the sensitive word to be updated is "coming soon-piecing".
Optionally, after the corresponding sequence to be updated is obtained, a new path is formed according to the sequence to be updated, and the path is inserted into the search tree to update the search tree.
Optionally, when the corresponding sequence to be updated is obtained, the corresponding path in the search tree may also be deleted according to the sequence to be updated.
Optionally, the manner of updating the search tree includes, but is not limited to, the above two manners.
In the embodiment of the application, the received sensitive words to be updated are used for updating the search trees cached in the distributed cache server in real time, so that the real-time updating efficiency of the search trees is improved, the sensitive words are identified according to the updated search trees in time in the sensitive word identification process, and the identification capability of the sensitive word identification is improved.
In addition, an embodiment of the present invention further provides a sensitive word recognition system, where the sensitive word recognition system includes a thesaurus search server, and a database and a distributed cache server connected to the thesaurus search server, and the sensitive word recognition includes: the system comprises a memory, a processor and a sensitive word recognition program stored on the memory and capable of running on the processor, wherein the sensitive word recognition program realizes the steps of the sensitive word recognition method of the various embodiments as described above when being executed by the processor.
In addition, an embodiment of the present invention further provides a computer-readable storage medium, where a sensitive word recognition program is stored on the computer-readable storage medium, and when being executed by a processor, the sensitive word recognition program implements the steps of the sensitive word recognition method of each of the embodiments described below.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.
- 上一篇:石墨接头机器人自动装卡簧、装栓机
- 下一篇:基于人工智能的图文内容质量识别方法和装置