Graph database construction methods, electronic devices, and storage media
By defining the sorting attribute of edges in the graph database and storing them in an ordered manner, the problem of low query efficiency in traditional graph databases is solved, and fast and efficient query results can be obtained.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-02
- Publication Date
- 2026-04-03
AI Technical Summary
Traditional graph databases have low query efficiency when processing data with complex relationships, especially during the reordering process, which consumes a lot of memory and time, affecting performance and user experience.
By creating metadata for the graph database, defining vertices, edges, and attributes, and setting sorting attributes for edges based on the attributes, the graph database is generated when writing edge data, and vertex and edge data are stored using columnar storage units to achieve ordered storage of edges.
It improves the query efficiency of graph databases, enabling the direct retrieval of an ordered full result set from any point, thus greatly enhancing query performance.
Smart Images

Figure CN115422405B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing, and in particular to methods for constructing graph databases, electronic devices, and storage media. Background Technology
[0002] With the advent of the era of big data and the Internet of Things, data is emerging in an explosive manner, and various complex relationships exist between these data. Traditional relational databases exhibit insufficient performance in handling this complex data, failing to adequately meet the needs of market users. Graph databases, based on graph theory, naturally support the rapid processing of complex relationships.
[0003] Sorting query result sets in graph databases involves reordering in memory or storing them in an ordered manner. For example, sorting by the `orderBy` operator on the query result set.
[0004] This approach can obtain a sorted result set, but a large number of unordered intermediate result sets will consume a lot of memory space and time to re-sort, which is time-consuming and laborious, affecting the overall query performance and user experience. Summary of the Invention
[0005] This invention provides a method for constructing a graph database, an electronic device, and a storage medium to solve the problem of low query efficiency in graph databases.
[0006] To address the aforementioned technical problems, this invention provides a method for constructing a graph database, comprising: creating metadata for the graph database and defining the nodes, edges, and attributes of the graph database in the metadata; setting a sorting attribute for the edges based on the attributes, wherein the edges are undirected edges; and writing source data, including node data of multiple nodes and edge data of multiple edges, based on the metadata to generate the graph database; wherein, when writing the edge data, the edges corresponding to each node are sorted in an ordered manner based on the sorting attribute in the edge data.
[0007] The process of sorting the edges corresponding to each point based on the sorting attributes in the edge data includes: determining the edge data of the edge as the point label, edge label, edge sorting attributes, and edge identifier code associated with the edge in the source data; wherein the point label associated with the edge includes the point labels of the two points associated with the edge; obtaining all edges associated with each point, and sorting the edges corresponding to each point in order based on the sorting attributes of each edge.
[0008] The process involves obtaining all edges associated with a point and sorting the edges corresponding to each point according to their sorting attributes. This includes: arranging the edges based on the point labels to obtain the edges corresponding to each point label; arranging the edges corresponding to each point label according to their edge labels to obtain the edges corresponding to each edge label; and sorting the edges corresponding to each edge label according to their sorting attributes to complete the sorting of the edge data.
[0009] The process of writing source data, which includes point data of multiple points and edge data of multiple edges, based on metadata, to generate a graph database includes: obtaining edge data of each edge and point data of the two points corresponding to each edge from the source data; creating two columnar storage units based on the point data of the two points corresponding to each edge to store the corresponding point data; and storing the edge data of the edges into the edge cells of the columnar storage units of the corresponding two points.
[0010] The point data includes the point label corresponding to the point and at least one attribute; the columnar storage unit includes a label cell, at least one edge cell and at least one attribute cell; the columnar storage unit is created based on the label of each point, and further includes: storing the point label and at least one attribute of each point into the label cell and at least one attribute cell of the columnar storage unit respectively.
[0011] The edge cell includes an edge label cell, a sorting attribute cell, a point label cell, and an edge identification code cell. Storing the edge data into the edge cells of the corresponding two point-based columnar storage units includes: storing the edge data's label, sorting attribute, point label, and edge identification code into the label cell, sorting attribute cell, point label cell, and edge identification code cell of the edge cell of the two columnar storage units, respectively.
[0012] This involves creating metadata for the graph database and defining the points, edges, and attributes of the graph database within the metadata. This includes: determining the points and attributes involved in the graph database; defining the relationships between points as edges and setting the sorting attributes of the edges based on the attributes; and generating the metadata of the graph database based on the points, edges, and attributes.
[0013] The process of generating a graph database by writing point data and edge data for each point based on metadata includes: preparing indexes for target points and corresponding target edges; querying target points from the graph database based on the indexes of target points; querying multiple target edges associated with target points from the graph database based on the indexes of target edges; and determining all target edges in the graph database that correspond to and are arranged in an orderly manner as the query results.
[0014] To address the aforementioned technical problems, the present invention also provides an electronic device comprising: a memory and a processor coupled to each other, wherein the processor is used to execute program instructions stored in the memory to implement the graph database construction method described above.
[0015] To address the aforementioned technical problems, the present invention also provides a computer-readable storage medium storing program data that can be executed to implement the graph database construction method as described above.
[0016] The beneficial effects of this invention are as follows: Unlike the prior art, this invention creates metadata for a graph database, defines the points, edges, and attributes of the graph database in the metadata, and sets the sorting attributes of the edges based on the attributes; wherein the edges are undirected edges; based on the metadata, source data including point data of multiple points and edge data of corresponding multiple edges is written to generate a graph database, and when writing edge data, the edges corresponding to each point are sorted in an ordered manner based on the sorting attributes of the edge data, and then the full result of the edges corresponding to each point is sorted and stored. Therefore, when performing edge queries on the graph database, querying the sorting attribute from any point can obtain an immediately ordered full result set, thereby greatly improving query efficiency. Attached Figure Description
[0017] Figure 1 This is a flowchart illustrating an embodiment of the graph database construction method provided by the present invention;
[0018] Figure 2 This is a schematic flowchart of another embodiment of the graph database construction method provided by the present invention;
[0019] Figure 3 This is a schematic diagram of a three-tuple implementation of the metadata of the present invention;
[0020] Figure 4 yes Figure 2 A schematic diagram of the structure of one embodiment of the columnar storage unit in the example;
[0021] Figure 5 yes Figure 4 A schematic diagram of the structure of the edge cell in the columnar storage unit in the implementation method;
[0022] Figure 6 yes Figure 2 A schematic diagram of the structure of a triplet in the database in this embodiment;
[0023] Figure 7 yes Figure 6 A schematic diagram of the storage structure of each side;
[0024] Figure 8This is a schematic diagram of the framework of an embodiment of the graph database construction device of the present invention;
[0025] Figure 9 This is a schematic diagram of the structure of an embodiment of the electronic device provided by the present invention;
[0026] Figure 10 This is a schematic diagram of an embodiment of the computer-readable storage medium provided by the present invention. Detailed Implementation
[0027] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.
[0028] Please see Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the graph database construction method provided by the present invention.
[0029] Step S11: Create the metadata of the graph database, define the nodes, edges and attributes of the graph database in the metadata, and set the sorting attribute of the edges based on the attributes.
[0030] The metadata of a graph database defines the rules for its construction, known as the schema. This schema defines specific information about the graph database's tables, columns, data types, views, stored procedures, relationships, primary keys, foreign keys, and other data. The specific schema is determined based on the type of graph database or the database's requirements.
[0031] In this implementation, the schema defines the points, edges, and attributes contained in the graph database to be obtained.
[0032] In one specific implementation, the domain to which the graph database belongs can be determined first, thereby identifying the vertices, edges, and attributes involved in the graph database. In another specific implementation, the source data of the graph database can be obtained first, and the vertices, edges, and attributes involved in the graph database can be determined based on the data type in the source data.
[0033] In this step, "points" refer to instances of data to be stored in the graph database. The relationships between points are called edges, while attributes refer to the properties and relationships associated with points. Point attributes may include time, location, scene, and purpose, while attributes related to relationships between points may include ownership and belonging. The sorting attribute is used for ranking and can be set based on other attributes. The specific attribute chosen for sorting is determined by actual needs and is not limited here.
[0034] Within the same graph database, different edges can have different sorting attributes, and the specific sorting attribute categories for each edge can be set based on actual needs, without any restrictions here.
[0035] Taking the field of interpersonal relationships as an example, the points in the field of interpersonal relationships can be individuals, and the edges can be the relationships between people, such as the existence of trust relationships or close relationships. The attributes can include the attributes of the points and the attributes of the edges. For example, the attributes of people can include ID card, gender, and age attributes, while the attributes of edges can include the trust level, intimacy level, and kinship level between people.
[0036] In this embodiment, the edges are defined as undirected edges. In one specific application scenario, an undirected edge can refer to an edge between points that has no pointing direction. In another specific application scenario, an undirected edge can also refer to an edge between points that has only one direction, such as an outgoing edge or an incoming edge.
[0037] In one specific application scenario, after defining the points, edges, and attributes of a graph database, metadata can be created using conventional metadata creation tools. In another specific application scenario, metadata can be created using creation functions. The specifics are not limited here.
[0038] Step S12: Based on metadata, write source data including point data of multiple points and edge data of corresponding multiple edges to generate a graph database.
[0039] Once the source data for the graph database is determined, the source data, including vertex data for multiple points and edge data for their corresponding edges, is written based on metadata to generate the graph database. The source data can originate from a general, unchanging information file, or it can be obtained through web page retrieval or external message push; there are no restrictions here.
[0040] In this process, when writing edge data, the edges corresponding to each point are sorted in an ordered manner based on the sorting attribute in the edge data, thereby achieving ordered storage of the edges corresponding to each point. Since the edges in this embodiment are defined as undirected edges, there is no distinction in direction. Therefore, when sorting the edges corresponding to each point, only a single index sorting is performed based on the sorting attribute in the edge data, resulting in the full sorted storage of the edges corresponding to each point. Thus, when performing edge queries on the graph database, the full sorted results of the edges corresponding to each point can be obtained directly, greatly improving query efficiency.
[0041] In one specific application scenario, when edge data without a sorting attribute exists, its sorting attribute can be set to have the lowest priority. That is, the edge data with a sorting attribute is sorted first based on the sorting attribute, and then the edge data without a sorting attribute is placed last. In another specific application scenario, when edge data without a sorting attribute exists, other attributes can be used to sort the edge data of each point; this is not limited here.
[0042] Through the above steps, the graph database construction method of this embodiment creates graph database metadata, defines the points, edges, and attributes of the graph database in the metadata, and sets the sorting attribute of the edges based on the attributes; wherein the edges are undirected edges; the graph database is generated by writing source data including point data of multiple points and edge data of corresponding multiple edges based on the metadata, and when writing edge data, the edges corresponding to each point are sorted in order based on the sorting attribute of the edge data, and then the full result of the edges corresponding to each point is sorted and stored. Thus, when performing edge queries on the graph database, querying the sorting attribute from any point can obtain an immediately ordered full result set, thereby greatly improving query efficiency.
[0043] Please see Figure 2 , Figure 2 This is a flowchart illustrating another embodiment of the graph database construction method provided by the present invention.
[0044] Step S21: Determine the points and attributes involved in the graph database; define the relationships between points as edges, and set the sorting attributes of the edges based on the attributes; determine the metadata of the graph database based on the points, edges, and attributes.
[0045] In one specific implementation, the domain to which the graph database belongs can be determined first, thereby identifying the points and attributes involved in the graph database. In another specific implementation, the source data of the graph database can be obtained first, and the points and attributes involved in the graph database can be determined based on the data type in the source data; this is not limited here.
[0046] The relationships between points are defined as edges, and the sorting attributes of these edges are set based on their properties. In a specific application scenario, a particular attribute of an edge can be selected as its sorting attribute. This sorting attribute can be determined based on either manual specification or historical experience.
[0047] The triplet data storage structure of points, edges, and nodes in this embodiment can improve the visualization of the relationships between data in the graph database, making it easier to manage and update the graph database.
[0048] Please see Figure 3 , Figure 3This is a schematic diagram of a triplet implementation of the metadata of the present invention. This embodiment uses the points "person" and "case" as examples, with edges representing close relationships and confidence associations, and attributes representing closeness and confidence. When the metadata is from other domains, the structure is similar and will not be described further.
[0049] In this embodiment, point 31 can include people and cases, and edge 32 can represent close relationships between people or a credible association between people and cases.
[0050] Within the same metadata, the type of point 31 can include one or more types, and the types of edges 32 between different points 31 can also be the same or different.
[0051] In this embodiment, edge 32 is an undirected edge. That is, there is no difference in direction between the edges 32, so the direction attribute of the edges 32 can be ignored when sorting them.
[0052] In a specific application scenario, after defining the attributes, points, and edges, the above definitions can be loaded into the graph database and serialized to the columnar storage backend to generate metadata.
[0053] The metadata defines the sorting attributes of each edge, so that when writing data, it can determine if the edge data includes sorting attributes, and sort the edges corresponding to each point in an ordered manner based on the sorting attributes of the edge data.
[0054] Step S22: Based on metadata, write source data including point data of multiple points and edge data of corresponding multiple edges to generate a graph database.
[0055] A graph database is generated by writing source data, which includes vertex data and corresponding edge data, based on metadata. The specific number of vertex and edge data in the graph database depends on the amount of source data.
[0056] In one specific implementation, edge data of each edge and point data of the two points corresponding to each edge are obtained from the source data; two columnar storage units are created based on the point data of the two points corresponding to each edge to store the corresponding point data; the edge data of each edge is stored in the edge cell of the columnar storage unit corresponding to the two points. The columnar storage unit is an HBase columnar storage unit or another type of columnar storage unit.
[0057] Please see Figure 4 , Figure 4 yes Figure 2 A schematic diagram of one embodiment of the columnar storage unit in the example.
[0058] The columnar storage unit 40 in this embodiment includes a label cell 41, at least one edge cell 43, and at least one attribute cell 42. The label cell 41 is used to store the punctuation of the point, the edge cell 43 is used to store the corresponding edge data, and the attribute cell 42 is used to store the attribute of the point.
[0059] The point data includes the point label corresponding to the point and at least one attribute. When creating a corresponding columnar storage unit based on the label of each point, the point label and at least one attribute of each point are stored in the label cell and at least one attribute cell of the columnar storage unit, respectively, and the edge data of the corresponding edge are stored in the edge cell of the columnar storage unit of the point, thus obtaining the columnar storage unit.
[0060] Please see Figure 5 , Figure 5 yes Figure 4 A schematic diagram of the structure of the edge cell in the columnar storage unit in the implementation method.
[0061] Edge cell 43 includes edge label cell 51, sorting attribute cell 52, point label cell 53, and edge identification code cell 54. Edge label cell 51 is used to store edge labels, sorting attribute cell 52 is used to store the sorting attribute of the edge, point label cell 53 is used to store the labels of the points associated with the edge, and identification code cell 54 is used to store the unique ID code of the edge.
[0062] Specifically, when storing the edge data into the edge cells of the two point-like columnar storage units, the label, sorting attribute, point label, and edge identification code of the edge data are respectively stored into the label cell 51, sorting attribute cell 52, point label cell 53, and edge identification code cell 54 of the edge cell 50 of the two point-like columnar storage unit 40.
[0063] By using the above method, the source data, including point data of multiple points and edge data of corresponding multiple edges, is written to generate a graph database.
[0064] Please see Figure 6 , Figure 6 yes Figure 2 The embodiment shows a schematic diagram of the structure of a triplet in the graph database according to one implementation method. After data is written into the triplet, specific data is stored in each point and each edge, thus completing the data storage.
[0065] This implementation uses points 61, 62, 63, edge 612, and edge 613 as examples for illustration. The data for other points and edges are similar and will not be described again.
[0066] Point 61 stores the data for Zhang San, point 62 stores the data for Li Si, and point 63 stores the data for theft case 63. Edge 612 stores the edge data representing the closeness relationship between Zhang San and Li Si, with a sorting attribute closeness of 0.7. Edge 613 stores the edge data representing the confidence association between Zhang San and the theft case, with a sorting attribute confidence of 0.3.
[0067] In one specific implementation, when sorting the edges corresponding to each point based on the sorting attributes of the edge data, the point labels, edge labels, sorting attributes of the edges, and the identification codes of the edges associated with the edges in the source data are first determined as the edge data of the edges; all edges associated with the points are obtained, and the edges corresponding to each point are sorted in order based on the sorting attributes of each edge; wherein, the point labels associated with the edge include the point labels of the two points associated with the edge.
[0068] Specifically, the edges are arranged based on the point labels to obtain the edges corresponding to each point label; the edges corresponding to each point label are arranged according to the edge labels to obtain the edges corresponding to each edge label; the edges corresponding to each edge label are sorted according to the edge sorting attribute to complete the sorting of the edge data.
[0069] In this embodiment, since the edges are defined as undirected edges and there is no distinction in direction, when sorting a certain edge at each point, only a single index sorting is performed based on the sorting attribute in the edge data, thus obtaining the full result sorted storage of the edges corresponding to each point. Therefore, when querying the graph database based on a point for a target edge, the full result sorted of the target edges corresponding to each point can be directly obtained, greatly improving query efficiency. Similarly, when querying a point, the full result sorted based on the edge label of all edges corresponding to that point can be directly obtained, which also greatly improves query efficiency.
[0070] Please see Figure 7 , Figure 7 yes Figure 6 A schematic diagram of the storage structure of each edge in the diagram. In this embodiment, undirected edges are edges without direction.
[0071] This implementation first arranges the point labels associated with each edge to obtain a sequence of point labels, i.e., Li Si - Zhang San; then, within the edges corresponding to each point label, arranges the edges according to the edge labels to obtain the edges corresponding to each edge label. When a point label corresponds to only one edge label, this step can be skipped. When a point label corresponds to at least two edge labels, the edge labels can be arranged first, followed by the next edge label. For example, in the Zhang San point label, the edge labels with confidence associations are arranged first, and then the edge labels with close relationships are arranged. The order of the edge labels can be alphabetically ordered by the first letter, alphabetically ordered by the first letter of the pinyin, etc., and is not limited here.
[0072] After the edge labels are sorted, each edge is further sorted according to its sorting attribute within the edges corresponding to each label, thus completing the sorting of the edge data. Specifically, the edges are sorted based on the values of their sorting attributes, thereby completing the sorted storage of the edges.
[0073] In other implementations, when the undirected edges are edges with a uniform direction, in Figure 7 A new column for edge direction can be added between the edge label column and the sorting attribute column. When all directions in the edge direction column are the same, they are all 1 or 0. Therefore, during the sorting process described above, the edge direction will not affect the sorting result. This implementation method can achieve single-index sorting of all results.
[0074] Through the above steps, the graph database construction method of this embodiment determines the points and attributes involved in the graph database; identifies the relationships between points as edges, and determines the sorting attributes of the edges based on the attributes; determines the metadata of the graph database based on the points, edges, and attributes; and then writes source data including point data of multiple points and edge data of corresponding multiple edges based on the metadata to generate the graph database. When writing edge data, the edges corresponding to each point are sorted in an orderly manner based on the sorting attributes of the edge data, and then the full results of the edges corresponding to each point are sorted and stored in a single index. Therefore, when performing edge queries on the graph database, the full results of the edges corresponding to each point can be directly obtained, thereby greatly improving the query efficiency.
[0075] In other embodiments, after generating the graph database, the method further includes: preparing an index of target points and corresponding target edges; querying the graph database to find target points based on the index of target points; querying the graph database to find multiple target edges associated with the target points based on the index of target edges; and determining all target edges in the graph database that correspond to and are arranged in an ordered manner as the query result. The index may include labels and / or identifiers.
[0076] In a specific application scenario, with Figure 6-7 The implementation method shown is used as an example for explanation.
[0077] When querying a graph database for data on people closely related to Zhang San, where the target vertex is Zhang San and the target edges represent those with close relationships, the process first retrieves Zhang San from the graph database using the index of the target vertex. Then, it retrieves multiple edges with close relationships to Zhang San from the graph database using the index of the edges with close relationships. The query result is then defined as all the edges in the graph database that correspond to Zhang San and are arranged in an ordered manner. Figure 7 The data in the last four rows of the middle section is determined as the query result.
[0078] At this point, the query results can sort the entire result set of multiple edges that have a close relationship with Zhang San, without the problems of missing edge information or duplicate edges.
[0079] Furthermore, since the data on each edge is already arranged in an ordered manner in the graph database, there is no need to sort it again during the query process; only the required data needs to be retrieved, which greatly improves the query efficiency of the graph database.
[0080] The graph database in this embodiment can be applied to the Janusgraph graph database. Traditional Janusgraph graph databases, when sorting edges, involve concatenating the sorted result sets from both the outgoing and incoming edges; it's not a pure, complete sort. Furthermore, if a fully ordered result set is selected, data from the other side may be missing.
[0081] The graph database construction method in this embodiment, through the setting of undirected edges, can achieve full result set sorting of all edges corresponding to vertex labels, without the problems of edge information loss or duplicate edges. This greatly improves the reliability and comprehensiveness of the Janusgraph graph database.
[0082] Please see Figure 8 , Figure 8 This is a schematic diagram of a framework of an embodiment of the graph database construction apparatus of the present invention. The graph database construction apparatus 80 includes a creation module 81 and a generation module 82. The creation module 81 is used to create metadata for the graph database, and define the points, edges, and attributes of the graph database in the metadata, and set the sorting attribute of the edges based on the attributes; wherein, the edges are undirected edges; the generation module 82 is used to write source data including point data of multiple points and edge data of corresponding multiple edges based on the metadata, and generate the graph database; wherein, when writing edge data, the edges corresponding to each point are sorted in an ordered manner based on the sorting attribute in the edge data.
[0083] The generation module 82 is also used to determine the edge data of the edge as the point label, edge label, edge sorting attribute and edge identification code associated with the edge in the source data; wherein, the point label associated with the edge includes the point labels of the two points associated with the edge; obtain all the edges associated with each point, and sort the edges corresponding to each point in order based on the sorting attribute of each edge.
[0084] The generation module 82 is also used to arrange the edges based on each point label to obtain the edges corresponding to each point label; arrange the edges corresponding to each point label according to the edge label to obtain the edges corresponding to each edge label; and sort the edges corresponding to each edge label according to the edge sorting attribute to complete the sorting of the edge data of each edge.
[0085] The generation module 82 is also used to obtain the edge data of each edge and the point data of the two points corresponding to each edge from the source data; to create two columnar storage units based on the point data of the two points corresponding to each edge, so as to store the corresponding point data through the columnar storage units; and to store the edge data of the edge into the edge cell of the columnar storage unit of the corresponding two points respectively.
[0086] The generation module 82 is also used to store the label of each point and at least one attribute into the label cell and at least one attribute cell of the columnar storage unit, respectively.
[0087] The generation module 82 is also used to store the labels, sorting attributes, point labels, and edge identification codes of the edge data into the label cells, sorting attribute cells, point label cells, and edge identification code cells of the edge cells in two columnar storage units, respectively.
[0088] The creation module 81 is also used to determine the points and attributes involved in the graph database; to determine the relationships between points as edges, and to set the sorting attributes of the edges based on the attributes; and to generate the metadata of the graph database based on the points, edges, and attributes.
[0089] The generation module 82 is also used to prepare indexes of target points and corresponding target edges. The target points are retrieved from the graph database based on the indexes of the target points; multiple target edges associated with the target points are retrieved from the graph database based on the indexes of the target edges; and all target edges corresponding to the target points and arranged in an orderly manner in the graph database are determined as the query results.
[0090] Among them, the graph database includes: janusgraph graph database.
[0091] The above solution can improve the query efficiency of graph databases.
[0092] Based on the same inventive concept, the present invention also proposes an electronic device capable of executing the graph database construction method of any of the above embodiments. Please refer to [link to relevant documentation]. Figure 9 , Figure 9 This is a schematic diagram of an embodiment of the electronic device provided by the present invention. The electronic device includes a processor 91 and a memory 92.
[0093] The processor 91 executes the program instructions stored in the memory 92 to implement the steps of any of the above-described graph database construction methods. In a specific implementation scenario, the electronic device may include, but is not limited to, a microcomputer or a server. Furthermore, the electronic device may also include mobile devices such as laptops and tablets, without limitation.
[0094] Specifically, processor 91 controls itself and memory 92 to implement the steps of any of the above embodiments. Processor 91 may also be referred to as a CPU (Central Processing Unit). Processor 91 may be an integrated circuit chip with signal processing capabilities. Processor 91 may also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor may be a microprocessor or any conventional processor. Furthermore, processor 91 may be implemented using integrated circuit chips.
[0095] The above scheme can improve the versatility of graph database construction and expand the application scope of graph database construction.
[0096] Based on the same inventive concept, the present invention also proposes a computer-readable storage medium, please refer to [link to relevant documentation]. Figure 10 , Figure 10 This is a schematic diagram of an embodiment of a computer-readable storage medium provided by the present invention. The computer-readable storage medium 100 stores at least one program data 101, which is used to implement any of the methods described above. In one embodiment, the computer-readable storage medium 100 includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0097] In the several embodiments provided by this invention, it should be understood that the disclosed methods and apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0098] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.
[0099] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0100] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium.
[0101] The above are merely embodiments of the present invention and do not limit the patent scope of the present invention. Any equivalent structural or procedural transformations made based on the content of the present invention's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for constructing a graph database, characterized in that, include: Create metadata for a graph database, defining the vertices, edges, and attributes of the graph database in the metadata, and setting the sorting attribute of the edges based on the attributes; wherein, a certain attribute of the edge is selected from the attributes as the sorting attribute of the edge; the edge is an undirected edge; Based on the metadata, source data including point data of multiple points and edge data of multiple edges is written to generate the graph database; Specifically, when writing the edge data, the edges corresponding to each point are ordered based on the sorting attributes in the edge data; wherein, the point labels, edge labels, edge sorting attributes, and edge identifiers associated with the edges in the source data are determined as the edge data of the edges; the edges are arranged based on each point label to obtain the edges corresponding to each point label; the edges corresponding to each point label are arranged according to the edge labels to obtain the edges corresponding to each edge label; the edges corresponding to each edge label are sorted according to the edge sorting attributes to complete the sorting of the edge data of each edge.
2. The method for constructing a graph database according to claim 1, characterized in that, The point labels associated with the edge include the point labels of the two points associated with the edge.
3. The method for constructing a graph database according to claim 1, characterized in that, The process of writing source data, including point data of multiple points and edge data of multiple edges, based on the metadata to generate the graph database includes: Obtain the edge data of each edge and the point data of the two points corresponding to each edge from the source data; Two columnar storage units are created based on the point data of the two points corresponding to each edge, so as to store the corresponding point data through the columnar storage units; The edge data of the edges are stored in the edge cells of the corresponding two point-like columnar storage units.
4. The method for constructing a graph database according to claim 3, characterized in that, The point data includes the point label corresponding to the point and at least one attribute; The columnar storage unit includes a label cell, at least one side cell, and at least one attribute cell; The method of creating two columnar storage units based on the point data of the two points corresponding to each edge, so as to store the corresponding point data through the columnar storage units, further includes: The point labels and at least one attribute of each point are stored respectively in the label cell and at least one attribute cell of the columnar storage unit.
5. The method for constructing a graph database according to claim 3 or 4, characterized in that, The edge cell includes an edge label cell, a sorting attribute cell, a point label cell, and an edge identification code cell; The step of storing the edge data of the edges into the edge cells of the corresponding two point-like columnar storage units includes: The labels, sorting attributes, point labels, and edge identifiers of the edge data are stored respectively in the label cell, sorting attribute cell, point label cell, and edge identifier cell of the edge cell in two columnar storage units.
6. The method for constructing a graph database according to claim 1, characterized in that, The metadata for creating the graph database defines the vertices, edges, and attributes of the graph database, and sets the sorting attributes of the edges based on the attributes, including: Determine the points and attributes involved in the graph database; The relationships between the points are defined as edges, and the sorting attributes of the edges are set based on the attributes. The metadata of the graph database is generated based on the points, edges, and attributes.
7. The method for constructing a graph database according to claim 1, characterized in that, After generating the graph database by writing source data including point data of multiple points and edge data of multiple edges based on the metadata, the process further includes: Prepare the indexes of the target point and the corresponding target edge, and query the target point from the graph database based on the index of the target point; Based on the index of the target edge, multiple target edges associated with the target point are queried from the graph database, and all target edges corresponding to the target point and arranged in an orderly manner in the graph database are determined as the query results.
8. An electronic device, characterized in that, The electronic device includes a memory and a processor coupled to each other, the processor being configured to execute program instructions stored in the memory to implement the method for constructing a graph database as described in any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores program data that can be executed to implement the method for constructing a graph database as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Knowledge management method and system based on graph database
CN113779313A
Data read-write method, device and equipment of graph database and storage medium
CN114817275A