CN116301895A - Text printing method, apparatus, computer device and storage medium - Google Patents

Text printing method, apparatus, computer device and storage medium Download PDF

Info

Publication number
CN116301895A
CN116301895A CN202310259126.XA CN202310259126A CN116301895A CN 116301895 A CN116301895 A CN 116301895A CN 202310259126 A CN202310259126 A CN 202310259126A CN 116301895 A CN116301895 A CN 116301895A
Authority
CN
China
Prior art keywords
target
word
printing
data stream
node
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310259126.XA
Other languages
Chinese (zh)
Inventor
曹似耀
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Qianhai Baidi Network Co ltd
Original Assignee
Shenzhen Qianhai Baidi Network Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Qianhai Baidi Network Co ltd filed Critical Shenzhen Qianhai Baidi Network Co ltd
Priority to CN202310259126.XA priority Critical patent/CN116301895A/en
Publication of CN116301895A publication Critical patent/CN116301895A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/425Lexical analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/12Digital output to print unit, e.g. line printer, chain printer
    • G06F3/1201Dedicated interfaces to print systems
    • G06F3/1202Dedicated interfaces to print systems specifically adapted to achieve a particular effect
    • G06F3/1203Improving or facilitating administration, e.g. print management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application relates to a text printing method, a text printing device, a computer device and a storage medium. Comprising the following steps: determining a source sentence in a printing instruction, and performing lexical analysis on the source sentence to obtain a data stream comprising a plurality of word nodes; when the data stream is analyzed, a target grammar tree is obtained, and the target grammar tree is compiled into a target sentence suitable for a preset environment; therefore, the resource loading can be carried out on the preset environment according to the target sentence, and the text printing result is obtained. The method can expand the use scene of the C-Lodop printing control.

Description

