Knowledge graph layout method, electronic equipment and storage medium
By calculating and storing various layout results of the knowledge graph in advance, and using sub-threads to respond to layout instructions to render directly on the main thread, the problem of low efficiency of knowledge graph layout in the existing technology is solved and efficient layout processing is achieved.
Patent Information
- Application Number
- CN202411166372.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-09-20
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Current knowledge graph layout methods are time-consuming in real-time calculations when the data scale is large and can easily cause main thread blocking, affecting layout efficiency.
Perform layout calculations of multiple preset layout types on the canvas data of the knowledge graph in advance, store the layout results in the local database, use sub-threads to respond to layout instructions to directly extract the target layout results and render them on the main thread, avoiding real-time calculations and the main thread block.
It effectively improves the efficiency of knowledge graph layout, avoids delays caused by real-time calculation and main thread blocking, and improves the speed and stability of layout.
Smart Images

Figure CN118673162A
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data visualization and knowledge graphs, and in particular to a knowledge graph layout method, electronic device and storage medium. Background Art
[0002] With the explosive growth of computer applications, artificial intelligence technology has developed rapidly in the current Internet environment, among which knowledge graphs play an important role; knowledge graphs describe entities in the objective world in a structured way, extract data from massive structured, unstructured and semi-structured data to form structured data, and construct knowledge based on relationships and attributes; the visualization technology of knowledge graphs is a technology that displays and presents knowledge in the form of graphs. The essence of the layout of knowledge graphs is to adjust the positions of graph points and edges.
[0003] In practice, the researchers of this application found that the current knowledge graph layout method usually switches to different layouts by actively clicking, and then calculates the new layout in real time to update the layout. Each time a different layout is switched, the layout needs to be recalculated. When the data scale is large, real-time calculation is very time-consuming and easily causes the main thread to be blocked, affecting the layout efficiency of the knowledge graph. Summary of the invention
[0004] The main technical problem solved by this application is to provide a knowledge graph layout method, electronic device and storage medium, which can store the layout results obtained by layout calculation in advance, and can immediately extract the layout results to the main thread when performing layout to execute layout rendering, thereby effectively improving the layout efficiency.
[0005] In order to solve the above technical problems, a technical solution adopted in the present application is: to provide a knowledge graph layout method, comprising: in response to a layout instruction, using at least one child thread to obtain a target layout result from a local database, and sending the target layout result to a main thread, wherein a plurality of layout results are pre-stored in the local database, and the layout result is obtained by performing layout calculation on the canvas data of the knowledge graph using a plurality of preset layout types; controlling the main thread to perform layout rendering using the target layout result; and using the layout rendering result to display the knowledge graph on the canvas.
[0006] In some embodiments, in response to a layout instruction, using at least one child thread to obtain a target layout result from the local database and sending the target layout result to the main thread includes: monitoring the layout operation of the current page; in response to the layout operation, controlling the main thread to send a layout instruction to at least one child thread; in response to the layout instruction, using at least one child thread to obtain a target layout result corresponding to the layout instruction from a plurality of layout results pre-stored in the local database, and sending the target layout result to the main thread.
[0007] In some embodiments, after the main thread sends a layout instruction to at least one child thread, it also includes: at least one child thread searches for a corresponding target repository table from the local database according to a preset layout type; determines the corresponding current layout state of the target repository table; and executes the layout instruction when the current layout state is a completed state.
[0008] In some embodiments, it also includes: when the current layout state is an unfinished state, controlling the child thread to send a waiting instruction to the main thread to put the main thread in a waiting state; after a preset time, controlling the main thread to resend the layout instruction.
[0009] In some embodiments, controlling the main thread to perform layout rendering using the target layout result includes: controlling the main thread to perform canvas update and rendering on the current page using point edge position information in the target layout result.
[0010] In some embodiments, before responding to a layout instruction, it also includes: controlling the main thread to obtain canvas data in the knowledge graph, and sending the canvas data to at least one child thread; controlling at least one child thread to perform layout calculations on the canvas data using a plurality of preset layout types, and storing the layout results obtained by the layout calculations and the canvas data in the local database.
[0011] In some embodiments, when the main thread obtains the canvas data in the knowledge graph, it also includes: obtaining the change value of the canvas data, and determining the load data of the canvas data based on the change value of the canvas data; in response to the update instruction, controlling at least one child thread to write or update the load data of the canvas data into the local database, and marking the current layout state as a pending state; the at least one child thread performs layout calculations on the canvas data using multiple preset layout types, including: performing layout calculations based on the written or updated load data to obtain multiple layout results; storing the multiple layout results in the local database, and marking the current layout state as a completed state.
[0012] In some embodiments, it also includes: using the preset layout type to establish storage repository tables in the local database respectively; using the preset layout type and the current layout state to store multiple layout results in the corresponding storage repository tables respectively.
[0013] In order to solve the above-mentioned technical problems, another technical solution adopted in the present application is: to provide an electronic device, the electronic device comprising a memory and a processor coupled to the memory, the memory storing at least one computer program, and the at least one computer program, when loaded and executed by the processor, is used to implement the knowledge graph layout method as mentioned above.
[0014] In order to solve the above-mentioned technical problems, another technical solution adopted in the present application is: to provide a computer-readable storage medium, wherein the computer-readable storage medium has at least one program, and when the at least one program is loaded and executed by the processor, it is used to implement the knowledge graph layout method as mentioned above.
[0015] Different from the current technology, the knowledge graph layout method provided by the present application includes: responding to a layout instruction, controlling at least one child thread to obtain a target layout result from a local database, and sending the target layout result to the main thread, wherein a plurality of layout results are pre-stored in the local database, and the layout result is obtained by performing layout calculations on the canvas data of the knowledge graph using a plurality of preset layout types; controlling the main thread to perform layout rendering using the target layout result; and displaying using the layout rendering result; that is, in the present application, layout calculations of a plurality of preset layout types are performed on the canvas data of the knowledge graph in advance to obtain a plurality of layout results, and then the plurality of layout results are pre-stored in the local database, so that when the layout needs to be executed, the child thread can directly respond to the layout instruction and extract the corresponding target layout result, and then perform layout rendering and knowledge graph canvas display in the main thread, avoiding the delay caused by real-time calculation and main thread blocking, and effectively improving the layout efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. 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 creative work. Among them: Figure 1 It is a flowchart of an embodiment of a knowledge graph layout method in this application; Figure 2 It is a flow chart of the operating principle in this application; Figure 3 It is a structural diagram of an embodiment of a knowledge graph layout system in this application; Figure 4 It is a structural schematic diagram of an embodiment of an electronic device in the present application; Figure 5 It is a structural diagram of an embodiment of a computer-readable storage medium in the present application. DETAILED DESCRIPTION
[0017] The present invention will be further described in detail below in conjunction with the accompanying drawings and examples. It is particularly noted that the following examples are only used to illustrate the present invention, but are not intended to limit the scope of the present invention. Similarly, the following examples are only partial embodiments of the present invention rather than all embodiments, and all other embodiments obtained by those of ordinary skill in the art without creative work are within the scope of protection of the present invention.
[0018] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0019] The traditional knowledge graph layout method usually switches to different layouts by actively clicking, then calculates the new layout in real time, and then updates the layout. Each time a different layout is switched, the layout needs to be recalculated. When the data scale is large, real-time calculation is very time-consuming. The current layout is performed on the main thread, which can easily cause the main thread to be blocked, affecting the layout efficiency of the knowledge graph.
[0020] Therefore, a knowledge graph layout method is provided, which performs layout calculations of multiple preset layout types on the canvas data of the knowledge graph in advance, and stores the layout results in a local database in advance, so that when the layout needs to be executed, the child thread can directly respond to the layout instruction and extract the corresponding target layout result, and then perform layout rendering and display in the main thread, avoiding the delay caused by real-time calculation and main thread blocking, and effectively improving the layout efficiency.
[0021] See also Figure 1 , Figure 1 is a flow chart of an embodiment of the knowledge graph layout method in this application; it should be noted that if there are substantial results, the method of this application is not based on Figure 1 The process sequence shown is limited.
[0022] like Figure 1 As shown, the knowledge graph layout method includes the following steps.
[0023] S10. In response to a layout instruction, use at least one child thread to obtain a target layout result from a local database, and send the target layout result to the main thread, wherein a number of layout results are pre-stored in the local database, and the layout result is obtained by performing layout calculations on the canvas data of the knowledge graph using a variety of preset layout types.
[0024] Among them, the layout instruction is the instruction corresponding to when the current page needs to be laid out; the main thread is automatically created by the system and is used for program initialization and execution; the child thread is created by the main thread or actively created in the program. There can be multiple child threads for performing specific tasks; the local database is the local database of the browser corresponding to the current page; the layout result is the layout of the canvas data displayed by the knowledge graph on the current page; the knowledge graph is an important branch technology of artificial intelligence. It is a structured semantic knowledge base used to describe concepts and their relationships in the physical world in symbolic form. Its basic component unit is the "entity-relationship-entity" triple, as well as entities and their related attribute-value pairs. Entities are connected to each other through relationships to form a network knowledge structure; the knowledge graph layout is a structural adjustment of the point and edge data of the canvas, which is used to switch the perspective to show the readability and comprehensibility of the data at a deeper level and more clearly.
[0025] Specifically, layout calculations are performed on the canvas data of the knowledge graph in advance using a variety of preset layout types to obtain a number of layout results, which are then stored in a local database corresponding to the current page, and at least one child thread is created through the main thread or actively created in the program; when the current page needs to update its layout, in response to the layout instruction, at least one child thread directly obtains the target layout result from a number of layout results pre-stored in the local database, and then sends the obtained target layout result to the main thread.
[0026] S20. Control the main thread to perform layout rendering using the target layout result.
[0027] The target layout result includes the position information of all points and edges in the current layout mode, and the layout rendering is to update the layout of the current page on the canvas using the layout result.
[0028] Specifically, after the main thread obtains the target layout result corresponding to the layout instruction, the main thread can be controlled to use the position information of all points and edges in the current layout mode in the target layout result, that is, to use the canvas data in the current layout mode contained in the target layout result to update the canvas data of the current page to complete the layout rendering of the current page.
[0029] S30. Use the layout rendering result to display the knowledge graph on a canvas.
[0030] Among them, the layout rendering result obtained by layout rendering needs to be displayed on the canvas of the knowledge graph, that is, it needs to be displayed in the current page.
[0031] Specifically, after the main thread uses the target layout result for layout rendering, the layout rendering result is used to display the knowledge graph on the canvas, that is, after the canvas data of the current page is updated, the updated page is displayed.
[0032] In this embodiment, layout calculations of multiple preset layout types are performed on the canvas data of the knowledge graph in advance, and the layout results are pre-stored in a local database, so that when the layout needs to be executed, the child thread can directly respond to the layout instruction and extract the corresponding target layout result, and then perform layout rendering and display in the main thread, avoiding the delay caused by real-time calculation and main thread blocking, and effectively improving the layout efficiency.
[0033] In some embodiments, before responding to the layout instruction, the following steps may be further included.
[0034] First, the main thread is controlled to obtain the canvas data in the knowledge graph, and the canvas data is sent to at least one sub-thread.
[0035] Among them, the main thread is the main thread corresponding to the browser, and the canvas data in the knowledge graph is the canvas data corresponding to the current page, which is a collection of point position information and edge position information. For example: "data={nodes:[ ],edges:[ ]}", nodes and edges are data types respectively, and the corresponding content is a collection of node position information and edge position information.
[0036] Specifically, when entering the current page, the main thread starts to obtain the canvas data in the knowledge graph of the current page. For example, the main thread can obtain the canvas data in the knowledge graph by monitoring, and then send the obtained canvas data to at least one child thread.
[0037] Among them, the child thread is a web worker child thread, which can support multi-threaded operations and will not block the main thread, that is, it will not block the operation and rendering of the current page; one child thread can correspond to the layout calculation of one layout type, and multiple child threads can correspond to multiple layout types for corresponding layout calculations.
[0038] In some embodiments, a web worker sub-thread may be instantiated first to implement multi-threading of the layout calculation of the knowledge graph.
[0039] The principle of multi-threaded work is as follows: the main thread is responsible for interacting with the web workers child thread: including (1) monitoring the changes in the canvas data of the knowledge graph, and sending the canvas data to the child thread in time for layout calculation; (2) monitoring whether the page needs to perform layout operations; (3) sending layout instructions to the web workers child thread; (4) receiving a certain time or a certain type of layout result sent back by the web workres child thread. The web workers child thread is mainly responsible for interacting with the browser's local database: including (1) receiving the layout instructions and data load from the main thread; (2) performing asynchronous layout calculations; (3) storing the layout results in the local database; (4) reading the layout results from the local database according to different layout reading instructions, and then sending the layout results back to the main thread.
[0040] Then, initialize the local database of the browser, that is, initialize the local database of the browser front end, and then use the local database to store the canvas data of the knowledge graph, store the current layout state of the layout results, and interact with the child thread, where the local database can be IndexedDB.
[0041] In some embodiments, when the main thread obtains canvas data in the knowledge graph, the following operation steps may also be included.
[0042] Get the change value of the canvas data, and determine the load data of the canvas data based on the change value of the canvas data.
[0043] When the canvas data needs to be updated, there will be a change value of the canvas data. Therefore, the change value of the canvas data can be used to determine the load data corresponding to the canvas data; and the main thread will send an update instruction to the child thread. The update instruction can be an object, such as: "{head: "update", data: {nodes:[ ],edges:[ ]}}".
[0044] In response to the update instruction, at least one sub-thread is controlled to write or update the load data of the canvas data into the local database, and the current layout state is marked as a pending state.
[0045] Specifically, the child thread receives the update instruction "update" and data payload data:{nodes:[ ],edges:[ ]} sent by the main thread. The child thread will write or update the payload data corresponding to the canvas data in the local database, that is, write or update the payload data of the canvas data to the local database, and mark the current layout state as a pending state, for example, mark the current write / update annotation state as an unfinished state; wherein, the first time the update instruction "update" is received, data and state are written, and subsequent update instructions "update" are all executed data update operations.
[0046] Then, at least one sub-thread is controlled to perform layout calculation on the canvas data using a plurality of preset layout types, and the layout result obtained by the layout calculation and the canvas data are stored in a local database.
[0047] There may be multiple preset layout types, such as tree layout, spherical gravity layout, grid layout, concentric circle layout, force-directed layout, etc., and the corresponding layout may be set according to actual conditions.
[0048] Specifically, after the child thread receives the canvas data, at least one child thread is controlled to perform layout calculations on the canvas data using multiple preset layout types to obtain layout results corresponding to multiple preset layout types, and then the multiple layout results and canvas data obtained by the layout calculation are stored in a local database.
[0049] At least one sub-thread performs layout calculation on the canvas data using multiple preset layout types, and further includes: Layout calculation is performed according to the written or updated load data to obtain multiple layout results.
[0050] Specifically, because there can be multiple preset layout types, each sub-thread can perform layout calculations corresponding to a preset layout type, and multi-threaded operations can be performed. Therefore, based on the written or updated load data, multiple preset layout types can be used to perform corresponding layout calculations to obtain multiple layout results corresponding to different preset layout types.
[0051] Store multiple layout results in a local database and mark the current layout status as completed.
[0052] Specifically, after obtaining the multiple layout results, the multiple layout results need to be stored in the local database of the browser, and the current layout state corresponding to the layout results needs to be marked as a completed state in which the layout calculation is completed.
[0053] In some embodiments, when storing multiple layout results in a local database, the following operation steps may also be included.
[0054] Use the preset layout types to create repository tables in the local database.
[0055] There may be multiple preset layout types. To distinguish them, they may be divided in the local database according to the preset layout types, and corresponding storage repository tables may be established to meet the division requirements and provide a basis for subsequent convenient searches.
[0056] The plurality of layout results are stored in corresponding storage repository tables respectively by using the preset layout type and the current layout state.
[0057] The current layout state includes a completed state and an unfinished state. In order to improve the subsequent layout efficiency, the current layout state needs to be stored together with the layout result in the repository table of the local database.
[0058] Specifically, after establishing storage repository tables in the local database according to the preset layout types, the multiple layout results obtained are stored in the corresponding storage repository tables according to the preset layout types, and the current layout state corresponding to each layout result is also stored together, wherein the current layout state is updated in real time, that is, after the current layout state of the layout result changes, the stored current layout state also changes accordingly.
[0059] In some embodiments, step S10 responds to the layout instruction, uses at least one child thread to obtain the target layout result from the local database, and sends the target layout result to the main thread, and may also include the following steps.
[0060] First, listen to the layout operation of the current page.
[0061] Among them, it is necessary to obtain the execution action of the current page, and then determine the layout operation corresponding to the current page. Therefore, the layout operation of the current page can be obtained by monitoring.
[0062] Specifically, after constructing the post-subthread, the main thread of the browser listens for possible execution actions of the current page, such as layout operations.
[0063] In some embodiments, it is necessary to first instantiate a sub-thread in the browser, and the sub-thread may be a workers sub-thread, to implement multi-threaded operation.
[0064] Then, in response to the layout operation, the main thread is controlled to send a layout instruction to at least one child thread.
[0065] There may be multiple child threads, so the main thread may send a layout instruction to one or more child threads, and the layout instruction includes a corresponding layout type.
[0066] Specifically, after monitoring a layout operation, in response to the layout operation, the main thread is controlled to send layout instructions corresponding to the layout operation to at least one child thread, that is, the main thread sends the layout type to the child thread, so that the child thread performs subsequent operations according to the layout type.
[0067] In some embodiments, there may be multiple layout instructions. Therefore, the main thread may send different layout instructions to the child threads respectively. Different layout instructions correspond to different layout types. For example, the layout type may include tree layout, spherical gravity layout, grid layout, concentric circle layout, force-directed layout, etc. The layout type may also be set according to actual conditions.
[0068] Next, in response to the layout instruction, at least one sub-thread is used to obtain a target layout result corresponding to the layout instruction from a plurality of layout results pre-stored in the local database, and the target layout result is sent to the main thread.
[0069] Among them, the local database is the local database corresponding to the browser, which can be used to store relevant data obtained from the browser; the layout results are pre-calculated and stored in the local database, and different layout types correspond to different layout results. Therefore, when there are multiple layout types, there are multiple layout results.
[0070] Specifically, after the child thread obtains the layout instruction, at least one child thread searches and matches several layout results pre-stored in the local database according to the layout type corresponding to the layout instruction to obtain the target layout result corresponding to the layout type of the layout instruction, retrieves the target layout result from the local database, and sends it to the main thread.
[0071] In some embodiments, after the main thread sends the layout instruction to at least one child thread, the following steps may also be included: At least one sub-thread searches the local database for a corresponding target storage repository table according to a preset layout type.
[0072] Among them, the layout type can be preset, and the layout type can be preset according to actual conditions; the layout result corresponding to each layout type can create a corresponding storage repository table in the local database according to the layout type.
[0073] Specifically, after the child thread receives the layout instruction, at least one child thread searches the corresponding storage repository table in the local database according to the preset layout type in the layout instruction to find the target storage repository table corresponding to the preset layout type of the layout instruction, and determines the target layout result in the target storage repository table.
[0074] Then, the corresponding current layout state of the target storage repository table is determined.
[0075] The current layout state corresponding to the target storage repository table is the mark state corresponding to the layout result in the target storage repository table, and the current layout state includes a completed state or an uncompleted state.
[0076] Specifically, after determining the target storage library table, the current layout states of all layout results in the target storage library table are judged, and then the current layout state corresponding to each layout result in the target storage library table, ie, the corresponding current layout state of the target storage library table, is determined.
[0077] In some embodiments, when entering the current page, the main thread obtains the canvas data of the knowledge graph corresponding to the current page, and then sends it to the child thread, which uses the child thread to perform layout calculations of different layout types on the canvas data, and obtains different layout results and stores them in the local database; among them, the current layout state that has completed the layout calculation is marked as the completed state, and the current layout state that is still in the layout calculation process is marked as the unfinished state.
[0078] Next, when the current layout state is a completed state, the layout instruction is executed.
[0079] Specifically, when the corresponding current layout state of the target storage repository table is the completed state, that is, in the target storage repository table, the layout calculation of the layout result corresponding to the layout instruction is in the completed state, it means that the layout result corresponding to the layout instruction has been calculated, and its layout result can be used directly. Therefore, the layout instruction can be executed so that at least one child thread responds to the layout instruction, obtains the target layout result corresponding to the layout instruction from the local storage repository, and sends the target layout instruction to the main thread, so that the main thread performs layout rendering according to the target layout result.
[0080] In some embodiments, when the current layout state is incomplete, it is also necessary to control the child thread to send a wait instruction to the main thread, so that the main thread is in a waiting state.
[0081] Specifically, when the corresponding current layout state of the target storage repository table is an unfinished state, that is, in the target storage repository table, the layout calculation of the layout result corresponding to the layout instruction is in an unfinished state, it means that the layout result corresponding to the layout instruction is still in the calculation process, and its layout result cannot be used yet. Therefore, the child thread will send a waiting instruction to the main thread and hand over the operation control to the main thread, so that the main thread is in the waiting process. At this time, the main thread can continue to wait.
[0082] And after a preset time, the control main thread can resend the layout instruction.
[0083] Among them, the preset time can be set according to actual conditions and is a delay setting.
[0084] Specifically, after a delay of a preset time, the main thread uses the operation control right to send a layout instruction to the child thread again, and executes the layout instruction when the current layout state is a completed state.
[0085] For example, taking the grid layout and the child thread as the web workers child thread, the main thread sends a layout instruction, "{head: "getLayout", data: {type: "grid"}}", the web workers child thread will receive the instruction "getLayout" as a layout instruction, and the layout type is "grid". It will first look up the corresponding repository table according to the layout type "grid" to determine whether the current mark status of the corresponding layout result in the local database is completed. After that, it will periodically query whether it is completed.
[0086] When the current layout state is unfinished, the child thread will send a waiting instruction to the main thread, "{head:"loading", data: null}, and hand over the operation control to the main thread. At this time, the main thread can continue to wait and delay sending another layout instruction "{head: "getLayout", data: {type: "grid"}}".
[0087] When the current layout state is completed, the corresponding layout result will be retrieved from the local database, that is, the target layout result corresponding to the layout type in the layout instruction will be retrieved, and the target layout result will be assembled into a result instruction and sent to the main thread, "{head: "layoutResult", data: {nodes:[ ],edges:[ ]}}". The instruction header of the result instruction is "layoutResult". The main thread determines that it is the result instruction corresponding to the target layout result based on the instruction header. The payload data (data) part of the result instruction is the information corresponding to the layout result of the corresponding layout type "grid" grid layout.
[0088] In some embodiments, there are two situations in which the main thread receives the layout result of the child thread.
[0089] The first case is that the layout result is still in the process of calculation and is in an unfinished state. The main thread will receive a command from the child thread: "{head: "loading", data: null}, which means that in the current layout mode, the background is still in the process of layout calculation of the layout result. Since the layout calculation in complex scenes takes a certain amount of time, the length of this time is closely related to the amount of data in the current canvas data, so it is necessary to query the waiting action. Here, the preset time can be appropriately set to K, for example, K=1s. After the preset time, the main thread sends another layout instruction to the child thread "{head: "getLayout", data: {type: "grid"}}". This process will continue to loop until it exceeds a certain time and number of times.
[0090] The second case is that the layout result has been calculated and is in the completed state. The main thread will receive a result instruction "{head: "layoutResult", data: {nodes:[ ],edges:[ ]}}" sent by the child thread, indicating that the layout operation can be responded to. Since this instruction contains the target layout result corresponding to the layout instruction, and the target layout result mainly contains all the vertex and edge position information in the current layout mode, the main thread can make corresponding canvas updates and rendering operations on the layout of the current page on the canvas based on the vertex and edge position information in the target layout result.
[0091] In some embodiments, step S20 in which the main thread performs layout rendering using the target layout result may include the following operation steps.
[0092] The control main thread uses the point edge position information in the target layout result to update and render the canvas of the current page.
[0093] Among them, the target layout result contains all the point position information and edge position information in the current layout mode, that is, the point edge position information. Therefore, the main thread can directly use the point edge position information in the target layout result to perform corresponding canvas updates and rendering on the current page to obtain the layout rendering result corresponding to the current page.
[0094] This allows the current page to use the obtained layout rendering results to display the knowledge graph on the canvas.
[0095] The operating principle can be found in Figure 2 , Figure 2 It is a flow chart of the operating principle in this application.
[0096] like Figure 2As shown in the figure, the brief process of the operation principle is as follows: after the process starts, the child thread is instantiated, that is, the web worker child thread is instantiated, and the local database of the browser is initialized. Then, the canvas data of the knowledge graph of the current page is monitored through the main thread of the browser, and it is determined whether to update; when an update is required, the main thread sends an update instruction and canvas data to the child thread, and the child thread is a web worker child thread, so the web The worker sub-thread receives the update instruction and the corresponding canvas data, marks the current layout state as an unfinished state, and uses multiple preset layout types to perform multiple layout calculations to obtain multiple layout results, and then stores the multiple layout results in the local database of the browser, and marks the current layout state as a completed state, and returns to the main thread to listen to the canvas data step of the knowledge graph; when no update is required, it determines whether the current page requires layout operation. If no layout operation is required, it returns to the main thread to listen to the canvas data step of the knowledge graph; if a layout operation is required, the main thread sends a layout instruction to the sub-thread. After receiving the layout instruction, the sub-thread determines whether the current layout state is a completed state. If the current layout state is an unfinished state, the layout instruction is sent again after a preset time; if it is a completed state, the sub-thread reads the corresponding target layout result in the local database of the browser, and sends the target layout result to the main thread, so that the main thread performs layout rendering according to the target layout result, and then displays the knowledge graph canvas according to the layout rendering result.
[0097] In this embodiment, the layout calculation results can be stored in advance, and the layout calculation results can be immediately extracted to the main thread when performing layout, which effectively improves the layout efficiency.
[0098] In some embodiments, a knowledge graph layout system is also provided.
[0099] See also Figure 3 , Figure 3 It is a structural diagram of an embodiment of the knowledge graph layout system in this application.
[0100] like Figure 3 As shown, the knowledge graph layout system 400 includes an execution module 410, a rendering module 420 and a display module 430; wherein, the execution module 410 responds to the layout instruction, uses at least one sub-thread to obtain the target layout result from the local database, and sends the target layout result to the main thread, wherein a number of layout results are pre-stored in the local database, and the layout result is obtained by performing layout calculation on the canvas data of the knowledge graph using a variety of preset layout types; the rendering module 420 controls the main thread to perform layout rendering using the target layout result; the display module 430 uses the layout rendering result to display the knowledge graph on the canvas.
[0101] In some embodiments, an electronic device is also provided.
[0102] See also Figure 4 , Figure 4 1 is a schematic diagram of the structure of an electronic device in the present application. The electronic device can execute the knowledge graph layout step in the above method.
[0103] The electronic device 500 includes a memory 520, a processor 510 coupled to the memory, and at least one computer program stored in the memory 520 and executable on the processor 510; when the processor 510 loads and executes the at least one computer program, it is used to implement the steps of knowledge graph layout in the above method. For related content, please refer to the detailed description in the above method, which will not be repeated here.
[0104] In some embodiments, a computer-readable storage medium is also included.
[0105] See also Figure 5 , Figure 5 It is a structural diagram of an embodiment of a computer-readable storage medium in the present application.
[0106] The computer-readable storage medium 600 stores at least one program 610, which, when loaded and executed by the processor, is used to implement the steps of knowledge graph layout in the above method. For related content, please refer to the detailed description of the above method, which will not be repeated here.
[0107] The above scheme performs layout calculations of multiple preset layout types on the canvas data of the knowledge graph in advance to obtain several layout results, and then stores the several layout results in the local database in advance, so that when the layout needs to be executed, the child thread can directly respond to the layout instruction and extract the corresponding target layout result, and then perform layout rendering and display in the main thread, avoiding the delay caused by real-time calculation and main thread blocking, and effectively improving the layout efficiency.
[0108] In the several embodiments provided by the present invention, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0109] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0110] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0111] If the integrated unit is implemented in the form of 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. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0112] The above description is only an implementation mode of the present invention, and does not limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made by using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A knowledge graph layout method, characterized in that: include: In response to the layout instruction, at least one child thread is used to obtain a target layout result from a local database, and the target layout result is sent to the main thread, wherein the local database has a plurality of layout results pre-stored therein, and the layout result is obtained by performing layout calculation on the canvas data of the knowledge graph using a plurality of preset layout types; Controlling the main thread to perform layout rendering using the target layout result; Use the layout rendering results to display the knowledge graph on the canvas.
2. The knowledge graph layout method according to claim 1, characterized in that: The method of obtaining a target layout result from the local database by using at least one sub-thread in response to the layout instruction and sending the target layout result to the main thread includes: Monitor the layout operation of the current page; In response to the layout operation, controlling the main thread to send a layout instruction to at least one child thread; In response to the layout instruction, at least one sub-thread is used to obtain a target layout result corresponding to the layout instruction from a plurality of layout results pre-stored in the local database, and the target layout result is sent to the main thread.
3. The knowledge graph layout method according to claim 2, characterized in that: After the main thread sends a layout instruction to at least one child thread, the method further includes: At least one sub-thread searches the local database for a corresponding target storage repository table according to a preset layout type; Determining a corresponding current layout state of the target storage repository table; When the current layout state is a completed state, the layout instruction is executed.
4. The knowledge graph layout method according to claim 3, characterized in that: Also includes: When the current layout state is an unfinished state, controlling the child thread to send a waiting instruction to the main thread, so that the main thread is in a waiting state; After a preset time, the main thread is controlled to resend the layout instruction.
5. The knowledge graph layout method according to claim 1, characterized in that: The controlling the main thread to perform layout rendering using the target layout result includes: The main thread is controlled to update and render the canvas of the current page using the point edge position information in the target layout result.
6. The knowledge graph layout method according to claim 1, characterized in that: Before responding to layout instructions, also include: Control the main thread to obtain canvas data in the knowledge graph, and send the canvas data to at least one sub-thread; At least one sub-thread is controlled to perform layout calculation on the canvas data using a plurality of preset layout types, and a layout result obtained by the layout calculation and the canvas data are stored in the local database.
7. The knowledge graph layout method according to claim 6, characterized in that: When the main thread obtains the canvas data in the knowledge graph, it also includes: Acquire a change value of the canvas data, and determine load data of the canvas data according to the change value of the canvas data; In response to the update instruction, control at least one sub-thread to write or update the load data of the canvas data into the local database, and mark the current layout state as a pending state; The at least one sub-thread performs layout calculation on the canvas data using a plurality of preset layout types, including: Performing layout calculation according to the written or updated load data to obtain multiple layout results; The plurality of layout results are stored in the local database, and the current layout state is marked as a completed state.
8. The knowledge graph layout method according to claim 7, characterized in that: Also includes: Using the preset layout type, respectively establish storage repository tables in the local database; The preset layout type and the current layout state are used to store a plurality of layout results in the corresponding storage repository tables respectively.
9. An electronic device, characterized in that: The electronic device includes a memory and a processor coupled to the memory, the memory stores at least one computer program, and when the at least one computer program is loaded and executed by the processor, it is used to implement the knowledge graph layout method as described in any one of claims 1-8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium has at least one program, which, when loaded and executed by the processor, is used to implement the knowledge graph layout method as described in any one of claims 1-8.
Citation Information
Patent Citations
Visible data loading method and device, computer equipment and storage medium
CN114816586A
Knowledge graph multi-thread layout method and device
CN115858171A
Interactive circle layer layout method for knowledge graph
CN117808087A
Method of performing layout of contents and apparatus for the same
US20070113175A1
