Text similarity determination method, device, storage medium and electronic device
By obtaining and comparing high-frequency word sequences of texts, extracting common word sequences and judging similarity, the problem of low accuracy in traditional methods is solved and higher accuracy of text similarity judgment is achieved.
Patent Information
- Application Number
- CN201910886796.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-09-19
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2039-09-19
AI Technical Summary
Traditional methods have low accuracy in judging the duplication of articles in online public opinion data, and cannot effectively identify duplicate articles in massive data.
By obtaining the first high-frequency word sequence and the second high-frequency word sequence of the text, the common word sequence is extracted, and the text similarity is determined based on word frequency and sequence similarity to improve accuracy.
It significantly improves the accuracy of text similarity judgment, can more effectively identify repetitions in text, and enhances the representation of the similarity in the number and frequency order of high-frequency words.
Smart Images

Figure CN112528630B
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method, device, storage medium and electronic device for determining text similarity. Background Art
[0002] With the development of society, the amount of information in various industries has increased dramatically. Usually, one of the important aspects of processing online public opinion data is to identify duplicate articles in the massive amount of online public opinion data.
[0003] The traditional method of judging whether two articles are duplicate is to divide the articles into sentences and words, then compare the repetition of the sentences and words of the two articles, and determine whether the two articles are duplicate texts based on the degree of repetition.
[0004] However, the traditional judgment method is based on a single principle and has low accuracy. Summary of the invention
[0005] Based on this, it is necessary to provide a method, device, storage medium and electronic device that can accurately determine text similarity in response to the above technical problems.
[0006] In a first aspect, an embodiment of the present application provides a method for determining text similarity, the method comprising:
[0007] Acquire a first high-frequency word sequence of a first text and a second high-frequency word sequence of a second text; the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from large to small according to word frequency;
[0008] Extracting common words from the first high-frequency word sequence and the second high-frequency word sequence to obtain a common word sequence of the first text and the second text; wherein the words in the common word sequence are arranged from large to small according to word frequency, and the order of any two words in the common word sequence is the same as the order of the any two words in the first high-frequency word sequence and the second high-frequency word sequence;
[0009] The text similarity between the first text and the second text is determined based on the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence.
[0010] In one embodiment, obtaining a common word sequence of the first text and the second text according to the first high-frequency word sequence and the second high-frequency word sequence includes:
[0011] Obtaining a union word sequence of the first high-frequency word sequence and the second high-frequency word sequence; wherein the words in the union word sequence are the union of all words in the first high-frequency word sequence and the second high-frequency word sequence;
[0012] From the union word sequence, words whose front-to-back order is the same as that in the first high-frequency word sequence and the second high-frequency word sequence are extracted to generate the common word sequence.
[0013] In one embodiment, determining the text similarity between the first text and the second text according to the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence includes:
[0014] The text similarity is determined based on the similarity between the number of words and / or the order of words in the common word sequence and the union word sequence.
[0015] In one embodiment, determining the text similarity based on the similarity of the number of words and / or the order of words in the common word sequence and the union word sequence includes:
[0016] The ratio of the number of words in the common word sequence to the number of words in the union word sequence is obtained as the text similarity.
[0017] In one embodiment, obtaining a first high-frequency word sequence of a first text and a second high-frequency word sequence of a second text includes:
[0018] Perform word segmentation on the first text and the second text respectively to obtain a first word segmentation set and a second word segmentation set;
[0019] Perform keyword screening in the first word segmentation set and the second word segmentation set respectively to obtain a first keyword set and a second keyword set;
[0020] The first keyword set and the second keyword set are sorted according to word frequency to obtain the first high-frequency word sequence and the second high-frequency word sequence.
[0021] In one embodiment, sorting the first keyword set and the second keyword set respectively according to word frequency to obtain the first high-frequency word sequence and the second high-frequency word sequence includes:
[0022] Sort the keywords in the first keyword set according to word frequency to obtain a first high-frequency word initial sequence;
[0023] Determining whether the number of keywords in the first high-frequency word initial sequence is greater than or equal to a preset word frequency threshold;
[0024] If not, the first high-frequency word initial sequence is used as the first high-frequency word sequence.
[0025] In one embodiment, the method further comprises:
[0026] If the number of words in the first high-frequency word initial sequence is greater than or equal to the word frequency threshold, the first N keywords in the first high-frequency word initial sequence are selected as the first high-frequency word sequence; wherein N is equal to the word frequency threshold.
[0027] In one embodiment, sorting the first keyword set and the second keyword set respectively according to word frequency to obtain the first high-frequency word sequence and the second high-frequency word sequence includes:
[0028] Sorting the keywords in the second keyword set according to word frequency to obtain a second high-frequency word initial sequence;
[0029] Determining whether the number of keywords in the second high-frequency word initial sequence is greater than or equal to a preset word frequency threshold;
[0030] If not, the second high-frequency word initial sequence is used as the second high-frequency word sequence.
[0031] In one embodiment, the method further comprises:
[0032] If the number of words in the second high-frequency word initial sequence is greater than or equal to the word frequency threshold, the first N keywords in the second high-frequency word initial sequence are selected as the second high-frequency word sequence; N is equal to the word frequency threshold.
[0033] In a second aspect, an embodiment of the present application provides a device for determining text similarity, the device comprising:
[0034] An acquisition module, configured to acquire a first high-frequency word sequence of a first text and a second high-frequency word sequence of a second text; the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from high to low according to word frequency;
[0035] A processing module, configured to extract common words from the first high-frequency word sequence and the second high-frequency word sequence to obtain a common word sequence of the first text and the second text; wherein the words in the common word sequence are arranged from high to low according to word frequency, and the order of any two words in the common word sequence is the same as the order of the any two words in the first high-frequency word sequence and the second high-frequency word sequence;
[0036] A determination module is used to determine the text similarity between the first text and the second text according to the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence.
[0037] In a third aspect, an embodiment of the present application provides an electronic device, the electronic device comprising at least one processor, and at least one memory and a bus connected to the processor; wherein the processor and the memory communicate with each other through the bus; the processor is used to call program instructions in the memory to perform the following steps:
[0038] Acquire a first high-frequency word sequence of a first text and a second high-frequency word sequence of a second text; the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from large to small according to word frequency;
[0039] Extracting common words from the first high-frequency word sequence and the second high-frequency word sequence to obtain a common word sequence of the first text and the second text; wherein the words in the common word sequence are arranged from large to small according to word frequency, and the order of any two words in the common word sequence is the same as the order of the any two words in the first high-frequency word sequence and the second high-frequency word sequence;
[0040] The text similarity between the first text and the second text is determined based on the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence.
[0041] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0042] Acquire a first high-frequency word sequence of a first text and a second high-frequency word sequence of a second text; the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from large to small according to word frequency;
[0043] Extracting common words from the first high-frequency word sequence and the second high-frequency word sequence to obtain a common word sequence of the first text and the second text; wherein the words in the common word sequence are arranged from large to small according to word frequency, and the order of any two words in the common word sequence is the same as the order of the any two words in the first high-frequency word sequence and the second high-frequency word sequence;
[0044] The text similarity between the first text and the second text is determined based on the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence.
[0045] The above-mentioned method, device, storage medium and electronic device for determining text similarity obtain the first high-frequency word sequence of the first text and the second high-frequency word sequence of the second text through the electronic device. Since the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from large to small according to the word frequency, the electronic device can extract the common words in the first high-frequency word sequence and the second high-frequency word sequence to obtain the common word sequence of the first text and the second text. Since the words in the common word sequence are arranged from large to small according to the word frequency, the order of any two words is the same as the order in the first high-frequency word sequence and the second high-frequency word sequence, respectively, the obtained common word sequence can not only characterize the number of the same common high-frequency words in the first text and the second text, but also characterize the order of the word frequency of these common high-frequency words in the first text and the second text. Since the common word sequence can characterize the similarity of the two dimensions of the number of high-frequency words and the word frequency order of high-frequency words in the two texts, the rationality of the determined text similarity is greatly increased and the accuracy is also greatly improved by using the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 is a diagram of the internal structure of an electronic device in one embodiment;
[0047] Figure 2 A flowchart of a method for determining text similarity provided by an embodiment;
[0048] Figure 3 A flowchart of a method for determining text similarity provided by another embodiment;
[0049] Figure 4 A flowchart of a method for determining text similarity provided in yet another embodiment;
[0050] Figure 5 A flowchart of a method for determining text similarity provided in yet another embodiment;
[0051] Figure 6 A flowchart of a method for determining text similarity provided in yet another embodiment;
[0052] Figure 7 A flowchart of a method for determining text similarity provided in yet another embodiment;
[0053] Figure 8 A schematic diagram of the structure of a device for determining text similarity provided by an embodiment. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0055] The text similarity determination method provided in the embodiment of the present application can be applied to Figure 1 The electronic device shown. The electronic device includes at least one processor, and at least one memory and bus connected to the processor, wherein the processor and the memory communicate with each other through the bus; the processor is used to call the program instructions in the memory, and optionally, it may also include a network interface, a display screen and an input device. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the electronic device can be used to communicate with other external devices through a network connection. Optionally, the electronic device can be a server, a desktop, a personal digital assistant, or other terminal devices, such as a tablet computer, a mobile phone, etc., or a cloud or remote server. The specific form of the electronic device is not limited in the embodiment of the present application. The display screen of the electronic device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the electronic device can be a touch layer covered on the display screen, or a button, a trackball or a touchpad set on the housing of the electronic device, or an external keyboard, touchpad or mouse, etc. Of course, the input device and the display screen may not be part of the electronic device, but may be external devices of the electronic device.
[0056] Those skilled in the art will understand that Figure 1 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the electronic device to which the scheme of the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0057] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0058] It should be noted that the execution subject of the following method embodiment may be a text similarity determination device, which may be implemented as part or all of the above electronic device through software, hardware, or a combination of software and hardware. The following method embodiment is described by taking the execution subject as an electronic device as an example.
[0059] Figure 2 A method for determining text similarity is provided in an embodiment. This embodiment relates to a specific process of an electronic device determining text similarity based on high-frequency words in a first text and a second text, such as Figure 2 As shown, the method includes:
[0060] S10, obtaining a first high-frequency word sequence of the first text and a second high-frequency word sequence of the second text; the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from high to low according to word frequency.
[0061] Specifically, the electronic device obtains the first high-frequency word sequence of the first text, which may be to read the first high-frequency word sequence pre-stored in the memory, or to recognize the first text, thereby identifying and statistically obtaining the first high-frequency word sequence about the first text. The first high-frequency word sequence includes multiple words, all of which are derived from the first text, and these words are arranged in the first high-frequency word sequence from most to least according to the word frequency, that is, the number of times they appear in the first text, and the words in the front have a higher word frequency than the words in the back. The specific method for the electronic device to obtain the second high-frequency word sequence of the second text can refer to the description of obtaining the first high-frequency word sequence; the detailed description of the second high-frequency word sequence can refer to the description of the first high-frequency word sequence, the difference being that the first high-frequency word sequence is the word sequence of the first text, and the second high-frequency word sequence is the word sequence of the second text.
[0062] S20. Extract common words from the first high-frequency word sequence and the second high-frequency word sequence to obtain a common word sequence of the first text and the second text; wherein the words in the common word sequence are arranged from high to low according to word frequency, and the order of any two words in the common word sequence is the same as the order of the any two words in the first high-frequency word sequence and the second high-frequency word sequence.
[0063] Specifically, the electronic device extracts common words from the first high-frequency word sequence and the second high-frequency word sequence, and arranges them according to word frequency to obtain a common word sequence. Optionally, the electronic device can determine whether each word in the first high-frequency word sequence appears in the second high-frequency word sequence one by one. If the word only appears in the first high-frequency word sequence but not in the second high-frequency word sequence, the word is not included in the sequence; if the word appears in both the first high-frequency word sequence and the second high-frequency word sequence, it continues to determine whether another word in the first high-frequency word sequence also exists in the second high-frequency word sequence. If the other word does not appear in the second high-frequency word sequence, the other word is not included in the sequence; if it appears in the second high-frequency word sequence, it is determined whether the order of the two words from large to small in terms of word frequency is the same as the order of the two words in the first high-frequency word sequence. If they are different, the two words are not included in the sequence; if they are the same, the two words are added to the sequence, and so on, until all the words in the first high-frequency word sequence are traversed, and all the words added to the sequence are arranged according to word frequency to obtain a common word sequence. Therefore, the common word sequence can satisfy the order of word frequency from large to small, and the order of any two words therein is the same as the order in the first high-frequency word sequence and the second high-frequency word sequence.
[0064] S30: Determine text similarity between the first text and the second text according to the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence.
[0065] Specifically, the electronic device determines the text similarity between the first text and the second text based on the first high-frequency word sequence, the second high-frequency word sequence and the above-mentioned common word sequence. Optionally, the electronic device can calculate the ratio of the number of words in the common word sequence to the sum of the number of words in the first high-frequency word sequence and the second high-frequency word sequence as the above-mentioned text similarity; the electronic device can also calculate the ratio of the number of words in the common word sequence to the sum of the number of identical words in the first high-frequency word sequence and the second high-frequency word sequence as the above-mentioned text similarity.
[0066] In this embodiment, the electronic device obtains the first high-frequency word sequence of the first text and the second high-frequency word sequence of the second text. Since the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from large to small according to the word frequency, the electronic device can extract the common words in the first high-frequency word sequence and the second high-frequency word sequence to obtain the common word sequence of the first text and the second text. Since the words in the common word sequence are arranged from large to small according to the word frequency, the order of any two words is the same as the order in the first high-frequency word sequence and the second high-frequency word sequence, respectively, the obtained common word sequence can not only characterize the number of the same common high-frequency words in the first text and the second text, but also characterize the order of the word frequency of these common high-frequency words in the first text and the second text. Since the common word sequence can characterize the similarity of the two dimensions of the number of high-frequency words and the word frequency order of high-frequency words in the two texts, the rationality of the determined text similarity is greatly increased and the accuracy is also greatly improved by using the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence.
[0067] Optionally, based on the above embodiment, a possible implementation of step S10 is as follows: Figure 3 As shown, including:
[0068] S11. Perform word segmentation on the first text and the second text respectively to obtain a first word segmentation set and a second word segmentation set.
[0069] Specifically, the electronic device performs word segmentation on the first text and the second text respectively, which may be to separate the first text and the second text into sentences respectively, and to further segment the sentences, thereby breaking up the article into word granularities, and obtaining a first word segmentation set and a second word segmentation set respectively. Alternatively, the first text and the second text may be respectively input into a neural network model, and the word segmentation of the first text and the second text may be achieved through intelligent recognition of the neural network model, thereby obtaining a first word segmentation set and a second word segmentation set.
[0070] S12: Perform keyword screening according to the first word segmentation set and the second word segmentation set respectively to obtain a first keyword set and a second keyword set.
[0071] Specifically, the electronic device performs keyword screening in the first word segmentation set and the second word segmentation set, respectively, such as removing stop words and useless words, thereby completing word filtering and obtaining the first keyword set and the second keyword set. This step can remove redundant and meaningless words, thereby reducing the time for subsequent processing and improving processing accuracy and efficiency.
[0072] S13. Sort the first keyword set and the second keyword set according to word frequency to obtain the first high-frequency word sequence and the second high-frequency word sequence.
[0073] It should be noted that after keyword screening, for example, after removing all stop words and useless words, the electronic device can count the words in the first keyword set and the second keyword set to obtain the number of times each word appears in the first text and the second text, that is, the word frequency of each word in the first text and the second text, and then the electronic device can arrange the words screened from each text according to the word frequency to obtain the first high-frequency word sequence and the second high-frequency word sequence. Optionally, after keyword screening, each text will still be composed of many words, so the electronic device can also delete words with a word frequency below a certain threshold, and only retain some words with a higher word frequency to form the first high-frequency word sequence and the second high-frequency word sequence.
[0074] In this embodiment, the electronic device performs word segmentation on the first text and the second text of text similarity, respectively, to obtain the first word segmentation set and the second word segmentation set, decomposes the first text and the second text into word granularity, and then performs keyword screening according to the first word segmentation set of text similarity and the second word segmentation set of text similarity, respectively, to obtain the first keyword set and the second keyword set, thereby filtering out some useless words, reducing the time of subsequent processing, and improving processing accuracy and efficiency. At the same time, the electronic device also sorts the first keyword set and the second keyword set according to word frequency, respectively, to obtain the first high-frequency word sequence and the second high-frequency word sequence, thereby enabling the text similarity to be characterized according to the high-frequency words of the two texts, so that the rationality of the determined text similarity is greatly increased, and the accuracy is also greatly improved.
[0075] Optionally, a possible implementation of step S13 may be as follows: Figure 4 As shown, specifically including:
[0076] S131. Sort the keywords in the first keyword set according to word frequency to obtain a first high-frequency word initial sequence.
[0077] S132. Determine whether the number of keywords in the first high-frequency word initial sequence is greater than or equal to a preset word frequency threshold; if not, execute S133A; optionally, if yes, execute S133B.
[0078] S133A. Use the first high-frequency word initial sequence as the first high-frequency word sequence.
[0079] S133B, selecting the first N keywords in the first high-frequency word initial sequence as the first high-frequency word sequence; wherein N is equal to the word frequency threshold.
[0080] Specifically, the electronic device arranges the keywords in the first keyword set from large to small according to the word frequency, thereby obtaining the first high-frequency word initial sequence, and then determines whether the number of keywords in the first high-frequency word initial sequence is greater than or equal to the preset word frequency threshold. If it is greater than or equal to, the first N keywords in the first high-frequency word initial sequence are selected as the first high-frequency word sequence; if it is less than, the first high-frequency word initial sequence is used as the first high-frequency word sequence. That is, if the number of keywords in the obtained first high-frequency word initial sequence does not exceed the word frequency threshold, the first high-frequency word initial sequence does not need to be screened, and the first high-frequency word initial sequence is directly used as the first high-frequency word sequence; if the number of keywords in the obtained first high-frequency word initial sequence is greater than the word frequency threshold, the first high-frequency word initial sequence needs to be screened, so that the number of keywords for similarity comparison is controllable, and the screened keywords are representative, so the first N keywords with large word frequencies in the first high-frequency word initial sequence can be selected as the first high-frequency word sequence. It should be noted that the above-mentioned word frequency threshold is represented by N, and the size of the word frequency threshold can be set as needed. If high comparison efficiency is required, a smaller N can be used to select fewer keywords for similarity comparison; if a more accurate comparison result is required, a larger N can be used to select more keywords for similarity comparison. This embodiment does not limit this.
[0081] In this implementation, the electronic device sorts the keywords in the first keyword set according to the word frequency to obtain the first high-frequency word initial sequence, and determines whether the number of keywords in the first high-frequency word initial sequence is greater than or equal to the preset word frequency threshold. When the number of keywords in the first high-frequency word initial sequence is less than the word frequency threshold, the first high-frequency word initial sequence is used as the first high-frequency word sequence, and when the number of keywords in the first high-frequency word initial sequence is greater than or equal to the word frequency threshold, the first N keywords in the first high-frequency word initial sequence are selected as the first high-frequency word sequence. By adopting this method, the first high-frequency word sequence can be determined from the first high-frequency word initial sequence according to the preset word frequency threshold N, thereby avoiding excessive calculation caused by too many keywords, thereby greatly saving system overhead; and when the number of keywords in the first high-frequency word initial sequence is greater than or equal to the word frequency threshold, the first N keywords in the first high-frequency word initial sequence can be selected as the first high-frequency word sequence, thereby realizing the determination of text similarity based on high-frequency words in the first text, thereby making the determination result more accurate.
[0082] Optionally, another possible implementation of the above step S13 can also be as follows Figure 5 As shown, specifically including:
[0083] S134. Sort the keywords in the second keyword set according to word frequency to obtain a second high-frequency word initial sequence.
[0084] S135: Determine whether the number of keywords in the second high-frequency word initial sequence is greater than or equal to a preset word frequency threshold. If not, execute S136A; alternatively, if yes, execute S136B.
[0085] S136A. Use the second high-frequency word initial sequence as the second high-frequency word sequence.
[0086] S136B, selecting the first N keywords in the second high-frequency word initial sequence as the second high-frequency word sequence; wherein N is equal to the word frequency threshold.
[0087] The implementation principle and technical effects of this embodiment can be found in the above Figure 4 The detailed description of the illustrated embodiment will not be repeated here.
[0088] Optionally, based on the above embodiments, step S20 can also be performed as follows: Figure 6 As shown, specifically including:
[0089] S21, obtaining a union word sequence of the first high-frequency word sequence and the second high-frequency word sequence; wherein the words in the union word sequence are the union of all words in the first high-frequency word sequence and the second high-frequency word sequence;
[0090] S22. Extract words from the union word sequence whose front-to-back order is the same as that in the first high-frequency word sequence and the second high-frequency word sequence to generate the common word sequence.
[0091] Specifically, the electronic device selects the union of the first high-frequency word sequence and the second high-frequency word sequence to obtain the union word sequence of the two. For example, the electronic device can perform a union operation on the words in the first high-frequency word sequence and the second high-frequency word sequence, that is, select the words that appear in both the first high-frequency word sequence and the second high-frequency word sequence. For example, it can be a traversal method to search each word that appears in the first high-frequency word sequence in the second high-frequency word sequence, so as to determine the union word sequence according to the search result. Then, the electronic device selects any two words in the union word sequence, and forms a phrase in different arrangement orders, and determines whether the order of the words in each phrase is the same as the order in the first high-frequency word sequence and the second high-frequency word sequence. If the order is the same, it is retained, and if it is different, the phrase is deleted. Then, the electronic device retains the combination of words that have the same order as the order in the first high-frequency word sequence and the second high-frequency word sequence, deletes the repeated words, and arranges them according to the word frequency, so as to obtain a common word sequence.
[0092] In this embodiment, the electronic device obtains the union word sequence of the first high-frequency word sequence and the second high-frequency word sequence, extracts words from the union word sequence that have the same front-to-back order as the first high-frequency word sequence and the second high-frequency word sequence, and generates a common word sequence. Since the words in the union word sequence are the union of all words in the first high-frequency word sequence and the second high-frequency word sequence, the words in the common word sequence are the high-frequency words in the first text and the second text, and the order of the word frequency of each word is the same as that in the first text and the second text, the common word sequence can characterize the similarity between the first text and the second text from two dimensions: the number of high-frequency words and the order of the number of high-frequency words, thereby making the judgment dimension of text similarity more comprehensive, the rationality is greatly increased, and the accuracy is also greatly improved.
[0093] Optionally, based on the above embodiments, step S30 can also be performed as follows: Figure 7 As shown, including:
[0094] S31. Determine the text similarity based on the similarity between the number of words in the common word sequence and the number of words in the union word sequence and / or the order of words. Specifically, the electronic device determines the text similarity based on the number of words in the common word sequence and the number of words in the union word sequence, or the similarity of the order of words, or a combination of the number of words and the similarity of the order of words. For example, the electronic device may arrange the words in the union word sequence according to the word frequency, and then compare the number of words in the common word sequence and the order of each word with the number of words in the union word sequence after arrangement and the order of each word. If the number is similar, such as reaching a preset number threshold, and the order is also similar, such as the order similarity exceeds the preset threshold, then the text similarity is determined to be high; if the number is greatly different and the order is also greatly different, then the text similarity is determined to be low.
[0095] Optionally, a possible implementation of step S31 above may also be: obtain the ratio of the number of words in the common word sequence to the number of words in the union word sequence as the text similarity. Specifically, the implementation may be expressed as: S=NS / NO*100%, where S is the text similarity, NS is the number of words in the common word sequence, and NO is the number of words in the union word sequence. For example, if the first high-frequency word sequence is [A, B, C] and the second high-frequency word sequence is [B, C, D], then the value of NO is 4, which is the number of words in the union of the two sequences [A, B, C, D], and the value of NS is 2, then the text similarity is 50%.
[0096] Optionally, when S is greater than or equal to St, the two articles can be judged to be similar, and when S is less than St, the two articles can be judged to be dissimilar. Wherein St is a set value, and the value range is 0-100%. The higher the value, the stricter the condition for similarity judgment. The recommended value is 90%. Setting St to 90% can make the judgment result more reasonable and more practical. In this implementation, by taking the ratio of the number of words in the common word sequence to the number of words in the union word sequence as the text similarity, this method has a simple calculation method, is easy to implement, and has a high accuracy rate.
[0097] Above Figure 7 In the illustrated embodiment, since the common word sequence can reflect the common features between the two texts from two dimensions, namely the number of high-frequency words and the order of the frequency of high-frequency words, and the union word sequence also includes all the high-frequency words of the two texts, the electronic device determines the text similarity by similarity between the number of words and / or the order of words in the common word sequence and the union word sequence, with more dimensions to rely on, thereby greatly increasing the rationality of the result and greatly improving the accuracy.
[0098] Here, a specific example is used to illustrate the embodiment of the present application. After the first text is segmented and screened, a first keyword set is obtained, represented as [C1, C2, C3...CM]. The first keyword set is arranged in descending order according to the frequency of the words appearing in the first text to obtain a first high-frequency word initial sequence [A1, A2, A3...AM]. The first P words of the first high-frequency word initial sequence are taken to form a first high-frequency word sequence. Wherein, P = Max(M,N). The larger N is, the more accurate the text similarity is. According to the above method, the second text is operated to obtain a second high-frequency word sequence.
[0099] It should be understood that although Figure 2-7 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 2-7 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0100] In one embodiment, Figure 8 As shown, a text similarity determination device is provided, comprising:
[0101] An acquisition module 100 is used to acquire a first high-frequency word sequence of a first text and a second high-frequency word sequence of a second text; the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from high to low according to word frequency;
[0102] The processing module 200 is used to extract common words from the first high-frequency word sequence and the second high-frequency word sequence to obtain the common word sequence of the first text and the second text; wherein the words in the common word sequence are arranged from large to small according to word frequency, and the order of any two words in the common word sequence is the same as the order of the any two words in the first high-frequency word sequence and the second high-frequency word sequence.
[0103] The determination module 300 is used to determine the text similarity between the first text and the second text according to the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence.
[0104] In one embodiment, the processing module 200 is specifically used to obtain a union word sequence of the first high-frequency word sequence and the second high-frequency word sequence; wherein the words in the union word sequence are the union of all words in the first high-frequency word sequence and the second high-frequency word sequence; from the union word sequence, extract words whose front-to-back order is the same as that in the first high-frequency word sequence and the second high-frequency word sequence to generate the common word sequence.
[0105] In one embodiment, the determination module 300 is specifically configured to determine the text similarity according to the similarity between the number of words and / or the order of words in the common word sequence and the union word sequence.
[0106] In one embodiment, the determination module 300 is specifically configured to obtain a ratio of the number of words in the common word sequence to the number of words in the union word sequence as the text similarity.
[0107] In one embodiment, the acquisition module 100 is specifically used to perform word segmentation on the first text and the second text respectively to obtain a first word segmentation set and a second word segmentation set; perform keyword screening in the first word segmentation set and the second word segmentation set respectively to obtain a first keyword set and a second keyword set; sort the first keyword set and the second keyword set according to word frequency respectively to obtain the first high-frequency word sequence and the second high-frequency word sequence.
[0108] In one embodiment, the acquisition module 100 is specifically used to sort the keywords in the first keyword set according to word frequency to obtain a first high-frequency word initial sequence; determine whether the number of keywords in the first high-frequency word initial sequence is greater than or equal to a preset word frequency threshold; if not, use the first high-frequency word initial sequence as the first high-frequency word sequence.
[0109] In one embodiment, the acquisition module 100 is specifically used to select the first N keywords in the first high-frequency word initial sequence as the first high-frequency word sequence if the number of words in the first high-frequency word initial sequence is greater than or equal to the word frequency threshold; the N is equal to the word frequency threshold.
[0110] In one embodiment, the acquisition module 100 is specifically used to sort the keywords in the second keyword set according to word frequency to obtain a second high-frequency word initial sequence; determine whether the number of keywords in the second high-frequency word initial sequence is greater than or equal to a preset word frequency threshold; if not, use the second high-frequency word initial sequence as the second high-frequency word sequence.
[0111] In one embodiment, the acquisition module 100 is specifically used to select the first N keywords in the second high-frequency word initial sequence as the second high-frequency word sequence if the number of words in the second high-frequency word initial sequence is greater than or equal to the word frequency threshold; the N is equal to the word frequency threshold.
[0112] For the specific definition of the text similarity determination device, please refer to the definition of the text similarity determination method above, which will not be repeated here. Each module in the above-mentioned text similarity determination device can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the electronic device in the form of hardware, or can be stored in the memory of the electronic device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0113] In one embodiment, an electronic device is provided, the electronic device comprising at least one processor, at least one memory connected to the processor, and a bus; wherein the processor and the memory communicate with each other through the bus; the processor is used to call program instructions in the memory to perform the following steps:
[0114] Acquire a first high-frequency word sequence of a first text and a second high-frequency word sequence of a second text; the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from large to small according to word frequency;
[0115] Extracting common words from the first high-frequency word sequence and the second high-frequency word sequence to obtain a common word sequence of the first text and the second text; wherein the words in the common word sequence are arranged from large to small according to word frequency, and the order of any two words in the common word sequence is the same as the order of the any two words in the first high-frequency word sequence and the second high-frequency word sequence;
[0116] The text similarity between the first text and the second text is determined based on the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence.
[0117] In one embodiment, the processor is used to call the program instructions in the memory and further execute the following steps:
[0118] Obtaining a union word sequence of the first high-frequency word sequence and the second high-frequency word sequence; wherein the words in the union word sequence are the union of all words in the first high-frequency word sequence and the second high-frequency word sequence;
[0119] From the union word sequence, words whose front-to-back order is the same as that in the first high-frequency word sequence and the second high-frequency word sequence are extracted to generate the common word sequence.
[0120] In one embodiment, the processor is used to call the program instructions in the memory and further execute the following steps:
[0121] The text similarity is determined based on the similarity between the number of words and / or the order of words in the common word sequence and the union word sequence.
[0122] In one embodiment, the processor is used to call the program instructions in the memory and further execute the following steps:
[0123] The ratio of the number of words in the common word sequence to the number of words in the union word sequence is obtained as the text similarity.
[0124] In one embodiment, the processor is used to call the program instructions in the memory and further execute the following steps:
[0125] Perform word segmentation on the first text and the second text respectively to obtain a first word segmentation set and a second word segmentation set;
[0126] Perform keyword screening in the first word segmentation set and the second word segmentation set respectively to obtain a first keyword set and a second keyword set;
[0127] The first keyword set and the second keyword set are sorted according to word frequency to obtain the first high-frequency word sequence and the second high-frequency word sequence.
[0128] In one embodiment, the processor is used to call the program instructions in the memory and further performs the following steps:
[0129] Sort the keywords in the first keyword set according to word frequency to obtain a first high-frequency word initial sequence;
[0130] Determining whether the number of keywords in the first high-frequency word initial sequence is greater than or equal to a preset word frequency threshold;
[0131] If not, the first high-frequency word initial sequence is used as the first high-frequency word sequence.
[0132] In one embodiment, the processor is used to call the program instructions in the memory and further execute the following steps:
[0133] If the number of words in the first high-frequency word initial sequence is greater than or equal to the word frequency threshold, the first N keywords in the first high-frequency word initial sequence are selected as the first high-frequency word sequence; wherein N is equal to the word frequency threshold.
[0134] In one embodiment, the processor is used to call the program instructions in the memory and further execute the following steps:
[0135] Sorting the keywords in the second keyword set according to word frequency to obtain a second high-frequency word initial sequence;
[0136] Determining whether the number of keywords in the second high-frequency word initial sequence is greater than or equal to a preset word frequency threshold;
[0137] If not, the second high-frequency word initial sequence is used as the second high-frequency word sequence.
[0138] In one embodiment, the processor is used to call the program instructions in the memory and further execute the following steps:
[0139] If the number of words in the second high-frequency word initial sequence is greater than or equal to the word frequency threshold, the first N keywords in the second high-frequency word initial sequence are selected as the second high-frequency word sequence; N is equal to the word frequency threshold.
[0140] It should be clear that the process of the processor calling the program instruction in the embodiment of the present application is consistent with the execution process of each step in the above method, and the details can be found in the description above.
[0141] In one embodiment, 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 following steps are implemented:
[0142] Acquire a first high-frequency word sequence of a first text and a second high-frequency word sequence of a second text; the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from large to small according to word frequency;
[0143] Extracting common words from the first high-frequency word sequence and the second high-frequency word sequence to obtain a common word sequence of the first text and the second text; wherein the words in the common word sequence are arranged from large to small according to word frequency, and the order of any two words in the common word sequence is the same as the order of the any two words in the first high-frequency word sequence and the second high-frequency word sequence;
[0144] The text similarity between the first text and the second text is determined based on the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence.
[0145] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0146] Obtaining a union word sequence of the first high-frequency word sequence and the second high-frequency word sequence; wherein the words in the union word sequence are the union of all words in the first high-frequency word sequence and the second high-frequency word sequence;
[0147] From the union word sequence, words whose front-to-back order is the same as that in the first high-frequency word sequence and the second high-frequency word sequence are extracted to generate the common word sequence.
[0148] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0149] The text similarity is determined based on the similarity between the number of words and / or the order of words in the common word sequence and the union word sequence.
[0150] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0151] The ratio of the number of words in the common word sequence to the number of words in the union word sequence is obtained as the text similarity.
[0152] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0153] Perform word segmentation on the first text and the second text respectively to obtain a first word segmentation set and a second word segmentation set;
[0154] Perform keyword screening in the first word segmentation set and the second word segmentation set respectively to obtain a first keyword set and a second keyword set;
[0155] The first keyword set and the second keyword set are sorted according to word frequency to obtain the first high-frequency word sequence and the second high-frequency word sequence.
[0156] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0157] Sort the keywords in the first keyword set according to word frequency to obtain a first high-frequency word initial sequence;
[0158] Determining whether the number of keywords in the first high-frequency word initial sequence is greater than or equal to a preset word frequency threshold;
[0159] If not, the first high-frequency word initial sequence is used as the first high-frequency word sequence.
[0160] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0161] If the number of words in the first high-frequency word initial sequence is greater than or equal to the word frequency threshold, the first N keywords in the first high-frequency word initial sequence are selected as the first high-frequency word sequence; wherein N is equal to the word frequency threshold.
[0162] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0163] Sorting the keywords in the second keyword set according to word frequency to obtain a second high-frequency word initial sequence;
[0164] Determining whether the number of keywords in the second high-frequency word initial sequence is greater than or equal to a preset word frequency threshold;
[0165] If not, the second high-frequency word initial sequence is used as the second high-frequency word sequence.
[0166] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0167] If the number of words in the second high-frequency word initial sequence is greater than or equal to the word frequency threshold, the first N keywords in the second high-frequency word initial sequence are selected as the second high-frequency word sequence; N is equal to the word frequency threshold.
[0168] It should be clear that the process of the processor executing the computer program in the embodiment of the present application is consistent with the execution process of each step in the above method, and the details can be found in the description above.
[0169] 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 this 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).
[0170] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above 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.
[0171] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. 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 of the present application shall be subject to the attached claims.
Claims
1. A method for determining text similarity, characterized in that: The method comprises: Acquire a first high-frequency word sequence of a first text and a second high-frequency word sequence of a second text; the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from large to small according to word frequency; Obtaining a union word sequence of the first high-frequency word sequence and the second high-frequency word sequence; wherein the words in the union word sequence are the union of all words in the first high-frequency word sequence and the second high-frequency word sequence; Extracting words whose front-to-back order is the same as that in the first high-frequency word sequence and the second high-frequency word sequence from the union word sequence to generate a common word sequence; wherein the words in the common word sequence are arranged from large to small according to word frequency, and the order of any two words in the common word sequence is the same as the order of the any two words in the first high-frequency word sequence and the second high-frequency word sequence; Determining the text similarity based on the similarity between the number of words and / or the order of words in the common word sequence and the union word sequence; The determining of the text similarity based on the similarity between the number of words and / or the order of words in the common word sequence and the union word sequence comprises: Obtaining a ratio of the number of words in the common word sequence to the number of words in the union word sequence as the text similarity; or, Obtaining a sequence of words in the common word sequence and comparing it with a sequence of words in the union word sequence as the text similarity; or, The number of words in the common word sequence and the order of words in the common word sequence are obtained and compared with the number of words in the union word sequence and the order of words in the union word sequence, respectively, as the text similarity.
2. The method according to claim 1, characterized in that The step of acquiring a first high-frequency word sequence of the first text and a second high-frequency word sequence of the second text comprises: Perform word segmentation on the first text and the second text respectively to obtain a first word segmentation set and a second word segmentation set; Perform keyword screening in the first word segmentation set and the second word segmentation set respectively to obtain a first keyword set and a second keyword set; The first keyword set and the second keyword set are sorted according to word frequency to obtain the first high-frequency word sequence and the second high-frequency word sequence.
3. The method according to claim 2, characterized in that The step of sorting the first keyword set and the second keyword set according to word frequency to obtain the first high-frequency word sequence and the second high-frequency word sequence comprises: Sort the keywords in the first keyword set according to word frequency to obtain a first high-frequency word initial sequence; Determining whether the number of keywords in the first high-frequency word initial sequence is greater than or equal to a preset word frequency threshold; If not, the first high-frequency word initial sequence is used as the first high-frequency word sequence; If so, the first N keywords in the first high-frequency word initial sequence are selected as the first high-frequency word sequence; the N is equal to the word frequency threshold.
4. The method according to claim 2 or 3, characterized in that: The step of sorting the first keyword set and the second keyword set according to word frequency to obtain the first high-frequency word sequence and the second high-frequency word sequence comprises: Sorting the keywords in the second keyword set according to word frequency to obtain a second high-frequency word initial sequence; Determining whether the number of keywords in the second high-frequency word initial sequence is greater than or equal to a preset word frequency threshold; If not, the second high-frequency word initial sequence is used as the second high-frequency word sequence; If so, the first N keywords in the second high-frequency word initial sequence are selected as the second high-frequency word sequence; the N is equal to the word frequency threshold.
5. A device for determining text similarity, characterized in that: The device comprises: An acquisition module, configured to acquire a first high-frequency word sequence of a first text and a second high-frequency word sequence of a second text; the words in the first high-frequency word sequence and the second high-frequency word sequence are arranged from high to low according to word frequency; A processing module, used to obtain a union word sequence of the first high-frequency word sequence and the second high-frequency word sequence; wherein the words in the union word sequence are the union of all words in the first high-frequency word sequence and the second high-frequency word sequence; A processing module is used to extract words whose front-to-back order is the same as that in the first high-frequency word sequence and the second high-frequency word sequence from the union word sequence, and generate a common word sequence; wherein the words in the common word sequence are arranged from large to small according to word frequency, and the order of any two words in the common word sequence is the same as the order of the any two words in the first high-frequency word sequence and the second high-frequency word sequence; A determination module, configured to determine the text similarity between the first text and the second text according to the first high-frequency word sequence, the second high-frequency word sequence and the common word sequence; The determination module is used to obtain the ratio of the number of words in the common word sequence to the number of words in the union word sequence as the text similarity; or, Obtaining a sequence of words in the common word sequence and comparing it with a sequence of words in the union word sequence as the text similarity; or, The number of words in the common word sequence and the order of words in the common word sequence are obtained and compared with the number of words in the union word sequence and the order of words in the union word sequence, respectively, as the text similarity.
6. 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 4 are implemented.
7. An electronic device, comprising at least one processor, and at least one memory and a bus connected to the processor; wherein: The processor and the memory communicate with each other via the bus; The processor is used to call the program instructions in the memory to execute the text similarity determination method according to any one of claims 1 to 4.
