Lyric analysis method, system and device based on abstract syntax tree and medium

By constructing an abstract grammar tree for lyrics, the efficiency and accuracy problems of the existing technology when dealing with complex lyric formats are solved, and the in-depth understanding and intelligent processing of lyric structure is achieved, and a variety of functional requirements are supported.

CN120031029APending Publication Date: 2025-05-23山东浪潮智慧医疗科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411917626.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-24
Publication Date
2025-05-23

AI Technical Summary

Technical Problem

When faced with complex and changeable lyric formats, existing lyric analysis techniques are difficult to effectively analyze the context information of lyric text, resulting in being unable to handle complex grammars such as nested structures and conditional judgments, and are inefficient and prone to errors.

Method used

The lyric analysis method based on abstract grammar tree (AST) is adopted to decompose the lyric text into lexical units through lexical analysis, and the abstract grammar tree of lyrics is constructed through parser to obtain the syntactic structure of the lyrics, thereby achieving in-depth understanding and intelligent processing of the lyrics structure.

Benefits of technology

It realizes accurate analysis and intelligent processing of lyric structure, improves analysis efficiency and accuracy, and supports automatic repair of lyric formats and multiple functional requirements, such as lyric translation and format conversion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120031029A_ABST
    Figure CN120031029A_ABST
Patent Text Reader

Abstract

The invention provides a lyric analysis method, system and device based on an abstract syntax tree and a medium, and belongs to the technical field of text recognition and analysis. The method comprises the following steps: acquiring an original lyric text, and preprocessing the original lyric text according to an LRC format specification to generate a process lyric text; decomposing the process lyric text into lexical units by using a lexical analyzer to generate a lexical unit set; based on the lexical unit set, constructing an abstract syntax tree of the lyrics through a parser, and obtaining a syntactic structure of the lyrics; and obtaining an analysis requirement, and based on the abstract syntax tree, generating a target lyric text meeting the requirement by utilizing a traversal device and a converter. The lyric text is analyzed and processed by constructing the abstract syntax tree of the lyrics, deep understanding and intelligent processing of the lyric structure are achieved, the lyric structure can be analyzed, and automatic repairing of the lyric format can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of text recognition and analysis, and more specifically relates to a lyric analysis method, system, device and medium based on an abstract syntax tree. Background Art

[0002] In the music industry, lyrics are the soul of songs, and their importance is self-evident. They are not only a direct reflection of the emotions and themes of songs, but also play a pivotal role in the creation, interpretation and dissemination of songs. Although traditional lyric processing methods, such as manual editing and proofreading, guarantee the accuracy and artistry of lyrics to a certain extent, facing the growing demand for music and complex and ever-changing lyric formats, their drawbacks such as low efficiency and proneness to errors are becoming increasingly prominent.

[0003] With the advancement of technology, especially the advent of the digital age, traditional LRC format lyrics can no longer meet the diverse music needs. In order to adapt to this change, LRC format lyrics have gradually evolved into extended versions of simple formats and more complex enhanced formats. These new formats not only contain the text content of the lyrics, but also incorporate rich information such as timestamps and style tags, making the presentation of lyrics more flexible and diverse. However, this also brings unprecedented challenges to the analysis of lyrics.

[0004] Most existing lyric parsing technologies rely on regular expressions for matching and parsing. Although regular expressions have certain advantages in processing specific rule texts, their limitations are clearly revealed when faced with complex and changeable lyric formats. Since regular expressions cannot effectively analyze the contextual information of lyric texts, they are often unable to cope with complex grammars such as nested structures and conditional judgments. Even for matching simple rules, a large number of boundary cases need to be considered, which undoubtedly increases the difficulty and complexity of parsing. Summary of the invention

[0005] In view of the above problems, the purpose of the present invention is to provide a lyric parsing method, system, device and medium based on an abstract syntax tree, which analyzes and processes the lyrics text by constructing an abstract syntax tree of the lyrics, thereby achieving an in-depth understanding and intelligent processing of the lyrics structure, and can not only analyze the structure of the lyrics, but also realize automatic repair of the lyrics format.