Text printing method, apparatus, computer device and storage medium
Technical Field
The present disclosure relates to the field of cloud printing technologies, and in particular, to a text printing method, a text printing device, a computer device, and a storage medium.
Background
The cloud printing technology integrates printing equipment resources through a network, and a multi-terminal shared printing platform can be constructed. Therefore, it is important to provide high quality, standardized print service standards.
At present, a C-Lodop printing control integrated with a plurality of general instructions is mainly adopted in cloud printing, and when a printer is connected, appointed text contents can be printed out through the instructions. However, because the C-Lodop printing control is in the form of a browser plug-in, system resources cannot be directly operated, and system calls such as interface operation and the like are performed, the use scene of cloud printing is greatly limited. Therefore, how to expand the usage scenario of the C-Lodop printing control is a problem that needs to be solved by the present disclosure.
Disclosure of Invention
Based on the foregoing, there is a need to provide a text printing method, apparatus, computer device, computer readable storage medium and computer program product capable of expanding the usage scenario of a C-Lodop printing control.
In a first aspect, the present application provides a text printing method. Comprising the following steps:
when a printing instruction is acquired, determining a source sentence in the printing instruction;
performing lexical analysis on the source sentence to obtain a data stream comprising a plurality of word nodes;
carrying out grammar analysis on the data stream to obtain a target grammar tree, and compiling the target grammar tree into a target sentence suitable for a preset environment;
and loading resources to the preset environment according to the target statement to obtain a text printing result.
In one embodiment, before the determining the source statement in the print instruction, the method further comprises: acquiring a technical document; the technical document includes a plurality of print functions; according to the technical document, responding to the editing operation of the printing function, and obtaining a source sentence; responding to the triggering operation of the printing control, and synthesizing the source statement and the printing statement corresponding to the printing control to generate a printing instruction; the print control exists in the form of a special plug-in.
In one embodiment, performing lexical analysis on the source sentence to obtain a data stream including a plurality of word nodes, including: determining a plurality of words in the source sentence, and carrying out semantic recognition on each word through a finite state automaton to obtain word nodes and word types corresponding to each word; marking the corresponding word nodes by using a plurality of word types to obtain marked word nodes; and connecting a plurality of marked word nodes in series according to the arrangement sequence of each word to obtain a data stream.
In one embodiment, the parsing the data stream to obtain a target syntax tree includes: determining an objective function corresponding to the data flow from a plurality of word nodes; the word nodes comprise nodes for representing functions; and determining a target grammar corresponding to the target function, and constructing the data stream into a target grammar tree from bottom to top according to the target grammar.
In one embodiment, the target grammar includes a plurality of production formulas; the constructing the data stream into a target grammar tree from bottom to top according to the target grammar comprises the following steps: taking an initial node in the data stream as a root node in the target grammar tree, and traversing a plurality of word nodes in the data stream; and matching the current word node with a plurality of production formulas in the target grammar to obtain a matching sub-result, and integrating a plurality of matching sub-results and the root node to obtain a target grammar tree.
In one embodiment, the generator includes a header; the header is a non-terminal symbol; the matching of the current word node with a plurality of production formulas in the target grammar to obtain a matching sub-result comprises the following steps: taking the current word node as an edge node in the target grammar tree; determining a target production formula matched with the edge node from a plurality of production formulas, and taking a non-terminal symbol in a head of the target production formula as a father node of the edge node; taking the father node as a new edge node, and returning to a process of determining a target production formula matched with the edge node from a plurality of production formulas, and continuing until the non-terminal symbol is a root node; and integrating all edge nodes to obtain a matching sub-result corresponding to the current word node.
In one embodiment, according to the target sentence, and loading resources on the preset environment, a text printing result is obtained, which includes: loading database resources corresponding to the preset environment, and synthesizing the target statement and the database resources to obtain an installation package file; the installation package file comprises a printer interface; and when the installation package file is triggered, calling the printer interface to enable the target printer corresponding to the printer interface to print out a text printing result.
In a second aspect, the present application also provides a text printing apparatus. The device comprises:
the lexical analysis module is used for determining a source sentence in the printing instruction when the printing instruction is acquired; performing lexical analysis on the source sentence to obtain a data stream comprising a plurality of word nodes;
the grammar analysis module is used for carrying out grammar analysis on the data stream to obtain a target grammar tree, and compiling the target grammar tree into a target sentence suitable for a preset environment;
and the printing result determining module is used for carrying out resource loading on the preset environment according to the target statement to obtain a text printing result.
In a third aspect, the present application also provides a computer device. The computer device comprises a memory storing a computer program and a processor which when executing the computer program performs the steps of:
when a printing instruction is acquired, determining a source sentence in the printing instruction;
performing lexical analysis on the source sentence to obtain a data stream comprising a plurality of word nodes;
carrying out grammar analysis on the data stream to obtain a target grammar tree, and compiling the target grammar tree into a target sentence suitable for a preset environment;
and loading resources to the preset environment according to the target statement to obtain a text printing result.
In a fourth aspect, the present application also provides a computer-readable storage medium. The computer readable storage medium has stored thereon a computer program which when executed by a processor performs the steps of:
when a printing instruction is acquired, determining a source sentence in the printing instruction;
performing lexical analysis on the source sentence to obtain a data stream comprising a plurality of word nodes;
carrying out grammar analysis on the data stream to obtain a target grammar tree, and compiling the target grammar tree into a target sentence suitable for a preset environment;
and loading resources to the preset environment according to the target statement to obtain a text printing result.
In a fifth aspect, the present application also provides a computer program product. The computer program product comprises a computer program which, when executed by a processor, implements the steps of:
when a printing instruction is acquired, determining a source sentence in the printing instruction;
performing lexical analysis on the source sentence to obtain a data stream comprising a plurality of word nodes;
carrying out grammar analysis on the data stream to obtain a target grammar tree, and compiling the target grammar tree into a target sentence suitable for a preset environment;
and loading resources to the preset environment according to the target statement to obtain a text printing result.
The text printing method, the text printing device, the computer equipment, the storage medium and the computer program product are used for obtaining a data stream comprising a plurality of word nodes by determining a source sentence in a printing instruction and performing lexical analysis on the source sentence; when the data stream is analyzed, a target grammar tree is obtained, and the target grammar tree is compiled into a target sentence suitable for a preset environment; therefore, the resource loading can be carried out on the preset environment according to the target sentence, and the text printing result is obtained. According to the method and the device, analysis of the source sentence can be achieved through lexical analysis and grammar analysis in sequence, and then the target sentence suitable for the preset environment is obtained, so that the C-Lodop printing control is separated from the use of the browser, and the use of the C-Lodop printing control in the preset environment is expanded. In addition, in the process of loading the resources in the preset environment, various functional interfaces can be acquired, so that system call such as interface operation and the like can be realized.
Drawings
FIG. 1 is an application environment diagram of a text printing method in one embodiment;
FIG. 2 is a flow diagram of a text printing method in one embodiment;
FIG. 3 is a schematic diagram of the structure of data flow in one embodiment;
FIG. 4 is a flow diagram of building a target syntax tree in one embodiment;
FIG. 5 is a schematic diagram of the construction of a target syntax tree in one embodiment;
FIG. 6 is a block diagram of a text printing device in one embodiment;
fig. 7 is an internal structural diagram of a computer device in one embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
The text printing method provided by the embodiment of the application can be applied to an application environment shown in fig. 1. Wherein the terminal 102 communicates with the server 104 via a network, and the printer 106 communicates with the server 104 via the network. The data storage system may store data that the server 104 needs to process. The data storage system may be integrated on the server 104 or may reside on other network servers. The server 104 is configured to determine a source sentence in a print instruction when obtaining the print instruction sent by the terminal 102, and perform lexical analysis on the source sentence to obtain a data stream including a plurality of word nodes; the server 104 is further configured to parse the data stream, load resources to a preset environment according to the target sentence, so that the printer 106 prints out a text printing result. The terminal 102 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, internet of things devices, and portable wearable devices, where the internet of things devices may be smart speakers, smart televisions, smart air conditioners, smart vehicle devices, and the like. The portable wearable device may be a smart watch, smart bracelet, headset, or the like. The server 104 may be a cloud server, or may be implemented by a stand-alone server or a server cluster formed by a plurality of servers.
In one embodiment, as shown in fig. 2, a text printing method is provided, and the method is applied to a computer device, which may be a terminal or a server in fig. 1, and includes the following steps:
step 202, when a print instruction is acquired, determining a source sentence in the print instruction.
The source sentence can be a source code, such as C-Lodop source code, and the source sentence can also represent a sentence which is adaptively edited by a user according to different printing requirements.
Specifically, when the computer device responds to the triggering operation of the user, the printing instruction can be determined, and at the moment, all codes required for executing the printing task are included in the printing instruction. Since the basic print statement which does not need to be modified at each printing is also included in all codes, the computer device can parse the source statement which is edited and modified by the user from the print instruction.
In one embodiment, before determining the source statement in the print instruction, the method further includes: acquiring a technical document; according to the technical document, and responding to the editing operation of the printing function, obtaining a source sentence; and responding to the triggering operation of the printing control, and synthesizing the source statement and the printing statement corresponding to the printing control to generate a printing instruction.
Wherein the technical document includes a plurality of printing functions; the printing function is embodied by a corresponding function; the technical documents can be technical documents of different versions in the C-Lodop printing control, and the like, namely the technical document specification describes the standard of the C-Lodop printing control; the printing control exists in the form of a special plug-in; the special plug-in may be a browser plug-in, that is, in the conventional scheme, when the user triggers the computer device that only provides the browser, the corresponding print instruction may be executed.
Specifically, since the technical document may be pre-stored in a database, such as a third party database corresponding to a preset environment, etc. When the technical document is obtained from the database, the user can use the technical document as an editing basis to obtain a corresponding source sentence. For example, when there is a function add_print_text, the specification of the corresponding source sentence is add_print_text (intTop, intLeft, intWidth, intHeight, content), the embodied printing function is to ADD a plain TEXT printing option, set the position and the area size of the printing item in the paper, automatically fold the TEXT content in the area, and the like, that is, call the line drawing function after initialization to PRINT the TEXT content. When the computer equipment responds to the triggering operation of the user on the printing control, the edited source statement and the basic printing statement corresponding to the printing control can be synthesized, and a printing instruction is generated.
In one embodiment, the source statement is not limited to the edited code, but may refer to all code required to perform a print job.
And 204, performing lexical analysis on the source sentence to obtain a data stream comprising a plurality of word nodes.
Specifically, the computer device pre-processes the source sentence, thereby filtering out redundant information, such as spaces, notes, etc. The computer device may then scan the source sentence from left to right as a sequence of characters, i.e. scan the stream of words constituting the source sentence according to the lexical rules of the source code language and recognize the words according to the word forming rules. Since lexical analysis is a process of converting a character sequence into a Token (Token) sequence, which is a word that is the smallest unit constituting a source code, a process of generating a Token from an input character sequence is called tokenization, i.e., dividing each word in the input character sequence into tokens.
For example, a character sequence of a source sentence lodop.add_print_text (10, 10,100,100, "hello") is parsed into ten lexical units: < LODOP >, < add_print_text >, < (>, <10>, <100>, < "hello" >, and < >.
Since each lexical unit corresponds to a word, when the computer device connects the lexical units in sequence, a data stream is obtained, and the lexical units are nodes of the corresponding words in the data stream. Wherein the data stream may be a Token formatted data stream.
In one embodiment, the lexical analysis may be accomplished by a lexical analyzer.
And 206, carrying out grammar analysis on the data stream to obtain a target grammar tree, and compiling the target grammar tree into a target sentence suitable for a preset environment.
In one embodiment, parsing the data stream to obtain a target syntax tree includes: determining an objective function corresponding to the data flow from a plurality of word nodes; and determining a target grammar corresponding to the target function, and constructing the data stream into a target grammar tree from bottom to top according to the target grammar.
Wherein the word nodes include nodes that characterize the function; the function of the function then corresponds to the print function in the technical document; the target grammar comprises a context-free grammar, which is an expression used to describe a programming language, by a collection of simple symbolic description languages.
Specifically, since word nodes in the data stream have different word types, the computer device can identify word nodes of a character string type by analyzing the data stream, and further identify word nodes representing functions from a plurality of word nodes. For example, referring to the above example, the word node is identified as < ADD_PRINT_TEXT >, which is the function embodied in the technical document and therefore is taken as the objective function for the data stream. Because the target grammar is used for realizing the construction of the grammar tree, the target grammar corresponding to the target function needs to be determined, and thus, the data stream can be constructed into the target grammar tree in a bottom-up mode.
Further, the computer device compiles the target grammar tree to perform code conversion on the target grammar tree according to a conversion rule between a preset natural language code and a preset environment code to obtain a final target sentence. The target sentence is a code that can be executed by the printer and implements the C-Lodop function. The preset environment may be an environment in which a Java program runs.
In one embodiment, the parsing may be accomplished by a parser. The parser may group the plurality of lexical elements into an abstract syntax tree (Abstract Syntax Tree, AST) based on relationships between the plurality of lexical elements.
In one embodiment, the target grammar is customizable by the user, thereby increasing the flexibility of building different grammar trees.
And step 208, loading resources to a preset environment according to the target sentence to obtain a text printing result.
In one embodiment, according to a target sentence, and loading resources on a preset environment, obtaining a text printing result includes: loading database resources corresponding to a preset environment, and synthesizing target sentences and the database resources to obtain an installation package file; when the installation package file is triggered, the printer interface is called, so that a target printer corresponding to the printer interface prints out a text printing result.
Wherein the installation package file includes a printer interface. The installation package file integrates a functional interface provided by the software development kit, installation package resource information corresponding to the software development kit and the like; the software development kit is, for example, an SDK, which can be regarded as a form of software delivery, through which the complete contents of the software code, resources, etc. of the initial application program can be packaged and integrated when the packaged file is delivered to another party.
Specifically, as the target sentence is suitable for the preset environment, when the target sentence with the corresponding printing function is formed, the computer equipment can also load other database resources corresponding to the preset environment, so that the ecology of the preset environment is expanded, the use of a third party database is realized, and further, the installation package file with small memory and convenient triggering is formed.
Further, when the computer sets up a server using a Spring framework, the resources of the corresponding server can be directly used, and when the installation package file is introduced and the user triggers the installation package file, the computer equipment can call the printer interface so as to enable the target printer corresponding to the printer interface to print out the text printing result. Because the installation package file comprises a plurality of functional interfaces, the computer equipment integrated with the C-Lodop printing control expands the functions, and further can realize system call such as interface operation and the like.
In one embodiment, the computer device may compromise a traditional local printer, or may trigger printing by remote JavaScript programming.
In the text printing method, a source sentence in a printing instruction is determined, and lexical analysis is carried out on the source sentence, so that a data stream comprising a plurality of word nodes is obtained; when the data stream is analyzed, a target grammar tree is obtained, and the target grammar tree is compiled into a target sentence suitable for a preset environment; therefore, the resource loading can be carried out on the preset environment according to the target sentence, and the text printing result is obtained. According to the method and the device, analysis of the source sentence can be achieved through lexical analysis and grammar analysis in sequence, and then the target sentence suitable for the preset environment is obtained, so that the C-Lodop printing control is separated from the use of the browser, and the use of the C-Lodop printing control in the preset environment is expanded. In addition, in the process of loading the resources in the preset environment, various functional interfaces can be acquired, so that system call such as interface operation and the like can be realized.
In one embodiment, lexical analysis of the source sentence results in a data stream comprising a plurality of word nodes, comprising: determining a plurality of words in a source sentence, and carrying out semantic recognition on each word through a finite state automaton to obtain word nodes and word types corresponding to each word; marking the corresponding word nodes by using a plurality of word types to obtain marked word nodes; and connecting a plurality of marked word nodes in series according to the arrangement sequence of each word to obtain a data stream.
Specifically, the computer device performs semantic recognition on each word in the source sentence through a finite state automaton (Deterministic Finite Automaton, DFA) to obtain a word node and a word type corresponding to each word. Where DFA is a five-tuple m=Σ (S, S0, f, Z), Σ representing each character, i.e. each word; s represents the state of each character; s0 represents an initial state; f represents a conversion function; z represents the final state set. Word types may include strings, integers, floating point numbers, punctuation, and the like. When the five-tuple M is represented by the node set form of the graph, the data stream with the initial structure can be obtained. Because each word node corresponds to a word type, when the corresponding word node is marked by the word type, the marked word node can be obtained, and at the moment, a plurality of marked word nodes are connected in series according to the arrangement sequence of each word to form a data stream corresponding to a source sentence, namely a data stream in a state Token format.
For example, when the source sentence is lodop. Add_print_text (10,10,100,100, "hello"), the identified DFA graph is shown in fig. 3, and fig. 3 is a schematic diagram of the structure of the data stream in one embodiment.
In one embodiment, when the source statement is INT: '-'? When [0-9] + is detected, the characterization identifies positive and negative integers, and numbers such as 10, -10 and the like; when the source statement is FLOAT: ([ 0-9] +' [0-9] +) the characterization identifies numbers with decimal points, such as 0.12, etc.
In the embodiment, the lexical unit of the source sentence can be accurately analyzed by adopting the finite state automaton to perform lexical analysis on the source sentence, so that when a grammar tree is subsequently constructed, a corresponding grammar tree can be accurately obtained, and the accuracy of printing the text is improved.
In one embodiment, as shown in fig. 4, fig. 4 is a schematic flow chart of constructing a target syntax tree. Constructing the data stream into a target grammar tree from bottom to top according to the target grammar, and further comprising the following steps:
step S402, taking an initial node in the data stream as a root node in a target grammar tree, and traversing a plurality of word nodes in the data stream.
Specifically, the computer device determines an initial node in the data stream and takes it as a root node in the target syntax tree. The initial node with reference to fig. 3 is < LODOP >. The computer device, starting from the root node, continuously traverses a plurality of word nodes in the data stream, and since the matching process of each word node is the same, for simplicity of expression, the description will be described later using the current word node as an example, for example, the current word node is < add_print_text >.
Step S404, matching the current word node with a plurality of production formulas in the target grammar to obtain a matching sub-result, and integrating the plurality of matching sub-results and the root node to obtain the target grammar tree.
In one embodiment, matching the current word node with a plurality of production formulas in the target grammar to obtain a matching sub-result includes: taking the current word node as an edge node in the target grammar tree; determining a target production formula matched with the edge node from a plurality of production formulas, and taking a non-terminal symbol in the head of the target production formula as a father node of the edge node; taking the father node as a new edge node, and returning to the process of determining a target generating formula matched with the edge node from a plurality of generating formulas, and continuing until the non-terminal symbol is the root node; and integrating all the edge nodes to obtain a matching sub-result corresponding to the current word node.
Wherein the target grammar comprises a plurality of production formulas; the generating type comprises a head part; the header is a non-terminal symbol. For example, the generation formula 1 corresponding to an integer in the target grammar is D- >0|1 |10, the generation formula 2 corresponding to a letter is L- > a|b|c|d|z, and the generation formula 3 corresponding to the integrated number and the letter is P- > l|d, that is, P may be deduced to be L or D, where P on the left side in the generation formula 3 is the head, and l|d on the right side is the body. For another example, the target grammar includes generating the expression 4 LODOP.ADD_PRINT_TEXT ' (ARG (', ' ARG):; ' a (ARG (', ' ARG); (',' ARG)? The characteristic target parameters can be 0 or more; the generation 5 characterizes the target parameter ARG as being derivable as an integer, string or floating point type.
Specifically, the computer device uses the current word node as an edge node in the target grammar tree, and the edge node is the end node far away from the root node when matching is performed from bottom to top. The computer device searches for a target generation formula which is identical to the edge node, namely matches the edge node, from the body corresponding to each of the plurality of generation formulas, and can take the non-terminal symbol in the head of the target generation formula as the father node of the edge node. For example, when the integer 10 is an edge node, it may be determined that the generation formula 1 is a target generation formula, and D in the generation formula 1 is a parent node of 10.
Since the target syntax tree is composed of a plurality of hierarchical nodes, a process of setting a parent node as a new edge node for each round of construction and returning to a process of determining a target generation formula matching the edge node from a plurality of generation formulas is performed. For example, when D is a new edge node, it may be determined that the generation formula 3 is a target generation formula, and P in the generation formula 3 is a parent node of D.
When the non-terminal symbol is a root node, the characterization round is finished, at the moment, no matched generation formula exists, the computer equipment synthesizes all edge nodes to obtain a matched sub-result corresponding to the current word node, and the matched sub-result characterizes the sub-structure tree constructed by the current word node. As shown in fig. 5, fig. 5 is a schematic diagram of a principle of building a target syntax tree, for example, specification add_print_text (intTop, intLeft, intWidth, intHeight, strContent) of a source sentence, five-term shape parameters may be obtained, and when a source sentence edited by a user is lodop.add_print_text (10, 10,100,100, "hello"), a word type corresponding to each shape parameter may be determined, and a value may be assigned to the corresponding shape parameter.
In this embodiment, the target grammar is adopted, and then the data stream is built into the target grammar tree from bottom to top, so that the identification of the source sentence can be quickly realized, and the source sentence only needs to edit a small amount of shape parameters, so that when different printing functions are triggered for many times, the corresponding target grammar tree can be quickly built, and the efficiency of text printing is ensured. In addition, as the target grammar can be customized by a user in advance, the flexibility of constructing different grammar trees is improved.
In one embodiment, the computer device may encrypt the target syntax tree according to a preset encryption algorithm, to obtain an encrypted syntax tree. The preset encryption Algorithm is, for example, an MD5 (Message-Digest Algorithm) encryption Algorithm, a base64 encryption Algorithm, or the like. The computer device may encrypt each node in the target syntax tree separately to generate an encrypted syntax tree; or encrypting part of nodes in the target grammar tree, and forming the encrypted target grammar tree according to the encrypted part of nodes and the unencrypted nodes. Thus, the security of compiling the target grammar tree can be ensured.
It should be understood that, although the steps in the flowcharts related to the above embodiments are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
Based on the same inventive concept, the embodiment of the application also provides a text printing device for realizing the above-mentioned related text printing method. The implementation of the solution provided by the device is similar to the implementation described in the above method, so the specific limitation in one or more embodiments of the text printing device provided below may refer to the limitation of the text printing method hereinabove, and will not be repeated herein.
In one embodiment, as shown in fig. 6, there is provided a text printing apparatus 600 including: a lexical analysis module 602, a grammar analysis module 604, and a print result determination module 606, wherein:
the lexical analysis module 602 is configured to determine a source sentence in the print instruction when the print instruction is acquired; and performing lexical analysis on the source sentence to obtain a data stream comprising a plurality of word nodes.
The syntax analysis module 604 is configured to parse the data stream to obtain a target syntax tree, and compile the target syntax tree into a target sentence suitable for a preset environment.
The print result determining module 606 is configured to obtain a text print result according to the target sentence and perform resource loading on the preset environment.
In one embodiment, the text printing device 600 further includes an instruction generation module 608 for obtaining a technical document; the technical document includes a plurality of printing functions; according to the technical document, and responding to the editing operation of the printing function, obtaining a source sentence; responding to the triggering operation of the printing control, and synthesizing a source sentence and a printing sentence corresponding to the printing control to generate a printing instruction; the print control exists in the form of a special plug-in.
In one embodiment, the lexical analysis module 602 is further configured to determine a plurality of words in the source sentence, and perform semantic recognition on each word through the finite state automaton to obtain a word node and a word type corresponding to each word; marking the corresponding word nodes by using a plurality of word types to obtain marked word nodes; and taking the created initial node as a starting point, and connecting a plurality of marked word nodes in series according to the arrangement sequence of each word to obtain a data stream.
In one embodiment, the parsing module 604 is further configured to determine an objective function corresponding to the data stream from the plurality of word nodes; word nodes include nodes that characterize functions; and determining a target grammar corresponding to the target function, and constructing the data stream into a target grammar tree from bottom to top according to the target grammar.
In one embodiment, the parsing module 604 is further configured to take an initial node in the data stream as a root node in the target syntax tree, and traverse a plurality of word nodes in the data stream; matching the current word node with a plurality of production formulas in the target grammar to obtain a matching sub-result, and integrating the plurality of matching sub-results and the root node to obtain the target grammar tree.
In one embodiment, the parsing module 604 is further configured to use the current word node as an edge node in the target syntax tree; determining a target production formula matched with the edge node from a plurality of production formulas, and taking a non-terminal symbol in the head of the target production formula as a father node of the edge node; taking the father node as a new edge node, and returning to the process of determining a target generating formula matched with the edge node from a plurality of generating formulas, and continuing until the non-terminal symbol is the root node; and integrating all the edge nodes to obtain a matching sub-result corresponding to the current word node.
In one embodiment, the print result determining module 606 is further configured to load a database resource corresponding to a preset environment, and synthesize the target sentence and the database resource to obtain an installation package file; the installation package file comprises a printer interface; when the installation package file is triggered, the printer interface is called, so that a target printer corresponding to the printer interface prints out a text printing result.
In one embodiment, a computer device is provided, which may be a server, and the internal structure of which may be as shown in fig. 7. The computer device includes a processor, a memory, an Input/Output interface (I/O) and a communication interface. The processor, the memory and the input/output interface are connected through a system bus, and the communication interface is connected to the system bus through the input/output interface. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database of the computer device is for storing text print data. The input/output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a text printing method.
It will be appreciated by those skilled in the art that the structure shown in fig. 7 is merely a block diagram of some of the structures associated with the present application and is not limiting of the computer device to which the present application may be applied, and that a particular computer device may include more or fewer components than shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, there is also provided a computer device including a memory and a processor, the memory storing a computer program, the processor implementing the steps of the method embodiments described above when executing the computer program.
In one embodiment, a computer-readable storage medium is provided, storing a computer program that, when executed by a processor, performs the steps of the method embodiments described above.
In one embodiment, a computer program product or computer program is provided that includes computer instructions stored in a computer readable storage medium. The processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps in the above-described method embodiments.
Those skilled in the art will appreciate that implementing all or part of the above-described methods may be accomplished by way of a computer program, which may be stored on a non-transitory computer readable storage medium and which, when executed, may comprise the steps of the above-described embodiments of the methods. Any application to memory, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high density embedded nonvolatile Memory, resistive random access Memory (ReRAM), magnetic random access Memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric Memory (Ferroelectric Random Access Memory, FRAM), phase change Memory (Phase Change Memory, PCM), graphene Memory, and the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, and the like. By way of illustration, and not limitation, RAM can be in the form of a variety of forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), and the like. The databases referred to in the various embodiments provided herein may include at least one of relational databases and non-relational databases. The non-relational database may include, but is not limited to, a blockchain-based distributed database, and the like. The processors referred to in the embodiments provided herein may be general purpose processors, central processing units, graphics processors, digital signal processors, programmable logic units, quantum computing-based data processing logic units, etc., without being limited thereto.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The foregoing examples represent only a few embodiments of the present application, which are described in more detail and are not thereby to be construed as limiting the scope of the present application. It should be noted that it would be apparent to those skilled in the art that various modifications and improvements could be made without departing from the spirit of the present application, which would be within the scope of the present application. Accordingly, the scope of protection of the present application shall be subject to the appended claims.

Claims (11)

1. A method of printing text, the method comprising:
when a printing instruction is acquired, determining a source sentence in the printing instruction;
performing lexical analysis on the source sentence to obtain a data stream comprising a plurality of word nodes;
carrying out grammar analysis on the data stream to obtain a target grammar tree, and compiling the target grammar tree into a target sentence suitable for a preset environment;
and loading resources to the preset environment according to the target statement to obtain a text printing result.
2. The method of claim 1, wherein prior to said determining a source statement in said print instruction, said method further comprises:
acquiring a technical document; the technical document includes a plurality of print functions;
according to the technical document, responding to the editing operation of the printing function, and obtaining a source sentence;
responding to the triggering operation of the printing control, and synthesizing the source statement and the printing statement corresponding to the printing control to generate a printing instruction; the print control exists in the form of a special plug-in.
3. The method of claim 1, wherein lexically analyzing the source sentence to obtain a data stream comprising a plurality of word nodes, comprises:
determining a plurality of words in the source sentence, and carrying out semantic recognition on each word through a finite state automaton to obtain word nodes and word types corresponding to each word;
marking the corresponding word nodes by using a plurality of word types to obtain marked word nodes;
and connecting a plurality of marked word nodes in series according to the arrangement sequence of each word to obtain a data stream.
4. The method of claim 1, wherein parsing the data stream to obtain a target syntax tree comprises:
determining an objective function corresponding to the data flow from a plurality of word nodes; the word nodes comprise nodes for representing functions;
and determining a target grammar corresponding to the target function, and constructing the data stream into a target grammar tree from bottom to top according to the target grammar.
5. The method of claim 4, wherein the target grammar comprises a plurality of production formulas; the constructing the data stream into a target grammar tree from bottom to top according to the target grammar comprises the following steps:
taking an initial node in the data stream as a root node in the target grammar tree, and traversing a plurality of word nodes in the data stream;
and matching the current word node with a plurality of production formulas in the target grammar to obtain a matching sub-result, and integrating a plurality of matching sub-results and the root node to obtain a target grammar tree.
6. The method of claim 5, wherein the generating comprises a header; the header is a non-terminal symbol; the matching of the current word node with a plurality of production formulas in the target grammar to obtain a matching sub-result comprises the following steps:
taking the current word node as an edge node in the target grammar tree;
determining a target production formula matched with the edge node from a plurality of production formulas, and taking a non-terminal symbol in a head of the target production formula as a father node of the edge node;
taking the father node as a new edge node, and returning to a process of determining a target production formula matched with the edge node from a plurality of production formulas, and continuing until the non-terminal symbol is a root node;
and integrating all edge nodes to obtain a matching sub-result corresponding to the current word node.
7. The method of claim 1, wherein the loading the resources of the preset environment according to the target sentence to obtain the text printing result includes:
loading database resources corresponding to the preset environment, and synthesizing the target statement and the database resources to obtain an installation package file; the installation package file comprises a printer interface;
and when the installation package file is triggered, calling the printer interface to enable the target printer corresponding to the printer interface to print out a text printing result.
8. A text printing device, the device comprising:
the lexical analysis module is used for determining a source sentence in the printing instruction when the printing instruction is acquired; performing lexical analysis on the source sentence to obtain a data stream comprising a plurality of word nodes;
the grammar analysis module is used for carrying out grammar analysis on the data stream to obtain a target grammar tree, and compiling the target grammar tree into a target sentence suitable for a preset environment;
and the printing result determining module is used for carrying out resource loading on the preset environment according to the target statement to obtain a text printing result.
9. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 7 when the computer program is executed.
10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method according to any one of claims 1 to 7.
11. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 7.
CN202310259126.XA 2023-03-08 2023-03-08 Text printing method, apparatus, computer device and storage medium Pending CN116301895A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310259126.XA CN116301895A (en) 2023-03-08 2023-03-08 Text printing method, apparatus, computer device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310259126.XA CN116301895A (en) 2023-03-08 2023-03-08 Text printing method, apparatus, computer device and storage medium

Publications (1)

Publication Number Publication Date
CN116301895A true CN116301895A (en) 2023-06-23

Family

ID=86786569

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310259126.XA Pending CN116301895A (en) 2023-03-08 2023-03-08 Text printing method, apparatus, computer device and storage medium

Country Status (1)

Country Link
CN (1) CN116301895A (en)

Similar Documents

Publication Publication Date Title
US20240078386A1 (en) Methods and systems for language-agnostic machine learning in natural language processing using feature extraction
US10691507B2 (en) API learning
CN106970820B (en) Code storage method and code storage device
US10719668B2 (en) System for machine translation
WO2018141140A1 (en) Method and device for semantic recognition
CN111190594B (en) Document generation method and device of Vue component
CN108984155B (en) Data processing flow setting method and device
CN108228676A (en) Information extraction method and system
CN112069456A (en) Model file generation method and device, electronic equipment and storage medium
TWI713015B (en) Language recognition method and device
JP2007041767A (en) Text mining device, method and program
CN114416926A (en) Keyword matching method and device, computing equipment and computer readable storage medium
Krishnan et al. Relative Extraction Methodology for class diagram generation using dependency graph
CN116400910A (en) Code performance optimization method based on API substitution
CN116301895A (en) Text printing method, apparatus, computer device and storage medium
Osis et al. Using Use Cases for Domain Modeling.
CN112115615A (en) SCR-oriented safety key system model conversion method, device and system
US20150324333A1 (en) Systems and methods for automatically generating hyperlinks
CN111522554A (en) Method and system for linear generalized LL recognition and context-aware parsing
CN117235236B (en) Dialogue method, dialogue device, computer equipment and storage medium
US20240004620A1 (en) Automated generation of web applications based on wireframe metadata generated from user requirements
KR102374034B1 (en) Apparatus for generating seed file and method thereof
CN114510922B (en) Text matching method and device
CN113885882B (en) Method for restoring iOS type character string
Plátek et al. On pumping RP-automata controlled by complete LRG (¢, $)-grammars

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination