A text-based compilation method, device, electronic device and storage medium
By obtaining and utilizing target position information during text compilation and determining the reading order of lexical units, the problem of low text compilation and development efficiency in the existing technology is solved, more efficient syntax expansion and compatibility are achieved, and the ductility of the compiled language is improved.
Patent Information
- Application Number
- CN202111653352.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-30
- Publication Date
- 2025-05-06
- Estimated Expiration
- 2041-12-30
AI Technical Summary
In the prior art, the order of reading of the lexical unit output by the lexical analyzer during text compilation is fixed, resulting in the non-structural nature of grammatical parsing, the inability to fully utilize grammatical rules, and the development efficiency is low.
By obtaining the input text carrying the target position information, lexical analysis is performed to determine each lexical unit and its reading order information, grammatical analysis is performed in order from small to large, and grammatical conversion is performed based on preset grammatical rules to obtain the compilation results.
It realizes the structure of lexical data flow, improves syntax expansion and compatibility, reduces the time cost and development efficiency of text compilation, and enhances the ductility of the compiled language.
Smart Images

Figure CN114443048B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a text-based compilation method, device, electronic device and storage medium. Background Art
[0002] In the computer field, the translation process from the source language to the target language is usually called compilation, and is usually performed by a finite state machine (FSM). Specifically, after the lexical analyzer performs lexical analysis on the input text, it converts the data stream represented by the input text into a corresponding lexical stream, and the syntax parser in the FSM further converts each lexical unit in the lexical stream into a syntax node in the corresponding syntax tree through conventions or deductions, thereby outputting the corresponding compiled text through each syntax node of the syntax tree.
[0003] However, in the above process, the reading order of each lexical unit output by the lexical analyzer is fixed. Therefore, when the syntax parser performs syntax parsing, it can only perform the corresponding reduction (deduction) process according to the reading order of each lexical unit. This non-structural syntax parsing method cannot make full use of the implemented grammatical rules, and the scalability and compatibility of the syntax are not high, resulting in low development efficiency of text compilation under related technologies. Summary of the invention
[0004] The embodiments of the present application provide a text-based compilation method, device, electronic device and storage medium for improving the development efficiency of text compilation.
[0005] In a first aspect, an embodiment of the present application provides a text-based compilation device, comprising:
[0006] An input text to be compiled is obtained, wherein the input text carries at least: target position information determined for each specified target text word.
[0007] Perform lexical analysis on the input text, and determine corresponding lexical units based on the text position information, wherein each lexical unit carries at least corresponding reading order information.
[0008] According to the order of arrangement from small to large, grammatical parsing is performed on each lexical unit carrying the corresponding reading order identifier in turn to obtain the corresponding parsed text stream.
[0009] Based on the preset grammar rules, the parsed text stream is converted into a grammar to obtain the compilation result of the input text.
[0010] In a second aspect, an embodiment of the present application provides a text-based compilation device, including:
[0011] The acquisition module is used to acquire input text to be compiled, wherein the input text carries at least: target position information determined for each specified target text word.
[0012] The lexical analysis module is used to perform lexical analysis on the input text and determine the corresponding lexical units based on the target position information, wherein each lexical unit carries at least: corresponding reading order information.
[0013] The grammar analysis module is used to perform grammar analysis on each lexical unit carrying a corresponding reading order identifier in order from small to large, and obtain a corresponding parsed text stream.
[0014] The conversion module is used to perform grammatical conversion on the parsed text stream based on preset grammatical rules to obtain the compilation result of the input text.
[0015] In an optional embodiment, when performing lexical analysis on the input text and determining corresponding lexical units based on the target position information, the lexical analysis module is specifically used to:
[0016] Based on a preset dictionary library, segment the input text and determine at least one corresponding segmentation position information;
[0017] Based on the at least one segmentation position information, a corresponding lexical acyclic graph is constructed, and based on a preset dynamic specification algorithm, a path analysis is performed on the lexical acyclic graph to obtain a corresponding target path;
[0018] Based on the target path and the target position information, corresponding lexical units are determined from the input text.
[0019] In an optional embodiment, when performing grammatical conversion on the parsed text stream based on preset grammatical rules to obtain a compilation result of the input text, the conversion module is specifically used to:
[0020] Based on the preset grammar rules, the text type of each parsed text unit in the parsed text stream is determined, and based on the determined text types, a corresponding parsed grammar tree is constructed.
[0021] Based on the preset traversal order, the parsing syntax tree is traversed to determine the corresponding syntax tree nodes.
[0022] Perform syntax conversion on each syntax tree node to obtain the corresponding target text, and use the target text as the compilation result of the input text.
[0023] In an optional embodiment, when performing syntax conversion on each syntax tree node to obtain the corresponding target text, the conversion module is specifically used to:
[0024] For each syntax tree node, the following operations are performed respectively: based on the node type of a syntax tree node, a target conversion function corresponding to the node type is determined from a preset conversion function set, and based on the target conversion function, a syntax conversion is performed on a syntax tree node to obtain a corresponding conversion text;
[0025] Based on the traversal order, the text rules for each conversion text are determined, and based on the text rules, each conversion text is arranged to obtain a corresponding target text.
[0026] 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 in the memory and executable on the processor, wherein when the computer program is executed by the processor, the processor implements any one of the text-based compilation methods in the first aspect described above.
[0027] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the text-based compilation method of the first aspect is implemented.
[0028] The technical effects brought about by any one of the implementation methods in the second to fourth aspects can refer to the technical effects brought about by the corresponding implementation method in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] Figure 1 A text compilation logic diagram under a related technology provided by an embodiment of the present application;
[0030] Figure 2 A schematic diagram of an application scenario provided for an embodiment of the present application;
[0031] Figure 3 An architectural diagram of a text compiler provided in an embodiment of the present application;
[0032] Figure 4 A flowchart of a text-based compilation method provided in an embodiment of the present application;
[0033] Figure 5 An example diagram of a parsed text tree provided in an embodiment of the present application;
[0034] Figure 6 A logical schematic diagram of a text-based compilation method provided in an embodiment of the present application;
[0035] Figure 7 A GROUPING SETS syntax extension logic diagram provided for an embodiment of the present application;
[0036] Figure 8A WITH FUNCTION syntax extension logic diagram provided for an embodiment of the present application;
[0037] Fig. 9 A schematic diagram of a text-based compilation device provided in an embodiment of the present application;
[0038] Fig.10 A schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0039] 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 application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0040] The design ideas of this application are as follows:
[0041] See also Figure 1 As shown, in the related art, a compiler is usually a streaming text processor, which mainly includes two important components: a lexical analyzer and a syntax parser. In the process of text compilation, the input language (text) is usually regarded as a series of continuous data streams. When the data stream passes through the lexical analyzer, the lexical analyzer analyzes and extracts each specified word contained in the text, and outputs a lexical data stream composed of multiple words. In the lexical data stream, each lexical unit can be considered as a terminal symbol (that is, the lexical deduction can be terminated here, and the word is a specific object of the input language (text) rather than an abstract grammatical concept). Therefore, the lexical analysis process usually corresponds to the process of converting the original data stream into a corresponding terminal symbol stream.
[0042] Furthermore, the lexical analyzer passes the converted lexical data stream to the syntax parser. The syntax parser determines the target state to be transferred to for each lexical unit (terminal symbol) read through conventions (or deductions), based on the lexical features of the currently read lexical unit (and the subsequently read lexical units) and the current state of the syntax parser, and performs a corresponding action. Through the above series of actions, the syntax parser converts the lexical data stream (terminal symbol stream) into a syntax tree containing non-terminal symbols (non-leaf nodes) and terminals (leaf nodes), that is, each lexical unit (terminal symbol) in the lexical data stream is parsed separately. During the entire syntax parsing process, the order in which each lexical unit (terminal symbol) is read remains unchanged, and each lexical unit is read only once, that is, the syntax parser can only read each lexical unit (terminal symbol) in sequence by shifting, and cannot loop or jump the reading work. In other words, the parser can only decide whether to shift and reduce (or deduce), and during the entire parsing process, the structure of the parser remains unchanged (only the current state is changed, not the state transfer function).
[0043] However, in the above process, since the syntax parser has a fixed reading order for each lexical unit (terminal), that is, the lexical data stream (terminal stream) composed of each lexical unit (terminal) is usually unstructured (that is, branching, looping, and jumping are not possible), although this method is Turing complete, it cannot make full use of the implemented grammar rules, and is not conducive to grammar reuse in grammar expansion, grammar compatibility and other work, resulting in low development efficiency of text compilation in related technologies.
[0044] In order to solve the problem of low text compilation development efficiency in related technologies, the embodiments of the present application provide a text-based compilation method, device, electronic device and storage medium. Based on the preset target position information, the designated target text words in the input text are positioned, so that the corresponding lexical units and the reading order information of each lexical unit are determined from the input text based on the positioning of each target text word. According to each reading order information, the selective reading of each lexical unit is realized, so as to realize the structuring of the corresponding lexical data stream. In the work of grammar expansion and grammar compatibility, the implemented grammar can be effectively reused, which reduces the time cost and development efficiency of text compilation. At the same time, based on the above method, the design of grammar and grammar can become more flexible, the expression range of grammar can be expanded by orders of magnitude, and tasks that were originally impossible to complete can be completed, which further significantly improves the scalability of the compiled language.
[0045] The preferred embodiments of the present application will be described and illustrated below in conjunction with the accompanying drawings.
[0046] See also Figure 22 is a schematic diagram of an application scenario of an embodiment of the present application, which includes a terminal device 210 and a text compiler 220 .
[0047] In the embodiment of the present application, the terminal device 210 includes but is not limited to mobile phones, tablet computers, laptop computers, desktop computers, e-book readers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals and other devices; a client related to text compilation can be installed on the terminal device, and the client can be software (such as a browser), or a web page, a small program, etc. The text compiler 220 can be a background server corresponding to the software or web page, small program, etc., or an electronic device (such as a server) specifically used for text compilation, and the present application does not make specific restrictions. The text compiler 220 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
[0048] It should be noted that the text-based compilation method in the embodiment of the present application can be executed by an electronic device, which can be a text compiler 220 or a terminal device 210, that is, the method can be executed by the text compiler 220 or the terminal device 210 alone, or can be executed by the text compiler 220 and the terminal device 210 together.
[0049] In an optional implementation, the terminal device 210 and the text compiler 220 may communicate with each other via a communication network.
[0050] In an optional implementation, the communication network is a wired network or a wireless network.
[0051] It should be noted that Figure 2 The figure is only an example. In fact, the number of terminal devices and text compilers is not limited and is not specifically limited in the embodiments of the present application.
[0052] To better explain the design concept of the embodiment of the present application, refer to Figure 3 As shown, it is assumed that the text compiler 220 includes four components, namely, a lexical positioning module 2201, a grammar editing module 2202, a lexical analysis module 2203, and a grammar parsing module 2204, wherein:
[0053] The lexical positioning module 2201 is used to obtain input text, determine target position information for each target text word, and adjust the current reading position of the lexical analysis module 2203 based on the target position information.
[0054] The grammar editing module 2202 is used to adjust the grammar parsing module 2204 so as to achieve the purpose of selectively reading the corresponding lexical units in a loop or jump manner.
[0055] Lexical analysis module 2203: used to analyze and extract each lexical unit contained in the input text, and output the corresponding structured lexical data stream.
[0056] Syntax parsing module 2204: used to execute corresponding state transfer actions for each lexical unit, and build a corresponding target syntax tree based on a series of transfer actions, and determine the compilation result for the input text based on the target syntax tree.
[0057] The text-based compilation method provided by the exemplary embodiment of the present application is described below with reference to the accompanying drawings in combination with the application scenarios described above. It should be noted that the above application scenarios are only shown for the purpose of facilitating the understanding of the spirit and principles of the present application, and the implementation of the present application is not limited in this respect. In addition, the embodiments of the present application can be applied to various scenarios, including not only computer language compilation scenarios, but also various scenarios including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc.
[0058] The text-based compilation method provided by the exemplary embodiment of the present application is described below with reference to the accompanying drawings in combination with the application scenarios described above.
[0059] See also Figure 4 As shown, the embodiment of the present application provides a text-based compilation method, including:
[0060] S401: Obtain an input text to be compiled, wherein the input text carries at least: target position information determined for each specified target text word.
[0061] Specifically, the lexical analysis module 2203 obtains the input text to be compiled, and the lexical positioning module 2201 determines the corresponding target position information for each specified target text word, and adjusts the current reading position of the lexical analysis module 2203 based on the target position information.
[0062] Optionally, the input text includes clauses, sentences, paragraphs or papers, and the input text is executable text, such as text composed of any natural language.
[0063] For example, in an optional embodiment, the input text is regarded as a set of input sentences, and the sentence is: "Today is sunny."
[0064] The corresponding target position information may be represented as a start symbol in the input text, or a stop symbol for the input text, indicating an initial position for reading the input text.
[0065] S402: Perform lexical analysis on the input text, and determine corresponding lexical units based on the target position information, wherein each lexical unit carries at least corresponding reading order information.
[0066] Specifically, based on a preset dictionary library, the input text is segmented to determine at least one corresponding segmentation position information, and based on each segmentation position information, a corresponding lexical acyclic graph is constructed, and the shortest target path is determined from the lexical acyclic graph, so as to determine the corresponding lexical units in turn according to the target path and the target position information determined by the lexical locator.
[0067] Based on the target position information, the lexical data stream determined based on the input text can be made more structured. For example, if the input text is "Today is sunny", the corresponding lexical units "today", "is", and "sunny" contained therein are relocated respectively through the target position information, and lexical data streams corresponding to various combinations can be obtained, such as "sunny"-"today"-"is", etc. Specifically, the following combinations are included:
[0068] 1) "Today" - "Yes", "Sunny"; 2) "Today" - "Sunny" - "Yes";
[0069] 3) "Yes" - "Sunny" - "Today"; 4) "Yes" - "Today" - "Sunny";
[0070] 5) "Sunny", "Today", "Yes"; 6) "Sunny" - "Yes" - "Today";
[0071] Based on the above method, the reading order information carried by each lexical unit can make the lexical data flow more structured. Specifically, branches, loops, jumps, etc. are allowed to appear in the above lexical data flow. Specifically, the above branch, loop, and jump structures are mainly realized by modifying the reading order information carried by each lexical unit.
[0072] For example, for each determined lexical unit "today", "is", "sunny", if the reading order is not modified accordingly, the default reading order information is determined to be "1", "2", "3" respectively. At this time, the corresponding lexical data stream does not have any structure. Each lexical unit can be considered as a terminal symbol indicating that the lexical unit is a specific object of the input text (such as "today"). In an optional embodiment, the reading order information of each of the above lexical units is determined as shown in Table 1 below:
[0073] Table 1
[0074] Token Read order information "today" 1、4 "yes" 3 "sunny" 2、5
[0075] Based on the reading order information shown in Table 1 above, the corresponding lexical data stream can be determined as "today" - "sunny" - "yes" - "today" - "sunny", and based on the corresponding reading order information, the corresponding lexical units can be read in a loop or jump manner without having to follow a fixed text reading order, thereby achieving the structuring of the lexical data stream (terminal symbol stream).
[0076] S403: performing grammatical analysis on each lexical unit carrying a corresponding reading order identifier in order from small to large, to obtain a corresponding parsed text stream.
[0077] Specifically, the grammatical parsing module 2204 performs grammatical parsing on each grammatical unit in turn according to the determined reading order, that is, based on the read grammatical unit (and subsequent grammatical units), determines the target state to be transferred, and executes the corresponding state transfer action to obtain the corresponding parsed text stream.
[0078] S404: Based on preset grammar rules, perform grammar conversion on the parsed text stream to obtain a compilation result of the input text.
[0079] Specifically, a corresponding parsed syntax tree is constructed according to the parsed text units representing the corresponding state transition actions in the obtained parsed text stream. Optionally, the parsed syntax tree is traversed in a preset traversal order, such as pre-order traversal, in-order traversal, post-order traversal, etc., to determine the corresponding syntax tree nodes, and further, text conversion is performed on each syntax tree node. Specifically, for each syntax tree node, based on the node type of a syntax tree node, a target conversion function corresponding to the node type is determined from a preset conversion function set, and based on the target conversion function, a syntax conversion is performed on a syntax tree node to obtain a corresponding target text according to the conversion results of each syntax tree node.
[0080] For example, if the parsed text stream is represented as a string "rename A01 to B01", after SQL script lexical analysis, the following word sequence is formed: "rename", "A01", "to", "B01", such as Figure 5 As shown, the word sequence can generate a corresponding parsing syntax tree based on preset syntax analysis rules, wherein 1 the parsing syntax tree describes the syntax structure of an SQL script in a tree structure.
[0081] A semantic analysis is performed on the Rename statement formed by the above-mentioned parsed syntax tree. Specifically, according to the depth-first traversal, a syntax conversion is performed on the Rename node in the parsed syntax tree, and it is determined that the syntax tree node represents the renaming operation of a database table; the depth traversal is continued to the subsequent syntax tree node OldTableName of the Rename node, and the syntax conversion is performed on the syntax tree node, and it is determined that the syntax tree node is the library table name before the renaming; then, the subsequent syntax tree node A01 of the OldTableName syntax tree node is deeply traversed, and the syntax conversion is performed on it, and the original database table name is determined to be A01. Based on the above process, after the parsed syntax tree is deeply traversed, the corresponding target text is obtained based on the syntax conversion results of each syntax tree node traversed in sequence, which is: rename the library table A01 to B01.
[0082] See also Figure 6 As shown, a logical schematic diagram of a text-based compilation method provided by an embodiment of the present application, in which the text compiler includes a lexical positioning module, a lexical analysis module, a grammar editing module and a grammar parsing module. The lexical positioning module in the text compiler relocates each designated target text word in the input text, thereby determining the corresponding lexical units and the reading order information of each lexical unit from the input text based on the respective positioning of each target text word. Furthermore, the grammar parsing module realizes the selective reading of each lexical unit according to each reading order information, ensures the structuring of the corresponding lexical data stream, and determines the corresponding target text by parsing the lexical data stream.
[0083] Based on the text-based compilation method proposed in the embodiment of the present application, the implemented syntax can be effectively reused in syntax extension and syntax compatibility work, reducing the time cost and development efficiency of text compilation. For example, in actual scenarios, the expansion of GROUPING SETS syntax can be achieved by reusing the two implemented syntaxes of UNION ALL and GROUP BY.
[0084] For details, see Figure 7As shown, in the GROUPING SETS syntax structure, the definition of data grouping is usually expressed as fixed data pairs, such as GROUPING SETS (a, b), GROUPING SETS (b, c), etc. In an optional embodiment, multiple extensible syntax structures consistent with the GROUPING SETS expression can be constructed through GROUP BY query and UNION ALL operation.
[0085] For example, through the GROUP BY query statement, the corresponding lexical unit "a" is read from GROUPING SETS(a,b), and the corresponding lexical unit "c" is read from GROUPING SETS(b,c). The corresponding steps of modifying the reading order are shown in S401-S404 above and will not be repeated here. Based on the read lexical units "a", "c" and UNION ALL operation, an equivalent expression for the GROUPING SETS grammatical structure can be achieved.
[0086] Alternatively, the WITH FUNCTION syntax can be extended by calling and passing parameters to local functions.
[0087] For details, see Figure 8 As shown, in the WITH FUNCTION syntax, a local function f(x,y) is called. For example, in an optional embodiment, f(x,y)=x+y, and the statement SELECT f(a,b)FROM t and WHERE f(c,d)>0 that conforms to the WITH FUNCTION syntax structure is further called. Based on the above statements and the text-based compilation method as described in S401-S404 in the embodiments of the present application, it can be implemented by structured reading of local functions and related parameters.
[0088] For example, through the statement SELECT f(a,b)FROM t of the WITH FUNCTION syntax structure and the called local function f(x,y)=x+y, the equivalent expression SELECT a+b FROM t for the WITH FUNCTION syntax structure can be realized. Similarly, in an optional embodiment, the corresponding equivalent expression WHERE c+d>0 can be realized for the WITH FUNCTION structure statement WHERE f(c,d)>0 by calling the local function f(x,y)=x+y.
[0089] It can be seen from the above process that the text-based compilation method provided in the embodiment of the present application makes the design of syntax and grammar more flexible, expands the expression scope of grammar by orders of magnitude, completes tasks that were originally impossible to complete, and further significantly improves the scalability of the compiled language.
[0090] See also Fig. 9 As shown, a text-based compilation device provided in an embodiment of the present application includes an acquisition module 901, a lexical analysis module 902, a syntax parsing module 903 and a conversion module 904, wherein:
[0091] The acquisition module 901 is used to acquire input text to be compiled, wherein the input text at least carries: target position information determined for each specified target text word.
[0092] The lexical analysis module 902 is used to perform lexical analysis on the input text and determine corresponding lexical units based on the target position information, wherein each lexical unit carries at least corresponding reading order information.
[0093] The grammar analysis module 903 is used to perform grammar analysis on each lexical unit carrying a corresponding reading order identifier in order from small to large, to obtain a corresponding parsed text stream.
[0094] The conversion module 904 is used to perform grammar conversion on the parsed text stream based on preset grammar rules to obtain the compilation result of the input text.
[0095] In an optional embodiment, when performing lexical analysis on the input text and determining corresponding lexical units based on the target position information, the lexical analysis module 902 is specifically used to:
[0096] Based on a preset dictionary library, segment the input text and determine at least one corresponding segmentation position information;
[0097] Based on the at least one segmentation position information, a corresponding lexical acyclic graph is constructed, and based on a preset dynamic specification algorithm, a path analysis is performed on the lexical acyclic graph to obtain a corresponding target path;
[0098] Based on the target path and target position information, corresponding lexical units are determined from the input text.
[0099] In an optional embodiment, when performing grammatical conversion on the parsed text stream based on preset grammatical rules to obtain the compilation result of the input text, the conversion module 904 is specifically used to:
[0100] Based on the preset grammar rules, the text type of each parsed text unit in the parsed text stream is determined, and based on the determined text types, a corresponding parsed grammar tree is constructed.
[0101] Based on the preset traversal order, the parsing syntax tree is traversed to determine the corresponding syntax tree nodes.
[0102] Perform syntax conversion on each syntax tree node to obtain the corresponding target text, and use the target text as the compilation result of the input text.
[0103] In an optional embodiment, when performing syntax conversion on each syntax tree node to obtain the corresponding target text, the conversion module 904 is specifically used to:
[0104] For each syntax tree node, the following operations are performed respectively: based on the node type of a syntax tree node, a target conversion function corresponding to the node type is determined from a preset conversion function set, and based on the target conversion function, a syntax conversion is performed on a syntax tree node to obtain a corresponding conversion text;
[0105] Based on the traversal order, the text rules for each conversion text are determined, and based on the text rules, each conversion text is arranged to obtain a corresponding target text.
[0106] Based on the same inventive concept as the above-mentioned application embodiment, the present application embodiment also provides an electronic device, which can be used for text-based compilation. In one embodiment, the electronic device can be a server, or a terminal device or other electronic device. In this embodiment, the structure of the electronic device can be as follows: Fig.10 As shown, it includes a memory 1001 , a communication interface 1003 and one or more processors 1002 .
[0107] The memory 1001 is used to store computer programs executed by the processor 1002. The memory 1001 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system and programs required for running the instant messaging function, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.
[0108] The memory 1001 may be a volatile memory, such as a random-access memory (RAM); the memory 1001 may also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), or the memory 1001 is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 1001 may be a combination of the above memories.
[0109] The processor 1002 may include one or more central processing units (CPU) or a digital processing unit, etc. The processor 1002 is used to implement the above text-based compilation method when calling the computer program stored in the memory 1001 .
[0110] The communication interface 1003 is used to communicate with terminal devices and other servers.
[0111] The specific connection medium between the memory 1001, the communication interface 1003 and the processor 1002 is not limited in the embodiment of the present application. Fig.10 In the embodiment, the memory 1001 and the processor 1002 are connected via a bus 1004. The bus 1004 is connected to the processor 1002 via a bus 1004. Fig.10 The connections between other components are shown in bold lines, which are only for illustration and are not intended to be limiting. Bus 1004 can be divided into address bus, data bus, control bus, etc. For ease of illustration, Fig.10 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0112] According to one aspect of the present application, a computer program product or computer program is provided, which includes computer instructions stored in a computer-readable storage medium. The processor of a computer device reads the computer instructions from a computer-readable storage medium, and the processor executes the computer instructions so that the computer device executes any text-based compilation method in the above-mentioned embodiments. The program product 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 - an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of readable storage media (non-exhaustive list) 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.
[0113] The embodiment of the present application provides a text-based compilation method, device, electronic device and storage medium, which locates each designated target text word in the input text based on preset target position information, thereby determining the corresponding lexical units and the reading order information of each lexical unit from the input text based on the positioning of each target text word, and realizing the selective reading of each lexical unit according to each reading order information, thereby realizing the structuring of the corresponding lexical data stream, and effectively reusing the implemented grammar in the grammar expansion and grammar compatibility work, reducing the time cost and development efficiency of text compilation. At the same time, based on the above method, the design of grammar and grammar can become more flexible, expanding the expression range of grammar by an order of magnitude, completing tasks that were originally impossible to complete, and further significantly improving the scalability of the compiled language.
[0114] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0115] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0116] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0117] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A text-based compilation method, characterized in that: include: Obtaining an input text to be compiled, wherein the input text carries at least: target position information determined for each target text word; the target position information indicates a start symbol or a stop symbol in the input text to indicate an initial position for reading the input text; Based on a preset dictionary library, the input text is segmented to determine at least one corresponding segmentation position information; based on the at least one segmentation position information, a corresponding lexical acyclic graph is constructed, and based on a preset dynamic specification algorithm, a path analysis is performed on the lexical acyclic graph to obtain a corresponding target path; based on the target path and the target position information, corresponding lexical units are determined from the input text, wherein each lexical unit carries at least: corresponding reading order information; According to the order of arrangement from small to large, grammatical parsing is performed on each lexical unit carrying the corresponding reading order identifier in turn to obtain the corresponding parsed text stream; Based on preset grammar rules, the parsed text stream is subjected to grammar conversion to obtain a compilation result of the input text.
2. The method according to claim 1, characterized in that The step of performing grammatical conversion on the parsed text stream based on preset grammatical rules to obtain a compilation result of the input text includes: Based on preset grammar rules, determining the text type of each parsed text unit in the parsed text stream, and constructing a corresponding parsed grammar tree based on each determined text type; Based on a preset traversal order, the parsing syntax tree is traversed to determine corresponding syntax tree nodes; Performing syntax conversion on each syntax tree node respectively to obtain a corresponding target text, and using the target text as a compilation result of the input text.
3. The method according to claim 2, characterized in that The step of performing syntax conversion on each syntax tree node to obtain a corresponding target text includes: For each of the syntax tree nodes, the following operations are performed respectively: based on the node type of a syntax tree node, a target conversion function corresponding to the node type is determined from a preset conversion function set, and based on the target conversion function, a syntax conversion is performed on the syntax tree node to obtain a corresponding conversion text; Based on the traversal order, text rules for each conversion text are determined, and based on the text rules, each conversion text is arranged to obtain a corresponding target text.
4. A text-based compilation device, characterized in that: include: An acquisition module, used for acquiring an input text to be compiled, wherein the input text carries at least: target position information determined for each target text word; the target position information indicates a start symbol or a stop symbol in the input text to indicate an initial position for reading the input text; The lexical analysis module is used to segment the input text based on a preset dictionary library and determine at least one corresponding segmentation position information; based on the at least one segmentation position information, construct a corresponding lexical acyclic graph, and based on a preset dynamic specification algorithm, perform path analysis on the lexical acyclic graph to obtain a corresponding target path; based on the target path and the target position information, determine the corresponding lexical units from the input text, wherein each lexical unit carries at least: corresponding reading order information; A grammar parsing module is used to parse the lexical units carrying the corresponding reading order identifiers in order from small to large, and obtain the corresponding parsed text stream; The conversion module is used to perform grammatical conversion on the parsed text stream based on preset grammatical rules to obtain the compilation result of the input text.
5. The device according to claim 4, characterized in that When performing grammatical conversion on the parsed text stream based on the preset grammatical rules to obtain the compilation result of the input text, the conversion module is specifically used to: Based on preset grammar rules, determining the text type of each parsed text unit in the parsed text stream, and constructing a corresponding parsed grammar tree based on each determined text type; Based on a preset traversal order, the parsing syntax tree is traversed to determine corresponding syntax tree nodes; Performing syntax conversion on each syntax tree node respectively to obtain a corresponding target text, and using the target text as a compilation result of the input text.
6. The device according to claim 5, characterized in that When performing syntax conversion on each syntax tree node to obtain the corresponding target text, the conversion module is specifically used to: For each of the syntax tree nodes, the following operations are performed respectively: based on the node type of a syntax tree node, a target conversion function corresponding to the node type is determined from a preset conversion function set, and based on the target conversion function, a syntax conversion is performed on the syntax tree node to obtain a corresponding conversion text; Based on the traversal order, text rules for each conversion text are determined, and based on the text rules, each conversion text is arranged to obtain a corresponding target text.
7. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the text-based compilation method according to any one of claims 1 to 3 is implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 3 are implemented.
Citation Information
Patent Citations
Processing Natural-Language Documents and Queries
US20160042058A1