[0006] In order to achieve the above object, the present invention is implemented through the following technical solutions: In a first aspect, an embodiment of the present application provides a lyrics parsing method based on an abstract syntax tree, comprising: Obtain the original lyrics text, and pre-process the original lyrics text according to the LRC format specification to generate the process lyrics text; Using a lexical analyzer to decompose the process lyrics text into lexical units, generating a lexical unit set; the lexical units include: tag unit Tag, time unit Time, inline time unit InlineTime, role unit Role, lyrics unit Lyric and separation unit Break; Based on the set of lexical units, the parser constructs the abstract syntax tree of the lyrics to obtain the syntactic structure of the lyrics; Obtain the parsing requirements, and based on the abstract syntax tree, use the traverser and converter to generate the target lyrics text that meets the requirements. In an optional implementation, the process of obtaining the original lyrics text and preprocessing the lyrics according to the LRC format specification to generate the lyrics text includes: Get the original lyrics text and add an ID tag to the front of the original lyrics text; Use regular expressions to match blank lines and time tags in the original lyrics text; Delete the blank lines; Determine whether the time label is at the beginning of each line; If yes, the time label format is unified as [mm:ss.xx], where mm is minutes, ss is seconds, and xx is the value of hundredths of a second.

[0007] In an optional embodiment, the process of decomposing the lyrics text into lexical units using a lexical analyzer to generate a lexical unit set includes: Use the lexical analyzer to identify and match each line of the process lyrics text according to the preset characters and preset separators, match the corresponding characters and the character segments between the preset separators, and return the corresponding lexical units and actual character values; If the currently recognized character is the letter F, D, or M, and the last matched lexical unit is the time unit Time, the role unit Role and the actual character value are returned; Extract the remaining characters of the current line and return the lyrics unit Lyric and the actual character value; Generate a token set based on the returned token and the actual character value; The preset characters include line breaks and blank characters, and the preset separators include square brackets and angle brackets.

[0008] In an optional implementation, the lexical analyzer is used to match the process lyrics text according to preset characters and preset separators, matches the corresponding characters and the character segments between the preset separators, and returns the corresponding lexical units and actual character values, including: When a newline character is matched, the separator unit Break is returned; When matching a whitespace character, skip the current character.

[0009] In an optional embodiment, the process of using a lexical analyzer to match the process lyrics text according to preset characters and preset separators, matching the corresponding characters and the character segments between the preset separators, and returning the corresponding lexical units and actual character values ​​also includes: When matching the character segment between the square brackets, if the format of the character segment is [mm:ss.xx], the time unit Time and the corresponding time value are returned; if the format of the character segment is [key:val], the tag unit Tag and the corresponding tag value are returned; When matching the character segment between angle brackets, determine whether the format of the character segment is<mm:ss.xx> ; If yes, return the inline time unit InlineTime and the corresponding time value; if no, return an error message.

[0010] In an optional implementation, the process of constructing an abstract syntax tree of the lyrics through a parser based on the lexical unit set to obtain the syntactic structure of the lyrics includes: Construct an abstract syntax tree; the nodes of the abstract syntax tree include: tag node TagNode, time node TimeNode, inline time node InlineTimeNode, role node RoleNode and lyric node LyricNode; The parser traverses the set of tokens, parses each token, and returns nodes based on the parsing results to generate an abstract syntax tree; If the currently parsed lexical unit is a tag unit Tag, the tag node TagNode is returned; If the currently parsed lexical unit is an inline time unit InlineTime, parse the next lexical unit; if the next lexical unit is a lyrics unit Lyric, encapsulate the inline time unit InlineTime into an inline time node InlineTimeNode, encapsulate the lyrics unit Lyric into a lyrics node LyricNode and put it into the current inline time node InlineTimeNode, and return the inline time node InlineTimeNode; If the currently parsed lexical unit is a role unit Role, encapsulate the role unit Role into a role node RoleNode and parse the next lexical unit; if the next lexical unit is a lyrics unit Lyric, encapsulate the lyrics unit Lyric into a lyrics node LyricNode and put it into the current role node RoleNode; If the currently parsed lexical unit is a time unit Time, the time unit Time is encapsulated as a time node TimeNode; the next lexical unit is parsed through the parser, and the returned parsing result is placed in the current time node TimeNode.

