Text segmentation method, device, computer equipment and storage medium
Through a finite state machine, the sentence cutting process is processed based on text character attribute information, and the problem of insufficient flexibility in cutting sentences based on punctuation marks in the prior art is solved, and flexible sentence cutting for complex texts is realized, which improves the accuracy of natural language processing and efficiency.
Patent Information
- Application Number
- CN202011185970.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-30
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2040-10-30
AI Technical Summary
The existing text sentence cutting method is based on punctuation and sentence cutting, and cannot effectively process complex texts, especially continuous punctuation and complex semantics in Chinese, resulting in inflexible sentence cutting and affecting the accuracy of natural language processing tasks.
The text sentence cutting method based on the finite state machine is adopted, and the sentence cutting state machine performs sentence cutting processing based on the attribute information of text characters and state transfer conditions, supporting flexible sentence cutting of multiple language scenarios and complex texts.
It realizes flexible sentence cutting for complex texts, improves the accuracy and adaptability of natural language processing tasks, reduces the cost of sentence cutting for different texts, and improves work efficiency.
Smart Images

Figure CN112307167B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of natural language processing, and in particular to a text segmentation method, apparatus, computer equipment and storage medium. Background Art
[0002] Sentence segmentation is the process of splitting a text into several sentences, which is the basic step in data processing for many natural language processing tasks. Incorrect sentence segmentation will affect the original meaning of the text, and further affect subsequent natural language processing tasks.
[0003] In the prior art, the method of segmenting text is generally: segmenting according to punctuation marks, that is, reading the characters of the target text to be segmented in sequence, and when the read characters are punctuation marks, segmenting is performed.
[0004] However, the above text segmentation method is not flexible and cannot achieve good sentence segmentation for complex texts. Summary of the invention
[0005] Based on this, the embodiments of the present application provide a text segmentation method, apparatus, computer device and storage medium.
[0006] In a first aspect, a text segmentation method is provided, the method comprising:
[0007] After receiving the sentence segmentation instruction, the sentence segmentation state machine is called, the sentence segmentation state machine includes multiple states, target events corresponding to each state, and multiple state transition conditions, wherein the multiple target events included in the sentence segmentation state machine include at least a sentence segmentation event and a reading event of a character in a finite input set of the sentence segmentation state machine, and each state transition condition is related to the attribute information of the character;
[0008] Taking characters in the target text to be segmented as a finite input set;
[0009] Based on a finite input set, the sentence segmentation state machine is used to segment the target text.
[0010] In one embodiment of the present application, sentence segmentation processing is performed on the target text using a sentence segmentation state machine, including:
[0011] Get the target event corresponding to the current state of the sentence segmentation state machine;
[0012] If the target event corresponding to the current state is a sentence segmentation event, the sentence segmentation event is executed to segment the target text at the position of the last character that has been read.
[0013] In one embodiment of the present application, the method further includes:
[0014] If the target event corresponding to the current state is not a sentence-cutting event, the execution result of the target event corresponding to the current state is obtained, and the target state transition condition satisfied by the execution result is determined from multiple state transition conditions;
[0015] The state transfer function corresponding to the target state transfer condition is called, and the state transfer function is used to jump the sentence cutting state machine from the current state to the target state.
[0016] In one embodiment of the present application, the target event corresponding to the current state is a read event, the execution result is the read character, and the target state transition condition satisfied by the execution result is determined from multiple state transition conditions, including:
[0017] Determine the type information of the characters read;
[0018] According to the type information, a target state transition condition satisfied by the type information is determined from a plurality of state transition conditions.
[0019] In one embodiment of the present application, the target event corresponding to the current state is a read event, the execution result is the read character, and the target state transition condition satisfied by the execution result is determined from multiple state transition conditions, including:
[0020] Determine the number of characters read;
[0021] A target state transition condition satisfied by the number of characters that have been read is determined from a plurality of state transition conditions according to the number of characters that have been read.
[0022] In one embodiment of the present application, the target event includes an event of reading the next character in the finite input set, an event of reading the previous character in the finite input set, a sentence segmentation event, and an end event;
[0023] The state transfer conditions include at least one of the character being a sentence stop symbol, the character being a book title mark, the character being the last character, the character being a foreign character, and the character being the Nth character, where N is the number of characters that have been read.
[0024] In one embodiment of the present application, before calling the sentence segmentation state machine, the method further includes:
[0025] Provide state machine configuration interface;
[0026] Receive state configuration information, target event information, and state transition condition information input by a user based on a state machine configuration interface;
[0027] Determine multiple states of the sentence segmentation state machine according to the state configuration information;
[0028] Determine the target events corresponding to each state according to the target event information;
[0029] determining a plurality of state transition conditions according to the state transition condition information;
[0030] A sentence segmentation state machine is generated according to a plurality of states, target events corresponding to each state, and a plurality of state transition conditions.
[0031] In a second aspect, a text segmentation device is provided, the device comprising:
[0032] A state machine calling module is used to call a sentence cutting state machine after receiving a sentence cutting instruction, wherein the sentence cutting state machine includes a plurality of states, target events corresponding to each state, and a plurality of state transition conditions, wherein the plurality of target events included in the sentence cutting state machine include at least a sentence cutting event and a reading event of characters in a finite input set of the sentence cutting state machine, and each state transition condition is related to attribute information of the characters;
[0033] A text processing module, used for taking characters in the target text to be segmented as a finite input set;
[0034] The sentence segmentation module is used to perform sentence segmentation processing on the target text based on a finite input set using a sentence segmentation state machine.
[0035] In one embodiment of the present application, the sentence segmentation module is also used to:
[0036] Get the target event corresponding to the current state of the sentence segmentation state machine;
[0037] If the target event corresponding to the current state is a sentence segmentation event, the sentence segmentation event is executed to segment the target text at the position of the last character that has been read.
[0038] In one embodiment of the present application, the sentence segmentation module is also used to:
[0039] If the target event corresponding to the current state is not a sentence-cutting event, the execution result of the target event corresponding to the current state is obtained, and the target state transition condition satisfied by the execution result is determined from multiple state transition conditions;
[0040] The state transfer function corresponding to the target state transfer condition is called, and the state transfer function is used to jump the sentence cutting state machine from the current state to the target state.
[0041] In one embodiment of the present application, the target event corresponding to the current state is a read event, the execution result is the read character, and the sentence segmentation module is further used to:
[0042] Determine the type information of the characters read;
[0043] According to the type information, a target state transition condition satisfied by the type information is determined from a plurality of state transition conditions.
[0044] In one embodiment of the present application, the target event corresponding to the current state is a read event, the execution result is the read character, and the sentence segmentation module is further used to:
[0045] Determine the number of characters read;
[0046] A target state transition condition satisfied by the number of characters that have been read is determined from a plurality of state transition conditions according to the number of characters that have been read.
[0047] In one embodiment of the present application, the target event includes an event of reading the next character in the limited input set, an event of reading the previous character in the limited input set, a sentence segmentation event, and an end event;
[0048] The state transfer conditions include at least one of the character being a sentence stop symbol, the character being a book title mark, the character being the last character, the character being a foreign character, and the character being the Nth character, where N is the number of characters that have been read.
[0049] In one embodiment of the present application, the state machine calling module is also used to:
[0050] Provide state machine configuration interface;
[0051] Receive state configuration information, target event information, and state transition condition information input by a user based on a state machine configuration interface;
[0052] Determine multiple states of the sentence segmentation state machine according to the state configuration information;
[0053] Determine the target events corresponding to each state according to the target event information;
[0054] determining a plurality of state transition conditions according to the state transition condition information;
[0055] A sentence segmentation state machine is generated according to a plurality of states, target events corresponding to each state, and a plurality of state transition conditions.
[0056] In a third aspect, a computer device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the steps of the method described in the first aspect are implemented.
[0057] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method described in any one of the second aspects are implemented.
[0058] The beneficial effects brought by the technical solution provided by the embodiment of the present application include at least:
[0059] After receiving the sentence segmentation instruction, the sentence segmentation state machine is called, and then a limited input set is determined according to the characters of the target text to be segmented, and the sentence segmentation state machine is used to segment the target text in the limited input set. Since the sentence segmentation state machine includes multiple states, multiple target events corresponding to each state, and multiple state transition conditions, wherein the multiple states are the states of the sentence segmentation state machine, the multiple target events at least include sentence segmentation events and read events of characters in the limited input set of the sentence segmentation state machine, and each state transition condition is related to the attribute information of the characters. In the embodiment of the present application, different language scenes can be mapped to target events corresponding to different states of the sentence segmentation state machine, and multiple state transition conditions related to the attribute information of the characters can be set according to the attribute information of the characters of the text in different scenes. In this way, through multiple states, target events corresponding to each state, and multiple state transition conditions related to the attribute information of the characters, the purpose of flexible sentence segmentation of texts in multiple different language scenes is achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1 A schematic diagram of an implementation environment involved in an embodiment of the present application;
[0061] Figure 2 A flowchart of a text segmentation method provided in an embodiment of the present application;
[0062] Figure 3 A state transition diagram of a sentence segmentation state machine provided in an embodiment of the present application;
[0063] Figure 4 A flowchart of a method for performing sentence segmentation processing on a target text provided in an embodiment of the present application;
[0064] Figure 5 A schematic diagram of a method for determining a target state transition condition provided in an embodiment of the present application;
[0065] Figure 6 A schematic diagram of another method for determining a target state transition condition provided in an embodiment of the present application;
[0066] Figure 7 A flowchart of a method for constructing a sentence segmentation state machine provided in an embodiment of the present application;
[0067] Figure 8 A block diagram of a text sentence segmentation device provided in an embodiment of the present application;
[0068] Fig. 9 A block diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0069] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0070] Generally speaking, in natural language processing tasks, it is necessary to segment text properly, which means dividing the text into several sentences. Incorrect segmentation will affect the original meaning of the text and further affect subsequent natural language processing tasks.
[0071] In a possible application scenario, a user can use the voice call function of a mobile terminal to input voice, perform voice recognition on the input audio, thereby converting the input audio into text, and then perform sentence segmentation on the text to obtain reasonable language sentences.
[0072] In another possible application scenario, after translating a foreign language, the language translation software can obtain a translated text. In actual application, the translated text can be segmented to obtain reasonable language sentences.
[0073] The above application scenarios are merely exemplary and are not intended to limit the present application. In practical applications, there may be other scenarios where text segmentation is required, which will not be described one by one in the present application embodiment.
[0074] In the related art, the method of segmenting text is generally: segmenting according to punctuation marks, that is, reading the characters of the target text to be segmented in order, and when the read characters are punctuation marks, segmenting is performed. However, the Chinese language is relatively complex and flexible. In practical applications, continuous punctuation marks often appear in the text, such as "What did you say!? This can't be defined like this!" In some special application scenarios, more complex continuous punctuation marks may also appear, such as "Zhang San asked, 'Where is this? Why am I here?' 'This is Donglai Country.' The old man in white replied. "The above-mentioned text segmentation method has a relatively single segmentation method and an inflexible segmentation method, so it is impossible to reasonably segment texts with complex semantics.
[0075] In the embodiment of the present application, considering the complexity and flexibility of the Chinese language, a text segmentation method based on a finite state machine is provided. The method is to call the segmentation state machine after receiving the segmentation instruction, and then determine the finite input set according to the characters of the target text to be segmented, and use the segmentation state machine to segment the target text in the finite input set. Since the segmentation state machine includes multiple states, multiple target events corresponding to each state, and multiple state transition conditions, wherein the multiple states are the states of the segmentation state machine, the multiple target events at least include the segmentation event and the reading event of the characters in the finite input set of the segmentation state machine, and each state transition condition is related to the attribute information of the character. In the embodiment of the present application, different language scenes can be mapped to target events corresponding to different states of the segmentation state machine, and multiple state transition conditions related to the attribute information of the characters can be set according to the attribute information of the characters of the text in different scenes. In this way, through multiple states, target events corresponding to each state, and multiple state transition conditions related to the attribute information of the characters, the purpose of flexible segmentation of texts in multiple different language scenes is achieved.
[0076] Below, the implementation environment involved in the text segmentation method provided in the embodiment of the present application will be briefly described.
[0077] like Figure 1 As shown, the implementation environment includes a server 101 and a terminal 102, wherein the server 101 and the terminal 102 can communicate in a wired or wireless manner.
[0078] Figure 1 In the implementation environment shown, the terminal 102 can obtain the target text to be segmented based on different application scenarios. After obtaining the target text to be segmented, the terminal 102 can send the target text to be segmented to the server 101, so that the server 101 can execute the text segmentation method provided by the embodiment of the present application on the target text to be segmented.
[0079] It should be pointed out that in some possible implementations, the implementation environment involved in the text segmentation method provided in the embodiment of the present application may only include the terminal 102. When the real-time environment only includes the terminal 102, the terminal 102 can obtain the target text to be segmented based on different application scenarios, and after obtaining the target text to be segmented, the terminal 102 can execute the text segmentation method provided in the embodiment of the present application on the target text to be segmented.
[0080] It should also be pointed out that in some other possible implementations, the implementation environment involved in the text segmentation method provided in the embodiment of the present application may only include the server 101. In the case where the implementation environment only includes the server 101, the server 101 may maintain a database, which may store target texts to be segmented, and the target texts to be segmented may be texts obtained in different application scenarios. The server 101 may execute the text segmentation method provided in the embodiment of the present application on the target texts to be segmented stored in the database.
[0081] Please refer to Figure 2 , which shows a flowchart of a text segmentation method provided by an embodiment of the present application, and the text segmentation method can be applied to the server or terminal (hereinafter collectively referred to as a computer device) in the implementation environment described above. Figure 2 As shown, the text segmentation method may include the following steps:
[0082] Step 201: After receiving the sentence segmentation instruction, the computer device calls the sentence segmentation state machine.
[0083] Among them, the sentence segmentation state machine includes multiple states, target events corresponding to each state, and multiple state transition conditions. Among them, the multiple target events included in the sentence segmentation state machine include at least sentence segmentation events and reading events of characters in a finite input set of the sentence segmentation state machine, and each state transition condition is related to the attribute information of the character.
[0084] In the embodiment of the present application, a command input interface may be provided, and the computer device may receive a sentence segmentation instruction in response to the user's input operation in the command input interface, and then call a pre-set sentence segmentation state machine. The process of setting the sentence segmentation state machine may be described in detail below.
[0085] The following is an explanation of the structure of the sentence segmentation state machine provided in the embodiment of the present application. The sentence segmentation state machine includes the following six parts: a finite set of states, a finite input set, an initial state, a terminal state, a state transition condition, and a state transition function. Among them:
[0086] The finite set of states refers to a set of multiple states included in the sentence segmentation state machine, wherein at any one time, the sentence segmentation state machine is in only one state. The finite set of states may also include target events corresponding to each state, and the target event is a driving event of the sentence segmentation state machine. In the embodiment of the present application, the target event is an event that occurs based on the target text to be segmented.
[0087] The finite input set refers to a set of characters of the target text to be segmented, and the finite input set is input data of the sentence segmentation state machine.
[0088] The initial state refers to the state of the sentence segmentation state machine after initialization. In the embodiment of the present application, after the computer device calls the sentence segmentation state machine, the sentence segmentation state machine is initialized in response to the sentence segmentation instruction. After initialization, the state of the sentence segmentation state machine is the initial state.
[0089] The terminal state refers to the state where the sentence segmentation state machine is when it completes the sentence segmentation task.
[0090] The state transition condition refers to the condition that needs to be satisfied when the sentence segmentation state machine transitions between multiple states. In an optional implementation, the multiple state transition conditions included in the sentence segmentation state machine can form a state transition condition set corresponding to each state, and the state transition conditions included in the state transition condition set corresponding to different states can be partially or completely the same. The state transition conditions included in the state transition condition set corresponding to each state refer to the conditions that need to be satisfied to transition from each state to other states.
[0091] The state transfer function includes state transfer functions corresponding to each state transfer condition. The state transfer function is used to jump the sentence segmentation state machine from the current state to the target state when the state transfer condition is met, wherein the target state is related to the state transfer condition.
[0092] like Figure 3 As shown, Figure 3 A state transition diagram of a sentence segmentation state machine is shown in FIG. , wherein a circle represents the state of the sentence segmentation state machine, the text in the circle represents the target event, the square represents the state transition condition, the arrow indicates the direction of the jump when the sentence segmentation state machine jumps between states, q0 represents the initial state, F represents the terminal state, and i represents the character read from the finite input set.
[0093] Step 202: The computer device uses characters in the target text to be segmented as a finite input set.
[0094] As described above, the target text to be segmented may be text obtained in different application scenarios.
[0095] The computer device may form a finite input set of characters in the target text into the sentence segmentation state machine and input the finite input set into the sentence segmentation state machine.
[0096] Step 203: The computer device performs sentence segmentation processing on the target text using a sentence segmentation state machine based on a finite input set.
[0097] In the embodiment of the present application, the target events corresponding to the multiple states included in the sentence segmentation state machine include at least a sentence segmentation event and a reading event of characters in the limited input combination of the sentence segmentation state machine. In this way, the sentence segmentation state machine can read the characters in the target text to be segmented through the reading event, and perform a state jump according to the read characters to jump from the current state to the next state. When the target event corresponding to the next state to which the sentence segmentation state machine jumps is a sentence segmentation event, the target text can be segmented.
[0098] After the sentence segmentation, the state of the sentence segmentation state machine can return to the initial state and prepare for the next sentence segmentation until it runs to the end of the target text, enters the terminal state, and outputs the sentence segmentation result of the target text.
[0099] The text segmentation method provided by the embodiment of the present application is to call the segmentation state machine after receiving the segmentation instruction, and then determine the limited input set according to the characters of the target text to be segmented, and use the segmentation state machine to segment the target text in the limited input set. Because the segmentation state machine includes multiple states, multiple target events corresponding to each state, and multiple state transition conditions, wherein the multiple states are the states of the segmentation state machine, the multiple target events at least include the segmentation event and the reading event of the characters in the limited input set of the segmentation state machine, and each state transition condition is related to the attribute information of the character. In the embodiment of the present application, different language scenes can be mapped to target events corresponding to different states of the segmentation state machine, and multiple state transition conditions related to the attribute information of the characters can be set according to the attribute information of the characters of the text in different scenes. In this way, through multiple states, target events corresponding to each state, and multiple state transition conditions related to the attribute information of the characters, the purpose of flexible segmentation of texts in multiple different language scenes is achieved.
[0100] Based on the above-described embodiment, the following embodiment of the present application will describe the technical process of using the sentence segmentation state machine to perform sentence segmentation processing on the target text. Figure 4 As shown, the technical process may include the following steps:
[0101] Step 401: The computer device obtains a target event corresponding to the current state of the sentence segmentation state machine.
[0102] In the embodiment of the present application, the sentence segmentation state machine is initialized in response to the sentence segmentation instruction, and after the initialization, the state of the sentence segmentation state machine is the initial state. Then, the computer device can call the sentence segmentation state machine to read the first character in the target text, call the sentence segmentation state machine to obtain the target event corresponding to the initial state, and execute the target event corresponding to the initial state machine to obtain the execution result.
[0103] For example, if the target event corresponding to the initial state is to read the next character, the execution result obtained is that the second character in the target text is read. In the embodiments of the present application, the target state transition condition satisfied by the second character can be determined from multiple state transition conditions according to the read second character. Then, the state transition function corresponding to the target state transition condition is called, and the state transition function is used to jump the sentence segmentation state machine from the initial state to the next state. Among them, as Figure 3 shown, the next state is the state pointed to by the arrow associated with the target state transition condition.
[0104] In an alternative implementation, in the embodiments of the present application, each state can respectively correspond to a set of state transition conditions. Each set of state transition conditions can include at least one state transition condition. The state transition conditions included in multiple sets of state transition conditions constitute the above-mentioned multiple state transition conditions. In the embodiments of the present application, the computer device can determine the target state transition condition satisfied by the second character from the set of state transition conditions corresponding to the initial state according to the read second character.
[0105] After the sentence segmentation state machine jumps to the next state, the next state is the state where the sentence segmentation state machine is currently located. The computer device can obtain the target event corresponding to the currently located state from the finite set of states according to the sentence segmentation state machine.
[0106] Optionally, the target event can include an event of reading the next character in the finite input set, an event of reading the previous character in the finite input set, a sentence segmentation event, and a termination event.
[0107] Step 402, if the target event corresponding to the currently located state is not a sentence segmentation event, the computer device obtains the execution result of the target event corresponding to the currently located state, and determines the target state transition condition satisfied by the execution result from multiple state transition conditions.
[0108] In the embodiments of the present application, when the target event corresponding to the currently located state is not a sentence segmentation event, the computer device can execute the target event corresponding to the currently located state and obtain the execution result. For example, for example, if the target event corresponding to the currently located state is "read the previous character", then the execution result of the target event corresponding to the currently located state is: a character is read. For the convenience of subsequent description, it is assumed below that the read character is "in".
[0109] Then the computer device can determine the target state transition condition satisfied by the execution result from multiple state transition conditions according to the execution result.
[0110] Optionally, in the embodiments of the present application, the state transition conditions may include at least one of the character belonging to a sentence-ending symbol, the character belonging to a book title mark, the character being the last character, the character being a foreign character, and the character being the Nth character, where N is the number of characters that have been read.
[0111] Among them, the embodiments of the present application provide two scenarios for determining the target state transition conditions satisfied by the execution result. Next, as Figure 5 shown, the first scenario is described. In the first scenario, the target event corresponding to the currently所处 state is the reading event of reading a character in the finite input set of the sentence segmentation state machine, and the execution result of this reading event is the read character.
[0112] Step 501, the computer device determines the type information of the read character.
[0113] In the embodiments of the present application, the type information of the character may include text, sentence-ending symbols, consecutive sentence-ending symbols, English letters, etc. Among them, the type information of the read character may be one of the above type information.
[0114] Continuing with the above example, in the embodiments of the present application, the read character is "zai", and the type information of this character is: text.
[0115] Step 502, the computer device determines the target state transition condition satisfied by the type information from the multiple state transition conditions.
[0116] In the embodiments of the present application, the multiple state transition conditions are related to the attribute information of the character. Among them, the type information of the character is one of the attribute information of the character. For example, the multiple state transition conditions may include, for example: belonging to a sentence-ending symbol, belonging to text, belonging to Arabic letters, etc.
[0117] The computer device can compare the type information of the read character "zai" one by one with the multiple state transition conditions included in the state transition condition set corresponding to the currently所处 state. Obviously, the type information of "zai" does not satisfy the state transition condition of "belonging to a sentence-ending symbol", nor does it satisfy the state transition condition of "belonging to Arabic letters", and satisfies the state transition condition of "belonging to text". Therefore, the state transition condition of "belonging to text" is the target state transition condition satisfied by this execution result.
[0118] In the embodiments of the present application, the sentence-ending symbol can be determined according to the type information of the character, and the target text can be segmented when a sentence-ending symbol is encountered.
[0119] Next, as Figure 6As shown, the second scenario is explained. In the second scenario, the target event corresponding to the current state is a read event of reading characters in a finite input set of the sentence segmentation state machine, and the execution result of the read event is the read characters.
[0120] Step 601: The computer device determines the number of characters that have been read.
[0121] In an embodiment of the present application, the number of characters read is one of the attribute information of the characters. The computer device can call the sentence segmentation state machine to record the number of characters read. Each time a character is read, the number is added by 1 to obtain the number of characters currently read.
[0122] Step 602: The computer device determines a target state transition condition satisfied by the number of characters that have been read from a plurality of state transition conditions according to the number of characters that have been read.
[0123] For example, the number of characters read is 10, and the target state transition condition set corresponding to the current state includes multiple state transition conditions: equal to 15 characters, not equal to 15 characters, belonging to text, and belonging to a stop symbol.
[0124] The computer device can compare the number of characters read one by one with the multiple state transition conditions included in the state transition condition set corresponding to the current state. Obviously, the number of characters read meets the state transition condition of "not equal to 15 characters". It does not meet other state transition conditions. Therefore, "not equal to 15 characters" is the target state transition condition satisfied by the execution result.
[0125] In the embodiment of the present application, short sentences of the target text are merged or long sentences are cut into short sentences according to the number of characters, so that flexible sentence segmentation of the target text can be achieved.
[0126] Step 403: the computer device calls the state transfer function corresponding to the target state transfer condition, and uses the state transfer function to jump the sentence segmentation state machine from the current state to the target state.
[0127] In the embodiment of the present application, the state transfer function corresponding to each state transfer condition is preset. In the computer code, the state transfer function can be implemented by a hash table.
[0128] Optionally, in an embodiment of the present application, the state transfer function can be customized according to user needs to facilitate the state of the sentence segmentation state machine to jump from the current state to any other state.
[0129] The computer device can determine the state transfer function corresponding to the target state transfer condition according to the target state transfer condition, and jump the sentence cutting state machine from the current state to the target state based on the state transfer function, wherein the target state is a state that has been pre-set in the target state transfer function.
[0130] Step 404: If the target event corresponding to the current state is a sentence segmentation event, the computer device executes the sentence segmentation event to segment the target text at the position of the last character that has been read.
[0131] If the target event corresponding to the current state is a sentence segmentation event, the computer device executes the sentence segmentation event. The execution process refers to segmenting the target text at the position of the last character read, for example, adding a space at the position of the last character read to separate the read characters from the unread characters.
[0132] In the embodiment of the present application, when the target event corresponding to the current state is a sentence segmentation event, sentence segmentation is performed on the target text, thereby achieving the purpose of flexibly segmenting the target text.
[0133] In an embodiment of the present application, a method for constructing a sentence segmentation state machine is provided, such as Figure 7 As shown, the method comprises the following steps:
[0134] Step 701: The computer device provides a state machine configuration interface.
[0135] In the embodiment of the present application, the state machine configuration interface can be as follows Figure 8 As shown, the state machine configuration interface can have a selection function and an editing function.
[0136] Step 702: The computer device receives state configuration information, target event information, and state transfer condition information input by the user based on the state machine configuration interface.
[0137] In an optional implementation, the user may perform editing operations based on the editing function of the state machine configuration interface to input state configuration information, target event information, and state transition condition information.
[0138] In another optional implementation, the computer device may pre-store a variety of state configuration information, a variety of target event configuration information, and a variety of state transition condition information; the user may use the selection function in the state machine configuration interface to select and input the required state configuration information, target event information, and state transition condition information from the pre-set multiple state configuration information, multiple target event configuration information, and multiple state transition condition information.
[0139] Step 703, the computer device determines multiple states of the sentence segmentation state machine according to the state configuration information, determines target events corresponding to each state according to the target event information, and determines multiple state transition conditions according to the state transition condition information.
[0140] Step 704: The computer device generates a sentence segmentation state machine according to the multiple states, the target events corresponding to the states, and the multiple state transition conditions.
[0141] In an embodiment of the present application, a computer device can construct sentence segmentation logic and state transfer functions corresponding to each state transfer condition based on multiple states, target events corresponding to each state, and multiple state transfer conditions, thereby generating a sentence segmentation state machine.
[0142] In the embodiment of the present application, the sentence segmentation state machine includes multiple states, target events corresponding to each state, and multiple state transition conditions, which can all be obtained in a customized manner. In this way, the user can customize any sentence segmentation logic as needed without spending time developing different sentence segmentation tools for different target texts. Therefore, the sentence segmentation state machine provided in the embodiment of the present application reduces the cost of sentence segmentation processing on the target text and improves work efficiency.
[0143] Please refer to Figure 8 , which shows a block diagram of a text segmentation device 800 provided in an embodiment of the present application. The text segmentation device 800 can be configured in Figure 1 In the server or terminal shown. Figure 8 As shown, the text sentence segmentation device may include: a state machine calling module 801, a text processing module 802 and a sentence segmentation module 803, wherein:
[0144] The state machine calling module 801 is used to call the sentence cutting state machine after receiving the sentence cutting instruction. The sentence cutting state machine includes multiple states, target events corresponding to each state, and multiple state transition conditions. The multiple target events included in the sentence cutting state machine include at least a sentence cutting event and a reading event of a character in a finite input set of the sentence cutting state machine. Each state transition condition is related to the attribute information of the character.
[0145] The text processing module 802 is used to take characters in the target text to be segmented as a finite input set;
[0146] The sentence segmentation module 803 is used to perform sentence segmentation processing on the target text based on a finite input set using a sentence segmentation state machine.
[0147] In one embodiment of the present application, the sentence segmentation module 803 is also used to:
[0148] Get the target event corresponding to the current state of the sentence segmentation state machine;
[0149] If the target event corresponding to the current state is a sentence segmentation event, the sentence segmentation event is executed to segment the target text at the position of the last character that has been read.
[0150] In one embodiment of the present application, the sentence segmentation module 803 is also used to:
[0151] If the target event corresponding to the current state is not a sentence-cutting event, the execution result of the target event corresponding to the current state is obtained, and the target state transition condition satisfied by the execution result is determined from multiple state transition conditions;
[0152] The state transfer function corresponding to the target state transfer condition is called, and the state transfer function is used to jump the sentence cutting state machine from the current state to the target state.
[0153] In one embodiment of the present application, the target event corresponding to the current state is a read event, the execution result is the read character, and the sentence segmentation module 803 is further used to:
[0154] Determine the type information of the characters read;
[0155] According to the type information, a target state transition condition satisfied by the type information is determined from a plurality of state transition conditions.
[0156] In one embodiment of the present application, the target event corresponding to the current state is a read event, the execution result is the read character, and the sentence segmentation module 803 is further used to:
[0157] Determine the number of characters read;
[0158] A target state transition condition satisfied by the number of characters that have been read is determined from a plurality of state transition conditions according to the number of characters that have been read.
[0159] In one embodiment of the present application, the target event includes an event of reading the next character in the limited input set, an event of reading the previous character in the limited input set, a sentence segmentation event, and an end event;
[0160] The state transfer conditions include at least one of the character being a sentence stop symbol, the character being a book title mark, the character being the last character, the character being a foreign character, and the character being the Nth character, where N is the number of characters that have been read.
[0161] In one embodiment of the present application, the state machine calling module 801 is also used to:
[0162] Provide state machine configuration interface;
[0163] Receive state configuration information, target event information, and state transition condition information input by a user based on a state machine configuration interface;
[0164] Determine multiple states of the sentence segmentation state machine according to the state configuration information;
[0165] Determine the target events corresponding to each state according to the target event information;
[0166] determining a plurality of state transition conditions according to the state transition condition information;
[0167] A sentence segmentation state machine is generated according to a plurality of states, target events corresponding to each state, and a plurality of state transition conditions.
[0168] For the specific definition of the text segmentation device, please refer to the definition of the text segmentation method above, which will not be repeated here. The various modules in the above-mentioned text segmentation device can be implemented in whole or in part by software, hardware and their combination. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations of the above modules.
[0169] In one embodiment of the present application, a computer device is provided. The computer device may be a terminal or a server, and its internal structure diagram may be as follows: Fig. 9 As shown. The computer device includes a processor and a memory connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. When the computer program is executed by the processor, a text segmentation method is implemented.
[0170] Those skilled in the art will understand that Fig. 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0171] In one embodiment of the present application, a computer device is provided, the computer device comprising a memory and a processor, the memory storing a computer program, and the processor implementing the following steps when executing the computer program:
[0172] After receiving the sentence segmentation instruction, the sentence segmentation state machine is called, the sentence segmentation state machine includes multiple states, target events corresponding to each state, and multiple state transition conditions, wherein the multiple target events included in the sentence segmentation state machine include at least a sentence segmentation event and a reading event of a character in a finite input set of the sentence segmentation state machine, and each state transition condition is related to the attribute information of the character;
[0173] Taking characters in the target text to be segmented as a finite input set;
[0174] Based on a finite input set, the sentence segmentation state machine is used to segment the target text.
[0175] In one embodiment of the present application, the processor implements the following steps when executing the computer program:
[0176] Get the target event corresponding to the current state of the sentence segmentation state machine;
[0177] If the target event corresponding to the current state is a sentence segmentation event, the sentence segmentation event is executed to segment the target text at the position of the last character that has been read.
[0178] In one embodiment of the present application, the processor implements the following steps when executing the computer program: if the target event corresponding to the current state is not a sentence segmentation event, obtaining the execution result of the target event corresponding to the current state, and determining the target state transition condition satisfied by the execution result from multiple state transition conditions;
[0179] The state transfer function corresponding to the target state transfer condition is called, and the state transfer function is used to jump the sentence cutting state machine from the current state to the target state.
[0180] In one embodiment of the present application, the target event corresponding to the current state is a read event, and the execution result is a read character. When the processor executes the computer program, the following steps are implemented: determining type information of the read character;
[0181] According to the type information, a target state transition condition satisfied by the type information is determined from a plurality of state transition conditions.
[0182] In one embodiment of the present application, the target event corresponding to the current state is a read event, and the execution result is a read character. When the processor executes the computer program, the following steps are implemented: determining the number of characters that have been read;
[0183] A target state transition condition satisfied by the number of characters that have been read is determined from a plurality of state transition conditions according to the number of characters that have been read.
[0184] In one embodiment of the present application, the processor implements the following steps when executing the computer program:
[0185] Provide state machine configuration interface;
[0186] Receive state configuration information, target event information, and state transition condition information input by a user based on a state machine configuration interface;
[0187] Determine multiple states of the sentence segmentation state machine according to the state configuration information;
[0188] Determine the target events corresponding to each state according to the target event information;
[0189] determining a plurality of state transition conditions according to the state transition condition information;
[0190] A sentence segmentation state machine is generated according to a plurality of states, target events corresponding to each state, and a plurality of state transition conditions.
[0191] The computer device provided in the embodiment of the present application has similar implementation principles and technical effects to those of the above-mentioned method embodiment, and will not be described in detail here.
[0192] In one embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0193] After receiving the sentence segmentation instruction, the sentence segmentation state machine is called, the sentence segmentation state machine includes multiple states, target events corresponding to each state, and multiple state transition conditions, wherein the multiple target events included in the sentence segmentation state machine include at least a sentence segmentation event and a reading event of a character in a finite input set of the sentence segmentation state machine, and each state transition condition is related to the attribute information of the character;
[0194] Taking characters in the target text to be segmented as a finite input set;
[0195] Based on a finite input set, the sentence segmentation state machine is used to segment the target text.
[0196] In one embodiment of the present application, when the computer program is executed by a processor, the following steps are implemented:
[0197] Get the target event corresponding to the current state of the sentence segmentation state machine;
[0198] If the target event corresponding to the current state is a sentence segmentation event, the sentence segmentation event is executed to segment the target text at the position of the last character that has been read.
[0199] In one embodiment of the present application, when the computer program is executed by a processor, the following steps are implemented:
[0200] If the target event corresponding to the current state is not a sentence-cutting event, the execution result of the target event corresponding to the current state is obtained, and the target state transition condition satisfied by the execution result is determined from multiple state transition conditions;
[0201] The state transfer function corresponding to the target state transfer condition is called, and the state transfer function is used to jump the sentence cutting state machine from the current state to the target state.
[0202] In one embodiment of the present application, the target event corresponding to the current state is a read event, the execution result is a read character, and the computer program implements the following steps when executed by the processor: determining the type information of the read character;
[0203] According to the type information, a target state transition condition satisfied by the type information is determined from a plurality of state transition conditions.
[0204] In one embodiment of the present application, the target event corresponding to the current state is a read event, the execution result is a read character, and the computer program implements the following steps when executed by the processor: determining the number of characters that have been read;
[0205] A target state transition condition satisfied by the number of characters that have been read is determined from a plurality of state transition conditions according to the number of characters that have been read.
[0206] In one embodiment of the present application, when the computer program is executed by a processor, the following steps are implemented:
[0207] Provide state machine configuration interface;
[0208] Receive state configuration information, target event information, and state transition condition information input by a user based on a state machine configuration interface;
[0209] Determine multiple states of the sentence segmentation state machine according to the state configuration information;
[0210] Determine the target events corresponding to each state according to the target event information;
[0211] determining a plurality of state transition conditions according to the state transition condition information;
[0212] A sentence segmentation state machine is generated according to a plurality of states, target events corresponding to each state, and a plurality of state transition conditions.
[0213] The computer-readable storage medium provided in this embodiment has similar implementation principles and technical effects to those of the above method embodiments, and will not be described in detail here.
[0214] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0215] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0216] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be construed as limiting the scope of the patent application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent application shall be subject to the attached claims.
Claims
1. A text sentence segmentation method, characterized in that: The method comprises: After receiving the sentence segmentation instruction, calling the sentence segmentation state machine, the sentence segmentation state machine includes a plurality of states, target events corresponding to each of the states, and a plurality of state transition conditions, wherein the plurality of target events included in the sentence segmentation state machine include at least a sentence segmentation event and a read event of reading characters in a finite input set of the sentence segmentation state machine, each of the state transition conditions is related to attribute information of the character, and the state transition condition includes at least one of the character being a stop symbol, the character being a book title mark, the character being the last character, the character being a foreign character, and the character being the Nth character, wherein N is the number of characters that have been read; Taking characters in the target text to be segmented as the finite input set; Based on the finite input set, the sentence segmentation state machine is used to perform sentence segmentation on the target text. The sentence segmentation state machine is used to read the characters in the target text through the read event, and perform state jumps according to the read characters to jump from the current state to the next state. When the target event corresponding to the next state to which the sentence segmentation state machine jumps is the sentence segmentation event, the target text is segmented.
2. The method according to claim 1, characterized in that The using the sentence segmentation state machine to perform sentence segmentation processing on the target text includes: Obtaining a target event corresponding to the current state of the sentence segmentation state machine; If the target event corresponding to the current state is the sentence segmentation event, the sentence segmentation event is executed to segment the target text at the position of the last character that has been read.
3. The method according to claim 2, characterized in that The method further comprises: If the target event corresponding to the current state is not the sentence-cutting event, obtaining the execution result of the target event corresponding to the current state, and determining the target state transition condition satisfied by the execution result from the multiple state transition conditions; The state transfer function corresponding to the target state transfer condition is called, and the sentence segmentation state machine is jumped from the current state to the target state by using the state transfer function.
4. The method according to claim 3, characterized in that The target event corresponding to the current state is the read event, the execution result is the read character, and determining the target state transition condition satisfied by the execution result from the multiple state transition conditions includes: Determine the type information of the characters read; The target state transition condition satisfied by the type information is determined from the multiple state transition conditions according to the type information.
5. The method according to claim 3, characterized in that: The target event corresponding to the current state is the read event, the execution result is the read character, and determining the target state transition condition satisfied by the execution result from the multiple state transition conditions includes: Determine the number of characters read; The target state transition condition satisfied by the number of the read characters is determined from the plurality of state transition conditions according to the number of the read characters.
6. The method according to claim 1, characterized in that The target events include an event of reading a next character in the limited input set, an event of reading a previous character in the limited input set, a sentence segmentation event, and an end event.
7. The method according to claim 1, characterized in that Before calling the sentence segmentation state machine, the method further includes: Provide state machine configuration interface; Receive state configuration information, target event information, and state transition condition information input by a user based on the state machine configuration interface; Determining a plurality of states of the sentence segmentation state machine according to the state configuration information; Determine the target events corresponding to the states respectively according to the target event information; Determine the multiple state transition conditions according to the state transition condition information; The sentence segmentation state machine is generated according to the multiple states, the target events corresponding to the states, and multiple state transition conditions.
8. A text sentence segmentation device, characterized in that: The device comprises: A state machine calling module is used to call a sentence cutting state machine after receiving a sentence cutting instruction, wherein the sentence cutting state machine includes a plurality of states, target events corresponding to each of the states, and a plurality of state transition conditions, wherein the plurality of target events included in the sentence cutting state machine include at least a sentence cutting event and a reading event of reading characters in a finite input set of the sentence cutting state machine, and each of the state transition conditions is related to attribute information of the character, and the state transition condition includes at least one of the character being a sentence stop symbol, the character being a book title mark, the character being the last character, the character being a foreign character, and the character being the Nth character, wherein N is the number of characters that have been read; A text processing module, used for taking characters in the target text to be segmented as the limited input set; A sentence segmentation module is used to perform sentence segmentation on the target text based on the finite input set using the sentence segmentation state machine. The sentence segmentation state machine is used to read characters in the target text through the read event and perform state jumps according to the read characters to jump from the current state to the next state. When the target event corresponding to the next state to which the sentence segmentation state machine jumps is the sentence segmentation event, the target text is segmented.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Method and device for realizing state machine
CN101957751A
Sentence-breaking model training method, sentence-breaking method, device and computer equipment
CN109145282A
