Lyric analysis method and system
By using the string matching algorithm and cache mechanism in the lyrics parsing system, the problem of low lyrics parsing efficiency is solved, and rapid matching and update are achieved, improving the parsing efficiency and synchronous display effect of lyrics file.
Patent Information
- Application Number
- CN202410996786.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-24
- Publication Date
- 2024-11-12
AI Technical Summary
In the prior art, lyric parsing efficiency is low, especially for longer lyric files, the parsing time is long, which affects the synchronous display of lyrics.
The string matching algorithm is used to extract and store the timestamps and text content in the lyrics file, and the parsed text is stored using cache storage, and the parsed text is updated according to the modification of the lyrics file to avoid repeated parsing. Specific methods include matching using regular expressions, KMP algorithms, or Boyer-Moore algorithms, and improving efficiency through sharding and parallel processing.
By cache storage of parsing text and fast matching algorithms, the lyric parsing time is reduced, the analysis efficiency is improved, and the delay in lyrics synchronous display is reduced.
Smart Images

Figure CN118940744A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of multimedia, and in particular to a lyrics analysis method and system. Background Art
[0002] Karaoke is one of the important functions of KTV song request machines. In order to improve the user experience, the lyrics and the song audio need to be displayed on the screen synchronously.
[0003] The existing technical solutions usually adopt the following method: parse the lyrics file into a list containing timestamps and text content, and then find and display the corresponding lyrics content according to the playback progress. This method has the following problems: the text parsing process usually needs to traverse the entire lyrics file, which is inefficient. Especially for longer lyrics files, the parsing time will be longer, affecting the synchronous display of the lyrics.
[0004] There is currently no effective solution to the above problems in the prior art. Summary of the invention
[0005] To solve the above problems, the present invention provides a lyric parsing method and system, which stores the parsed text to avoid re-parsing; uses a string matching algorithm to match the timestamps and corresponding text content in the lyric file, so as to quickly obtain the text content corresponding to each timestamp; updates the parsed text corresponding to the modified lyric file to solve the problems of long lyric parsing time and low parsing efficiency in the prior art.
[0006] To achieve the above-mentioned purpose, an embodiment of the present invention provides a lyric parsing method, including: obtaining a lyric file, and determining whether there is a parsed text corresponding to the lyric file in a cache; when the parsed text corresponding to the lyric file does not exist in the cache, using a string matching algorithm to extract the timestamp and corresponding text content in the lyric file to obtain the parsed text, storing the parsed text in the cache, and displaying the corresponding text content according to the timestamp in the parsed text; when the parsed text corresponding to the lyric file exists in the cache, updating the corresponding parsed text according to the modification of the lyric file, and displaying the corresponding text content according to the timestamp in the updated parsed text.
[0007] Further optionally, the string matching algorithm includes a regular expression matching algorithm, a KMP algorithm and a Boyer-Moore algorithm; the use of the string matching algorithm to extract the timestamp and the corresponding text content in the lyrics file includes: determining a target regular expression according to the text type of the lyrics file, and using the target regular expression to extract the timestamp and the corresponding text content in the lyrics file; or, using the KMP algorithm to locate the timestamp identifier in the lyrics file, and extracting the timestamp and the corresponding text content according to the timestamp identifier; or, using the Boyer-Moore algorithm to locate the timestamp identifier in the lyrics file, and extracting the timestamp and the corresponding text content according to the timestamp identifier.
[0008] Further optionally, the use of a string matching algorithm to extract the timestamp and corresponding text content in the lyrics file to obtain a parsed text includes: segmenting the lyrics file according to preset segmentation conditions to obtain multiple lyrics fragments; assigning a thread to each lyrics fragment, and for the lyrics fragments in each thread, using the string matching algorithm to extract the time information of the timestamp and the corresponding text content to obtain the parsed result corresponding to each lyrics fragment; and summarizing all the parsing results to obtain the parsed text.
[0009] Further optionally, updating the corresponding parsed text according to the modification of the lyrics file includes: comparing the modification time or hash value of the lyrics file and the corresponding parsed text to determine whether the lyrics file has been modified; when the lyrics file has not been modified, loading the parsed text in the cache; when the lyrics file has been modified, using a text difference algorithm to calculate the difference between the lyrics file and the old lyrics file; using a string matching algorithm to extract the timestamp and corresponding text content in the difference lyrics file to obtain an updated text; using the updated text to update the corresponding parsed text, and recording the latest modification time or latest hash value of the updated parsed text; wherein the old lyrics file corresponds to the parsed text in the cache.
[0010] Further optionally, after obtaining the lyrics file, the method includes: identifying and deleting tabs, line breaks and extra spaces in the lyrics file; identifying and deleting tags and comments in the lyrics file.
[0011] On the other hand, the present invention provides a lyric parsing system, including: a data acquisition module, used to acquire a lyric file and determine whether there is a parsed text corresponding to the lyric file in a cache; a first parsing module, used to extract the timestamp and corresponding text content in the lyric file using a string matching algorithm to obtain the parsed text when the parsed text corresponding to the lyric file does not exist in the cache, store the parsed text in the cache, and display the corresponding text content according to the timestamp in the parsed text; a second parsing module, used to update the corresponding parsed text according to the modification of the lyric file when the parsed text corresponding to the lyric file exists in the cache, and display the corresponding text content according to the timestamp in the updated parsed text.
[0012] Further optionally, the string matching algorithm includes a regular expression matching algorithm, a KMP algorithm and a Boyer-Moore algorithm; the first parsing module includes: a first content extraction submodule, used to determine a target regular expression according to a text type of the lyrics file, and use the target regular expression to extract the timestamp and corresponding text content in the lyrics file; a second content extraction submodule, used to use the KMP algorithm to locate the timestamp identifier in the lyrics file, and extract the timestamp and corresponding text content according to the timestamp identifier; a third content extraction submodule, used to use the Boyer-Moore algorithm to locate the timestamp identifier in the lyrics file, and extract the timestamp and corresponding text content according to the timestamp identifier.
[0013] Further optionally, the first parsing module includes: a segmentation submodule, used to segment the lyrics file according to preset segmentation conditions to obtain multiple lyrics fragments; a parallel parsing submodule, used to assign a thread to each lyrics fragment, and for the lyrics fragment in each thread, using the string matching algorithm to extract the time information of the timestamp and the corresponding text content to obtain the parsing result corresponding to each lyrics fragment; and a summary submodule, used to summarize all parsing results to obtain the parsed text.
[0014] Further optionally, the second parsing module includes: a judgment submodule, used to compare the modification time or hash value of the lyrics file and the corresponding parsed text to determine whether the lyrics file has been modified; a loading submodule, used to load the parsed text in the cache when the lyrics file has not been modified; an updating submodule, used to calculate the difference between the lyrics file and the old lyrics file using a text difference algorithm when the lyrics file has been modified; using a string matching algorithm to extract the timestamp and corresponding text content in the difference lyrics file to obtain an updated text; using the updated text to update the corresponding parsed text, and recording the latest modification time or latest hash value of the updated parsed text; wherein the old lyrics file corresponds to the parsed text in the cache.
[0015] Further optionally, the system also includes: a first preprocessing module for identifying and deleting tabs, line breaks and extra spaces in the lyrics file; and a second preprocessing module for identifying and deleting tags and comments in the lyrics file.
[0016] The above technical solution has the following beneficial effects: by storing the parsed text in the cache, re-parsing of the corresponding lyrics file is avoided; by using a string matching algorithm to quickly match the timestamp in the lyrics file and the text content corresponding to the timestamp, the tabulation time is reduced and the parsing efficiency is improved; the parsed text of the parsed lyrics file is updated according to the modification status, which reduces the time for re-parsing and improves the parsing efficiency of the lyrics file. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0018] Figure 1 is a flow chart of a lyrics parsing method provided by an embodiment of the present invention;
[0019] Figure 2 is a flowchart of a text parsing method provided by an embodiment of the present invention;
[0020] Figure 3 is a flow chart of a parsed text updating method provided by an embodiment of the present invention;
[0021] Figure 4 is a flow chart of a preprocessing method provided by an embodiment of the present invention;
[0022] Figure 5 is a structural diagram of a lyrics parsing system provided by an embodiment of the present invention;
[0023] Figure 6 is a schematic diagram of the structure of a submodule of the first parsing module for content extraction provided by an embodiment of the present invention;
[0024] Figure 7 It is a schematic diagram of the structure of a submodule of the first parsing module for text parsing provided by an embodiment of the present invention;
[0025] Figure 8 is a schematic diagram of the structure of a second parsing module provided in an embodiment of the present invention;
[0026] Fig. 9It is a structural schematic diagram of a module for data preprocessing provided in an embodiment of the present invention.
[0027] Figure markings: 100-data acquisition module; 200-first parsing module; 2001-first content extraction submodule; 2002-second content extraction submodule; 2003-third content extraction submodule; 2004-segmentation submodule; 2005-parallel parsing submodule; 2006-aggregation submodule; 300-second parsing module; 3001-judgment submodule; 3002-loading submodule; 3003-update submodule; 400-first preprocessing module; 500-second preprocessing module. DETAILED DESCRIPTION
[0028] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0029] In order to solve the problem of long lyrics parsing time in the prior art, an embodiment of the present invention provides a lyrics parsing method. Figure 1 is a flowchart of a lyrics parsing method provided by an embodiment of the present invention. Figure 1 As shown, the method includes:
[0030] S1. Obtain a lyrics file and determine whether there is a parsed text corresponding to the lyrics file in the cache.
[0031] When a user requests a song, the system obtains the lyrics file of the song and determines whether the parsed text corresponding to the lyrics file exists in the cache.
[0032] The lyrics file is a file containing the song timeline and lyrics text, such as an LRC file, a KRC file, etc.
[0033] As an optional implementation, the corresponding parsed text in the cache may be determined by the name or identifier of the lyrics file.
[0034] Parsed text is a structured data representation that separates and organizes the timestamps and lyrics content in the original lyrics file for subsequent processing and display. Parsed text is usually stored in the form of key-value pairs, where the key is the timestamp and the value is the corresponding lyrics text.
[0035] S2. When the parsed text corresponding to the lyrics file does not exist in the cache, a string matching algorithm is used to extract the timestamp and corresponding text content in the lyrics file to obtain the parsed text, which is stored in the cache, and the corresponding text content is displayed according to the timestamp in the parsed text.
[0036] When the parsed text corresponding to the lyrics file does not exist in the cache, it means that the lyrics file is being parsed for the first time. A string matching algorithm is used to locate the timestamp and the text content corresponding to the timestamp, thereby extracting all the lyrics and the corresponding time in the entire lyrics file to obtain the parsed text, and displaying the lyrics in chronological order based on the information in the parsed text content.
[0037] The timestamp is the time point when a certain sentence or word in the lyrics text begins to be displayed, usually in milliseconds. The text content is the lyrics text information corresponding to the timestamp.
[0038] S3. When the parsed text corresponding to the lyrics file exists in the cache, the corresponding parsed text is updated according to the modification of the lyrics file, and the corresponding text content is displayed according to the timestamp in the updated parsed text.
[0039] When the parsed text corresponding to the lyrics file exists in the cache, the lyrics file does not need to be fully parsed, and the parsed text can be updated according to the modified content, and the lyrics can be displayed in chronological order according to the information in the updated parsed text.
[0040] As an optional implementation, the string matching algorithm includes a regular expression matching algorithm, a KMP algorithm and a Boyer-Moore algorithm;
[0041] A string matching algorithm is used to extract the timestamp and corresponding text content in the lyrics file, including:
[0042] S201, determining a target regular expression according to the text type of the lyrics file, and using the target regular expression to extract the timestamp and corresponding text content in the lyrics file.
[0043] Different regular expressions are required for lyrics files of different formats. For example, for lyrics files in LRC format, the following regular expression is used for matching:
[0044] \[(? <minute> \d{2}):(? <second> \d{2})\.(? <millisecond> \d{2,3})\](? <content>.*)
[0045] in, <minute>Matching minutes, <second>Matches seconds, <millisecond>Matches milliseconds, <content>Match the lyrics file content. The above regular expression can be used to directly extract the timestamp and its corresponding text content.
[0046] Regular expressions can be determined in advance according to different file types, and when matching, you only need to select according to the file type.
[0047] Or, S202, using the KMP algorithm to locate the timestamp identifier in the lyrics file, and extracting the timestamp and the corresponding text content according to the timestamp identifier.
[0048] The KMP algorithm is used to efficiently match timestamp identifiers (such as "["), so as to quickly locate the timestamp position and then extract the timestamp and text content.
[0049] Specifically, after locating the "[" symbol in the lyrics file using the KMP algorithm, read backward until encountering "]", then extract the timestamp [mm:ss.xx] or [mm:ss.xxx]. Continue to read backward until the end of the line or the next "[", then extract the corresponding text content.
[0050] Or, S203, using the Boyer-Moore algorithm to locate the timestamp identifier in the lyrics file, and extracting the timestamp and the corresponding text content according to the timestamp identifier.
[0051] The Boyer-Moore algorithm is used to efficiently match timestamp identifiers, thereby quickly locating the timestamp and then extracting the timestamp and text content.
[0052] Specifically, after matching the lyrics file to the "[" symbol in the lyrics file using the Boyer-Moore algorithm, read backward until encountering "]", then extract the timestamp [mm:ss.xx] or [mm:ss.xxx]. Continue to read backward until the end of the line or the next "[", then extract the corresponding text content.
[0053] As an optional implementation, Figure 2 is a flowchart of a text parsing method provided by an embodiment of the present invention. Figure 2 As shown, a string matching algorithm is used to extract the timestamp and corresponding text content in the lyrics file to obtain the parsed text, including:
[0054] S204: Segment the lyrics file according to a preset segmentation condition to obtain a plurality of lyrics segments.
[0055] The lyrics file is segmented as a whole to divide the lyrics file into multiple lyrics segments.
[0056] Furthermore, before the lyrics file is segmented, the text volume of the lyrics file can be judged. When the text volume of the lyrics file is greater than a preset text volume threshold, the lyrics file is segmented. Otherwise, the lyrics file is not segmented, and the timestamp and corresponding text content are directly extracted through a string matching algorithm.
[0057] As an optional implementation, the preset segmentation condition is segmentation according to a preset number of lines or according to a preset number of bytes. It should be noted that the timestamp identifier and the number are not segmented during segmentation to avoid damaging the timestamp during segmentation and affecting the parsing of the lyrics file.
[0058] S205, a thread is allocated to each lyric segment, and for the lyric segment in each thread, a string matching algorithm is used to extract the time information of the timestamp and the corresponding text content to obtain the parsing result corresponding to each lyric segment.
[0059] A thread pool is created in advance to manage and execute parsing tasks. After the lyrics file is segmented, a separate thread is assigned to each lyrics segment for parallel parsing. Specifically, the lyrics file in each thread is timestamped and the corresponding text content is located and extracted using regular expressions, KMP algorithm or Boyer-Moore algorithm. Finally, each thread obtains the parsing result of the lyrics segment.
[0060] S206: Summarize all the parsing results to obtain the parsed text.
[0061] All parsing results are sorted and aggregated according to timestamps to obtain a parsed text, which is a complete lyrics data structure.
[0062] As an optional implementation, Figure 3 is a flowchart of a parsed text updating method provided by an embodiment of the present invention. Figure 3 As shown, the corresponding parsed text is updated according to the modification of the lyrics file, including:
[0063] S301, comparing the modification time or hash value of the lyrics file with the corresponding parsed text to determine whether the lyrics file has been modified;
[0064] S302, when the lyrics file is not modified, loading the parsed text in the cache;
[0065] S303. When the lyrics file has been modified, a text difference algorithm is used to calculate the difference between the lyrics file and the old lyrics file; a string matching algorithm is used to extract the timestamp and corresponding text content in the difference lyrics file to obtain an updated text; the updated text is used to update the corresponding parsed text, and the latest modification time or the latest hash value of the updated parsed text is recorded; wherein the old lyrics file corresponds to the parsed text in the cache.
[0066] After the lyrics file is parsed for the first time, the parsed text of the lyrics file is stored, and the last modification time of the corresponding lyrics file is recorded, or the hash value of the lyrics file is recorded.
[0067] When a new lyrics file is obtained, and the corresponding parsed file of the lyrics file is found in the cache, it is necessary to further determine whether its modification time is consistent with the last modification time of the parsed file. If they are consistent, it is considered that the lyrics file has not been modified, and the parsed text in the cache can be directly used for display. Alternatively, it is determined whether the hash value of the new lyrics file is consistent with the hash value corresponding to the parsed file. If they are consistent, it is considered that the lyrics file has not been modified, and the parsed text in the cache can be directly used for display.
[0068] If the modification time or hash value is inconsistent, the lyrics file is considered to have been modified. The difference lyrics file between the new lyrics file and the old lyrics file needs to be calculated through the text difference algorithm. The difference lyrics file includes the difference content between the two. The string matching algorithm is used to match the timestamp of the difference lyrics file and extract the corresponding text content to obtain the updated text, and the updated text is used to update the parsed text. After the parsed text is updated, the latest modification time or hash value corresponding to the parsed text needs to be updated. Ensure that only the changed part is processed, and the entire part is not re-parsed.
[0069] Specifically, the updated text includes newly added, deleted or modified text content.
[0070] The newly added content is inserted into the corresponding position of the parsed text according to the timestamp; the deleted content is directly deleted; the modified content is replaced and updated.
[0071] As an optional implementation, the text difference algorithm includes Myers algorithm, Levenshtein distance, etc. The calculation of the hash value includes MD5, SHA-1, SHA-256, etc.
[0072] As an optional implementation, Figure 4 is a flow chart of a preprocessing method provided by an embodiment of the present invention, such as Figure 4 As shown, after obtaining the lyrics file, it includes:
[0073] S4, identifying and deleting tabs, line breaks and extra spaces in the lyrics file;
[0074] S5. Identify and delete tags and comments in the lyrics file.
[0075] After obtaining the lyrics file, the lyrics file is preprocessed to reduce the impact of redundant data on the parsing process, including: removing spaces before and after each line, as well as extra spaces between lines; removing non-printing characters and special control characters, such as tabs, carriage returns, line feeds, etc.; and deleting tags and comments in the lyrics file.
[0076] Furthermore, it is also possible to detect and process abnormal values in timestamps (such as negative values or values exceeding a normal range), and convert all timestamps into a unified format (such as [mm:ss.xx] or [mm:ss.xxx]).
[0077] The embodiment of the present invention also provides a lyrics analysis system. Figure 5 is a schematic diagram of the structure of the lyrics parsing system provided by an embodiment of the present invention. Figure 5 As shown, the system includes:
[0078] The data acquisition module 100 is used to acquire the lyrics file and determine whether there is a parsed text corresponding to the lyrics file in the cache.
[0079] When a user requests a song, the system obtains the lyrics file of the song and determines whether the parsed text corresponding to the lyrics file exists in the cache.
[0080] The lyrics file is a file containing the song timeline and lyrics text, such as an LRC file, a KRC file, etc.
[0081] As an optional implementation, the corresponding parsed text in the cache may be determined by the name or identifier of the lyrics file.
[0082] Parsed text is a structured data representation that separates and organizes the timestamps and lyrics content in the original lyrics file for subsequent processing and display. Parsed text is usually stored in the form of key-value pairs, where the key is the timestamp and the value is the corresponding lyrics text.
[0083] The first parsing module 200 is used to extract the timestamp and corresponding text content in the lyrics file using a string matching algorithm when there is no parsed text corresponding to the lyrics file in the cache, obtain the parsed text, store the parsed text in the cache, and display the corresponding text content according to the timestamp in the parsed text.
[0084] When the parsed text corresponding to the lyrics file does not exist in the cache, it means that the lyrics file is being parsed for the first time. A string matching algorithm is used to locate the timestamp and the text content corresponding to the timestamp, thereby extracting all the lyrics and the corresponding time in the entire lyrics file to obtain the parsed text, and displaying the lyrics in chronological order based on the information in the parsed text content.
[0085] The timestamp is the time point when a certain sentence or word in the lyrics text begins to be displayed, usually in milliseconds. The text content is the lyrics text information corresponding to the timestamp.
[0086] The second parsing module 300 is used to update the corresponding parsed text according to the modification of the lyrics file when the parsed text corresponding to the lyrics file exists in the cache, and display the corresponding text content according to the timestamp in the updated parsed text.
[0087] When the parsed text corresponding to the lyrics file exists in the cache, the lyrics file does not need to be fully parsed, and the parsed text can be updated according to the modified content, and the lyrics can be displayed in chronological order according to the information in the updated parsed text.
[0088] As an optional implementation, the string matching algorithm includes a regular expression matching algorithm, a KMP algorithm and a Boyer-Moore algorithm;
[0089] Figure 6 is a schematic diagram of the structure of a submodule of the first parsing module for content extraction provided by an embodiment of the present invention, such as Figure 6 As shown, the first parsing module 200 includes:
[0090] The first content extraction submodule 2001 is used to determine a target regular expression according to the text type of the lyrics file, and use the target regular expression to extract the timestamp and the corresponding text content in the lyrics file.
[0091] Different regular expressions are required for lyrics files of different formats. For example, for lyrics files in LRC format, the following regular expression is used for matching:
[0092] \[(? <minute> \d{2}):(? <second> \d{2})\.(? <millisecond> \d{2,3})\](? <content>.*)
[0093] in, <minute>Matching minutes, <second>Matches seconds, <millisecond>Matches milliseconds, <content>Match the lyrics file content. The above regular expression can be used to directly extract the timestamp and its corresponding text content.
[0094] Regular expressions can be determined in advance according to different file types, and when matching, you only need to select according to the file type.
[0095] The second content extraction submodule 2002 is used to locate the timestamp identifier in the lyrics file using the KMP algorithm, and extract the timestamp and the corresponding text content according to the timestamp identifier.
[0096] The KMP algorithm is used to efficiently match timestamp identifiers (such as "["), so as to quickly locate the timestamp position and then extract the timestamp and text content.
[0097] Specifically, after locating the "[" symbol in the lyrics file using the KMP algorithm, read backward until encountering "]", then extract the timestamp [mm:ss.xx] or [mm:ss.xxx]. Continue to read backward until the end of the line or the next "[", then extract the corresponding text content.
[0098] The third content extraction submodule 2003 is used to locate the timestamp identifier in the lyrics file using the Boyer-Moore algorithm, and extract the timestamp and the corresponding text content according to the timestamp identifier.
[0099] The Boyer-Moore algorithm is used to efficiently match timestamp identifiers, thereby quickly locating the timestamp and then extracting the timestamp and text content.
[0100] Specifically, after matching the lyrics file to the "[" symbol in the lyrics file using the Boyer-Moore algorithm, read backward until encountering "]", then extract the timestamp [mm:ss.xx] or [mm:ss.xxx]. Continue to read backward until the end of the line or the next "[", then extract the corresponding text content.
[0101] As an optional implementation, Figure 7 is a schematic diagram of the structure of the submodules of the first parsing module for text parsing provided by an embodiment of the present invention, such as Figure 7 As shown, the first parsing module 200 includes:
[0102] The segmentation submodule 2004 is used to segment the lyrics file according to a preset segmentation condition to obtain multiple lyrics segments.
[0103] The lyrics file is segmented as a whole to divide the lyrics file into multiple lyrics segments.
[0104] Furthermore, before the lyrics file is segmented, the text volume of the lyrics file can be judged. When the text volume of the lyrics file is greater than a preset text volume threshold, the lyrics file is segmented. Otherwise, the lyrics file is not segmented, and the timestamp and corresponding text content are directly extracted through a string matching algorithm.
[0105] The parallel parsing submodule 2005 is used to allocate a thread to each lyric segment, and to extract the time information of the timestamp and the corresponding text content of the lyric segment in each thread using a string matching algorithm to obtain the parsing result corresponding to each lyric segment.
[0106] A thread pool is created in advance to manage and execute parsing tasks. After the lyrics file is segmented, a separate thread is assigned to each lyrics segment for parallel parsing. Specifically, the lyrics file in each thread is timestamped and the corresponding text content is located and extracted using regular expressions, KMP algorithm or Boyer-Moore algorithm. Finally, each thread obtains the parsing result of the lyrics segment.
[0107] The summarizing submodule 2006 is used to summarize all parsing results to obtain parsed text.
[0108] All parsing results are sorted and aggregated according to timestamps to obtain a parsed text, which is a complete lyrics data structure.
[0109] As an optional implementation, Figure 8 is a schematic diagram of the structure of the second parsing module provided in an embodiment of the present invention, such as Figure 8 As shown, the second parsing module 300 includes:
[0110] The judging submodule 3001 is used to compare the modification time or hash value of the lyrics file with the corresponding parsed text to judge whether the lyrics file has been modified;
[0111] The loading submodule 3002 is used to load the parsed text in the cache when the lyrics file is not modified;
[0112] The updating submodule 3003 is used to calculate the difference between the lyrics file and the old lyrics file by using a text difference algorithm when the lyrics file has been modified; extract the timestamp and corresponding text content in the difference lyrics file by using a string matching algorithm to obtain the updated text; update the corresponding parsed text by using the updated text, and record the latest modification time or the latest hash value of the updated parsed text; wherein the old lyrics file corresponds to the parsed text in the cache.
[0113] After the lyrics file is parsed for the first time, the parsed text of the lyrics file is stored, and the last modification time of the corresponding lyrics file is recorded, or the hash value of the lyrics file is recorded.
[0114] When a new lyrics file is obtained, and the corresponding parsed file of the lyrics file is found in the cache, it is necessary to further determine whether its modification time is consistent with the last modification time of the parsed file. If they are consistent, it is considered that the lyrics file has not been modified, and the parsed text in the cache can be directly used for display. Alternatively, it is determined whether the hash value of the new lyrics file is consistent with the hash value corresponding to the parsed file. If they are consistent, it is considered that the lyrics file has not been modified, and the parsed text in the cache can be directly used for display.
[0115] If the modification time or hash value is inconsistent, the lyrics file is considered to have been modified. The difference lyrics file between the new lyrics file and the old lyrics file needs to be calculated through the text difference algorithm. The difference lyrics file includes the difference content between the two. The string matching algorithm is used to match the timestamp of the difference lyrics file and extract the corresponding text content to obtain the updated text, and the updated text is used to update the parsed text. After the parsed text is updated, the latest modification time or hash value corresponding to the parsed text needs to be updated. Ensure that only the changed part is processed, and the entire part is not re-parsed.
[0116] Specifically, the updated text includes newly added, deleted or modified text content.
[0117] The newly added content is inserted into the corresponding position of the parsed text according to the timestamp; the deleted content is directly deleted; the modified content is replaced and updated.
[0118] As an optional implementation, the text difference algorithm includes Myers algorithm, Levenshtein distance, etc. The calculation of the hash value includes MD5, SHA-1, SHA-256, etc.
[0119] As an optional implementation, Fig. 9 is a schematic diagram of the structure of a module for data preprocessing provided by an embodiment of the present invention, such as Fig. 9 As shown, the system also includes:
[0120] The first pre-processing module 400 is used to identify and delete tabs, line breaks and extra spaces in the lyrics file;
[0121] The second pre-processing module 500 is used to identify and delete tags and comments in the lyrics file.
[0122] After obtaining the lyrics file, the lyrics file is preprocessed to reduce the impact of redundant data on the parsing process, including: removing spaces before and after each line, as well as extra spaces between lines; removing non-printing characters and special control characters, such as tabs, carriage returns, line feeds, etc.; and deleting tags and comments in the lyrics file.
[0123] Furthermore, it is also possible to detect and process abnormal values in timestamps (such as negative values or values exceeding a normal range), and change all timestamps to a unified format (such as [mm:ss.xx] or [mm:ss.xxx]).
[0124] The above technical solution has the following beneficial effects: by storing the parsed text in the cache, re-parsing of the corresponding lyrics file is avoided; by using a string matching algorithm to quickly match the timestamp in the lyrics file and the text content corresponding to the timestamp, the tabulation time is reduced and the parsing efficiency is improved; the parsed text of the parsed lyrics file is updated according to the modification status, which reduces the time for re-parsing and improves the parsing efficiency of the lyrics file.
[0125] The specific implementation methods of the above invention further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above content is only the specific implementation methods of the present invention and is not intended to limit the protection scope of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.< / content> < / millisecond> < / second> < / minute> < / content> < / millisecond> < / second> < / minute> < / content> < / millisecond> < / second> < / minute> < / content> < / millisecond> < / second> < / minute>
Claims
1. A lyrics analysis method, characterized in that: include: Obtain a lyrics file, and determine whether there is a parsed text corresponding to the lyrics file in the cache; When the parsed text corresponding to the lyrics file does not exist in the cache, a string matching algorithm is used to extract the timestamp and the corresponding text content in the lyrics file to obtain the parsed text, the parsed text is stored in the cache, and the corresponding text content is displayed according to the timestamp in the parsed text; When the parsed text corresponding to the lyrics file exists in the cache, the corresponding parsed text is updated according to the modification of the lyrics file, and the corresponding text content is displayed according to the timestamp in the updated parsed text.
2. The lyrics analysis method according to claim 1, characterized in that: The string matching algorithm includes a regular expression matching algorithm, a KMP algorithm and a Boyer-Moore algorithm; The method of extracting the timestamp and the corresponding text content in the lyrics file by using a string matching algorithm includes: Determine the target regular expression according to the text type of the lyrics file; Using a target regular expression to extract the timestamp and corresponding text in the lyrics file; Or, using the KMP algorithm to locate the timestamp identifier in the lyrics file, and extracting the timestamp and the corresponding text content; Alternatively, a Boyer-Moore algorithm is used to locate a timestamp identifier in the lyrics file, and the timestamp and corresponding text content are extracted according to the timestamp identifier.
3. The lyrics analysis method according to claim 2, characterized in that: The string matching algorithm is used to extract the timestamp and the corresponding text content in the lyrics file to obtain the parsed text, including: Segment the lyrics file according to a preset segmentation condition to obtain a plurality of lyrics segments; A thread is allocated to each lyric segment, and for each lyric segment in each thread, the string matching algorithm is used to extract the time information of the timestamp and the corresponding text content to obtain the parsing result corresponding to each lyric segment; All parsing results are aggregated to obtain the parsed text.
4. The lyrics analysis method according to claim 3, characterized in that: The updating of the corresponding parsed text according to the modification of the lyrics file includes: Compare the modification time or hash value of the lyrics file with the corresponding parsed text to determine whether the lyrics file has been modified; When the lyrics file is not modified, loading the parsed text in the cache; When the lyrics file has been modified, a text difference algorithm is used to calculate the difference between the lyrics file and the old lyrics file; a string matching algorithm is used to extract the timestamp and corresponding text content in the difference lyrics file to obtain an updated text; the updated text is used to update the corresponding parsed text, and the latest modification time or the latest hash value of the updated parsed text is recorded; wherein the old lyrics file corresponds to the parsed text in the cache.
5. The lyrics analysis method according to any one of claims 1 to 4, characterized in that: After obtaining the lyrics file, the following steps are included: Identify and delete tabs, line breaks and extra spaces in the lyrics file; Identify and delete tags and comments in the lyrics file.
6. A lyrics analysis system, characterized in that: include: The data acquisition module acquires the lyrics file and determines whether there is a parsed text corresponding to the lyrics file in the cache; A first parsing module is used for, when the parsed text corresponding to the lyrics file does not exist in the cache, extracting the timestamp and the corresponding text content in the lyrics file by using a string matching algorithm to obtain the parsed text, storing the parsed text in the cache, and displaying the corresponding text content according to the timestamp in the parsed text; The second parsing module is used to update the corresponding parsed text according to the modification of the lyrics file when the parsed text corresponding to the lyrics file exists in the cache, and display the corresponding text content according to the timestamp in the updated parsed text.
7. The lyrics analysis system according to claim 6, characterized in that: The string matching algorithm includes a regular expression matching algorithm, a KMP algorithm and a Boyer-Moore algorithm; The first parsing module comprises: A first content extraction submodule, used to determine a target regular expression according to the text type of the lyrics file, and extract the timestamp and corresponding text content in the lyrics file using the target regular expression; A second content extraction submodule, configured to use the KMP algorithm to locate the timestamp identifier in the lyrics file, and extract the timestamp and corresponding text content according to the timestamp identifier; The third content extraction submodule is used to locate the timestamp identifier in the lyrics file by using the Boyer-Moore algorithm, and extract the timestamp and the corresponding text content according to the timestamp identifier.
8. The lyrics analysis system according to claim 7, characterized in that: The first parsing module comprises: A segmentation submodule, used to segment the lyrics file according to a preset segmentation condition to obtain a plurality of lyrics segments; The parallel parsing submodule is used to allocate a thread to each lyric segment, and for the lyric segment in each thread, the string matching algorithm is used to extract the time information of the timestamp and the corresponding text content to obtain the parsing result corresponding to each lyric segment; The summary submodule is used to summarize all parsing results to obtain the parsed text.
9. The lyrics analysis system according to claim 8, characterized in that: The second parsing module comprises: A judgment submodule, used for comparing the modification time or hash value of the lyrics file with the corresponding parsed text to determine whether the lyrics file has been modified; A loading submodule, used for loading the parsed text in the cache when the lyrics file is not modified; The update submodule is used to calculate the difference between the lyrics file and the old lyrics file using a text difference algorithm when the lyrics file has been modified; extract the timestamp and corresponding text content in the difference lyrics file using a string matching algorithm to obtain an updated text; use the updated text to update the corresponding parsed text, and record the latest modification time or the latest hash value of the updated parsed text; wherein the old lyrics file corresponds to the parsed text in the cache.
10. The lyrics analysis system according to any one of claims 6 to 9, characterized in that: Also includes: A first pre-processing module, used for identifying and deleting tabs, line breaks and extra spaces in the lyrics file; The second pre-processing module is used to identify and delete tags and comments in the lyrics file.