[0011] In an optional implementation, the obtaining of parsing requirements, based on the abstract syntax tree, using a traverser and a converter to generate a target lyric text that meets the requirements, includes: Get the current parsing needs for lyrics translation; Extract all the lyrics nodes LyricNode in the abstract syntax tree, obtain the characters stored in the nodes, use the translator to translate the characters, and store the translated characters in the corresponding lyrics nodes LyricNode; Create a blank text file as the target lyrics text file; Use the traverser to traverse the nodes of the abstract syntax tree; If the current node is a tag node TagNode, a tag in the format of [key:val] is generated and written into the target lyrics text file; If the current node is a time node TimeNode, generate a time value in the format of [mm:ss.xx], write the time value in a new line in the target lyrics text file, and traverse the subtree of the time node TimeNode; If the current node is an InlineTimeNode, the generated format is<mm:ss.xx> The time value is written into the current line of the target lyrics text file, and the subtree of the inline time node InlineTimeNode is traversed; If the current node is a role node RoleNode, write the corresponding characters into the current line of the target lyrics text file, and traverse the subtree of the role node RoleNode; If the current node is a lyrics node LyricNode, the corresponding characters are written into the current line of the target lyrics text file.

[0012] In a second aspect, the embodiment of the present application further provides a lyrics parsing system based on an abstract syntax tree, comprising: The preprocessing module is used to obtain the original lyrics text and preprocess the original lyrics text according to the LRC format specification to generate the process lyrics text; The lexical analysis module is used to decompose the process lyrics text into lexical units using a lexical analyzer to generate a lexical unit set; the lexical units include: a tag unit Tag, a time unit Time, an inline time unit InlineTime, a role unit Role, a lyric unit Lyric and a separation unit Break; The syntax analysis module is used to construct an abstract syntax tree of the lyrics through a parser based on a set of lexical units to obtain the syntactic structure of the lyrics; The parsing module is used to obtain the parsing requirements and generate the target lyrics text that meets the requirements based on the abstract syntax tree using a traverser and a converter.

[0013] In a third aspect, an embodiment of the present application further provides an electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein when the processor executes the program, the steps of the lyric parsing method based on the abstract syntax tree as described in any one of the above items are implemented.

[0014] In a fourth aspect, an embodiment of the present application further provides a storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the lyric parsing method based on an abstract syntax tree as described in any one of the above items are implemented.

[0015] It can be seen from the above technical solutions that the present invention has the following advantages: In the lyrics parsing method based on the abstract syntax tree provided in the present application, by constructing the abstract syntax tree of the lyrics to analyze and process the lyrics text, the structure of the lyrics can be analyzed more accurately, and the lyrics format can be automatically repaired to a certain extent. This method can be applied to lyrics production, lyrics parsing, and automatic conversion between lyrics in different formats.

[0016] Compared with regular expression parsing, this application has a higher error tolerance and higher parsing efficiency.

[0017] This application only needs to perform the abstract syntax tree conversion on one side. Based on the parsed abstract syntax tree, multiple requirements such as lyrics playback synchronization, lyrics translation, and lyrics conversion can be achieved.

[0018] In this application, the parsed abstract syntax tree can be converted into JSON format for easy transmission. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solution of the present invention, the accompanying drawings required for use in the description will be briefly introduced below. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying creative work.

[0020] Figure 1 A flowchart of the lyrics parsing method based on the abstract syntax tree provided in this application.

[0021] Figure 2 A schematic diagram of the structure of the lyrics parsing system based on the abstract syntax tree provided in this application.

[0022] Figure 3 A schematic diagram of the structure of the electronic device provided in this application. DETAILED DESCRIPTION

[0023] In the specific steps of the lyric parsing method based on the abstract syntax tree, which will be described in detail below, various embodiments of the present disclosure will be described more comprehensively. The present disclosure may have various embodiments, and adjustments and changes may be made therein. However, it should be understood that there is no intention to limit the various embodiments of the present disclosure to the specific embodiments disclosed herein, but rather the present disclosure should be understood to cover all adjustments, equivalents and / or alternatives that fall within the spirit and scope of the various embodiments of the present disclosure.

