CN108595171B - Object model generation method, device, equipment and storage medium - Google Patents

Object model generation method, device, equipment and storage medium Download PDF

Info

Publication number
CN108595171B
CN108595171B CN201810390448.7A CN201810390448A CN108595171B CN 108595171 B CN108595171 B CN 108595171B CN 201810390448 A CN201810390448 A CN 201810390448A CN 108595171 B CN108595171 B CN 108595171B
Authority
CN
China
Prior art keywords
model
language
programming language
modeled
file
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.)
Active
Application number
CN201810390448.7A
Other languages
Chinese (zh)
Other versions
CN108595171A (en
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.)
Guangzhou Shiyuan Electronics Thecnology Co Ltd
Guangzhou Shirui Electronics Co Ltd
Original Assignee
Guangzhou Shiyuan Electronics Thecnology Co Ltd
Guangzhou Shirui Electronics 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 Guangzhou Shiyuan Electronics Thecnology Co Ltd, Guangzhou Shirui Electronics Co Ltd filed Critical Guangzhou Shiyuan Electronics Thecnology Co Ltd
Priority to CN201810390448.7A priority Critical patent/CN108595171B/en
Publication of CN108595171A publication Critical patent/CN108595171A/en
Application granted granted Critical
Publication of CN108595171B publication Critical patent/CN108595171B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/35Creation or generation of source code model driven
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms
    • G06F8/315Object-oriented languages

Abstract

The invention discloses a method, a device, equipment and a storage medium for generating a model of an object, and relates to the technical field of computers. The method specifically comprises the following steps: acquiring a model definition file, wherein the model definition file is used for defining an object to be modeled; generating a language model of a programming language based on the model definition file, wherein the language models corresponding to different programming languages are different; acquiring object model basic data of an object to be modeled; inputting the basic data of the object model into a language model of a programming language to obtain a model object of the object to be modeled in the programming language, wherein the model object is generated by converting the basic data of the object model by the language model of the programming language, the model object is called in an application program, and the application program is a program in the programming language environment. By adopting the method, the technical problem of high development difficulty in object definition under different programming languages can be solved, the modeling procedure is simplified, and the compatibility of model objects is ensured.

Description

