Table construction method and device
By building a table template to automatically parse JSON data to generate a table, the problem of needing to define the table structure in advance in the existing technology is solved, and the effect of quickly building complex tables is achieved, which improves development efficiency.
Patent Information
- Application Number
- CN202110973078.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-24
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2041-08-24
AI Technical Summary
When converting JSON data into a table, the existing technology requires defining the table structure in advance, which cannot quickly cope with complex JSON data, resulting in increased development time and low parsing efficiency.
By building a table template, based on the attribute name of the source dataset, JSON data is automatically parsed to generate table header and table content layout objects, and then they are spliced into table layout objects to finally generate a table, avoiding the pre-definition of the table format.
It enables the rapid construction of various complex structured tables, reduces the workload of developers, and improves the efficiency of table development.
Smart Images

Figure CN115719055B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a table construction method and device. Background Art
[0002] There are two main ways of converting JSON data into tables in the existing technology: one is for more complex JSON data, which requires defining the table structure to be displayed in advance, and then reading the JSON data for display. The other is for simple JSON data, which loops through the JSON data and parses it into a table. Generally, this type of table will only have a single-row header. It can be seen that the existing technology needs to define the table format in advance to display the JSON data. JSON data with increasing types and different attributes cannot be displayed quickly, and the table format needs to be added synchronously to correspond, which increases development time. Deep and complex JSON data cannot be parsed quickly, and parsing shallow JSON data can only have a single-row header, which is not enough to cope with the complex structure of tables and data.
[0003] Therefore, it is necessary to provide a table construction method and device to quickly construct tables corresponding to various complex source data sets and store them in the cloud, thereby reducing the workload of developers and improving table development efficiency. Summary of the Invention
[0004] The present application provides a table construction method and device, which can quickly construct tables corresponding to various complex source data sets and store them in the cloud, thereby reducing the workload of developers and improving table development efficiency.
[0005] In one aspect, the present application provides a table construction method, the method comprising:
[0006] Obtain a source data set in a target format; the source data set includes at least one set of attribute-value pairs; each set of attribute-value pairs includes an attribute name and an attribute value;
[0007] Based on the attribute names in the source data set, construct a table template corresponding to the source data set; the table template includes a plurality of table tags;
[0008] Based on the table template, a table header layout object is obtained;
[0009] Parsing the attribute values in the source data set based on the table template to obtain a table content layout object;
[0010] Splicing the table header layout object with the table content layout object to obtain a table layout object;
[0011] The data in the table layout object is parsed according to the table tag to obtain the table corresponding to the source data set.
[0012] Another aspect provides a table construction device, the device comprising:
[0013] A source data set acquisition module is used to acquire a source data set in a target format; the source data set includes at least one set of attribute value pairs; each set of attribute value pairs includes an attribute name and an attribute value;
[0014] A table template construction module, configured to construct a table template corresponding to the source data set based on the attribute names in the source data set; the table template includes a plurality of table tags;
[0015] A table header layout object construction module, used to obtain a table header layout object based on the table template;
[0016] A table content arrangement object construction module, configured to parse the attribute values in the source data set based on the table template to obtain a table content arrangement object;
[0017] A table layout object construction module, configured to combine the table header layout object with the table content layout object to obtain a table layout object;
[0018] The table construction module is used to parse the data in the table layout object according to the table tags to obtain the table corresponding to the source data set.
[0019] On the other hand, a table construction device is provided, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the table construction method described above.
[0020] On the other hand, a computer storage medium is provided, wherein the computer storage medium stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by a processor to implement the table construction method described above.
[0021] Another aspect provides a computer program product or computer program, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to implement the table construction method described above.
[0022] The table construction method and device provided in this application have the following technical effects:
[0023] This application constructs a table template based on the attribute names in the source data; obtains a header layout object based on the table template, and parses the source data set to obtain a table content layout object; then, the header layout object and the table layout object are spliced into a table layout object, thereby parsing to obtain a table; when this application converts the source data set into a table, there is no need to know the data format in advance and define the table structure to be displayed, so that the data is automatically parsed to obtain the table format, and the table corresponding to various complex source data sets can be quickly constructed, thereby reducing the workload of developers and improving the efficiency of table development. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions and advantages of the embodiments of the present application or the prior art, the following is a brief introduction to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0025] Figure 1 is a schematic diagram of a table construction system provided in an embodiment of the present application;
[0026] Figure 2 This is a flow chart of a table construction method provided in an embodiment of the present application;
[0027] Figure 3 This is a flowchart of a method for obtaining a table header layout object based on a table template provided in an embodiment of the present application;
[0028] Figure 4 This is a flowchart of a method for recursively traversing a table template to obtain table attribute parameters corresponding to each attribute name provided by an embodiment of the present application;
[0029] Figure 5 This is a flowchart of a method for determining the column number of a current attribute name in a table provided by an embodiment of the present application;
[0030] Figure 6 1 is a flowchart of a method for determining the row height and column width of the current attribute name in the table according to the attribute value corresponding to the current attribute name, provided by an embodiment of the present application;
[0031] Figure 7 This is a flowchart of a method provided by an embodiment of the present application for recursively traversing the above source data set to obtain table attribute parameters corresponding to each character attribute value;
[0032] Figure 8 This is a schematic diagram of a header arrangement object provided in an embodiment of the present application;
[0033] Figure 9 This is a schematic diagram of a table content arrangement object provided by an embodiment of the present application;
[0034] Figure 10 This is a schematic diagram of a table layout object provided in an embodiment of the present application;
[0035] Figure 11 This is a schematic diagram of a table display interface provided in an embodiment of the present application;
[0036] Figure 12 This is a schematic diagram of the structure of a table construction device provided in an embodiment of the present application;
[0037] Figure 13 This is a structural diagram of a server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0038] Cloud technology refers to a hosting technology that unifies hardware, software, network and other resources within a wide area network or local area network to achieve data computing, storage, processing and sharing.
[0039] Cloud technology is a general term for network technologies, information technologies, integration technologies, management platform technologies, and application technologies based on the cloud computing business model. It can form a resource pool that can be used flexibly and conveniently on demand. Cloud computing technology will become a crucial support. Backend services for technical network systems, such as video websites, image websites, and more portals, require extensive computing and storage resources. With the rapid development and application of the internet industry, every item will likely have its own unique identifier, requiring transmission to backend systems for logical processing. Different levels of data will be processed separately, and data from various industries will require a strong system backend, which can only be achieved through cloud computing.
[0040] Cloud storage is a new concept that has been extended and developed from the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as storage system) refers to a storage system that uses cluster applications, grid technology, and distributed storage file systems to bring together a large number of different types of storage devices (storage devices are also called storage nodes) in the network through application software or application interfaces to work together and provide external data storage and business access functions.
[0041] Currently, storage systems utilize a storage method that creates logical volumes. When creating a logical volume, physical storage space is allocated to each logical volume. This physical storage space may consist of disks on a specific storage device or several storage devices. When a client stores data on a logical volume, it stores the data on a file system. The file system divides the data into multiple parts, each of which is an object. Objects contain not only data but also additional information such as data identifiers (IDs, IDentities). The file system writes each object to the physical storage space of the logical volume and records the storage location information for each object. Therefore, when a client requests access to data, the file system can provide access based on the storage location information for each object.
[0042] The storage system allocates physical storage space to logical volumes by pre-dividing the physical storage space into stripes based on the estimated capacity of the objects to be stored in the logical volume (this estimate often has a large margin relative to the actual capacity of the objects to be stored) and the Redundant Array of Independent Disks (RAID) groupings. A logical volume can be understood as a stripe, thereby allocating physical storage space to the logical volume.
[0043] In the embodiment of the present application, the source data set and its corresponding table can be stored in the cloud.
[0044] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0045] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products, or devices.
[0046] The English explanations involved in this application are as follows:
[0047] JSON: JSON (JavaScript Object Notation) is a lightweight data exchange format;
[0048] originData: JSON data object;
[0049] originDataTemplate: JSON data object table template;
[0050] customDataTemplate: custom JSON data object table template;
[0051] depth: JSON object depth;
[0052] tableLayoutData: table layout object;
[0053] headerLayoutData: header layout object;
[0054] bodyLayoutData: table content layout object;
[0055] tableCodeData: table code format data;
[0056] layoutFormat: template data format ({key: string (attribute name), label: string (label content), props: array (subset)})
[0057] dataFormat: Arrange data format ({row:number (row number), col:number (column number), rowSpan:number (row width), colSpan:number (column width), label:string (label content)}).
[0058] See also Figure 1 , Figure 1 is a schematic diagram of a table construction system provided in an embodiment of the present application, such as Figure 1 As shown, the table construction system may include at least a server 01 and a client 02 .
[0059] Specifically, in the embodiments of this specification, the server 01 may include an independently operated server, or a distributed server, or a server cluster composed of multiple servers. It may also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. Server 01 may include a network communication unit, a processor, a memory, and the like. Specifically, the server 01 can be used to perform deduplication processing of text.
[0060] Specifically, in the embodiments of this specification, the client 02 may include a physical device such as a smartphone, desktop computer, tablet computer, laptop computer, digital assistant, smart wearable device, smart speaker, in-vehicle terminal, smart TV, etc. It may also include software running on the physical device, such as a web page provided by a service provider to a user, or an application provided by the service provider to a user. Specifically, the client 02 may be used to query the similarity between feedback texts online.
[0061] The following describes a table construction method for this application. Figure 2 It is a flow chart of a table construction method provided in an embodiment of the present application. This specification provides the method operation steps as described in the embodiment or flow chart, but may include more or fewer operation steps based on conventional or non-creative labor. The order of steps listed in the embodiment is only one way of executing the order of many steps and does not represent the only execution order. When the actual system or server product is executed, it can be executed in sequence or in parallel according to the method shown in the embodiment or the accompanying drawings (for example, in a parallel processor or multi-threaded processing environment).
[0062] Specific examples Figure 2 As shown, the method may include:
[0063] S201: Acquire a source data set in a target format; the source data set includes at least one set of attribute-value pairs; each set of attribute-value pairs includes an attribute name and an attribute value.
[0064] In the embodiments of this specification, the target format is a lightweight data exchange format (JSON); specifically, data in Excel or Word can be converted into a source data set in JSON format; each set of attribute-value pairs can include one or more attribute names, and each attribute name can correspond to one or more attribute values; the attribute value can be a string, an object, or an array.
[0065] In the embodiment of this specification, obtaining the source data set in the target format may include:
[0066] Receive a generation request for a form, and the source data set in the target format is carried in the generation request.
[0067] Specifically, in the embodiments of this specification, obtaining the source data set may be obtaining a JSON data object. For example, originData: [{id:'01', name:'Wang Yi', birthday:'1998 / 09 / 10', parent:{mother:'Xiao Hong', father:'Wang Er'}, school:[{name:'Primary School', time:'1998'}, {name:'Middle School', time:'1999'}]}, {id:'02', name:'Zhang Yi', birthday:'1998 / 09 / 10', parent:{mother:'Li Xiao', father:'Zhang Er'}, school:[{name:'Primary School', time:'1998'}, {name:'Middle School', time:'1999'}, {name:'High School', time:'2000'}]}]. Among them, the attribute names are id, name, parent, etc.
[0068] In the embodiments of this specification, an attribute value being an object can be understood as each attribute in the JSON data object, such as id, whose corresponding value is of string type: "01", an object such as {the attributes included in the curly braces}, and an array type such as [the value list included in the square brackets]; for example, id:'01', the value of id is a string, for example, parent:{mother:'Xiao Hong', father:'Wang Er'}, here the value of parent is an object {}, and it has sub-attributes such as mother in the form of attribute-value pairs; for example, school:[{name:'Primary School', time:'1998'}, {name:'Middle School', time:'1999'}, {name:'High School', time:'2000'}], the value corresponding to the school attribute is an array, and each item in the array here is an object and needs to be further parsed; an object has only multiple attributes, but an array may contain multiple objects, for example: the object is {a:1}, and the array can be [{a:1}, {b:2}].
[0069] S203: Based on the attribute names in the above source data set, construct a table template corresponding to the above source data set; the above table template includes multiple table tags.
[0070] In the embodiments of this specification, the table tags may include attribute name tags, marked content tags, and subset tags.
[0071] Specifically, in the embodiments of this specification, the JSON data object is directly parsed, and the attribute name and attribute value of the JSON data object are replaced with the format of layoutFormat({key: string (attribute name), label: string (label content), props: array (subset)}) using a depth-first traversal algorithm. Specifically: if the attribute value is a string, the key and label are stored in the attribute name, and there is no props attribute; if the attribute value is an object or an array, the attribute value is stored in props, and the props attribute is deeply recursed; and finally converted into template format data.
[0072] Specifically, in the embodiment of this specification, the JSON data object is parsed to generate a data object table template (originDataTemplate). The table template obtained by directly parsing the JSON data object is specifically shown in Table 1.
[0073] Specifically, in the embodiment of this specification, as shown in Table 1, the table template object customDataTemplate can also be manually customized. The table template object complies with the layoutFormat template data format.
[0074] Table 1
[0075]
[0076] S205: Based on the above table template, a table header layout object is obtained.
[0077] In the embodiment of this specification, before obtaining the header layout object based on the table template, the method further includes:
[0078] Recursively traverse the source data set to determine the depth of each attribute name and each attribute value in the source data set;
[0079] Update the above table template according to the depth of each attribute name.
[0080] In the embodiment of this specification, the updated table template carries depth information of the data.
[0081] In the embodiment of this specification, the recursive traversal of the source data set to determine the depth of each attribute name and each attribute value in the source data set includes:
[0082] According to the order of the attribute-value pairs in the above source data set, recursively traverse each set of attribute-value pairs in turn;
[0083] Determine the depth of the attribute name in each set of attribute value pairs according to the traversal order of each set of attribute value pairs; wherein the depth of the root attribute name of the first traversal is the first value; the depth of the root attribute name of the Nth traversal is the second value;
[0084] Based on the depth of each attribute name, the depth of each attribute value is determined.
[0085] In the embodiment of this specification, the depth of the outermost attribute name defaults to 0, for example, the first value may be 0; the second value may be 1.
[0086] Specifically, in the embodiment of this specification, originData is recursively traversed, the depth of originData is calculated, and a temporary object of the data object table template (originDataTemplate) with depth in props is obtained, such as: [{key:'id',title:'id'},{key:'name',title:'name'},{key:'birthday',title:'birthday'},{key:'parent',title:'parent',props:[[Object],[Object],depth:1]},{key:'school',title:'school',props:[[Object],[Object],depth:1]},depth:2].
[0087] In the embodiment of this specification, the header layout object is obtained based on the table template, including:
[0088] Based on the updated table template, get the table header layout object.
[0089] In the embodiments of this specification, Figure 3 As shown above, based on the above table template, the header layout object is obtained, including:
[0090] S2051: recursively traverse the above table template to obtain the table attribute parameters corresponding to each attribute name;
[0091] In the embodiment of this specification, table attribute parameters may include parameters such as row number, column number, row height, column width, etc.
[0092] In the embodiments of this specification, Figure 4 As shown, the above recursive traversal of the above table template obtains the table attribute parameters corresponding to each attribute name, including:
[0093] S20511: recursively traverse the table template to obtain the depth of the current attribute name, the number of traversals, and the number of traversals of the sub-attribute name corresponding to the current attribute name;
[0094] In the embodiments of this specification, the depth and traversal count of the current attribute name can be obtained; at the same time, the traversal count of the sub-attribute name corresponding to the current attribute name can be obtained. Traversal is started group by group according to the arrangement order of the attribute value pairs in the source data set; that is, the recursive traversal starts from the first attribute name, and the current attribute name includes the first attribute name, the second attribute name, and so on. When the attribute value in the attribute value pair is not a string, the attribute value can include the sub-attribute name and the corresponding sub-attribute value, so as to continue traversing the sub-attribute name until the last traversed attribute value is a string, and then traversal of the next group of attribute value pairs begins.
[0095] S20513: Determine the row number of the current attribute name in the table according to the depth of the current attribute name and the number of traversals of the sub-attribute names corresponding to the current attribute name;
[0096] In the embodiment of this specification, the calculation formula of the row number is: Row = (depth + 1) + traversal times
[0097] S20515: Determine the column number of the current attribute name in the table based on the number of traversals of the current attribute name;
[0098] In the embodiments of this specification, Figure 5 As shown, the above-mentioned determination of the column number of the current attribute name in the above-mentioned table based on the number of traversals of the above-mentioned current attribute name includes:
[0099] S205151: If the current attribute name has a parent attribute name, obtain the traversal count M of the current attribute name in the attribute names of the same level, and the traversal count N of the parent attribute name;
[0100] S205153: Determine the sum of M-1 and N as the column number of the current attribute name in the table.
[0101] Wherein, M and N are both positive integers.
[0102] In the embodiment of this specification, if the attribute value corresponding to the current attribute name is an object, the attribute value corresponding to its sub-attribute name can be a sub-object; if the current attribute name corresponds to multiple sub-attribute names, a sub-object list is obtained; the sub-object list inherits the traversal count value of the parent object as the column number for the first traversal (in this case, M = 1).
[0103] In the embodiment of this specification, determining the column number of the current attribute name in the table based on the number of traversals of the current attribute name includes:
[0104] If the current attribute name does not have a parent attribute name, the number of traversals of the current attribute name is determined as the column number of the current attribute name in the table.
[0105] S20517: Determine the row height and column width of the current attribute name in the table according to the attribute value corresponding to the current attribute name.
[0106] In the embodiments of this specification, Figure 6 As shown, the above-mentioned determination of the row height and column width of the above-mentioned current attribute name in the above-mentioned table according to the attribute value corresponding to the above-mentioned current attribute name includes:
[0107] S205171: Determine the total depth of each attribute value corresponding to the current attribute name;
[0108] S205173: Calculate a first ratio of the total depth to the row number of the current attribute name;
[0109] S205175: Obtain a second ratio based on the first ratio and the number of sub-attribute names corresponding to the current attribute name;
[0110] In this embodiment of the present specification, the second ratio may be obtained by calculating the quotient of the first ratio and the number of sub-attribute names corresponding to the current attribute name.
[0111] S205177: Determine the row height of the current attribute name in the table based on the second ratio;
[0112] S205179: Determine the column width of the current attribute name according to the attribute value corresponding to the current attribute name.
[0113] In the embodiment of the present specification, determining the column width of the current attribute name according to the attribute value corresponding to the current attribute name includes:
[0114] If the attribute value corresponding to the current attribute name is a character string, the first preset value is determined as the column width of the current attribute name.
[0115] In the embodiment of this specification, the first preset value can be set to 1. It can also be set to other values according to actual needs. When the attribute value is a string, it is a character attribute value.
[0116] In the embodiment of the present specification, determining the column width of the current attribute name according to the attribute value corresponding to the current attribute name includes:
[0117] If the property value corresponding to the above current property name is an array or an object, determine the column width of the current property name as the number of sub-property names in the above array or object.
[0118] In the embodiments of this specification, the column width of the current property name can be determined according to the category of the property value corresponding to the current property name.
[0119] S2053: Based on the table property parameters corresponding to each of the above property names, construct the above table header layout object.
[0120] Specifically, in the embodiments of this specification, the originDataTemplate temporary object with depth in props can be parsed into the headerLayoutData table header layout object in the dataFormat layout data format. According to the JSON data object originData: [{id:'01', name:'Wang Yi', birthday:'1998 / 09 / 10', parent:{mother:'Xiao Hong', father:'Wang Er'}, school:[{name:'Primary School', time:'1998'}, {name:'Middle School', time:'1999'}]}, {id:'02', name:'Zhang Yi', birthday:'1998 / 09 / 10', parent:{mother:'Li Xiao', father:'Zhang Er'}, school:[{name:'Primary School', time:'1998'}, {name:'Middle School', time:'1999'}, {name:'High School', time:'2000'}]}], the obtained Figure 8 headerLayoutData.
[0121] In the embodiments of this specification, parsing the property values in the above source data set based on the above table template to obtain the table content layout object includes:
[0122] S20531: Based on the above table template, recursively traverse the above source data set to obtain the table property parameters corresponding to each character property value;
[0123] In the embodiments of this specification, as Figure 7 shown, recursively traversing the above source data set to obtain the table property parameters corresponding to each character property value includes:
[0124] S205311: Recursively traverse the above source data set to obtain the depth, traversal count of the current character property value, and the row number of the data traversed before the current character property value;
[0125] S205313: Determine the row number of the current character attribute value in the table according to the depth of the current character attribute value, the number of traversals, and the row number of the data traversed before the current character attribute value;
[0126] In the embodiment of this specification, the above method further includes:
[0127] The target row number is determined based on the row number of the data traversed before the current character attribute value; the target row number is the largest row number among the row numbers corresponding to the multiple attribute names traversed previously.
[0128] In the embodiment of this specification, the calculation formula for the row number of the current character attribute value in the above table is as follows:
[0129] Row = target row number + depth of current character attribute value + 1 + number of traversals.
[0130] S205315: Determine the column number of the current character attribute value in the table based on the number of traversals of the current character attribute value;
[0131] In the embodiment of the present specification, the determining of the column number of the current character attribute value in the table based on the number of traversals of the current character attribute value includes:
[0132] Obtain the traversal times P of the current character attribute value among the character attribute values at the same level, and the traversal times Q of the attribute name corresponding to the current character attribute value;
[0133] The sum of P-1 and Q is determined as the column number of the current character attribute value in the above table.
[0134] Where P and Q are both positive integers.
[0135] S205317: Determine the second preset value as the row height and column width of the current attribute value in the table.
[0136] In the embodiment of this specification, the second preset value may be 1, and may also be set to other values according to actual needs.
[0137] S20533: Construct the table content layout object based on the table attribute parameters corresponding to each character attribute value.
[0138] S207: Parsing the attribute values in the source data set based on the table template to obtain a table content layout object.
[0139] In the embodiment of this specification, the above-mentioned parsing of the attribute values in the above-mentioned source data set based on the above-mentioned table template to obtain the table content arrangement object includes:
[0140] Based on the updated table template, parse the character attribute values in the above source dataset to obtain the table content layout object.
[0141] In the embodiments of this specification, according to the JSON data object originData: [{id:'01', name:'Wang Yi', birthday:'1998 / 09 / 10', parent:{mother:'Xiao Hong', father:'Wang Er'}, school:[{name:'Primary School', time:'1998'}, {name:'Middle School', time:'1999'}]}, {id:'02', name:'Zhang Yi', birthday:'1998 / 09 / 10', parent:{mother:'Li Xiao', father:'Zhang Er'}, school:[{name:'Primary School', time:'1998'}, {name:'Middle School', time:'1999'}, {name:'High School', time:'2000'}]}], the table content layout object obtained from some of the data is as Figure 9 shown.
[0142] S209: Concatenate the above table header layout object and the above table content layout object to obtain the table layout object.
[0143] In the embodiments of this specification, according to the JSON data object originData: [{id:'01', name:'Wang Yi', birthday:'1998 / 09 / 10', parent:{mother:'Xiao Hong', father:'Wang Er'}, school:[{name:'Primary School', time:'1998'}, {name:'Middle School', time:'1999'}]}, {id:'02', name:'Zhang Yi', birthday:'1998 / 09 / 10', parent:{mother:'Li Xiao', father:'Zhang Er'}, school:[{name:'Primary School', time:'1998'}, {name:'Middle School', time:'1999'}, {name:'High School', time:'2000'}]}], the table layout object obtained from some of the data is as Figure 10 shown.
[0144] S2011: Parse the data in the above table layout object according to the table tags to obtain the table corresponding to the above source dataset.
[0145] In the embodiments of this specification, the display result of the parsed table on the page is as Figure 11 shown.
[0146] Specifically, in the embodiments of this specification, recursive traversal starts from the first value in the brackets; regarding the determination of depth, if the attribute value of an attribute is an object or an array, the depth of the object or array will be written and placed at the depth of their location; for example, originData is an object with a total depth of 2; parent is an object with a depth of 1.
[0147] Specifically, in the embodiment of this specification, the recursive traversal method based on the depth-first algorithm is as follows:
[0148] 1. Start traversing from the first attribute of the data object;
[0149] 2. When encountering id:'01', its attribute value is not an object or array (only objects or arrays can contain other attributes). The current attribute ends. Since it is at the outermost layer, the depth value is not written. The default depth is 0 in subsequent processing.
[0150] 3. When parent is encountered, its attribute value is an object, so recursively traverse parent (that is, let parent repeat steps 1 and 2 and then return the final result of the traversal)
[0151] 4. When encountering school, whose attribute value is an array, loop each item in the array and repeat the traversal steps according to the attribute value in each item until the attribute value is a string. Finally, assemble the results and return them to the array.
[0152] Specifically, in the embodiment of this specification, the data is converted into an originDataTemplate temporary object with a depth value depth by recursive traversal, so as to be able to calculate the specific position of each object in the table format later.
[0153] Through deep recursive traversal, the originDataTemplate is parsed into headerLayoutData format data. The calculation formula for each headerLayoutData data during the parsing process is as follows:
[0154] row = (depth value of the current object location + 1) + (number of sub-object traversals, starting from 0);
[0155] col = (the loop where the current object is located or the number of times the current object is traversed)
[0156] Among them, the first traversal of the child object list inherits the traversal times of the parent object
[0157] rowSpan = round up (total array depth / row) / (number of child objects)
[0158] Among them, if there is no child object, the value of the number of child objects is set to 1;
[0159] colSpan = the number of props contained in the child object
[0160] label = the label value of the object
[0161] The following examples illustrate:
[0162] 1. Parsing of ID objects
[0163] row = (o + 1) + 0 = 1 (the id is located at the outermost layer, and the default value is 0 if there is no depth value)
[0164] col=1 (id is the first value and the first traversal)
[0165] rowSpan=Math.ceil(2 / row) / 1=2
[0166] (The total array depth is 2, the default value is 1 if there is no child object, and Math.ceil means rounding up)
[0167] colSpan = 1 (no child object props, default is 1)
[0168] Specifically, in the embodiments of this specification, if there are child objects, colSpan is the length of props, that is, the number of data contained in props;
[0169] 2. Mother object analysis
[0170] row = (1 + 1) + 0 = 2 (the depth value of the mother position is 1)
[0171] col=4 (mother is the first child object of parent, and parent is the fourth traversal of the data, so mother inherits the parent traversal count value)
[0172] rowSpan = Math.ceil(2 / row) / 1 = 1 (the total depth of the array is 2, the default value is 1 if there is no child object, and Math.ceil means rounding up)
[0173] colSpan = 1 (no child object props, default is 1)
[0174] Specifically, in the embodiments of this specification, the table parameter calculation methods of character attribute values are the same except for the row number calculation method.
[0175] row = the maximum row of the previous parsed data + (the depth value of the parent attribute corresponding to the current value + 1) + (the number of child objects traversed, starting from 0);
[0176] Specifically, in the embodiment of this specification, Wang Er sees the first row in the current data, and the maximum row of the previous header is added, so the final data is the 2nd + 1 = 3rd row;
[0177] Primary school: In the school, the current primary school's depth is 0 (the row calculation here is different. Primary school is a value, contained in the school parent attribute, so it is the depth of the parent attribute) + 1 + 0 (primary school is the first item in the school array, and the count starts from 0, so it is 0) + 2. The header is the largest data parsed in the previous row; the primary school's row = 3;
[0178] Middle school: 0+1+1 (middle school is the second item in the school array, counting starts from 0 and is 1) + 2 (the largest row number in the previous parsed data in the table header); Middle school row = 4
[0179] For example, if the maximum row of the previous table header is 2, after Wang Er finishes parsing it, its maximum row is 4, and the next time Zhang Er is parsed, 4 will be added.
[0180] It can be seen from the technical solutions provided by the above embodiments of this specification that the embodiments of this specification construct a table template based on the attribute names in the source data; obtain a header layout object based on the table template, and parse the source data set to obtain a table content layout object; then, the header layout object and the table layout object are spliced into a table layout object, thereby parsing to obtain a table; when the source data set is converted into a table, the application does not need to know the data format in advance and define the table structure to be displayed, and realizes automatic parsing of data to obtain a table format, and can quickly construct tables corresponding to various complex source data sets, thereby reducing the workload of developers and improving the efficiency of table development.
[0181] The present application also provides a table construction device, such as Figure 12 As shown, the device includes:
[0182] The source data set acquisition module 1210 is used to acquire a source data set in a target format; the source data set includes at least one set of attribute-value pairs; each set of attribute-value pairs includes an attribute name and an attribute value;
[0183] The table template construction module 1220 is used to construct a table template corresponding to the source data set based on the attribute names in the source data set; the table template includes multiple table tags;
[0184] A table header layout object construction module 1230 is used to obtain a table header layout object based on the table template;
[0185] A table content arrangement object construction module 1240 is configured to parse the attribute values in the source data set based on the table template to obtain a table content arrangement object;
[0186] A table layout object construction module 1250 is configured to combine the table header layout object with the table content layout object to obtain a table layout object.
[0187] The table construction module 1260 is used to parse the data in the table layout object according to the table tags to obtain the table corresponding to the source data set.
[0188] In some embodiments, the apparatus may further include:
[0189] A depth determination module, configured to recursively traverse the source data set to determine the depth of each attribute name and each attribute value in the source data set;
[0190] The template updating module is used to update the above table template according to the depth of each attribute name.
[0191] In some embodiments, the header arrangement object construction module may include:
[0192] A first attribute parameter determination unit is used to recursively traverse the table template to obtain a table attribute parameter corresponding to each attribute name;
[0193] The header layout object construction unit is used to construct the above header layout object based on the table attribute parameters corresponding to each of the above attribute names.
[0194] In some embodiments, the table content arrangement object construction module may include:
[0195] A second attribute parameter determining unit is configured to recursively traverse the source data set based on the table template to obtain a table attribute parameter corresponding to each character attribute value;
[0196] The table content layout object construction unit is used to construct the table content layout object based on the table attribute parameters corresponding to each character attribute value.
[0197] In some embodiments, the first attribute parameter determining unit may include:
[0198] The first traversal count acquisition subunit is used to recursively traverse the above table template to obtain the depth of the current attribute name, the traversal count, and the traversal count of the sub-attribute name corresponding to the current attribute name;
[0199] A first row number determination subunit is used to determine the row number of the current attribute name in the table according to the depth of the current attribute name and the number of traversals of the sub-attribute names corresponding to the current attribute name;
[0200] A first column number determination subunit is used to determine the column number of the current attribute name in the table based on the number of traversals of the current attribute name;
[0201] The first row height and column width determining subunit is used to determine the row height and column width of the current attribute name in the table according to the attribute value corresponding to the current attribute name.
[0202] In some embodiments, the first row number determining subunit may include:
[0203] The traversal count acquisition submodule is used to obtain the traversal count M of the current attribute name in the attribute names of the same level, and the traversal count N of the parent attribute name, if the current attribute name has a parent attribute name;
[0204] The column number determination submodule is used to determine the sum of M-1 and N as the column number of the current attribute name in the table.
[0205] In some embodiments, the first row height and column width determining subunit may include:
[0206] A total depth determination submodule is used to determine the total depth of each attribute value corresponding to the current attribute name;
[0207] A first ratio determination submodule, configured to calculate a first ratio of the total depth to the row number of the current attribute name;
[0208] a second ratio determination submodule, configured to obtain a second ratio based on the first ratio and the number of sub-attribute names corresponding to the current attribute name;
[0209] a row height determination submodule, configured to determine a row height of the current attribute name in the table based on the second ratio;
[0210] The column width determination submodule is used to determine the column width of the current attribute name according to the attribute value corresponding to the current attribute name.
[0211] In some embodiments, the column width determination submodule may include:
[0212] The first value determination submodule is configured to determine a first preset value as the column width of the current attribute name if the attribute value corresponding to the current attribute name is a character string.
[0213] In some embodiments, the column width determination submodule may include:
[0214] The second value determination submodule is configured to determine the number of sub-attribute names in the array or object as the column width of the current attribute name if the attribute value corresponding to the current attribute name is an array or an object.
[0215] In some embodiments, the second attribute parameter determining unit may include:
[0216] The second traversal count acquisition subunit is used to recursively traverse the source data set to obtain the depth of the current character attribute value, the traversal count, and the row number of the data traversed before the current character attribute value;
[0217] A second row number subunit is configured to determine the row number of the current character attribute value in the table according to the depth of the current character attribute value, the number of traversals, and the row number of the data traversed before the current character attribute value;
[0218] A second column number determining subunit is configured to determine the column number of the current character attribute value in the table based on the number of traversals of the current character attribute value;
[0219] The second row height and column width determining subunit is used to determine the second preset value as the row height and column width of the current character attribute value in the table.
[0220] The device and method embodiments in the device embodiments are based on the same inventive concept.
[0221] An embodiment of the present application provides a table construction device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the table construction method provided in the above method embodiment.
[0222] An embodiment of the present application also provides a computer storage medium, which can be set in a terminal to store at least one instruction or at least one program related to implementing a table construction method in a method embodiment. The at least one instruction or at least one program is loaded and executed by the processor to implement the table construction method provided by the above method embodiment.
[0223] Embodiments of the present application also provide a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to implement the table construction method provided in the above method embodiment.
[0224] Optionally, in the embodiments of this specification, the storage medium may be located in at least one of the multiple network servers of the computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to, various media that can store program code, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0225] The memory described in the embodiments of this specification can be used to store software programs and modules, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory may mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs required for functions, etc.; the data storage area can store data created according to the use of the device, etc. In addition, the memory may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide the processor with access to the memory.
[0226] The table construction method embodiment provided in the embodiment of the present application can be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Taking running on a server as an example, Figure 13 This is a hardware structure diagram of a server of a table construction method provided in an embodiment of the present application. Figure 13As shown, the server 1300 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPUs) 1310 (the processor 1310 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 1330 for storing data, and one or more storage media 1320 (such as one or more mass storage devices) for storing application programs 1323 or data 1322. Among them, the memory 1330 and the storage medium 1320 can be temporary storage or permanent storage. The program stored in the storage medium 1320 may include one or more modules, each module may include a series of instruction operations on the server. Furthermore, the central processing unit 1310 can be configured to communicate with the storage medium 1320 to execute a series of instruction operations in the storage medium 1320 on the server 1300. The server 1300 may also include one or more power supplies 1360, one or more wired or wireless network interfaces 1350, one or more input and output interfaces 1340, and / or one or more operating systems 1321, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0227] The input / output interface 1340 can be used to receive or send data via a network. Specific examples of the aforementioned network may include a wireless network provided by the communication provider of the server 1300. In one embodiment, the input / output interface 1340 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the input / output interface 1340 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0228] It can be understood by those skilled in the art that Figure 13 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 13 More or fewer components than shown, or with Figure 13 Different configurations shown.
[0229] It can be seen from the embodiments of the table construction method, device, server or storage medium provided by the above-mentioned present application that the present application constructs a table template based on the attribute name in the source data; obtains a header layout object based on the table template, and parses the source data set to obtain a table content layout object; then splices the header layout object and the table layout object into a table layout object, thereby parsing to obtain a table; when the present application converts the source data set into a table, there is no need to know the data format in advance and define the table structure to be displayed, so that automatic parsing of data to obtain a table format is realized, and tables corresponding to various complex source data sets can be quickly constructed, thereby reducing the workload of developers and improving table development efficiency.
[0230] It should be noted that the order of the embodiments of the present application described above is for descriptive purposes only and does not represent the superiority or inferiority of the embodiments. The above description is of specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the accompanying drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0231] The various embodiments in this specification are described in a progressive manner. Similar portions between the various embodiments can be referenced to each other, and each embodiment focuses on the differences from the other embodiments. In particular, the device, equipment, and storage medium embodiments are generally similar to the method embodiments, so their descriptions are relatively simplified. For relevant portions, refer to the descriptions of the method embodiments.
[0232] Those skilled in the art will understand that all or part of the steps of implementing the above embodiments may be accomplished by hardware, or by a program instructing the relevant hardware to accomplish the steps. The program may be stored in a computer storage medium, and the above-mentioned storage medium may be a read-only memory, a disk, or an optical disk, etc.
[0233] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.
Claims
1. A table construction method, characterized in that: The method comprises: Obtain a source data set in a target format; the source data set includes at least one set of attribute-value pairs; each set of attribute-value pairs includes an attribute name and an attribute value; Based on the attribute names in the source data set, construct a table template corresponding to the source data set; the table template includes a plurality of table tags; Recursively traverse the table template to obtain the depth of the current attribute name, the number of traversals, and the number of traversals of the sub-attribute name corresponding to the current attribute name; Determine the row number of the current attribute name in the table according to the depth of the current attribute name and the number of traversals of the sub-attribute names corresponding to the current attribute name; Determine the column number of the current attribute name in the table based on the number of traversals of the current attribute name; Determine the row height and column width of the current attribute name in the table according to the attribute value corresponding to the current attribute name, and use the row number, column number, row height and column width corresponding to the current attribute name as table attribute parameters of the current attribute name; Construct a table header layout object based on the table attribute parameters corresponding to each attribute name; Parsing the attribute values in the source data set based on the table template to obtain a table content layout object; Joining the table header layout object with the table content layout object to obtain a table layout object; The data in the table layout object is parsed according to the table tag to obtain the table corresponding to the source data set.
2. The method according to claim 1, characterized in that Before obtaining the header layout object based on the table template, the method further includes: Recursively traverse the source data set to determine the depth of each attribute name and each attribute value in the source data set; updating the table template according to the depth of each attribute name; Accordingly, the header layout object is obtained based on the table template, including: Based on the updated table template, get the header layout object; Accordingly, the parsing of the attribute values in the source data set based on the table template to obtain the table content arrangement object includes: Based on the updated table template, the character attribute values in the source data set are parsed to obtain a table content layout object.
3. The method according to claim 1, characterized in that The step of parsing the attribute values in the source data set based on the table template to obtain a table content layout object includes: Based on the table template, recursively traverse the source data set to obtain the table attribute parameters corresponding to each character attribute value; The table content layout object is constructed based on the table attribute parameters corresponding to each character attribute value.
4. The method according to claim 1, wherein The determining the column number of the current attribute name in the table based on the number of traversals of the current attribute name includes: If the current attribute name has a parent attribute name, obtain the traversal times M of the current attribute name in the attribute names of the same level, and the traversal times N of the parent attribute name; The sum of M-1 and N is determined as the column number of the current attribute name in the table.
5. The method according to claim 1, wherein The determining, according to the attribute value corresponding to the current attribute name, the row height and column width of the current attribute name in the table includes: Determine the total depth of each attribute value corresponding to the current attribute name; Calculating a first ratio of the total depth to the row number of the current attribute name; obtaining a second ratio based on the first ratio and the number of sub-attribute names corresponding to the current attribute name; determining a row height of the current attribute name in the table based on the second ratio; The column width of the current attribute name is determined according to the attribute value corresponding to the current attribute name.
6. The method according to claim 5, characterized in that The determining the column width of the current attribute name according to the attribute value corresponding to the current attribute name includes: If the attribute value corresponding to the current attribute name is a character string, a first preset value is determined as the column width of the current attribute name.
7. The method according to claim 5, characterized in that The determining the column width of the current attribute name according to the attribute value corresponding to the current attribute name includes: If the attribute value corresponding to the current attribute name is an array or an object, the number of sub-attribute names in the array or object is determined as the column width of the current attribute name.
8. The method according to claim 3, characterized in that The recursive traversal of the source data set to obtain the table attribute parameters corresponding to each character attribute value includes: Recursively traverse the source data set to obtain the depth of the current character attribute value, the number of traversals, and the row number of the data traversed before the current character attribute value; Determining the row number of the current character attribute value in the table according to the depth of the current character attribute value, the number of traversals, and the row number of the data traversed before the current character attribute value; Determining a column number of the current character attribute value in the table based on the number of traversals of the current character attribute value; The second preset value is determined as the row height and column width of the current character attribute value in the table.
9. A table construction device, characterized in that: The device comprises: A source data set acquisition module is used to acquire a source data set in a target format; the source data set includes at least one set of attribute value pairs; each set of attribute value pairs includes an attribute name and an attribute value; A table template construction module, configured to construct a table template corresponding to the source data set based on the attribute names in the source data set; the table template includes a plurality of table tags; A table header layout object construction module, used to obtain a table header layout object based on the table template; A table content arrangement object construction module, configured to parse the attribute values in the source data set based on the table template to obtain a table content arrangement object; A table layout object construction module, configured to combine the table header layout object with the table content layout object to obtain a table layout object; A table construction module is used to parse the data in the table layout object according to the table tags to obtain the table corresponding to the source data set; The header layout object construction module includes: a first traversal count acquisition subunit, used to recursively traverse the table template to obtain the depth of the current attribute name, the traversal count, and the traversal count of the sub-attribute name corresponding to the current attribute name; a first row number determination subunit, used to determine the row number of the current attribute name in the table based on the depth of the current attribute name and the traversal count of the sub-attribute name corresponding to the current attribute name; a first column number determination subunit, used to determine the column number of the current attribute name in the table based on the traversal count of the current attribute name; a first row height and column width determination subunit, used to determine the row height and column width of the current attribute name in the table based on the attribute value corresponding to the current attribute name, and use the row number, column number, row height and column width corresponding to the current attribute name as the table attribute parameters of the current attribute name; a header layout object construction unit, used to construct the header layout object based on the table attribute parameters corresponding to each attribute name.
10. The device according to claim 9, characterized in that The device further comprises: A depth determination module, configured to recursively traverse the source data set to determine the depth of each attribute name and each attribute value in the source data set; A template updating module, used for updating the table template according to the depth of each attribute name; The header arrangement object construction module includes: A first attribute parameter determination unit is used to recursively traverse the table template to obtain a table attribute parameter corresponding to each attribute name; The header layout object construction unit is used to construct the above header layout object based on the table attribute parameters corresponding to each of the above attribute names.
11. The device according to claim 9, characterized in that The table content arrangement object construction module includes: A second attribute parameter determining unit is configured to recursively traverse the source data set based on the table template to obtain a table attribute parameter corresponding to each character attribute value; The table content layout object construction unit is used to construct the table content layout object based on the table attribute parameters corresponding to each character attribute value.
12. The device according to claim 9, characterized in that The first row number determining subunit includes: The traversal count acquisition submodule is used to obtain the traversal count M of the current attribute name in the attribute names of the same level, and the traversal count N of the parent attribute name, if the current attribute name has a parent attribute name; The column number determination submodule is used to determine the sum of M-1 and N as the column number of the current attribute name in the table.
13. The device according to claim 9, characterized in that The first row height and column width determining subunit includes: A total depth determination submodule is used to determine the total depth of each attribute value corresponding to the current attribute name; A first ratio determination submodule, configured to calculate a first ratio of the total depth to the row number of the current attribute name; a second ratio determination submodule, configured to obtain a second ratio based on the first ratio and the number of sub-attribute names corresponding to the current attribute name; a row height determination submodule, configured to determine a row height of the current attribute name in the table based on the second ratio; The column width determination submodule is used to determine the column width of the current attribute name according to the attribute value corresponding to the current attribute name.
14. The device according to claim 13, characterized in that The column width determination submodule includes: The first value determination submodule is configured to determine a first preset value as the column width of the current attribute name if the attribute value corresponding to the current attribute name is a character string.
15. The device according to claim 13, characterized in that The column width determination submodule includes: The second value determination submodule is configured to determine the number of sub-attribute names in the array or object as the column width of the current attribute name if the attribute value corresponding to the current attribute name is an array or an object.
16. The device according to claim 11, characterized in that The second attribute parameter determining unit includes: The second traversal count acquisition subunit is used to recursively traverse the source data set to obtain the depth of the current character attribute value, the traversal count, and the row number of the data traversed before the current character attribute value; A second row number subunit is configured to determine the row number of the current character attribute value in the table according to the depth of the current character attribute value, the number of traversals, and the row number of the data traversed before the current character attribute value; A second column number determining subunit is configured to determine the column number of the current character attribute value in the table based on the number of traversals of the current character attribute value; The second row height and column width determining subunit is used to determine the second preset value as the row height and column width of the current character attribute value in the table.
17. A table building device, characterized in that: The device includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the table construction method according to any one of claims 1 to 8.
18. A computer storage medium, characterized in that The computer storage medium stores at least one instruction or at least one program segment, and the at least one instruction or the at least one program segment is loaded and executed by a processor to implement the table construction method according to any one of claims 1 to 8.
19. A computer program product, characterized in that The computer program product includes computer instructions, and the computer instructions are used to be executed to implement the table construction method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Method, device and apparatus for processing multi-level header report based on service metadata
CN109635011A