[0024] Hereinafter, the terms "include" or "may include" used in various embodiments of the present disclosure indicate the presence of disclosed functions, operations, or elements, and do not limit the addition of one or more functions, operations, or elements. In addition, as used in various embodiments of the present disclosure, the terms "include", "have", and their cognates are intended only to indicate specific features, numbers, steps, operations, elements, components, or a combination of the foregoing, and should not be understood as first excluding the presence of one or more other features, numbers, steps, operations, elements, components, or a combination of the foregoing or the possibility of adding one or more features, numbers, steps, operations, elements, components, or a combination of the foregoing.

[0025] 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.

[0026] See also Figure 1 The figure is a flowchart of a method for parsing lyrics based on an abstract syntax tree in a specific embodiment, the method comprising: S1: Obtain the original lyrics text, and pre-process the original lyrics text according to the LRC format specification to generate the process lyrics text.

[0027] In a specific implementation, since the lyrics obtained on the Internet are of varying quality, they may not fully comply with the LRC format specification. Therefore, the first step is to process the obtained lyrics into a form that complies with the LRC format specification. The specific process is: First, the original lyrics text is obtained, and an ID tag is added to the front of the original lyrics text. Thus, the ID tag is uniformly placed in front of all lyrics.

[0028] Then, the blank lines and time labels in the original lyrics text are matched by regular expressions.

[0029] After the matching is completed, the matched blank lines are deleted.

[0030] For the matched time tags, the time tag format is unified into [mm:ss.xx]. Where mm is minutes, ss is seconds, and xx is hundredths of a second. For the enhanced LRC format, the time tags in a single sentence are unified into<mm:ss.xx> In addition, you need to make sure that each line of lyrics begins with a time stamp.

[0031] The above process may use regular expression matching or manual proofreading.

[0032] S2: Use a lexical analyzer to decompose the process lyrics text into lexical units to generate a lexical unit set; the lexical units include: tag unit Tag, time unit Time, inline time unit InlineTime, role unit Role, lyrics unit Lyric and separation unit Break.

[0033] S3: Based on the set of lexical units, the abstract syntax tree of the lyrics is constructed through the parser to obtain the syntactic structure of the lyrics.

[0034] Based on the lexical units, the parser constructs the abstract syntax tree (AST) of the lyrics to obtain the syntactic structure of the lyrics. The abstract syntax tree contains the following nodes: TagNode, TimeNode, InlineTimeNode, RoleNode, LyricNode.

[0035] S4: Obtain parsing requirements, and based on the abstract syntax tree, use a traverser and a converter to generate a target lyric text that meets the requirements. Based on the abstract syntax tree, this step can develop different traversers according to different needs to achieve functions such as automatic repair of lyrics format, conversion between different lyrics formats, and lyrics translation.

[0036] For example, first get the current parsing needs for lyrics translation requirements.

[0037] Since each node of the abstract syntax tree stores node type and value information, for each LyricNode node, the lyrics in the node are obtained, the translation service or translation converter is called to obtain the translated lyrics, and the lyrics in the original LyricNode node are replaced.

[0038] At this point, a processed abstract syntax tree is obtained. First, create a blank text file, and then use the traverser to traverse the processed abstract syntax tree in depth-first order to generate the translated target lyrics text. The specific traversal and generation process is as follows: S401: For a TagNode node, write a tag in the format of [key:val] into a text file.

[0039] S402: For a TimeNode node, write a time label in the format of [mm:ss.xx] into a new row, and traverse its subtree.

[0040] S403: For InlineNode nodes, the format is<mm:ss.xx> The timestamp is written to the current line of the text file and its subtree is traversed.

[0041] S404: For the RoleNode node, write the role characters (F, M, D) into the current line of the text file, and traverse its subtree.

[0042] S405: For the LyricNode node, write the corresponding lyrics characters into the current line of the text file.