Object model generation method, device, equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for generating a model of an object.
Background
A programming language (programming language) is a formal language used to define computer programs. It is a standardized communication technique used to instruct computers. A programming language allows programmers to accurately define the data needed by a computer and to accurately define the actions that should be taken under different circumstances. Application programs in various programming language environments are generally integrated in existing intelligent devices. For example, the client electronic whiteboard application in the C # language, and the web page version application in the JavaScript language.
When a certain data is to be used in different programming language environments, a developer is required to define an object appearing in the data in a corresponding programming language so as to realize the invocation of the object. At this time, in order to ensure the compatibility of the data in different programming language environments, it is necessary to ensure that objects defined by different programming languages are completely consistent when a developer defines the objects, so that the data volume in the object definition process is large, and the development difficulty of the developer during program development is greatly increased.
Disclosure of Invention
In view of this, embodiments of the present invention provide a method, an apparatus, a device, and a storage medium for generating a model of an object, so as to solve the technical problem in the prior art that development difficulty is large when defining an object in different programming languages.
In a first aspect, an embodiment of the present invention provides a method for generating a model of an object, including:
obtaining a model definition file, wherein the model definition file is used for defining an object to be modeled;
generating a language model of a programming language based on the model definition file, wherein the language models corresponding to different programming languages are different;
acquiring object model basic data of an object to be modeled;
inputting the basic data of the object model into a language model of a programming language to obtain a model object of the object to be modeled under the programming language, wherein the model object is generated by converting the basic data of the object model by the language model of the programming language, the model object is called in an application program, and the application program is a program under the environment of the programming language.
In a second aspect, an embodiment of the present invention further provides an apparatus for generating a model of an object, including:
the file acquisition module is used for acquiring a model definition file, and the model definition file is used for defining an object to be modeled;
the model generation module is used for generating language models of programming languages based on the model definition file, and the language models corresponding to different programming languages are different;
the data acquisition module is used for acquiring the basic data of an object model of the object to be modeled;
the model establishing module is used for inputting the basic data of the object model into a language model of a programming language to obtain a model object of the object to be established under the programming language, the model object is generated after the language model of the programming language converts the basic data of the object model, the model object is called in an application program, and the application program is a program under the programming language environment.
In a third aspect, an embodiment of the present invention further provides an apparatus for generating a model of an object, including:
a memory and one or more processors;
the memory for storing one or more programs;
when the one or more programs are executed by the one or more processors, the one or more processors implement the method for generating a model of an object according to the embodiment of the present invention.
In a fourth aspect, the present invention further provides a storage medium containing computer-executable instructions, which when executed by a computer processor, are used for executing the model generation method of the object according to the present invention.
The method, the device, the equipment and the storage medium for generating the object model generate the language model of the programming language through the model definition file, and convert the basic data of the object model of the object to be modeled into the model object under the programming language by utilizing the language model of the programming language, thereby solving the technical problems that in the prior art, the technical problem of great development difficulty in object definition can quickly generate the model object of the object to be modeled in the programming language environment, and the model definition file can ensure that the same object to be modeled has consistent model objects in different programming language environments, and meanwhile, the model object can be defined by adopting a model definition file under different programming languages, so that the modeling process is simplified, the development difficulty is reduced, and the utilization rate of the model definition file is improved.
Drawings
Other features, objects and advantages of the invention will become more apparent upon reading of the detailed description of non-limiting embodiments made with reference to the following drawings:
fig. 1 is a flowchart of a method for generating a model of an object according to an embodiment of the present invention;
fig. 2 is a flowchart of a method for generating a model of an object according to a second embodiment of the present invention;
FIG. 3 is a block diagram of a process flow in generating a language model;
fig. 4 is a schematic structural diagram of an object model generation apparatus according to a third embodiment of the present invention;
fig. 5 is a schematic structural diagram of an object model generation device according to a fourth embodiment of the present invention.
Detailed Description
The present invention will be described in further detail with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the invention and are not limiting of the invention. It should be further noted that, for the convenience of description, only some but not all of the relevant aspects of the present invention are shown in the drawings.
The method for generating a model of an object provided in the embodiments may be performed by a model generating device of an object, where the model generating device of an object may be implemented in a software and/or hardware manner, and the model generating device of an object may be formed by two or more physical entities or may be formed by one physical entity. The model generation device of the object can be a computer, a mobile phone, a tablet or an intelligent interactive tablet and the like. In the embodiment, the model generating apparatus with a computer as an object is described as an example, wherein the computer may be a desktop computer or a notebook computer, which has a code input function and is provided with a grammar library of a plurality of programming languages, and in general, the computer can meet general programming requirements.
Specifically, the method for generating the object model provided by the embodiment is suitable for a scene in which the same object is modeled in different programming languages. For example, in a Windows system, a local electronic whiteboard application is developed by using a C # language, and a web-based electronic whiteboard application is developed by using a JavaScript language. At this time, objects in the local electronic whiteboard application exist model objects in the C # language, and all of "handwriting", "rectangle", "circle", and "picture" have model objects in the C # language. The object in the webpage version electronic whiteboard application also has a model object in the JavaScript language. In order to ensure compatibility between the local electronic whiteboard application and the web page version electronic whiteboard application, for example, the same "rectangle" may be used in both the local electronic whiteboard application and the web page version electronic whiteboard, it is necessary to ensure that the model object of the same object in the C # language is completely consistent with the model object in the JavaScript language. The method for generating the model of the object provided in the embodiment is just applied to the above example scenario to provide a simple and fast method for realizing modeling of the same object in different programming languages.
Example one
Fig. 1 is a flowchart of a method for generating a model of an object according to an embodiment of the present invention. Referring to fig. 1, the object code generation method provided in this embodiment specifically includes:
and S110, acquiring a model definition file.
The model definition file is used for defining an object to be modeled.
Specifically, an object refers to a single individual that actually exists in the real world. The object to be modeled refers to an object which needs to be modeled currently. The model object is a section of program which ensures that the object to be modeled can be called by an application program in the using process of the application program. For example, if the object to be modeled is a rectangle, then the model object may be a piece of program that enables an electronic whiteboard application to draw the rectangle. Generally, the programming language of the model object is the same as the programming language used by the application program when running, for example, the application program is an application in C # language, and then the programming language of the model object is C #.
For example, when generating the model definition file, the programming language of the model object does not need to be considered, and the model object is described by using the set intermediate syntax. Specifically, the specific content of the intermediate grammar can be set according to the actual situation. Optionally, in the embodiment, the model definition file includes: the documentation of the field, the name the field was used to store, and the field definition. Wherein the field represents the object to be modeled or the model base data of the object to be modeled. The model basic data of the object to be modeled comprises elements of the object to be modeled or parameters called by the model object. An element is a child object that the object to be modeled includes at the time of invocation. For example, the object to be modeled is a page, the corresponding element may be a rectangular box displayed in the page, and the called parameter may be height, width, background color, and the like. Further, the name used when the field is stored may be understood as the name used when the field is stored by the computer, which is generally the name of the field type, for example, the name may be: page, height, width, background color, etc., without reference to the type specific data. In the subsequent process, the computer can call corresponding programs in other files according to the name. In general, the same field stores the same name in different files, e.g., the name in the model definition file is the same as the name that the field stores in the object model base data. The basic data of the object model is generated by the pointer to the object to be modeled and contains the code data of the attribute information of the object to be modeled.
Based on the specific contents of the model definition file, exemplary description of the corresponding intermediate syntax is as follows:
Figure BDA0001643324400000061
the syntax includes a model name (modelname), a document description of a field, a name used when the field is stored, and a field definition. Based on the model definition file, the computer may determine the object to be modeled. In general, a model definition file only implements the definition of objects to be modeled, and does not refer to the specific programming language of the corresponding model object.
And S120, generating a language model of the programming language based on the model definition file.
Wherein, the language models corresponding to different programming languages are different.
In particular, the programming language is a formal language used to define computer programs. The programming language mentioned in the embodiments may be selected as a high-level programming language, which may include at least one of: c language, C + + language, C # language, Java language, JavaScript language (JS language), Typescript language, Microsoft Visual C + + language. In practice, the programming language may also include other categories, such as structured query language, etc. Generally, as long as the conversion relation and the language library of the programming language are stored in the computer, the language model of the programming language can be generated based on the model definition file. Optionally, the programming language of the currently generated language model may be determined according to a programming language environment when the application program is running, for example, a certain application program only includes a Java language environment and a C + + language environment, and at this time, only the Java language model and the C + + language model need to be generated.
Specifically, the language model of the programming language is generally source code in the programming language, which represents basic rules of the object to be modeled when generating the model object in the programming language. The same object to be programmed can correspond to different language models in different programming languages, and different objects to be programmed can correspond to different language models in the same programming language. In generating the language model of the programming language, the template recognition model definition file may be generated using a code of the programming language. The code generation template is a basic rule of the code writing under the programming language, is irrelevant to an object to be coded, and can be understood as a universal rule. Generally, a code generation template of a programming language only needs to be generated once, and can be used for identifying a model definition file of any object to be coded to generate a language model of the object to be modeled in the programming language.
And S130, acquiring the basic data of the object model of the object to be modeled.
Illustratively, the object model basic data refers to code data which is generated aiming at an object to be modeled and contains attribute information of the object to be modeled. In short, the basic data of the object model may include an application program or all data that may be used by the application program when the application program uses the object to be modeled in a certain scenario, where the application program does not limit the version mode, such as the application programs of a mobile phone end, a computer end, and a web page end. In practical application, the contents of the object model basic data corresponding to different objects to be modeled may be different, and the specific contents included therein may be set according to actual conditions. Taking an object to be modeled displayed in a display screen as an example, the basic data of the object model comprises: the method comprises the following steps of identifying Identification (ID) of an object to be modeled, height of the object to be modeled, width of the object to be modeled, background information of the object to be modeled, element data contained in the object to be modeled and the like. Wherein, the background information of the object to be modeled comprises a background color. Further, the element data included in the object to be modeled includes basic information of the element, and the basic information specifically includes: the geometry of the element, the background color of the element, the foreground color of the element, the thickness of the element, the line type of the element, the opacity of the element, the ID of the element, the coordinate position of the origin of the element, the width of the element, the height of the element, the angle of the element, whether the element is locked, whether the element is copied, the position of the center of rotation, and the like. Generally, the basic data of the object model is input by a developer and then stored in a computer so as to be called and used by the computer when needed, and the basic data can be generally regarded as a document and not a method.
Further, the Object model basic data is Extensible Markup Language (XML) data or JavaScript Object Notation (JSON) data.
In the embodiment, an XML or JSON is adopted to describe the object to be modeled so as to obtain basic data of the object model. XML is a markup language for marking electronic documents to have a structure. XML can structure documents and data to facilitate the description of objects. JSON is a lightweight data exchange format that stores and represents data in a text format that is completely independent of the programming language. XML and JSON can simply and clearly describe the object to be modeled in a structured way, so that the model object can be conveniently generated according to the basic data of the object model. It should be noted that XML and JSON are only two preferred formats of the object model basic data, and in practical applications, other data formats that can be used for describing the object to be modeled can be used for the object model basic data.
And S140, inputting the basic data of the object model into a language model of the programming language to obtain a model object of the object to be modeled in the programming language.
The model object is generated by converting the basic data of the object model by the language model of the programming language, the model object is used in the application program, and the application program is a program in the programming language environment. For example, the model object is a rectangle used in the electronic whiteboard software, and the electronic whiteboard software is web-based electronic whiteboard software used in JS language, or the model object is still a rectangle used in the electronic whiteboard software, and the electronic whiteboard software is client-side electronic whiteboard software used in C # language.
Specifically, the way in which the language model identifies the basic data of the object model is not limited in the embodiment, and is generally determined according to the basic rule when the model object is encoded in the language model. The basic data of the object model is irrelevant to the programming language, and different programming languages adopt the same model definition file and are also irrelevant to the programming language when the language model is generated, so after the language models of different coding languages identify the basic data of the object model, the obtained model objects are completely consistent, and the compatibility of the same object in the same application program under different programming languages is ensured.
According to the technical scheme provided by the embodiment, the language model of the programming language is generated through the model definition file, the language model of the programming language is utilized, the object model basic data of the object to be modeled is converted into the model object under the programming language, the model object of the object to be modeled under the programming language environment can be rapidly generated, the model objects of the same object to be modeled under different programming language environments can be ensured to be consistent through the model definition file, the compatibility of the object to be modeled is further ensured, meanwhile, the model object can be defined by adopting one model definition file under different programming languages, the modeling process is simplified, the development difficulty is reduced, and the utilization rate of the model definition file is improved.
Example two
Fig. 2 is a flowchart of a method for generating a model of an object according to a second embodiment of the present invention. The present embodiment is embodied on the basis of the above-described embodiments. Specifically, generating the language model of the programming language based on the model definition file includes: compiling the model definition file to obtain a syntax tree file; and utilizing a code generation template recognition grammar tree file of the programming language to obtain a language model of the programming language.
Referring to fig. 2, the object code generation method provided in this embodiment specifically includes:
and S210, obtaining a model definition file.
The model definition file is used for defining an object to be modeled.
And S220, compiling the model definition file to obtain a syntax tree file.
Illustratively, a syntax tree may be considered as a tree formed when a model definition file is derived according to a certain rule, which is helpful for understanding the hierarchy of sentence syntax structure in the model definition file. Each node in the syntax tree represents a structure of the model definition file. Generally, a file containing a syntax tree can be referred to as a syntax tree file.
The specific manner of editing the model definition file is not limited in the embodiments. For example, after lexical and grammatical parsing of the model definition file, a grammar tree is constructed from at least one grammar phrase obtained. The specific operation is as follows:
and S221, performing lexical analysis on the model definition file to determine recognizable words contained in the model definition file.
By way of example, lexical analysis is a process of converting a sequence of characters into a sequence of words in computer science, which is a principle of compilation. In short, lexical analysis identifies various types of words according to the lexical rules of the language. Lexical analysis is generally located in the first stage of the compilation process, and in embodiments is located in the first stage of compiling the model definition file. The program or function that performs the lexical analysis is called a lexical analyzer, which may also be called a scanner, and generally exists in the form of a function.
Specifically, during lexical analysis, the model definition file is scanned in a preselected manner. The method comprises the following steps: reading characters in the model definition file in sequence from left to right, and recognizing words with independent meanings in the model definition file by using lexical rules of the language. Where words with independent meaning can be marked as recognizable words, which are typically used by a parser.
S222, carrying out grammar analysis on the recognizable words to form at least one grammar short sentence.
Specifically, the grammar analysis belongs to program editing, and is mainly used for combining recognizable words into various grammar short sentences on the basis of lexical analysis. The program that performs the parsing task is called a parser. Specifically, the grammar analyzer identifies a corresponding grammar category from a lexical analysis result according to grammar rules of the source language to obtain at least one grammar clause. Optionally, the syntax analysis may further determine whether the model definition file is correct in structure, specifically: and when the grammar short sentence is obtained, carrying out grammar check on the grammar short sentence so as to determine whether the model definition file is correct in structure. Further, during parsing, a top-down parsing method may be adopted, or a bottom-up parsing method may also be adopted, which is not limited in the embodiments.
S223, converting at least one grammar short sentence into a grammar tree and forming a corresponding grammar tree file.
Specifically, the nodes of the syntax tree are allocated according to at least one syntax short sentence obtained by syntax analysis, the syntax tree can be obtained after the node allocation is completed, and the syntax tree is further stored to obtain a corresponding syntax tree file.
And S230, generating a template recognition grammar tree file by using codes of the programming language to obtain a language model of the programming language.
The code generation template is a basic rule of the code writing under the programming language, is irrelevant to an object to be coded, and can be understood as a universal rule. It is typically written by a developer and saved and called when needed. Generally, a code generation template of a programming language only needs to be written once and can be reused.
Further, the file format of the code generation template of the programming language is as follows: an EJS file format, an extended Stylesheet Language Transformation (XSLT) format, or a Mustache file format. The EJS is a JavaScript template library which is mainly used for generating an HTML character string from JSON data. When the basic data of the object model is JSON data, the code generation template can adopt a file in an EJS format to ensure that the generated language model accurately identifies the JSON data. XSLT is a language for translating XML documents. When the basic data of the object model is XML data, the code generation template can adopt a file in an XSLT format to ensure that the generated language model can accurately identify the XML data. Mustache is a front-end template engine, and can directly generate HTML of a corresponding module through JSON data. When the basic data of the object model is JSON data, a Mustache file can be selected as the code generation template so as to ensure that the generated language model can accurately identify the JSON data.
Further, after the code generation template identifies the syntax tree file, the rule for calling the object model basic data and the processing rule for calling the object model basic data can be determined, that is, the language model of the programming language is generated, and at this time, the language model can be regarded as the generation method of the model object.
The following describes an exemplary creation process of the language model in the embodiment:
specifically, the programming languages include: c + + language, Java language and JS language, at this time, the corresponding language model includes: a language model of C + +, a language model of Java, and a language model of JS.
Illustratively, FIG. 3 is a block flow diagram of the generation of a language model. Referring to fig. 3, the model definition file is compiled by the compiler 21, wherein the compiler 21 includes three parts: lexical analysis, syntactic analysis, and construction of a syntax tree. Specifically, after the model definition file is input into the compiler 21, the compiler 21 performs lexical analysis on the model definition file to obtain at least one recognizable word, and then uses syntactic analysis to form at least one syntactic short sentence from the at least one recognizable word, and then allocates nodes of the syntactic tree based on the syntactic short sentence to obtain the syntactic tree.
Further, the language model is executed by the model generation module 22. Specifically, the compiler 21 compiles the model definition file and outputs the syntax tree file to the model generation module 22. Further, the model generation module 22 may call the C + + code generation template, the Java code generation template, and the JS code generation template, and respectively identify the syntax tree file by using the three code generation templates to obtain a corresponding C + + language model, a Java language model, and a JS language model, where the language model is a source code in a corresponding programming language. The specific execution sequence of the three code generation templates identifying the syntax tree file is not limited in the embodiment. For example, three code generation templates may simultaneously recognize syntax tree files to simultaneously generate language models for three programming languages. For another example, any one of the three code generation templates is selected to identify the syntax tree file, and after the language model is generated, another code generation template is selected to identify the syntax tree file, and so on, so as to obtain the three language models in sequence.
And S240, acquiring the basic data of the object model of the object to be modeled.
And S250, acquiring a programming language selection instruction.
Specifically, the programming language selection instruction is used to instruct the computer to determine which type of programming language the model object belongs to, which may be determined by the computer according to the programming language environment of the application program, and generally speaking, the programming language selection instruction includes a name or an identifier of at least one programming language. For example, if the current application program can be executed in JS language or C # language, the computer can determine that the programming language selected instruction includes JS language and C # language. As another example, the current application may run in the Java language, and the computer may then determine that the programming language selected instructions include the Java language.
And S260, determining a programming language according to the selected programming language instruction.
Specifically, after the selected instruction of the programming language is analyzed, the selected programming language can be determined, and then the language model of the selected programming language is called to obtain the object model of the object to be selected in the programming language.
S240 may be executed after the execution of S250 and S260 is completed. In addition, the execution sequence of S210-S230 is not limited in the embodiments, and may be executed before, after, or simultaneously with S240, S250, or S260. When S210-S230 is executed before S240 or S250, it is a language model that generates all possible programming languages in advance so as to directly call the language model in the subsequent process. When the S210-S230 is executed after S260, it may be determined whether a language model of a programming language exists, if the language model of the programming language exists, the language model may be directly called, and if the language model of the programming language does not exist, the language model in the programming language may be generated according to S210-S230. This has the advantage that the entire language model does not need to be generated in advance, reducing the computer throughput.
And S270, inputting the basic data of the object model into a language model of the programming language to obtain a model object of the object to be modeled in the programming language.
The model object is generated by converting the basic data of the object model by the language model of the programming language, the model object is used in the application program, and the application program is a program in the programming language environment.
The technical solution provided by this embodiment is to generate a syntax tree file by identifying a model definition file, generate a language model of a programming language by identifying the syntax tree file by a code generation template, convert object model basic data of an object to be modeled into a model object in the programming language by using the language model of the programming language, the model objects of the objects to be modeled can be obtained quickly, and the model objects of the same object to be modeled are consistent under different programming language environments, so as to ensure the compatibility of the objects to be modeled, and simultaneously, since the basic data of the object model is a document, and the code generation template in the language model is a general method, therefore, the model definition file can be considered to associate the general method with the document of the object to be modeled to obtain the model object, and the model object under different programming languages is not required to be defined repeatedly.
The following describes an exemplary method for generating a model of an object provided in the embodiment:
specifically, the object to be modeled is a page of the electronic whiteboard, and the model definition file is recorded as: the TopModel model file has the following specific model definition file:
Figure BDA0001643324400000141
Figure BDA0001643324400000151
based on the model definition file, the model definition file includes: the method comprises the steps of describing a document description 'representing page' of an object to be modeled, a name 'Slide' of the object to be modeled when the object to be modeled is stored, defining 'model Slide' of a model of the object to be modeled, and describing, names and definitions of model basic data (such as unique identification, page width, page height, background and the like) contained in the page.
Furthermore, the model definition file is analyzed in a lexical mode and a syntactic mode, a syntactic tree file is constructed, and the syntactic tree file is recognized according to a code generation template so as to obtain a language model of the programming language.
The source code of the language model is as follows:
Figure BDA0001643324400000152
Figure BDA0001643324400000161
Figure BDA0001643324400000171
further, the basic data of the object model is JSON data, which is specifically as follows:
Figure BDA0001643324400000172
specifically, the basic rule of the model object can be obtained from the language model, and the description is performed by combining the language model and the basic data of the object model by taking the unique identifier, the page width and the element combination as examples. When a model object is created, its unique identification needs to reference an "Id" in the object model base data. The page Width of the model object needs to be according to the numerical value recorded in the Width of the object model basic data. The set of Elements contained in the model object needs to be based on the data set of "Elements" in the object model base data.
Further, the following is a model object generated by the language model recognizing the object model basic data:
Figure BDA0001643324400000181
the obtained model object can be called by an application program. If a model object of another programming language needs to be obtained, only a corresponding code generation template needs to be called to identify a syntax tree file of the TopModel template file so as to obtain a language model, and then basic data of the object model is input into the language model so as to obtain a corresponding model object without reprogramming a source program of the model object by developers.
EXAMPLE III
Fig. 4 is a schematic structural diagram of an object model generation apparatus according to a third embodiment of the present invention. Referring to fig. 4, the model generation apparatus for an object provided in this embodiment includes: a file acquisition module 301, a model generation module 302, a data acquisition module 303, and a model building module 304.
The file acquiring module 301 is configured to acquire a model definition file, where the model definition file is used to define an object to be modeled; the model generation module 302 is configured to generate language models of programming languages based on the model definition file, where the language models corresponding to different programming languages are different; a data obtaining module 303, configured to obtain object model basic data of an object to be modeled; the model establishing module 304 is configured to input the object model basic data into a language model of a programming language to obtain a model object of the object to be modeled in the programming language, where the model object is generated by converting the object model basic data by the language model of the programming language, the model object is called in an application program, and the application program is a program in the programming language environment.
According to the technical scheme provided by the embodiment, the language model of the programming language is generated through the model definition file, the language model of the programming language is utilized, the object model basic data of the object to be modeled is converted into the model object under the programming language, the model object of the object to be modeled under the programming language environment can be rapidly generated, the model objects of the same object to be modeled under different programming language environments can be ensured to be consistent through the model definition file, the compatibility of the object to be modeled is further ensured, meanwhile, the model object can be defined by adopting one model definition file under different programming languages, the modeling process is simplified, the development difficulty is reduced, and the utilization rate of the model definition file is improved.
On the basis of the above embodiment, the model generation module 302 includes: the syntax tree construction unit is used for compiling the model definition file to obtain a syntax tree file; and the grammar tree recognition unit is used for recognizing the grammar tree file by utilizing the code generation template of the programming language so as to obtain a language model of the programming language.
On the basis of the above embodiment, the model definition file includes: the document description of the field, the name used by the field in the object model base data, and the field definition, the field representing the object to be modeled or the model base data of the object to be modeled.
On the basis of the above embodiment, the syntax tree construction module unit: the lexical analysis subunit is used for carrying out lexical analysis on the model definition file so as to determine recognizable words contained in the model definition file; a grammar analysis subunit, which is used for carrying out grammar analysis on the recognizable words so as to form at least one grammar short sentence; and the grammar tree forming subunit is used for converting the at least one grammar short sentence into a grammar tree so as to form a corresponding grammar tree file.
On the basis of the above embodiment, the file format of the code generation template of the programming language is: the EJS file format, the extended style sheet conversion language file format or the Mustache file format.
On the basis of the above embodiment, the object model basic data is data in extensible markup language format or data in JavaScript object markup language format.
On the basis of the above embodiment, the programming language includes at least one of: c language, C + + language, C # language, Java language, JavaScript language, Typescript language, Microsoft Visual C + + language.
On the basis of the above embodiment, the object code generating apparatus further includes: the selected instruction acquisition module is used for acquiring a programming language selected instruction before or after acquiring the object model basic data of the object to be modeled; and the language determination module is used for determining the programming language according to the selected instruction of the programming language.
The object model generation device provided by this embodiment can be used to execute the object model generation method provided by any of the above embodiments, and has corresponding functions and advantages.
Example four
Fig. 5 is a schematic structural diagram of an object model generation device according to a fourth embodiment of the present invention. As shown in fig. 5, the model generating apparatus of the object includes: a processor 40, a memory 41, an input device 42, and an output device 43. The number of processors 40 in the model generation apparatus of the object may be one or more, and one processor 40 is taken as an example in fig. 5. The number of the memories 41 in the model generation device of the object may be one or more, and one memory 41 is taken as an example in fig. 5. The processor 40, the memory 41, the input device 42 and the output device 43 of the model generation apparatus of the object may be connected by a bus or other means, and fig. 5 illustrates the case of connection by a bus. In an embodiment, the model generation device of the object may be a notebook, a mobile phone, a tablet, or an interactive smart tablet.
The memory 41 is a computer-readable storage medium, and can be used for storing software programs, computer-executable programs, and modules, such as program instructions/modules corresponding to the model generation method of the object according to any embodiment of the present invention (for example, the file acquisition module 301, the model generation module 302, the data acquisition module 303, and the model creation module 304 in the model generation device of the object). The memory 41 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function; the storage data area may store data created according to use of the device, and the like. Further, the memory 41 may include high speed random access memory, and may also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other non-volatile solid state storage device. In some instances, memory 41 may further include memory located remotely from processor 40, which may be connected to a model generation facility for the object via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The input device 42 may be used to receive input numeric or character information and to generate key signal inputs related to user settings and function controls of the model generating apparatus of the object, a camera for acquiring images and/or a sound pickup apparatus for acquiring audio data, and the like. The output means 43 may comprise a display device such as a display screen and/or an audio device such as a speaker. It should be noted that the model generation device of the object may further include a communication device (not shown) for establishing a communication connection with other devices, which may be a wired communication device and/or a wireless communication device.
The processor 40 executes various functional applications of the device and data processing, i.e., implements the above-described model generation method of the object, by executing software programs, instructions, and modules stored in the memory 41.
Specifically, in the embodiment, when the processor 40 executes one or more programs stored in the memory 41, the following operations are specifically implemented: acquiring a model definition file, wherein the model definition file is used for defining an object to be modeled; generating a language model of a programming language based on the model definition file, wherein the language models corresponding to different programming languages are different; acquiring object model basic data of an object to be modeled; inputting the basic data of the object model into a language model of a programming language to obtain a model object of the object to be modeled in the programming language, wherein the model object is generated by converting the basic data of the object model by the language model of the programming language, the model object is called in an application program, and the application program is a program in the programming language environment.
On the basis of the above embodiment, when the processor 40 implements the language model of the programming language by executing one or more programs stored in the memory 41 based on the model definition file, the following operations are specifically implemented: compiling the model definition file to obtain a syntax tree file; and utilizing a code generation template recognition grammar tree file of the programming language to obtain a language model of the programming language.
On the basis of the above embodiment, the model definition file includes: the document description of the field, the name used by the field in the object model base data, and the field definition, the field representing the object to be modeled or the model base data of the object to be modeled.
On the basis of the above embodiment, when the processor 40 implements compiling the model definition file by executing one or more programs stored in the memory 41 to obtain the syntax tree file, the following operations are implemented: performing lexical analysis on the model definition file to determine recognizable words contained in the model definition file; performing syntactic analysis on the recognizable words to form at least one syntactic phrase; and converting the at least one grammar short sentence into a grammar tree to form a corresponding grammar tree file.
On the basis of the above embodiment, the file format of the code generation template of the programming language is: the EJS file format, the extended style sheet conversion language file format or the Mustache file format.
On the basis of the above embodiment, the object model basic data is data in extensible markup language format or data in JavaScript object markup language format.
On the basis of the above embodiment, the programming language includes at least one of: c language, C + + language, C # language, Java language, JavaScript language, Typescript language, Microsoft Visual C + + language.
On the basis of the above embodiment, the processor 40 implements the following operations before or after acquiring the basic data of the object model by executing one or more programs stored in the memory 41: acquiring a programming language selection instruction; the programming language is determined according to the selected instructions of the programming language.
The model generation device for the object provided above can be used to execute the model generation method for the object provided in any of the above embodiments, and has corresponding functions and advantages.
EXAMPLE five
An embodiment of the present invention further provides a storage medium containing computer-executable instructions, which when executed by a computer processor, perform a method for generating a model of an object, including:
acquiring a model definition file, wherein the model definition file is used for defining an object to be modeled;
generating a language model of a programming language based on the model definition file, wherein the language models corresponding to different programming languages are different;
acquiring object model basic data of an object to be modeled;
and inputting the basic data of the object model into a language model of a programming language so as to convert the basic data of the object model into a model object of the object to be modeled under the programming language, wherein the model object is called in an application program, and the application program is a program under the programming language environment.
Of course, the storage medium containing the computer-executable instructions provided by the embodiments of the present invention is not limited to the operations of the model generation method of the object described above, and may also perform related operations in the model generation method of the object provided by any embodiments of the present invention, and has corresponding functions and advantages.
From the above description of the embodiments, it is obvious for those skilled in the art that the present invention can be implemented by software and necessary general hardware, and certainly, can also be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions to enable a computer device (which may be a robot, a personal computer, a server, or a network device) to execute the method for generating the model of the object according to any embodiment of the present invention.
It should be noted that, in the above object model generation apparatus, each unit and each module included in the object model generation apparatus are only divided according to functional logic, but are not limited to the above division as long as the corresponding functions can be realized; in addition, specific names of the functional units are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present invention.
It should be understood that portions of the present invention may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above do not necessarily refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present invention and the technical principles employed. It will be understood by those skilled in the art that the present invention is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the invention. Therefore, although the present invention has been described in greater detail by the above embodiments, the present invention is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims (10)

1. A method of generating a model of an object, comprising:
obtaining a model definition file, wherein the model definition file is used for defining an object to be modeled;
generating a language model of a programming language based on the model definition file, wherein the language models corresponding to different programming languages are different;
acquiring object model basic data of an object to be modeled;
inputting the basic data of the object model into a language model of a programming language to obtain a model object of the object to be modeled under the programming language, wherein the model object is generated by converting the basic data of the object model by the language model of the programming language, the model object is called in an application program, and the application program is a program under the environment of the programming language;
wherein the generating a language model of a programming language based on the model definition file comprises:
compiling the model definition file to obtain a syntax tree file;
and recognizing the grammar tree file by utilizing a code generation template of the programming language to obtain a language model of the programming language.
2. The method of generating a model of an object according to claim 1, wherein the model definition file comprises: the method comprises the following steps of describing a document of a field, using a name of the field when the field is stored and defining the field, wherein the field represents the object to be modeled or model basic data of the object to be modeled.
3. The method for generating a model of an object according to claim 1, wherein compiling the model definition file to obtain a syntax tree file comprises:
performing lexical analysis on the model definition file to determine recognizable words contained in the model definition file;
parsing the recognizable words to form at least one grammatical phrase;
and converting the at least one grammar short sentence into a grammar tree to form a corresponding grammar tree file.
4. The method of generating a model of an object according to claim 1, wherein the file format of the code generation template of the programming language is: the EJS file format, the extended style sheet conversion language file format or the Mustache file format.
5. The method of generating an object model according to claim 1, wherein the object model base data is extensible markup language format data or JavaScript object markup language format data.
6. The method of generating a model of an object according to claim 1, wherein the programming language comprises at least one of:
c language, C + + language, C # language, Java language, JavaScript language, Typescript language, Microsoft Visual C + + language.
7. The method of claim 6, wherein before or after the obtaining of the object model basic data of the object to be modeled, the method further comprises:
acquiring a programming language selection instruction;
and determining a programming language according to the selected instruction of the programming language.
8. An apparatus for generating a model of an object, comprising:
the file acquisition module is used for acquiring a model definition file, and the model definition file is used for defining an object to be modeled;
the model generation module is used for generating language models of programming languages based on the model definition file, and the language models corresponding to different programming languages are different;
the data acquisition module is used for acquiring the basic data of an object model of the object to be modeled;
the model building module is used for inputting the basic data of the object model into a language model of a programming language to obtain a model object of the object to be modeled under the programming language, wherein the model object is generated after the basic data of the object model is converted by the language model of the programming language, the model object is called in an application program, and the application program is a program under the programming language environment;
wherein the model generation module comprises:
the syntax tree construction unit is used for compiling the model definition file to obtain a syntax tree file;
and the grammar tree recognition unit is used for recognizing the grammar tree file by using a code generation template of the programming language so as to obtain a language model of the programming language.
9. An apparatus for generating a model of an object, comprising:
a memory and one or more processors;
the memory for storing one or more programs;
when executed by the one or more processors, cause the one or more processors to implement a method of model generation of an object as claimed in any one of claims 1-7.
10. A storage medium containing computer-executable instructions for performing a method of model generation of an object according to any of claims 1-7 when executed by a computer processor.
CN201810390448.7A 2018-04-27 2018-04-27 Object model generation method, device, equipment and storage medium Active CN108595171B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810390448.7A CN108595171B (en) 2018-04-27 2018-04-27 Object model generation method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810390448.7A CN108595171B (en) 2018-04-27 2018-04-27 Object model generation method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN108595171A CN108595171A (en) 2018-09-28
CN108595171B true CN108595171B (en) 2021-08-10

Family

ID=63610609

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810390448.7A Active CN108595171B (en) 2018-04-27 2018-04-27 Object model generation method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN108595171B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110457264B (en) * 2019-08-15 2022-04-01 深圳市威屏科技有限公司 Conference file processing method, device, equipment and computer readable storage medium
CN111736840A (en) * 2019-09-19 2020-10-02 北京沃东天骏信息技术有限公司 Compiling method and running method of applet, storage medium and electronic equipment
CN110851119A (en) * 2019-10-21 2020-02-28 杭州米圈科技有限公司 Method for realizing correlation between user-defined object and object of software as a service (SaaS) software product
CN111625243B (en) * 2020-05-13 2023-07-18 北京字节跳动网络技术有限公司 Cross-language task processing method and device and electronic equipment
CN111966333A (en) * 2020-07-28 2020-11-20 锐达互动科技股份有限公司 Method, device, equipment and medium for realizing dynamic template background insertion
CN112269566B (en) * 2020-11-03 2022-09-02 支付宝(杭州)信息技术有限公司 Script generation processing method, device, equipment and system
CN115826935B (en) * 2023-02-14 2023-04-28 中国航空油料集团有限公司 Digital twin model integration system and method based on unified language middleware

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1783090A (en) * 2004-11-30 2006-06-07 国际商业机器公司 Sharable two way method and system for switching between object model and XML
CN101841515A (en) * 2009-03-19 2010-09-22 北京理工大学 Target variable protocol data unit codec code automatic generation implementation method
CN102929681A (en) * 2012-10-31 2013-02-13 中国运载火箭技术研究院 Frame code automatic generating method of virtual test distributed type object model
CN106951310A (en) * 2016-01-06 2017-07-14 北京仿真中心 A kind of automatic generation method of simulation frame towards LVC

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7287035B2 (en) * 2004-02-20 2007-10-23 Microsoft Corporation Evaluating queries against in-memory objects without serialization

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1783090A (en) * 2004-11-30 2006-06-07 国际商业机器公司 Sharable two way method and system for switching between object model and XML
CN101841515A (en) * 2009-03-19 2010-09-22 北京理工大学 Target variable protocol data unit codec code automatic generation implementation method
CN102929681A (en) * 2012-10-31 2013-02-13 中国运载火箭技术研究院 Frame code automatic generating method of virtual test distributed type object model
CN106951310A (en) * 2016-01-06 2017-07-14 北京仿真中心 A kind of automatic generation method of simulation frame towards LVC

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
程序设计语言模型的设计与实现;王玫;《中国优秀博硕士学位论文全文数据库(硕士)信息科技辑》;20050315;全文 *

