A method for automatically generating a templated document based on a SysML metamodel
By using the SysML metamodel templated document automatic generation method, the problem of low efficiency in model design and document publishing is solved, and efficient mapping and flexible publishing of models and documents are achieved.
Patent Information
- Application Number
- CN202210892984.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-27
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2042-07-27
AI Technical Summary
The existing development process relies heavily on documentation, resulting in low model design efficiency and difficulty in flexible release, and a lack of effective mapping between models and documentation.
A templated document automatic generation method based on the SysML metamodel is adopted. By parsing the SysML metamodel and extension packages, an instance-attribute export structure is constructed, model elements are extracted using model-independent metamodel path expressions, and documents are automatically generated based on the automated document generation module.
It enables easy mapping between models and documents, improves model publishing efficiency, provides flexible expressiveness and versatility, and simplifies report writing.
Smart Images

Figure CN115358200B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the field of computer aided design, and particularly relates to a template document automatic generation method based on a SysML meta model. BACKGROUND
[0002] With the increasing complexity of systems, MBSE (Model-Based Systems Engineering) has been paid more and more attention. Using models can change the system design process which is mainly based on documents, improve the efficiency of design and the clarity of description, and make the requirements traceable. However, the current development process is still mainly based on documents, and researchers are also used to reading and reporting with documents. Models are the main carriers of analysis and design, and documents are the interface for external release. Therefore, a method is needed to publish the designed models in the form of documents simply, and provide flexible expression ability and sufficient universality. SUMMARY
[0003] In order to overcome the deficiencies of the prior art, the application provides a template document automatic generation method based on a SysML meta model. A user only needs to define a document template in advance, and then the model can be published as a document simply by using the document template and the model.
[0004] The technical scheme adopted by the application to solve the technical problems is: a template document automatic generation method based on a SysML meta model, comprising the following steps:
[0005] (1) based on the standardized meta model of the system modeling language SysML and the extended package thereof, constructing an instance-attribute export structure;
[0006] The method for constructing the instance-attribute export structure comprises:
[0007] (1-1) performing an analysis processing on the standard meta model of SysML, and dividing instance attributes and basic attributes; performing the same recursive processing on the parent class meta model, and attaching the parent class meta model attributes to the current meta model;
[0008] (1-2) performing an analysis processing on the standard structure type of SysML, and dividing instance attributes and basic attributes; performing the same recursive processing on the parent class and meta class meta model, and attaching the parent class and meta class meta model attributes to the current meta model;
[0009] (1-3) performing the same analysis processing on the structure type in the extended package which extends SysML; performing the same analysis processing on the structure type defined in the extended package which is recursively introduced by the extended package;
[0010] (2) Based on the model-independent metamodel path expression associated with the template node, the specified range of model elements is extracted from any SysML model according to the model-independent pathing filtering condition;
[0011] (3) According to the model instance-related-data source, the model elements within the data source mapping range are obtained;
[0012] (4) Based on the automated document generation module, the model instance is applied to the template with data extraction and stylized expression capability to automatically generate the required document.
[0013] Further, the extraction process in step (2) includes,
[0014] (2-1) Determine the nature of the conditional path to determine static search or dynamic extraction;
[0015] (2-2) Group the conditions and determine the flow continuity and the passable elements of each level of the path according to whether they are related to the path;
[0016] (2-3) Obtain the path starting point from the metamodel-object pool, and perform breadth-first search along the instance attributes of the metamodel based on the instance-attribute export structure constructed using the SysML standard metamodel and extended package.
[0017] Further, step (3) includes requesting a data source specified interface, filtering the specified package level model data, mapping the filtering rules to the specified metamodel elements, and excluding the transmission of static model data and dynamic model view URI based on UML 5 basic type data.
[0018] Further, step (4) includes,
[0019] (4-1) Map the template structure to the corresponding hierarchical document structure;
[0020] (4-2) According to the model element data associated with the node of the template node and the node style definition, generate a direct template readable by the template engine, associate the extracted data with the direct template in order, and connect data extraction and style representation;
[0021] (4-3) Based on the template engine used, map the model element data extracted by the template node to the specified position in the node style definition.
[0022] Further, the mapping process in step (4-1) includes,
[0023] (4-11) According to the template structure processing, a directed adjacency list is obtained, and the root title level of each subtree is initialized;
[0024] (4-12)If the node has a title, generate the node organization table for it, and set the parent node as the head node in the node organization table of the original parent node;
[0025] (4-13)If the node has no title, set its node organization table as the node organization table of the parent node, and set the parent node as the parent node of the parent node;
[0026] (4-14)Consider the template structure as a compressed tree with nodes as node organization tables, and decompress to obtain a node list with correct title levels and arrangement order.
[0027] Further, the mapping process in step (4-3) includes,
[0028] (4-31)The data extracted from the model is always one of the five UML basic data types or an image URI; the data received by the document generation module is always one of the five UML basic data types or an image URI; in this way, the complex model structure is decoupled from the document generation;
[0029] (4-32)The mapping expression in the template is directed at model data-independent-static properties or model data-dependent-dynamic properties; a dynamic property is always associated with a certain UML basic type property or image URI at a specified position in the model;
[0030] (4-33)The basic mapping point is the mapping of the meta-model-instance element-basic type property to the dynamic property expression, which is further embedded in static text.
[0031] Further, for each iteration node associated with a meta-model path expression, it is always mapped to a block / list in the direct template and to 0 to multiple blocks of document content in the generated document, each block having or not having a same-level ordered title, each block having at most one title and 0 to multiple paragraphs of content, the styles of each block being consistent; each block is associated with a node associated with the meta-model-instance;
[0032] In the specific document generation process, the filtered instance set associated with the current node is associated with the corresponding node block in order and sent to the template engine to generate multiple blocks of document content for the number of instances in the set.
[0033] Further, in step (2-1), the following process is included,
[0034] (2-11)Aggregate the conditions corresponding to each level path by level, and if there is no corresponding complex condition expression, the default logical operator is AND;
[0035] (2-12)Initialize the priority of each logical operator and perform a correctness check on the condition name and logical operator name in the expression;
[0036] (2-13) Process the original complex condition expression string into a list of separated [condition name / logical operator name];
[0037] Wherein (2-131) processes all the condition name distribution of the left and right intervals, and arranges them in ascending order of the left interval;
[0038] (2-132) If the number of intervals is 0, or overlap occurs between intervals, the process is abnormally terminated;
[0039] (2-133) Traverse the expression string from left to right, and the cursor can only be at the start of the condition name interval, or the current character is the start character of the logical operator, otherwise the process is abnormally terminated; each time a condition name or a logical operator is placed in the result list;
[0040] (2-14) Convert the infix expression obtained in the previous step into a reverse Polish postfix expression;
[0041] (2-15) Check the legality of the reverse Polish postfix expression, i.e. there is no extra left bracket left, each binary expression and unary expression should have a corresponding number of operands, and only one operand is left at the end;
[0042] (2-16) Use the reverse Polish postfix expression to check all instances mapped by the current length path, if the remaining Boolean type variable in the operand stack is False, filter out the current instance; wherein, for each individual condition, a unique meta-model attribute is determined by the meta-model type of the tail node of the current path and the attribute name in the current condition, which is one of the five basic types of SysML, and is delegated to different condition processing services according to its type, which determines the returned Boolean type value according to the instance attribute value, operator and condition value.
[0043] Further, the search method for the meta-model path expression in step (2) locates to any position in the meta-model derived multi-ary tree according to the input meta-model path expression,
[0044] Precise search,
[0045] Generate a dictionary tree from the existing meta-model;
[0046] For the last character of the first layer word (meta-model type), record isEnd=true; the last character of the second layer word (attribute name) is the leaf node of the dictionary tree, which is associated with the corresponding meta-model type end character node (midpoint);
[0047] For a search path, start from the root node, the first level of the path needs to reach a node with isEnd=true in the dictionary tree, i.e. the midpoint of the path from the root node to the leaf node;
[0048] For the search word of the second level and after, it needs to start from the current midpoint, reach the leaf node, and return the midpoint associated with the leaf node after the search word;
[0049] Any failed match, that is, the corresponding dictionary tree path of the search word does not reach the isEnd=true node, or exceeds the path length in a certain dictionary tree;
[0050] For one search, the time complexity and the length of the search word are linearly related;
[0051] The association word is extracted, and the node matched by the prefix substring in the current level can be extended to all nodes corresponding to the word with isEnd=true;
[0052] Fuzzy search association,
[0053] Search all candidate strings that can take the current search string as a positive sequence subsequence;
[0054] Preprocess all candidate words, and preprocess the position X of the next character C appearing at the current position for each position. Process in reverse order and continuously update the position of each character appearing later;
[0055] In the judgment of whether the search word is a subsequence of the candidate word, the search word characters are traversed from left to right, and for each search word character, the next occurrence position of the current character in the candidate word can be obtained in O(1) time;
[0056] For each association word search, the worst time complexity is O(N*M), N is the length of the search string input by the user, and M is the number of all candidate strings in the current level.
[0057] The first aspect of the present application provides a document template definition method based on a meta model, comprising: giving all meta models in the SysML standard; optionally, importing a user-defined extension package, which is a user-defined construction type; editing / creating a template structure in the form of a node tree; associating specific nodes in the node tree with meta model path expressions; completing detailed node definition, defining the filtering conditions of the model elements satisfying the current path expression, and how to display them in the document; optionally, a formatted document template such as a.dot format file corresponding to Word can be associated; save the defined template.
[0058] In the technical scheme, the display of the meta model is divided into a basic meta model and an extension package; the basic meta model is all meta models in SysML1.6; and the extension package is an extension package imported by a user, i.e., a stereotype defined by the user. The basic meta model is further divided into a structure model, a behavior model, a requirement model and others; i.e., classified according to three types of structure, behavior and requirement, each type contains diagrams and other elements, and the others contain all other meta models not in the three types. Under each meta model, associated meta models derivable therefrom can be selected; meanwhile, a specific node definition can be constructed using a basic type attribute expression thereof.
[0059] In the technical scheme, the step of selecting, under each meta model, associated meta models derivable therefrom, specifically includes: dividing all attributes of the meta model into associated types and basic types; and taking the attributes of the associated types as the associated meta models derivable therefrom. Additionally, the attributes of each associated type can be further derived according to the meta model corresponding to the type, to an arbitrary depth; and the associated types of the meta model are derived and displayed in a tree structure.
[0060] In the technical scheme, the associated types of the meta model are derived and displayed in a tree structure, which is a dynamically generated multi-way tree having an arbitrary depth, and a search can be performed on the tree in a form of MetaClassType1.attributeName1.attributeName2… to locate a certain position of the dynamically generated multi-way tree; and the specific steps are as follows:
[0061] (1) Precise search:
[0062] According to the existing meta models (SysML standard meta models + imported user-defined stereotypes), a dictionary tree is generated from the two-layer multi-way tree original data;
[0063] For the last character of the first layer word (meta model type), isEnd=true is recorded; and the last character of the second layer word (attribute name) is a leaf node of the dictionary tree;
[0064] Each leaf node is associated with a node (midpoint) of the last character of the meta model type name corresponding to the attribute name of the child attribute;
[0065] For a search path (using “.” as a separator), starting from the root node, the first level of the path needs to reach a node with isEnd=true in the dictionary tree, i.e., the midpoint of the path from the root node to the leaf node;
[0066] For the search words of the second level and subsequent levels of the path, the search words need to start from the current midpoint, reach the leaf node, and then return the midpoint associated with the leaf node;
[0067] Any failed match, i.e. the path of the search word in the Trie does not reach a node with isEnd=true, or exceeds the length of the path in some Trie;
[0068] For one such search, the time complexity is linear to the length of the search word.
[0069] (1-1) Suggestion of associated words:
[0070] i.e. return all the words corresponding to the isEnd=true nodes that the node matched by the prefix substring in the current level can extend to;
[0071] When the prefix string is too long, i.e. one or more (only in the first level) end=true nodes have been found in the process of matching the prefix substring, or the depth of the Trie is exceeded, i.e. return the only string corresponding to the first end=true node encountered.
[0072] (2) Fuzzy search association:
[0073] i.e. for each onChange() event of user input, associate (find) all candidate strings that can take the current search string as their own ordered subsequences;
[0074] Construct a hash table HashMap<String, List <string>>, which is a list of sub-attribute names corresponding to each meta-model name;
[0075] All meta-model names and attribute names are preprocessed, and for each position, the position X of the next character C appearing at the current position is preprocessed. The processing is performed in reverse order, and the positions of each character appearing later are continuously updated. Because there are Chinese characters, a hash table Map<Character, Integer> is used to store the positions of appearance.
[0076] For each search path a.b.c, all A matching the sub-sequence a are found first, and the user is allowed to select; then all B matching the sub-sequence b in Map.get(A) of the determined A are found, and the user is allowed to select; and so on.
[0077] In the judgment of whether the search word is a sub-sequence of the candidate word, the search word characters are traversed from left to right, and for each search word character, the next position of the current character appearing in the candidate word can be obtained in O(1) time.
[0078] That is, for each search, the worst time complexity is O(N*M), where N is the length of the search string input by the user, and M is the number of all candidate strings at the current level.
[0079] That is, the above technical solution provides the user with a variety of selectable search capabilities, so that the user can easily locate the selected position in the meta-model derivative tree with thousands of numbers at each level and multiple levels.
[0080] In the above technical solution, preferably, under each meta-model, a basic type attribute expression can be used to construct a specific node definition, which specifically includes: dividing all attributes of the meta-model into association types and basic types; the basic type attributes are used as non-derivable value attributes that can directly appear in the content definition of a specific node; in a specific node associated with the meta-model type, any value attribute is selected and placed at any position in the content definition.
[0081] In this technical solution, the template structure is a node tree, the node types are divided into text nodes, iteration nodes, and table nodes, the nodes have parent-child relationships, the nodes with the same parent node have a sequence, and the relationships and sequences between different nodes in the template are reflected in the generated document. Thus, the structure of the report document can be easily structured.
[0082] In the above technical solution, preferably, the nodes have parent-child relationship and sequence, which will be embodied in the generated document, specifically: the title level of the parent node = the title level of the child node + 1, the first level node in the document, i.e. the direct child node of the virtual root node, has a title level of Heading1 in Word, and so on until Heading9, which no longer increases; the sequence is embodied in the node content in the template node tree, which is arranged in the generated document in the order of depth-first traversal pre-order.
[0083] In the above technical solution, preferably, the text node specifically has two parts of title and content, the content of the title part will be embodied as HeadingN style in the generated document, and the content part is embodied as any paragraph content under the title; if the title content is empty, the node does not display the title, and the Heading level of the node is increased by one, and the same applies to the child nodes; static attributes can appear in the text node with any text format content.
[0084] In the above technical solution, preferably, the iteration node specifically has two parts of title and content, the content of the title part will be embodied as HeadingN style in the generated document, and the content part is embodied as any paragraph content under the title; if the title content is empty, the node does not display the title, and the Heading level of the node is increased by one, and the same applies to the child nodes; dynamic attributes of the meta-model type associated with the current node can appear in the iteration node with any text format content; the iteration node automatically has two nodes, which are a whole, but have parent-child relationship in actual processing; the iteration node has a meta-model associated path of any length and any number of filtering conditions.
[0085] In the technical solution, preferably, the iteration node has an arbitrary-length meta-model associated path and an arbitrary number of filtering conditions, specifically: the path specifies a part of the model; the start of each path is a virtual root node, i.e., model / project, which is an arbitrary-length meta-model type expression starting from the model; a path like [model]->[package]->[owingBlock] specifies all the blocks owned by all the packages in the model that meet the filtering conditions; the filtering conditions can be an arbitrary number, which can be filtering of the meta-model on the current path or filtering of the meta-model in any other path in the model; the filtering conditions are specifically for whether the basic value attribute of the meta-model meets a certain condition, and the meta-model actually corresponds to a plurality of model element objects, i.e., all of which need to meet the condition to pass the filtering. That is, the iteration node corresponds to an arbitrary number of model element objects of the meta-model type at the end of the path. In the generated document, the node will show the number of times of the model element objects filtered out in the model.
[0086] In the technical solution, preferably, the table node, specifically: a table node corresponds to a table in the generated document; the table node can be static, and the actual number of rows and columns in the generated document is what is seen and what is obtained, which is completely consistent with the template and can only use static attributes and any text content; the table node can be dynamic, similar to the iteration node, having an arbitrary-length meta-model associated path and an arbitrary number of filtering conditions, and in the generated document, it will be displayed as a table header and the number of times of the table body of the model element objects filtered out in the model; the dynamic table node can use static attributes, dynamic attributes, and any text content.
[0087] The second aspect of the application provides a template-based model automatic document generation method, including: selecting a format of a document output; selecting a template from a template corresponding to the output format, which describes how to display model data; selecting a data source that specifies a model instance; selecting a package element of the model instance as model data for this document generation; and setting an output position, so that the required document can be generated to the specified position. Thus, the user only needs to select the model part to be exported and select a pre-defined template to generate a report document, greatly simplifying the tedious work of manually writing a report.
[0088] In the technical solution, the model data is obtained by specifying a data source, so that the application can be adapted to different applications and has universality and scalability.
[0089] In the technical solution, preferably, the data source is a data source for obtaining model instance data, and includes: a REST GET interface URI for specifying model instance data acquisition, which is necessary; a filter part, exclude and include, both of which have the same style, and include can cover the excluded content; and a main part of "MetaClassType":[], which specifies an array of meta-model types, and excludes data of the specified meta-model types when obtaining model data from the data source.
[0090] In the technical solution, preferably, the specific steps of requesting model data through the data source are as follows: a data source is specified with a REST GET interface, and a request is initiated to the data source; a model data is rendered into an image by a front end of an application side, and a model image URL is transmitted together with the model data; a package-level model structure tree of the model instance is displayed to a user; the user selects nodes of the package-level model tree; and a plurality of specified package-level elements and all model elements under the package-level elements filtered by the filter information are selected to participate in a document generation process.
[0091] In the technical solution, the steps of generating the document include: given model data and a document template; processing the document template to process a template node tree into a node list in sequence; processing the node list in sequence to process specific text with a style in a title and content into a direct template readable by a template engine and containing a placeholder, wherein the title is additionally set with a title style according to a current level; processing the model data to pool the model data according to a meta-model type; processing a model element object specified by a path and a condition for each iteration node and a dynamic table node; making all extracted model element value attributes and set numbers consistent with the direct template readable by the template engine; processing the direct template and the numbered structured model data by the template engine to generate a document; formatting the generated document by a format document template associated with the document template if the format document template exists; saving the generated document to a specified location; and determining whether the generated document and the predefined document template are visible according to user permissions, which is not the focus of the present application and thus is not described herein.
[0092] The present application has the beneficial effect that the defined template can be applied to any model instance, and is defined once, used on any model, and used multiple times, so that the model can be automatically generated into a document according to the document template, and the efficiency of SysML model publishing is greatly improved. BRIEF DESCRIPTION OF DRAWINGS
[0093] Figure 1 A product use scenario diagram according to an embodiment of the present application is shown.
[0094] Figure 2 The overall function tree diagram of the template-based document generation tool based on the SysML meta-model is shown.
[0095] Figure 3 The structural schematic diagram of the template definition device of the template-based document generation tool based on the SysML meta-model is shown.
[0096] Figure 4 The data source organization form schematic diagram of the template-based document generation method based on the SysML meta-model is shown.
[0097] Figure 5 The document generation flow schematic diagram of the template-based document generation method based on the SysML meta-model is shown. DETAILED DESCRIPTION
[0098] In order for those skilled in the art to better understand the present application, the technical solutions in the embodiments of the application will be described clearly and completely below with reference to the accompanying drawings of the embodiments of the application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work should fall within the scope of protection of the present application.
[0099] Figure 1 The product use scenario diagram of the present application is shown.
[0100] As Figure 1 shown, the method proposed by the present application is composed of two main modules, which are a document generation module and a template definition module. The document generation module exists in the form of plug-in / extension package, and the template definition module exists in the form of independent application. The document generation user uses the document generation plug-in to generate a document with a predefined template in different applications; and the administrator creates and edits a template in the template definition independent application.
[0101] The functions of the present application are decomposed according to different modules to obtain an overall function tree diagram, as Figure 2 shown. Figure 2 The combination of each function point shown above constitutes a complete template definition and document generation capability. Figure 2 Some functions in the above will be embodied in the embodiments below and further described in detail.
[0102] As Figure 2 As shown, for the data organization defined by the node in the application, it includes: document-independent node definition, specifically node name and description which do not affect the document generation process; how to extract model data, specifically path associated with the node, filtering condition of the node, sorting rule of the node definition, and display rule when there is no specified data of the actual model to be displayed; how to display the content, specifically title in the node, text in the content, and style definition.
[0103] In the technical solution, preferably, the sorting rule of the node is defined to specify the order in which the currently specified model element instance is iterated, and the specific steps include: the user selects the key attribute, i.e., the basic type attribute of the current meta-model type; the selected attribute type is judged, which is divided into two categories: String and Number; different selectable sorting rules are provided to the user according to the attribute type: ascending or descending order, and whether to ignore the case of letters; the user can continue to select the key and the rule; according to the order of the sorting rules, the priority of the Comparator is determined. For a plurality of model element objects specified according to the associated path and the filtering condition, the Comparator is used for comparison and sorting to determine the order in which the content represented by the model element objects is displayed in the document. Thus, the user is provided with flexible multi-level sorting rule definition capability, so that the user can freely arrange the iteration of the document content generated by the plurality of different instances corresponding to the node according to the needs.
[0104] In the above technical solution, preferably, the selected instance is sorted according to the specified multi-level sorting rule, and the specific implementation steps include: constructing a Comparator for comparing and sorting the selected instance, and in the comparison method of the Comparator, two instances in the sorting rule comparison method parameter passed in are compared in turn, and if the result of any sorting rule comparison is not 0, the result is returned; if the results returned by all sorting rules are 0, i.e., equal, 0 is returned; in the sorting method definition of the sorting rule, according to which of the five basic types of UML the type of the current MetaClassProperty belongs to, different comparison methods are determined.
[0105] In the technical solution, preferably, the display rule of the node when there is no specified data of the actual model to be displayed is defined, and the specific steps include: the user defines whether to skip the node or display the alternative text; the alternative text is defined; when the number of model element objects specified according to the associated path and the filtering condition is 0, the display rule is checked; and the specified placeholder in the direct template is associated with the alternative text or an empty string.
[0106] In the technical solution, preferably, the data organization defined by the node mainly includes data extraction and style display: the data extraction part specifies where to extract data from the model, how to filter the extracted data, how to sort the extracted and filtered model element objects, and how to display if the obtained data is empty; the style display part includes static text with style, any dynamic attribute, and how to embed the dynamic value extracted by the data extraction part into the static text and finally display in the document.
[0107] Figure 3 A structural schematic diagram of a template definition device of a template-based document generation tool based on a SysML meta-model according to an embodiment of the application is shown.
[0108] As shown in Figure 3 , the template definition device of the template-based document generation tool based on the SysML meta-model according to an embodiment of the application includes a meta-model analysis and display module, a basic type attribute display module, a template structure definition module, and a node definition module.
[0109] The meta-model analysis and display module is configured to analyze all meta-models in the SysML and display them in groups according to the grouping display in the above technical solution, analyze the standard meta-models, the standard stereotypes, and the custom extension package file imported by the user, recursively analyze the custom stereotypes, and analyze the meta-models in advance before the template structure definition stage starts to construct an instance-attribute export structure to group the attributes for the meta-model tree structure display and the basic type attribute display; when a point at any level in the meta-model tree structure is selected, the point is dragged to the template structure definition module below to generate an iteration node associated with the path from the selected starting node to the node.
[0110] The method for analyzing the meta-models and constructing the instance-attribute export structure includes:
[0111] (1-1) Analyzing the standard meta-models of the SysML to divide the instance attributes and the basic attributes;
[0112] The same recursive processing is performed on the parent meta-models to attach the parent meta-model attributes to the current meta-models;
[0113] (1-2) Analyzing the standard stereotypes of the SysML to divide the instance attributes and the basic attributes;
[0114] The same recursive processing is performed on the parent meta-models to attach the parent meta-model attributes to the current meta-models;
[0115] The same recursive processing is performed on the parent meta-models to attach the parent meta-model attributes to the current meta-models;
[0116] (1-3) For the extension package extended to SysML, the same parsing process is performed on the construction type therein; for the construction type defined in the extension package recursively introduced by the extension package, the same parsing process is performed;
[0117] Basic type attribute display module: display the basic type attributes of the currently selected meta-model type; select a certain attribute and drag it to the content definition in the node definition module, and if the node is associated with the meta-model type, a dynamic attribute expression is generated accordingly.
[0118] Template structure definition module: used for defining a tree type template structure composed of three types of nodes, which will be reflected as the title and paragraph hierarchy in the generated document.
[0119] Node definition module: define the detailed content of a node. Including: content, divided into title and text two parts, that is, the style display part of the node, each node corresponds to a title and multiple paragraphs in the generated document; iteration, which can specify an associated path to convert the current node into an iteration node, and the node and all its sub-trees are displayed in the document a number of times of the filtered model element instances; condition, which can specify multiple iteration conditions; sorting, which can specify multiple sorting rules; no data display rule, which specifies the display rule when the currently specified data is empty, which is only valid when the current node is associated with a path; and renaming and description editing of the current node.
[0120] In the technical solution, according to the template tree structure in the template structure definition, the generated document has the same hierarchical structure, and if the title content is empty, no title is generated for it, and the level is increased by one, and the specific steps are: the front end ensures that the id, parentId, and sortedIdUnderSameParent of each node are arranged in the correct order, parent-child relationship; preprocess the adjacency list of the directed graph from the parent node to the child node; get the root nodes of each sub-tree in the template structure, set their levels to 1 and 0 according to whether they have titles, and generate a node organization linked list for each root node; build a sub-tree from each root node; sort each child node list according to sortedIdUnderSameParent; if a node has a title, generate a node organization linked list for it, set its level to one more than the parent node's level, and add it to the child node list of the first node in the node organization linked list of the parent node; if a node has no title, set its node organization linked list to the node organization linked list of the parent node, set its parent node to the parent node of the parent node, and set its node level to the parent node level; treat the node tree as a tree with node organization linked list as nodes, and decompress the node organization linked list in the tree according to the depth-first traversal preorder, to get a node list arranged in the correct order and with the correct level, which can be used for divide-and-conquer processing and thread pool acceleration; traverse the list and generate the hierarchical number before the title according to the rearranged parent-child node relationship.
[0121] According to the technical solution, the template writer does not need to pay attention to the maintenance of the title level, and only needs to define the correct template structure to obtain the generated document with correct level. The template does not need to be strictly defined according to the title-content format, and the continuous paragraphs can be arranged into different nodes according to the logical relationship of the document.
[0122] In any of the above technical solutions, preferably, the node definition module of the template definition device of the template-based document generation tool based on the SysML meta-model further comprises: embedding a dynamic attribute expression in the node content definition, specifically comprising: selecting a meta-model attribute associated with the current node in the basic type attribute display module, or selecting a basic type attribute of any meta-model on the path associated with the current node; generating a dynamic attribute expression in the node content definition, expressing the display of a certain basic type attribute of a certain instance model element object iterated to on the path associated with the current node; parsing the node detailed content definition to extract all dynamic expressions for use when generating the document.
[0123] In any of the above technical solutions, preferably, the attributes in the attribute expression are divided into static and dynamic. Dynamic attributes can only be used in the second level of the iteration node and the table body of the dynamic table node, and are dynamic model element attributes that change with the specified model data when generating the document. Static attributes can be used everywhere, including: static text with style; header; footer; page number; date; time; hyperlink; attachment; picture; separator; item-related information. In this technical solution, when generating the document, the attribute expression is replaced with a placeholder readable by the template engine, and the specified information is obtained in real time and associated with the specified placeholder.
[0124] In this technical solution, the iteration node is associated with a path, and has two levels, specifically: a specified path in the model; the first level and the second level of the iteration node have a parent-child relationship in the hierarchical structure, the first level is displayed once, and the second level can be displayed multiple times; the first level is generally used to display a large title with one or more summary or introductory texts; the second level and all sub-trees thereunder will be displayed multiple times, and the number of display times is determined by the number of model element objects filtered by the path and the condition; the actual associated meta-model type is the meta-model type at the tail of the path; the path is determined by the path associated with the current node and the path associated with the parent iteration node. In this technical solution, when generating the document, according to the currently used template engine, for example, the currently used template engine is poi-tl, a block is generated for each iteration node, the block contains nested content including text and sub-placeholders, and the block is associated with a nested set, that is, the iteration node content text of the length of the set will be repeatedly generated.
[0125] In the technical solution, preferably, the associated path is determined by the path associated with the current node and the path associated with the parent iteration node, and the specific steps include: selecting a path from the meta-model tree, or selecting a derivable path from the current iteration node path; selecting a parent node for the current path; searching for the nearest iteration node or the virtual root node representing the model from the current parent node upwards, as the actual parent iteration node for path inheritance; judging whether the path associated with the parent iteration node is adapted to the current path, i.e., whether the tail end meta-model of the parent path can derive the meta-model at the head of the current path; if yes, the current path is an extension of the parent path, and the starting point of the current path is set as the path starting point of the parent iteration node, and the relationship is transitive; if not, the starting point of the current path is set as the model, i.e., the parent-child level only represents the document title hierarchical structure, and the parent-child level does not have any association or filtering relationship related to the model.
[0126] For example, dragging Action->comments[Comment]->anchoredElements[ModelElement]->comments[Comment]->comments[Comment] to the iteration node From class "Model"......iterate over instances of class "Action" under will obtain a new node: From class "Action".......iterate over association "[comments]->[anchoredElements]->[comments]->[comments]"; and the actual path is from Model.
[0127] Figure 4 A schematic diagram of the data source organization form of the template-based document generation method based on the SysML meta-model is shown according to an embodiment of the present application.
[0128] As Figure 4 shown, the data source of the template-based document generation method based on the SysML meta-model is in the form of a JSON file, specifies a REST GET interface URI of a model instance, and specifies a filtering rule for the model data; the original attributes of the model elements and the URI of the additional rendered model element image can be obtained from the data source.
[0129] Figure 5 A schematic diagram of the document generation flow of the template-based document generation method based on the SysML meta-model is shown according to an embodiment of the present application.
[0130] As Figure 5 As shown, the document generation flow of the template-based document generation method based on the SysML meta-model according to one embodiment of the present application comprises:
[0131] The specified data source is acquired; the model data is read from the data source; and the specified model data is obtained by filtering according to the input of the user.
[0132] One data source specifies a REST GET interface to which a request is initiated; the model data is rendered into an image by the application-side front end, and the model image URI is transmitted together with the model data; the package-level model structure tree of the model instance is displayed to the user; the user selects multiple nodes of the package-level model tree; and the specified multiple package-level elements and all model elements under the package-level elements filtered by the filtered information participate in the document generation process.
[0133] The pre-prepared document template is acquired from the specified location; the template is parsed, the model data extraction rule of each node is acquired, and the content and style definition are acquired; the model data extraction rule of the node is applied to the current model instance to extract the specified data; the model and style definition are converted into a text containing placeholders readable by the template engine; the data of the node is associated with each placeholder; the direct template obtained by processing and the data set extracted from the model are transmitted to the template engine for processing to generate a document in a corresponding format; optionally, if the user specifies a formatted document template, the formatted document template is used for additional formatting processing; and the final document is obtained and stored in the specified location.
[0134] In the technical solution, preferably, the model data extraction rule of the node is applied to the current model instance to extract the specified data, and the specific steps include: for a static attribute that does not need to depend on model data, a corresponding resource is found by going to a specified path; for a dynamic attribute, a filtering condition is first associated with each level of the path; for a condition that is irrelevant to the current path, a new path is generated for it; if there is a condition path that is irrelevant to the current path, it is first checked whether all model element objects specified by the path meet the specified conditions, and if any model element object specified by the condition path does not meet the corresponding condition, the process ends; for any path, an approximate breadth-first search is performed; first, starting from the <metamodel, object list> pool of the model, the metamodel type of the first node after the model node, i.e. the head node of the path, is searched; for the object list of the current specified metamodel, the condition responsibility chain / complex condition expression associated with the current path node is entered for filtering; if it is not a tail node, the object list of the next level of the metamodel is derived from the current model element object filtered according to the metamodel associated with the next level of the path node, and the object list of the next level of the metamodel is used as the current object list; if the object list after filtering or derivation is empty, the process ends; if the current path node is the end of the path, the current object list is returned as the path extraction result; for the object list extracted by the specified path, the specified attribute of the object is extracted as the final result using the basic type attribute specified by the dynamic attribute; additionally, if the dynamic attribute is a model element image, the extracted is an image URI, and the real image data is transmitted as the final result by using it to establish a connection with the application side.
[0135] In the above technical solution, preferably, the filtering in the condition responsibility chain / complex condition expression associated with the current path node is characterized by the following features:
[0136] (1) The conditions corresponding to each level of the path are aggregated by level, and if there is no corresponding complex condition expression, the logical operators are all AND by default;
[0137] (2) The priority of each logical operator is initialized, and the correctness of the condition name and the logical operator name is checked;
[0138] (3) The original complex condition expression string is processed into a list of separated [condition name / logical operator name];
[0139] (3-1) All condition names in the [left, right) interval are processed, and the left is sorted in ascending order;
[0140] (3-2) If the number of intervals is 0 or the intervals overlap, the process ends abnormally;
[0141] (3-3) Traverse the expression string from left to right, the cursor can only be at the start of a condition name interval or the start of a logical operator character, otherwise the process is terminated abnormally; each time a condition name or logical operator is put into the result list;
[0142] (4) Convert the infix expression obtained in the previous step into a reverse Polish postfix expression;
[0143] (4-1) Scan the entire infix expression from left to right in order:
[0144] Maintain a logical operator stack and a postfix expression list;
[0145] If the current element is an operand, store the element directly into the postfix expression list;
[0146] If the current element is a left parenthesis, push it directly into the stack; if it is a right parenthesis, pop the operators from the stack and store the popped operators into the postfix expression until a left parenthesis is encountered; finally, pop the left parenthesis from the stack;
[0147] If it is another operator, if its priority is higher than that of the top operator on the stack, push it onto the stack, if it is less than or lower than the priority of the top operator on the stack, pop the top operators one by one and store them into the postfix expression until a top priority less than the priority of the current element or a top element being a left parenthesis is encountered, keep the current top element unchanged, and push the current element onto the stack;
[0148] (4-2) When the entire infix expression is scanned, check if the logical operator stack is empty, if not, pop the logical operators from the stack one by one and place them at the end of the postfix expression list.
[0149] (5) Check the legality of the reverse Polish postfix expression, i.e. there is no redundant left parenthesis left, each binary expression and unary expression should have a corresponding number of operands, and only one operand is left at the end;
[0150] (6) Use the reverse Polish postfix expression to check all instances mapped by the current length path, if the remaining Boolean type variable in the operand stack is False, filter out the current instance;
[0151] (6-1) For each individual condition, determine a unique MetaClassProperty with the metamodel type of the tail node of the current path and the attribute name in the current condition, whose type is one of the five basic types of SysML, and delegate it to different condition processing services according to its type, which determines the returned Boolean type value according to the instance attribute value, operator, and condition value;
[0152] (6-2) The calculation processing step of the reverse polish postfix expression:
[0153] An operand stack of a Boolean type is maintained; the postfix expression is scanned from left to right; if it is a conditional name, the corresponding conditional check result of the conditional name is pushed into the stack; if it is a logical operator, a corresponding number of operands are popped from the stack; the popped operands are operated according to the logical operator, and the operation result is pushed into the stack again; until the postfix expression list is scanned completely; since the legality of the postfix expression has been ensured, after the scanning, there is only one operand of a Boolean type in the stack, and the value of the operand is the check result of the complex conditional expression.
[0154] The template engine in the technical solution described above is not limited to a specific template engine, and the output document format is not limited to a Word document. Template engines such as poi-tl and Thymeleaf can be used as replacements in specific implementations; at the same time, for the formatted document template, if the output document is a Word document format, it is a document template in the.dot format, and if the output document is an HTML document, it is a.css file.
[0155] The above specific embodiments are used to explain and illustrate the present application, rather than limit the present application, and any modifications and changes made to the present application within the spirit and protection scope of the claims of the present application all fall within the protection scope of the present application.< / string>
Claims
1. A method for automatic generation of templated documents based on SysML meta-models, characterized in that, The method comprises the following steps: (1) constructing an instance-attribute derived structure based on a standardized meta-model of a system modeling language SysML and an extension package thereof; The method of constructing the instance-attribute derived structure comprises: (1-1) performing a parsing process on the standardized meta-model of SysML, and dividing instance attributes and basic attributes; performing the same recursive process on the parent class meta-model, and adding the attributes of the parent class meta-model to the current meta-model; (1-2) performing a parsing process on the standardized meta-model of SysML, and dividing instance attributes and basic attributes; performing the same recursive process on the parent class, meta-class meta-model, and adding the attributes of the parent class, meta-class meta-model to the current meta-model; (1-3) performing the same parsing process on the meta-model of the extension package extended from SysML; performing the same parsing process on the meta-model defined in the extension package recursively introduced by the extension package; (2) extracting model elements in a specified range from any SysML model according to a model-independent path expression associated with a template node based on a model-independent path filtering condition; (3) obtaining model elements in a data source mapping range according to a model instance correlation-data source; (4) automatically generating a required document by applying the model instance to a template having data extraction and stylized expression capabilities based on an automatic document generation module.
2. The SysML meta-model based templated document auto-generation method according to claim 1, characterized in that: The extraction process in step (2) comprises: (2-1) judging the nature of the conditional path to determine static searching or dynamic extraction; (2-2) grouping the conditions, and determining the flow continuity and the passable elements at each level of the path according to whether the conditions are related to the path; (2-3) obtaining the path starting point from a meta-model-object pool, and performing a breadth-first search along the instance attributes of the meta-model downward based on the instance-attribute derived structure constructed by the standardized meta-model of SysML and the extension package.
3. The SysML meta-model based templated document auto-generation method of claim 1, wherein: Step (3) comprises requesting a data source specified interface, filtering specified package level model data, mapping filtering rules to specified meta-model elements, and excluding the transmission of static model data and dynamic model view URI based on five basic types of UML data.
4. The method of claim 1, wherein the SysML meta-model based templated document auto-generation method is characterized by: Step (4) comprises: (4-1) mapping the template structure to a corresponding hierarchical document structure; (4-2) generating a template engine readable direct template according to the model element data associated with the node style definition of the template node, associating the extracted data with the direct template in sequence, and connecting data extraction and style representation; (4-3) mapping the model element data extracted by the template node to a specified position in the node style definition based on the template engine used.
5. The SysML meta-model based templated document auto-generation method of claim 4, wherein: The mapping process in step (4-1) comprises: (4-11) processing a directed adjacency list according to the template structure, and initializing the root title level of each subtree; (4-12) generating a node organization table for a node having a title, and setting the parent node as the head node in the node organization table of the original parent node; (4-13) setting the node organization table of a node without a title as the node organization table of the parent node, and setting the parent node as the parent node of the parent node. (4-14) The template structure is regarded as a compressed tree with nodes as nodes, and the decompression is performed to obtain a node list with correct title level and arrangement order.
6. The SysML meta-model based templated document auto-generation method of claim 4, wherein: The mapping process in the step (4-3) includes, (4-31) The data extracted from the model is always one of the five UML basic data types or an image URI; the data received by the document generation module is always one of the five UML basic data types or an image URI; in this way, the complex model structure is decoupled from the document generation; (4-32) The mapping expression in the template is directed to a model data-independent-static attribute or a model data-dependent-dynamic attribute; one dynamic attribute is always associated with a certain UML basic type attribute or image URI at a specified position of the model; (4-33) The basic mapping point is the mapping of the meta-model-instance element-basic type attribute to the dynamic attribute expression, and then the static text is embedded.
7. The SysML meta-model-based templated document automatic generation method according to claim 1, characterized in that: For each iteration node associated with a meta-model path expression, it is always mapped to a block / list in the direct template and is always mapped to 0 to multiple blocks of document content in the generated document, each block has or does not have a same-level ordered title, each block has at most one title and 0 to multiple paragraphs of content, and the styles of each block are consistent; each block is associated with a node associated meta-model-instance; In the specific document generation process, the instance set associated with the current node is associated with the corresponding node block in order and sent to the template engine to generate multiple blocks of document content with the number of instances in the set.
8. The SysML meta-model based templated document auto-generation method of claim 2, wherein: The step (2-1) includes the following processes, (2-11) The conditions corresponding to each level of path are aggregated by level, and if there is no corresponding complex condition expression, the default logical operator is AND; (2-12) The priority of each logical operator is initialized, and the correctness of the condition name and the logical operator name in the expression is checked; (2-13) The original complex condition expression string is processed into a list of separated [condition name / logical operator name]; (2-131) The left and right intervals of all condition names are processed and arranged in ascending order of left interval; (2-132) If the number of intervals is 0 or the intervals overlap, the process is abnormally ended; (2-133) The expression string is traversed from left to right, and the cursor can only be at the start of the condition name interval or the start of the logical operator, otherwise the process is abnormally ended; each time a condition name or a logical operator is placed in the result list; (2-14) The infix expression obtained in the previous step is converted into a reverse Polish postfix expression; (2-15) The reverse Polish postfix expression is checked for legality, i.e., there is no redundant left bracket left, each binary expression and unary expression should have a corresponding number of operands, and only one operand is left at the end. (2-16) Check all instances mapped by current length path with reverse polish postfix expression, if the Boolean variable left in the operand stack is False, filter out the current instance; wherein, for each individual condition, determine a unique meta-model attribute with the meta-model type of the tail node of current path and the attribute name in current condition, which is one of the five basic types of SysML, and delegate it to different condition processing services according to its type, which determines the returned Boolean value according to the instance attribute value, operator and condition value.
9. The method of claim 1, wherein the SysML meta-model based templated document auto-generation method is characterized by: The search method for the meta-model path expression in step (2) is to locate to any position in the meta-model derived multi-way tree according to the input meta-model path expression, Exact search, Generate a dictionary tree according to the existing meta-model; For the last character of the first layer word, record isEnd=true; the last character of the second layer word is the leaf node of the dictionary tree, which is associated with the last character node of the corresponding meta-model type; For a search path, start from the root node, the first level of the path needs to reach a node with isEnd=true in the dictionary tree, which is the midpoint of the path from the root node to the leaf node; For the search word of the second level and after, it needs to start from the current midpoint, reach the leaf node, and return the midpoint associated with the leaf node; Any failed match, i.e. the search word corresponding to the dictionary tree path does not reach the node with isEnd=true, or exceeds the path length in a certain dictionary tree; For one search, the time complexity and the length of the search word are linearly related; Suggest words, return all words corresponding to the nodes that the prefix substring matched in the current level can be extended to isEnd=true; Fuzzy search association, Search all candidate strings that can take the current search string as their own ordered subsequences; Preprocess all candidate words, and for each position, preprocess the position X where the next character C appears at the current position; Process in reverse order and continuously update the positions of each character appearing later; In the judgment of whether the search word is a subsequence of the candidate word, traverse the search word characters from left to right, and for each search word character, you can get the next occurrence position of the current character in the candidate word in O(1) time; For each association word search, the worst time complexity is O(N*M), N is the length of the search string input by the user, and M is the number of all candidate strings at the current level.
Citation Information
Patent Citations
Enterprise search engine technology based on multiple data resources
CN102033910A
Product detailed design model automatic generation method based on SysML drive
CN102243677A