[0043] Repeat the above steps until the current abstract text tree is processed, and the translated LRC lyrics file can be obtained.

[0044] In this embodiment, a systematic preprocessing process is used to ensure that the original lyrics text complies with the LRC format specification, laying a solid foundation for subsequent processing. Through lexical analysis, the lyrics text is decomposed into multiple lexical units, and a clear abstract syntax tree is further constructed through the parser to show the syntactic structure of the lyrics. This method not only improves the accuracy and efficiency of lyrics parsing, but also flexibly supports multiple functional requirements such as lyrics translation and format conversion, providing strong technical support for the diversified processing, efficient application and innovative development of lyrics.

[0045] In an embodiment of the present invention, based on step S2, a possible embodiment is given below to illustrate its specific implementation scheme in a non-limiting manner.

[0046] In step S2, the lexical analyzer is used to match the lyrics character by character, and the matched lexical units and actual character values ​​are returned to generate a lexical unit set. The specific implementation process is as follows: S201: When a line break “\n” is matched, the separator unit Break is returned.

[0047] S202: When a blank character (such as a space or a tab) is matched, the current character is skipped.

[0048] S203: When the "[" character is matched, the next character is obtained in a loop until the "]" character is encountered. The character segment in the interval is matched using a regular expression.

[0049] If the string segment conforms to the "[mm:ss.xx]" format, the time unit Time and the time value are returned.

[0050] If the string segment conforms to the "[key:val]" format, the tag unit Tag and the tag value are returned.

[0051] If it does not conform to the above two formats, an error message is returned.

[0052] S204: When the "<" character is matched, the next character is obtained in a loop until a ">" character is encountered. The character segment in the interval is matched using a regular expression.

[0053] If the character segment matches "<mm:ss.xx> " format, returns the inline time unit InlineTime and the time value.

[0054] If the format is not met, an error message is returned.

[0055] S205: If the last matched lexical unit is the time unit Time, and the current character is "F", "D" or "M", the role unit Role and the character value are returned.

[0056] S206: Get the remaining characters of the current line until the line breaks, and return the lyrics unit Lyric and the character value.

[0057] At this time, the lexical unit set of the lyrics can be obtained.

[0058] In an embodiment of the present invention, based on step S3, a possible embodiment is given below to illustrate its specific implementation scheme in a non-limiting manner.

[0059] In step S3, the parser traverses the lexical unit set, parses each lexical unit, and returns a node based on the parsing result to generate an abstract syntax tree. The specific traversal process is as follows: S301: If the current lexical unit is a tag unit Tag, return a tag node TagNode.

[0060] S302: If the current lexical unit is an inline time node InlineTime, and the next lexical unit is a lyric unit Lyric, encapsulate the current lexical unit into an inline time node InlineTimeNode, encapsulate the next lyric unit Lyric into a lyric node LyricNode and put it into the current inline time node InlineTimeNode, and return the inline time node InlineTimeNode.

[0061] S303: If the current lexical unit is a role unit Role, encapsulate the current lexical unit into a role node RoleNode.

[0062] At this time, if the next lexical unit is a lyric unit Lyric, the next lexical unit is encapsulated as a lyric node LyricNode and put into the current role node RoleNode. If the next lexical unit is an inline time node InlineTime, step S302 is executed.

[0063] S304: If the current lexical unit is a time unit Time, encapsulate the current lexical unit into a time node TimeNode, repeat the above steps, and put the return value into the current time node TimeNode.

[0064] Follow the above steps to traverse all lexical units until the processing is completed, and then you can get an abstract syntax tree consisting of the above nodes.

[0065] like Figure 2 As shown, the following is an embodiment of the lyrics parsing system based on an abstract syntax tree provided by an embodiment of the present disclosure. The system and the lyrics parsing method based on an abstract syntax tree of the above-mentioned embodiments belong to the same inventive concept. For details not described in detail in the embodiment of the lyrics parsing system based on an abstract syntax tree, please refer to the embodiment of the lyrics parsing method based on an abstract syntax tree.

[0066] A lyrics parsing system based on an abstract syntax tree comprises: a preprocessing module 1, a lexical analysis module 2, a grammatical analysis module 3 and a parsing module 4.