Also Published As

Publication number Publication date
CN108595171A (en) 2018-09-28

Similar Documents

Publication Publication Date Title
CN108595171B (en) Object model generation method, device, equipment and storage medium
CN111708539B (en) Application program code conversion method and device, electronic equipment and storage medium
EP3433732B1 (en) Converting visual diagrams into code
US9886268B1 (en) Dual programming interface
US20080221870A1 (en) System and method for revising natural language parse trees
WO2019233293A1 (en) Method and apparatus for developing application program
CN108958725B (en) Graphical mode programming platform generation method and device and computer equipment
CN111736840A (en) Compiling method and running method of applet, storage medium and electronic equipment
CN110941427B (en) Code generation method and code generator
KR20080018160A (en) Using strong data types to express speech recognition grammars in software programs
CN112416788B (en) Hierarchical standard Web application UI automatic test method
CN109857389B (en) Model data generation method and device, computer equipment and storage medium
CN111656453A (en) Hierarchical entity recognition and semantic modeling framework for information extraction
CN114153459A (en) Interface document generation method and device
CN114138244A (en) Method and device for automatically generating model files, storage medium and electronic equipment
CN111753140A (en) XML file parsing method and related equipment
CN107766036B (en) Module construction method and device and terminal equipment
CN110275712B (en) Text replacement method, device and equipment
CN112667202B (en) Software design method and device combining MDA and BPMN
CN104657340A (en) Expandable script-based Word report generating system and method
Djukić et al. Handling complex representations in visual modeling tools for MDSD/DSM by means of code generator languages
CN113239670A (en) Method and device for uploading service template, computer equipment and storage medium
CN113391806A (en) Method, device, equipment and readable medium for converting color codes
US7428697B2 (en) Preserving content or attribute information during conversion from a structured document to a computer program
CN112306493A (en) Hot repair patch generation method and device, storage medium and computer equipment

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
GR01 Patent grant
GR01 Patent grant