[0067] The preprocessing module 1 is used to obtain the original lyrics text and preprocess the original lyrics text according to the LRC format specification to generate the process lyrics text.

[0068] The lexical analysis module 2 is used to use a lexical analyzer to decompose the process lyrics text into lexical units to generate a lexical unit set; the lexical units include: tag unit Tag, time unit Time, inline time unit InlineTime, role unit Role, lyrics unit Lyric and separation unit Break.

[0069] The syntax analysis module 3 is used to construct an abstract syntax tree of the lyrics through a parser based on a set of lexical units to obtain the syntactic structure of the lyrics.

[0070] The parsing module 4 is used to obtain the parsing requirements and generate the target lyrics text that meets the requirements based on the abstract syntax tree using a traverser and a converter.

[0071] The lyric parsing system based on the abstract syntax tree provided in this embodiment effectively solves the problem of different lyric formats through preprocessing, lexical analysis, construction of abstract syntax trees and target text generation, improves parsing accuracy and efficiency, supports functions such as lyric translation and format conversion, and provides a solid foundation for diversified processing and application of lyrics.

[0072] Figure 3 A schematic diagram of the hardware structure of an electronic device for implementing various embodiments of the present invention.

[0073] The lyrics parsing method of the abstract syntax tree provided in the embodiment of the present application can be applied to electronic devices. It can be understood by those skilled in the art that the electronic device structure involved in the embodiment of the present invention does not constitute a limitation on the electronic device, and the electronic device may include more or less components than shown, or combine certain components, or arrange different components. In an embodiment of the present invention, the electronic device includes but is not limited to a laptop computer, a desktop computer, a workbench, a personal digital assistant, a server, a blade server, a mainframe computer, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples, and are not intended to limit the implementation of the embodiments of the present application described and / or required herein.

[0074] The electronic device may include a processor, an external memory interface, an internal memory, a universal serial bus (USB) interface, a charging management module, a power management module, a battery, a wireless communication module, an audio module, a speaker, a microphone, a sensor module, buttons, a camera, a display, and a SIM card interface, etc.

[0075] The processor may include one or more processing units, for example, the processor may include a central processing unit (CPU), an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units may be independent devices or integrated into one or more processors.

[0076] The processor can be the nerve center and command center of the electronic device. The controller can generate an operation control signal according to the instruction operation code and timing signal to complete the control of fetching and executing instructions.

[0077] A memory may also be provided in the processor for storing instructions and data. In some embodiments, the memory in the processor is a cache memory. The memory may store instructions or data that the processor has just used or is cyclically used. If the processor needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor, and thus improves system efficiency.

[0078] The external memory interface can be used to connect an external memory card, such as a MicroSD card, to expand the storage capacity of the electronic device. The external memory card communicates with the processor through the external memory interface to implement data storage functions. For example, files such as music and videos can be saved in the external memory card.

[0079] The internal memory can be used to store computer executable program codes, which include instructions. The processor executes various functional applications and data processing of the electronic device by running the instructions stored in the internal memory. The internal memory may include a program storage area and a data storage area. The internal memory may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.

[0080] The wireless communication function of an electronic device can be realized through an antenna, a wireless communication module, a modem processor, and a baseband processor.

[0081] The wireless communication module can provide wireless communication solutions for electronic devices, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared technology (IR), etc.

[0082] Electronic devices can implement audio functions, etc. through audio modules, speakers, receivers, microphones, headphone jacks, and application processors.

[0083] Electronic devices can achieve shooting functions through ISP, camera, video codec, GPU, display and application processor.

[0084] Electronic devices can achieve display functions through GPU, display screen and application processor.

[0085] The GPU is a microprocessor for image processing that connects the display screen and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor may include one or more GPUs that execute program instructions to generate or change display information.

[0086] The display screen is used to display images, videos, etc. The display screen includes a display panel.

[0087] The electronic device implements the lyric parsing method of the abstract syntax tree of the present application through the system preprocessing, lexical analysis, abstract syntax tree construction and target text generation process, effectively solving the problem of different formats and messy content of the original lyrics text, and realizing the standardization of the lyrics format and flexible processing of the content. This method not only improves the accuracy and efficiency of lyrics parsing, but also supports multiple functional requirements such as lyrics translation and format conversion, providing strong support for the secondary creation and diversified application of lyrics.

[0088] The storage medium provided in the present application stores a program product capable of implementing a lyrics parsing method using an abstract syntax tree.

[0089] The lyrics parsing method of the abstract syntax tree includes: obtaining the original lyrics text, and preprocessing the original lyrics text according to the LRC format specification to generate a process lyrics text; using a lexical analyzer to decompose the process lyrics text into lexical units to generate a lexical unit set; the lexical units include: tag unit Tag, time unit Time, inline time unit InlineTime, role unit Role, lyrics unit Lyric and separation unit Break; based on the lexical unit set, constructing an abstract syntax tree of the lyrics through a parser to obtain the syntactic structure of the lyrics; obtaining parsing requirements, and based on the abstract syntax tree, using a traverser and a converter to generate a target lyrics text that meets the requirements.

[0090] In some possible implementations, the lyric parsing method of the abstract syntax tree of the present disclosure can be implemented in the form of a program product, which includes a program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps described in the above "Exemplary Method" section of this specification according to various exemplary implementations of the present disclosure.

[0091] The storage medium of the present disclosure can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0092] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A lyrics parsing method based on an abstract syntax tree, characterized in that: include: Obtain the original lyrics text, and pre-process the original lyrics text according to the LRC format specification to generate the process lyrics text; Decompose the process lyrics text into lexical units using a lexical analyzer to generate a lexical unit set; The lexical units include: a tag unit Tag, a time unit Time, an inline time unit InlineTime, a role unit Role, a lyrics unit Lyric and a separation unit Break; Based on the set of lexical units, the parser constructs the abstract syntax tree of the lyrics to obtain the syntactic structure of the lyrics; Obtain the parsing requirements, and based on the abstract syntax tree, use the traverser and converter to generate the target lyrics text that meets the requirements.

2. The lyrics parsing method based on the abstract syntax tree according to claim 1 is characterized in that: The process of obtaining the original lyrics text and preprocessing the lyrics according to the LRC format specification to generate the lyrics text includes: Get the original lyrics text and add an ID tag to the front of the original lyrics text; Use regular expressions to match blank lines and time tags in the original lyrics text; Delete the blank lines; Determine whether the time label is at the beginning of each line; If yes, the time label format is unified as [mm:ss.xx], where mm is minutes, ss is seconds, and xx is the value of hundredths of a second.

3. The lyrics parsing method based on the abstract syntax tree according to claim 2 is characterized in that: The process of using a lexical analyzer to decompose the lyrics text into lexical units to generate a lexical unit set includes: Use the lexical analyzer to identify and match each line of the process lyrics text according to the preset characters and preset separators, match the corresponding characters and the character segments between the preset separators, and return the corresponding lexical units and actual character values; If the currently recognized character is the letter F, D, or M, and the last matched lexical unit is the time unit Time, the role unit Role and the actual character value are returned; Extract the remaining characters of the current line and return the lyrics unit Lyric and the actual character value; Generate a token set based on the returned token and the actual character value; The preset characters include line breaks and blank characters, and the preset separators include square brackets and angle brackets.

4. The lyrics parsing method based on the abstract syntax tree according to claim 3 is characterized in that: The lexical analyzer is used to match the process lyrics text according to preset characters and preset separators, match the corresponding characters and the character segments between the preset separators, and return the corresponding lexical units and actual character values, including: When a newline character is matched, the separator unit Break is returned; When matching a whitespace character, skip the current character.

5. The lyrics parsing method based on the abstract syntax tree according to claim 4 is characterized in that: The method uses a lexical analyzer to match the process lyrics text according to preset characters and preset separators, matches the corresponding characters and the character segments between the preset separators, and returns the corresponding lexical units and actual character values, and also includes: When matching the character segment between the square brackets, if the format of the character segment is [mm:ss.xx], the time unit Time and the corresponding time value are returned; if the format of the character segment is [key:val], the tag unit Tag and the corresponding tag value are returned; When matching the character segment between angle brackets, determine whether the format of the character segment is<mm:ss.xx> ; If yes, return the inline time unit InlineTime and the corresponding time value; if no, return an error message.

6. The lyrics parsing method based on the abstract syntax tree according to claim 5 is characterized in that: The method of constructing an abstract syntax tree of the lyrics through a parser based on a set of lexical units to obtain a syntactic structure of the lyrics includes: Construct an abstract syntax tree; the nodes of the abstract syntax tree include: tag node TagNode, time node TimeNode, inline time node InlineTimeNode, role node RoleNode and lyric node LyricNode; The parser traverses the set of tokens, parses each token, and returns nodes based on the parsing results to generate an abstract syntax tree; If the currently parsed lexical unit is a tag unit Tag, the tag node TagNode is returned; If the currently parsed lexical unit is an inline time unit InlineTime, parse the next lexical unit; if the next lexical unit is a lyrics unit Lyric, encapsulate the inline time unit InlineTime into an inline time node InlineTimeNode, encapsulate the lyrics unit Lyric into a lyrics node LyricNode and put it into the current inline time node InlineTimeNode, and return the inline time node InlineTimeNode; If the currently parsed lexical unit is a role unit Role, encapsulate the role unit Role into a role node RoleNode and parse the next lexical unit; if the next lexical unit is a lyrics unit Lyric, encapsulate the lyrics unit Lyric into a lyrics node LyricNode and put it into the current role node RoleNode; If the currently parsed lexical unit is a time unit Time, the time unit Time is encapsulated as a time node TimeNode; the next lexical unit is parsed through the parser, and the returned parsing result is placed in the current time node TimeNode.

7. The lyrics parsing method based on the abstract syntax tree according to claim 6 is characterized in that: The obtaining of the parsing requirements, based on the abstract syntax tree, using a traverser and a converter to generate a target lyrics text that meets the requirements, includes: Get the current parsing needs for lyrics translation; Extract all the lyrics nodes LyricNode in the abstract syntax tree, obtain the characters stored in the nodes, use the translator to translate the characters, and store the translated characters in the corresponding lyrics nodes LyricNode; Create a blank text file as the target lyrics text file; Use the traverser to traverse the nodes of the abstract syntax tree; If the current node is a tag node TagNode, a tag in the format of [key:val] is generated and written into the target lyrics text file; If the current node is a time node TimeNode, generate a time value in the format of [mm:ss.xx], write the time value in a new line in the target lyrics text file, and traverse the subtree of the time node TimeNode; If the current node is an InlineTimeNode, the generated format is<mm:ss.xx> The time value is written into the current line of the target lyrics text file, and the subtree of the inline time node InlineTimeNode is traversed; If the current node is a role node RoleNode, write the corresponding characters into the current line of the target lyrics text file, and traverse the subtree of the role node RoleNode; If the current node is a lyrics node LyricNode, the corresponding characters are written into the current line of the target lyrics text file.

8. A lyrics parsing system based on an abstract syntax tree, characterized in that: The system adopts the lyrics parsing method based on the abstract syntax tree as claimed in any one of claims 1 to 7; The system comprises: The preprocessing module is used to obtain the original lyrics text and preprocess the original lyrics text according to the LRC format specification to generate the process lyrics text; The lexical analysis module is used to decompose the process lyrics text into lexical units using a lexical analyzer to generate a lexical unit set; the lexical units include: a tag unit Tag, a time unit Time, an inline time unit InlineTime, a role unit Role, a lyric unit Lyric and a separation unit Break; The syntax analysis module is used to construct an abstract syntax tree of the lyrics through a parser based on a set of lexical units to obtain the syntactic structure of the lyrics; The parsing module is used to obtain the parsing requirements and generate the target lyrics text that meets the requirements based on the abstract syntax tree using a traverser and a converter.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the lyrics parsing method based on the abstract syntax tree as described in any one of claims 1 to 7 are implemented.

10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the lyrics parsing method based on the abstract syntax tree as claimed in any one of claims 1 to 7 are implemented.