A knowledge graph operation method and device, electronic equipment and storage medium
By determining the density of knowledge graph nodes and utilizing server clusters and technologies such as Kafka and Spark, the problem of high pressure on dense nodes in knowledge graph operations is solved, achieving more efficient node operations.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SHANGHAI SHIZHUANG INFORMATION TECHNOLOGY CO LTD
- Filing Date
- 2022-11-11
- Publication Date
- 2026-05-29
AI Technical Summary
When manipulating knowledge graphs, especially when querying the vertex relationships of a four-hop graph, the workload is significant, and existing technologies cannot effectively alleviate the operational burden on dense nodes.
By determining whether the node corresponding to the node identifier is a dense node, and by utilizing the dense nodes in the knowledge graph through server cluster operations, including using node attribute values and the number of cluster vertices to determine dense nodes, and by using Kafka message queues and Spark task programs to share the load, four-hop queries are transformed into two-hop relation queries.
It effectively reduces the pressure on knowledge graph operations, improves the processing efficiency of dense nodes, and reduces system load.
Smart Images

Figure CN115658922B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of computer data processing and knowledge graphs, and more specifically, to a knowledge graph operation method, apparatus, electronic device, and storage medium. Background Technology
[0002] Currently, operations on knowledge graphs (also known as graph databases) are typically performed indiscriminately. For example, in knowledge graphs like Neo4j, querying one-hop or two-hop graph vertex relationships (i.e., the number of edges between two vertices) results in relatively fast responses when querying vertices where the number of edges between two vertices is within one or two hops. However, in practice, it has been found that a large number of client queries and operations on four-hop graph vertex relationships put significant pressure on knowledge graph operations. Summary of the Invention
[0003] The purpose of this application is to provide a knowledge graph operation method, apparatus, electronic device, and storage medium to alleviate the problem of high pressure when operating knowledge graphs.
[0004] This application provides a knowledge graph operation method, including: obtaining an operation request, the operation request including: a node identifier; determining whether the node corresponding to the node identifier is a dense node; if so, operating the dense node in the knowledge graph through a server cluster based on the node identifier. In the implementation of the above scheme, by operating the dense node in the knowledge graph through a server cluster based on the node identifier in the operation request when the node corresponding to the node identifier is a dense node, the server cluster alleviates the pressure of operating a large number of dense nodes in the knowledge graph, effectively reducing the pressure on operating the knowledge graph.
[0005] Optionally, in this embodiment, determining whether the node corresponding to the node identifier is a dense node includes: obtaining the node attribute value corresponding to the node identifier, obtaining multiple node attribute values; determining whether the multiple node attribute values include a preset attribute label; if so, the node corresponding to the node identifier is determined as a dense node; otherwise, the node corresponding to the node identifier is determined as a normal node. In the implementation of the above scheme, by determining the node corresponding to the node identifier as a dense node when the node attribute value includes a preset attribute label, the server cluster shares the burden of operating on a large number of dense nodes in the knowledge graph, effectively reducing the pressure of operating the knowledge graph.
[0006] Optionally, in this embodiment, before determining whether multiple node attribute values include preset attribute labels, the method further includes: querying cluster vertices whose number of edges traversed from the node corresponding to the node identifier is less than or equal to a preset edge threshold; determining whether the total number of cluster vertices is greater than a preset number threshold; and if so, setting the node attribute value corresponding to the node identifier to the preset attribute label. In the implementation of the above scheme, by setting the node attribute value corresponding to the node identifier to the preset attribute label when the total number of cluster vertices corresponding to the node identifier is greater than the preset number threshold, the server cluster operates on dense nodes in the knowledge graph according to the node identifier in the operation request. This effectively reduces the pressure on the knowledge graph by using the server cluster to share the burden of operating a large number of dense nodes.
[0007] Optionally, in this embodiment, setting the node attribute value corresponding to the node identifier to a preset attribute label includes: setting the node attribute value corresponding to the node identifier to the preset attribute label through a Spark task program. In the implementation of the above scheme, setting the node attribute value corresponding to the node identifier to a preset attribute label through a Spark task program allows the Spark task program and the server cluster to share the pressure when operating on a large number of dense nodes in the knowledge graph, effectively reducing the pressure on operating the knowledge graph.
[0008] Optionally, in this embodiment, determining whether the node corresponding to the node identifier is a dense node includes: querying cluster vertices whose number of edges traversed from the node corresponding to the node identifier is less than or equal to a preset edge threshold; determining whether the total number of cluster vertices is greater than a preset number threshold; if so, the node corresponding to the node identifier is determined as a dense node; otherwise, the node corresponding to the node identifier is determined as a normal node. In the implementation of the above scheme, by determining the node corresponding to the node identifier as a dense node when the total number of cluster vertices from the node identifier is greater than the preset number threshold, the server cluster operates on dense nodes in the knowledge graph according to the node identifier in the operation request. This reduces the pressure of operating a large number of dense nodes in the knowledge graph by using the server cluster, effectively alleviating the pressure of operating the knowledge graph.
[0009] Optionally, in this embodiment, operating dense nodes in the knowledge graph based on node identifiers via a server cluster includes: storing operation requests in a Kafka message queue; retrieving operation requests from the Kafka message queue via the server cluster, and operating dense nodes in the knowledge graph based on node identifiers in the operation requests. In the implementation of the above scheme, retrieving operation requests from the Kafka message queue via a server cluster and operating dense nodes in the knowledge graph based on node identifiers in the operation requests, effectively reduces the pressure on the knowledge graph by allowing the Kafka message queue and server cluster to share the burden of operating a large number of dense nodes.
[0010] Optionally, in this embodiment, the operation request further includes: a four-hop relationship; operating dense nodes in the knowledge graph based on node identifiers via a server cluster, including: querying the knowledge graph for intermediate nodes of a two-hop relationship starting from the node corresponding to the node identifier; and querying the knowledge graph for the target node of the two-hop relationship again starting from the intermediate node. In the implementation of the above scheme, by converting the query request for a four-hop relationship into a query for intermediate nodes and target nodes of a two-hop relationship, two simple query operations are effectively used to replace complex query operations. This reduces the pressure on the knowledge graph from operating on a large number of dense nodes, effectively alleviating the pressure of operating the knowledge graph.
[0011] This application also provides a knowledge graph operation device, including: an operation request acquisition module for acquiring an operation request, the operation request including: a node identifier; a dense node judgment module for judging whether the node corresponding to the node identifier is a dense node; and a knowledge graph operation module for operating the dense nodes in the knowledge graph according to the node identifier through a server cluster if the node corresponding to the node identifier is a dense node.
[0012] Optionally, in this embodiment, the dense node determination module includes: a node attribute acquisition submodule, used to acquire the node attribute value corresponding to the node identifier and acquire multiple node attribute values; a node attribute determination submodule, used to determine whether the multiple node attribute values include a preset attribute label; and a dense node determination submodule, used to determine the node corresponding to the node identifier as a dense node if the multiple node attribute values include the preset attribute label, otherwise, determine the node corresponding to the node identifier as a normal node.
[0013] Optionally, in this embodiment of the application, the knowledge graph operation device further includes: a cluster vertex query module, used to query cluster vertices whose number of edges traversed from the node corresponding to the node identifier is less than or equal to a preset edge threshold; a cluster vertex judgment module, used to judge whether the total number of cluster vertices is greater than a preset number threshold; and an attribute label setting module, used to set the node attribute value corresponding to the node identifier to a preset attribute label if the total number of cluster vertices is greater than the preset number threshold.
[0014] Optionally, in this embodiment, the attribute label setting module includes: a preset attribute setting submodule, used to set the node attribute value corresponding to the node identifier to a preset attribute label through the Spark task program.
[0015] Optionally, in this embodiment, the dense node determination module includes: a node identifier query submodule, used to query cluster vertices whose number of edges traversed from the node corresponding to the node identifier is less than or equal to a preset edge threshold; a vertex quantity determination submodule, used to determine whether the total number of cluster vertices is greater than a preset quantity threshold; and a normal node determination submodule, used to determine the node corresponding to the node identifier as a dense node if the total number of cluster vertices is greater than the preset quantity threshold, otherwise, determine the node corresponding to the node identifier as a normal node.
[0016] Optionally, in this embodiment of the application, the knowledge graph operation module includes: an operation request storage submodule, used to store operation requests in a Kafka message queue; and an operation request retrieval submodule, used to retrieve operation requests from the Kafka message queue through a server cluster, and operate on dense nodes in the knowledge graph according to the node identifier in the operation request.
[0017] Optionally, in this embodiment, the operation request further includes: a four-hop relationship; operating dense nodes in the knowledge graph based on node identifiers through a server cluster, including: a transit node query submodule, used to query the transit node of the two-hop relationship from the knowledge graph starting from the node corresponding to the node identifier through the server cluster; and a target node query submodule, used to query the target node of the two-hop relationship from the knowledge graph again starting from the transit node through the server cluster.
[0018] This application also provides an electronic device, including a processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and the machine-readable instructions, when executed by the processor, perform the method described above.
[0019] This application also provides a computer-readable storage medium storing a computer program that is executed by a processor to perform the methods described above.
[0020] Other features and advantages of embodiments of this application will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing embodiments of this application. Attached Figure Description
[0021] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 The diagram shown is a flowchart illustrating the knowledge graph operation method provided in an embodiment of this application.
[0023] Figure 2 The illustration shown is a partial data diagram of the knowledge graph provided in an embodiment of this application;
[0024] Figure 3 The diagram shown is a structural schematic of the knowledge graph manipulation device provided in an embodiment of this application.
[0025] Figure 4 The diagram shows a structural schematic of an electronic device provided in an embodiment of this application. Detailed Implementation
[0026] The technical solutions of the embodiments of this application 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 this application, and not all of them. The components of the embodiments of this application described and shown in the accompanying drawings can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this application provided in the accompanying drawings is not intended to limit the scope of the claimed embodiments of this application, but merely represents selected embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of the embodiments of this application.
[0027] It is understood that the terms "first" and "second" in the embodiments of this application are used to distinguish similar objects. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that the terms "first" and "second" are not necessarily different.
[0028] Before introducing the knowledge graph operation method provided in the embodiments of this application, let's first introduce some concepts involved in the embodiments of this application:
[0029] A server is a device that provides computing services over a network. Examples of servers include x86 servers and non-x86 servers. Non-x86 servers include mainframes, minicomputers, and UNIX servers.
[0030] It should be noted that the knowledge graph operation method provided in this application embodiment can be executed by an electronic device. Here, an electronic device refers to a device terminal with the function of executing computer programs or the aforementioned server. Device terminals include, for example, smartphones, personal computers, tablet computers, personal digital assistants, or mobile internet devices.
[0031] The following describes the applicable scenarios for this knowledge graph operation method. These scenarios include, but are not limited to: using this knowledge graph operation method to optimize the operation of knowledge graphs such as Neo4j and Nebula; if the target node of the operation is determined to be a dense node, the server cluster will operate on the dense nodes in the knowledge graph according to the node identifier in the operation request, thereby using the server cluster to share a large amount of the operation pressure of the knowledge graph.
[0032] Please see Figure 1 The illustration shows a flowchart of a knowledge graph manipulation method provided in an embodiment of this application; this application provides a knowledge graph manipulation method, including:
[0033] Step S110: Obtain the operation request, which includes: node identifier.
[0034] An operation request is a message request used to manipulate a knowledge graph. Operation requests include, but are not limited to, query requests, update requests, and delete requests.
[0035] The implementation methods of step S110 above include, but are not limited to: In the first implementation, if the knowledge graph is not installed on the user's terminal device, the user can operate the knowledge graph on the terminal device when needed. The terminal device sends an operation request to the electronic device (e.g., a server) via Transmission Control Protocol (TCP) or User Datagram Protocol (UDP). The electronic device receives the operation request from the terminal device and parses the node identifier from it. The communication method between the electronic device and the terminal device can be a browser / server (B / S) approach or a client / server (C / S) approach. In the second implementation, if the knowledge graph is installed on the user's terminal device, the user can directly operate the knowledge graph on the terminal device. In this case, the electronic device is the terminal device, responds to the user's input, obtains the corresponding operation request, and parses the node identifier from it.
[0036] Step S120: Determine whether the node corresponding to the node identifier is a dense node.
[0037] Dense nodes refer to nodes that affect the operation speed of a knowledge graph during operations such as querying, adding nodes, or adding edges. There are several ways to determine dense nodes, including but not limited to: The first method is based on node attribute values. For example, if a node's attribute value is a preset attribute label (e.g., it has already been labeled "dense node"), then the node is considered dense. The second method is based on the total number of cluster vertices connected to the node. For example, if the total number of cluster vertices connected to the node exceeds a preset threshold, then the node is considered dense. Both of these methods will be described in detail below.
[0038] Step S130: If the node corresponding to the node identifier is a dense node, then the dense node in the knowledge graph is operated through the server cluster according to the node identifier.
[0039] It is understood that since there are many ways to implement steps S120 to S130, the implementation methods of steps S120 to S130 will be described in detail below. The server cluster mentioned above, also known as a computer cluster, refers to a group of loosely or tightly connected computers that need to have an operating system and collaborative software installed before they can work together. These collaboratively working computers can also be referred to as cluster nodes.
[0040] In the implementation of the above scheme, when the node corresponding to the node identifier is a dense node, the server cluster operates on the dense node in the knowledge graph according to the node identifier in the operation request. In this way, the server cluster shares the pressure of operating a large number of dense nodes in the knowledge graph, effectively reducing the pressure of operating the knowledge graph.
[0041] Please see Figure 2 The diagram shown is a partial data illustration of the knowledge graph provided in an embodiment of this application; the knowledge graph displays a total of 6 users as nodes of the knowledge graph (i.e. Figure 2 The circles in the diagram represent nodes. These six users are: User A, User B, User C, User D, User E, and User F. The relationships between any two users are represented by an edge (i.e., ...). Figure 2 The nodes in the knowledge graph are represented by edges connecting them. For example, users A and B are both colleagues and classmates. The node attribute values in the knowledge graph are represented by rectangles. Therefore, if one of user B's node attribute values is a dense node, then user B's node is considered a dense node.
[0042] As a first optional implementation of step S120 above, when determining whether the node corresponding to the node identifier is a dense node, the determination can be made based on the node attribute value. This implementation may include:
[0043] Step S121: Obtain the node attribute value corresponding to the node identifier, and obtain multiple node attribute values.
[0044] For example, in implementing step S121 above, it can be understood that the node attribute value corresponding to the node identifier can be set to one or more values depending on the specific circumstances. Figure 2The node attribute value corresponding to user B is only shown once. In addition, node attribute values such as user name, contact information, and address can be set. Assuming we retrieve the node attribute value corresponding to user B, we can obtain multiple node attribute values such as dense nodes, user name, contact information, and address. Similarly, assuming we retrieve the node attribute value corresponding to user D, we can obtain multiple node attribute values such as user name, contact information, and address.
[0045] Step S122: Determine whether the attribute values of multiple nodes include preset attribute tags.
[0046] Preset attribute labels refer to the labels that users set in advance in the node attributes. These preset attribute labels can be set according to specific situations, such as dense nodes, or using special numbers or codes to represent dense nodes, etc.
[0047] For example, the implementation of step S122 above involves using an executable program compiled or interpreted in a preset programming language to determine whether multiple node attribute values include preset attribute tags; among which, the programming languages that can be used include: C, C++, Java, BASIC, JavaScript, LISP, Shell, Perl, Ruby, Python, and PHP, etc.
[0048] Step S123: If multiple node attribute values include preset attribute labels, then the node corresponding to the node identifier is determined as a dense node.
[0049] Step S124: If multiple node attribute values do not include preset attribute labels, then the node corresponding to the node identifier is determined as a normal node.
[0050] For example, the implementation of steps S123 to S124 above is as follows: Assuming the preset attribute label is a dense node, the node attribute value corresponding to user B can be obtained. This yields multiple node attribute values such as dense node, user name, contact information, and address. Therefore, it can be determined that the node attribute value corresponding to user B includes the preset attribute label (i.e., includes dense nodes), and thus the node corresponding to user B can be identified as a dense node. Similarly, by obtaining the node attribute value corresponding to user D, multiple node attribute values such as user name, contact information, and address can be obtained. This shows that the node attribute value corresponding to user D does not include the preset attribute label (i.e., does not include dense nodes), and thus the node corresponding to user D can be identified as a normal node.
[0051] As an optional implementation of step S122 above, before determining whether multiple node attribute values include preset attribute tags, the node attribute values can also be set to preset attribute tags (i.e., tagged). This implementation may include:
[0052] Step S122a: Query the cluster vertices whose number of edges traversed from the node corresponding to the node identifier is less than or equal to a preset edge threshold.
[0053] A specific example of implementing step S122c above is as follows: Assuming the preset edge threshold is set to 2, and the node identifier is user C, then the query is to find the cluster vertices whose number of edges traversed from user C node is less than or equal to 2. That is, to find all nodes that can be reached from user C node through 1 or 2 hops as cluster vertices. The cluster vertices queried here (see...) Figure 2 It can include four nodes: User A, User B, User D, and User E.
[0054] Step S122b: Determine whether the total number of cluster vertices is greater than a preset threshold.
[0055] The specific implementation of step S122b above is as follows: an executable program compiled or interpreted using a preset programming language is used to determine whether the total number of cluster vertices is greater than a preset threshold. The programming languages that can be used include C, C++, Java, BASIC, JavaScript, LISP, Shell, Perl, Ruby, Python, and PHP, etc.
[0056] Step S122c: If the total number of cluster vertices is greater than the preset number threshold, then set the node attribute value corresponding to the node identifier to the preset attribute label.
[0057] A specific example of the implementation of step S122c above is as follows: Assume the preset quantity threshold is 3, and the query selects cluster vertices whose number of edges traversed from user C node is less than or equal to 2 (see...). Figure 2 The table can include four nodes: user A, user B, user D, and user E. It can be determined that the total number of cluster vertices with a number of edges less than or equal to 2 traversed from user C node is 4, which is greater than the preset threshold of 3. Therefore, the node attribute value corresponding to user C node can be set to the preset attribute label (for example, the node attribute value corresponding to user C node can be set to dense node).
[0058] Understandably, when setting the node attribute value corresponding to the node identifier to the preset attribute label, a Spark task program can be used. If the total number of cluster vertices exceeds a preset threshold, the preset attribute label is obtained through a Spark task program, and the node attribute value corresponding to the node identifier is set to the preset attribute label through the Spark task program.
[0059] As a second optional implementation of step S120 above, when determining whether the node corresponding to the node identifier is a dense node, the determination can also be made based on the total number of cluster vertices. This implementation may include:
[0060] Step S125: Query the cluster vertices whose number of edges traversed from the node corresponding to the node identifier is less than or equal to a preset edge threshold.
[0061] Step S126: Determine whether the total number of cluster vertices is greater than a preset threshold.
[0062] The implementation principles and methods of steps S125 to S126 are similar to those of steps S122a to S122b. Therefore, their implementation principles and methods will not be described here. If there is anything unclear, please refer to the description of steps S122a to S122b.
[0063] Step S127: If the total number of cluster vertices is greater than the preset number threshold, then the node corresponding to the node identifier is determined as a dense node.
[0064] Step S128: If the total number of cluster vertices is less than or equal to a preset threshold, then the node corresponding to the node identifier is determined as a normal node.
[0065] For example, the implementation of steps S127 to S128 above is as follows: Assume the preset quantity threshold is 3, and the query user C node has traversed a cluster of vertices with a number of edges less than or equal to 2 (see...). Figure 2 The query could include four nodes: User A, User B, User D, and User E. Since the total number of clustered vertices (4) whose edges traversed from User C are less than or equal to 2 is greater than the preset threshold of 3, User C can be classified as a dense node. Similarly, assuming the preset threshold is 3, and the query returns clustered vertices whose edges traversed from User F are less than or equal to 2 (see...). Figure 2 The following can be included: User B and User E, a total of 2 nodes. It can be known that the total number of cluster vertices with the number of edges traversed by User F node is less than or equal to 2, which is less than the preset number threshold 3. Therefore, User F node can be determined as a normal node.
[0066] As a first optional implementation of step S130 above, when operating on dense nodes in the knowledge graph based on node identifiers through a server cluster, a Kafka message queue can be used to relay operation requests. This implementation may include:
[0067] Step S131: Store the operation request in the Kafka message queue.
[0068] For example, the implementation of step S131 above is as follows: the electronic device stores the operation request in the Kafka message queue. Kafka is an open-source stream processing platform, also known as Apache Kafka, and is also a distributed event stream platform. It is written in Scala and Java. Kafka's goal is to provide a unified, high-throughput, low-latency platform for processing real-time data. The Kafka persistence layer is essentially a large-scale publish or subscribe message queue based on a distributed transaction log architecture.
[0069] Step S132: Obtain operation requests from the Kafka message queue through the server cluster, and operate on dense nodes in the knowledge graph according to the node identifier in the operation request.
[0070] For example, in the above step S132, the electronic device obtains an operation request from the Kafka message queue through the server cluster of the Java application service, and operates on the dense nodes in the knowledge graph according to the node identifier in the operation request.
[0071] As a second optional implementation of step S130 above, the operation request may further include: a four-hop relationship, and the operation request may be a query request for the four-hop relationship; when operating on dense nodes in the knowledge graph based on node identifiers through a server cluster, the query operation of the four-hop relationship can be converted into a query operation of two hops plus two hop relationships. This implementation may include:
[0072] Step S133: Using the node identifier corresponding to the node as the starting point, query the knowledge graph to find the intermediate node of the two-hop relationship through the server cluster.
[0073] Step S134: Starting from the intermediate node, query the target node of the two-hop relationship from the knowledge graph again through the server cluster.
[0074] For example, in implementing steps S133 to S134 above, the electronic device sends an operation request to the Java application service server cluster via Transmission Control Protocol (TCP) or User Datagram Protocol (UDP). After receiving the operation request from the electronic device via TCP or UDP, the server cluster, starting from the node corresponding to the node identifier, queries the knowledge graph to find the intermediate node of the two-hop relationship, and then, starting from the intermediate node, queries the knowledge graph again to find the target node of the two-hop relationship.
[0075] It is understandable that when the server cluster performs a query based on a query request with this four-hop relationship, it can parse the query template of the four-hop relationship from the query request as a graph indicator and use this graph indicator for the query. Specifically, for example, an electronic device parses the query template of the four-hop relationship from the query request as a graph indicator and stores this graph indicator in cache databases such as Memcached and Redis. Then, the Java application service server cluster retrieves the query request from the cache databases such as Memcached and Redis and queries for dense nodes in the knowledge graph based on the node identifiers in the query request.
[0076] In practice, graph metrics can be bound to user identifiers in query requests, and the query data for the graph metric can be responded to based on the importance of the user identifier. Because graph metrics uniformly define and encapsulate the syntax format of the query template for this four-hop relationship, they are easier to read and modify when the server cluster parses the graph metrics from the query request, thus increasing the maintainability of the graph metrics.
[0077] Please see Figure 3 The diagram shown is a structural schematic of a knowledge graph manipulation device provided in an embodiment of this application; this application provides a knowledge graph manipulation device 200, including:
[0078] The operation request acquisition module 210 is used to acquire operation requests, which include: node identifiers.
[0079] The dense node determination module 220 is used to determine whether the node corresponding to the node identifier is a dense node.
[0080] The knowledge graph operation module 230 is used to operate on the dense nodes in the knowledge graph according to the node identifier if the node corresponding to the node identifier is a dense node.
[0081] Optionally, in this embodiment of the application, the dense node determination module includes:
[0082] The node attribute retrieval submodule is used to obtain the node attribute values corresponding to the node identifier, and to obtain multiple node attribute values.
[0083] The node attribute judgment submodule is used to determine whether multiple node attribute values include preset attribute tags.
[0084] The dense node determination submodule is used to determine the node corresponding to the node identifier as a dense node if multiple node attribute values include preset attribute labels; otherwise, it determines the node corresponding to the node identifier as a normal node.
[0085] Optionally, in this embodiment of the application, the knowledge graph manipulation device further includes:
[0086] The cluster vertex query module is used to query cluster vertices whose number of edges traversed from the node corresponding to the node identifier is less than or equal to a preset edge threshold.
[0087] The cluster vertex determination module is used to determine whether the total number of cluster vertices is greater than a preset threshold.
[0088] The attribute label setting module is used to set the node attribute value corresponding to the node identifier to the preset attribute label if the total number of cluster vertices is greater than a preset threshold.
[0089] Optionally, in this embodiment, the attribute label setting module includes:
[0090] The Preset Attribute Setting submodule is used to set the node attribute value corresponding to the node identifier to the preset attribute label through the Spark task program.
[0091] Optionally, in this embodiment of the application, the dense node determination module includes:
[0092] The node identifier query submodule is used to query cluster vertices whose number of edges traversed from the node corresponding to the node identifier is less than or equal to a preset edge threshold.
[0093] The vertex count determination submodule is used to determine whether the total number of vertices in a cluster is greater than a preset threshold.
[0094] The ordinary node determination submodule is used to determine the node corresponding to the node identifier as a dense node if the total number of cluster vertices is greater than a preset threshold; otherwise, it determines the node corresponding to the node identifier as an ordinary node.
[0095] Optionally, in this embodiment of the application, the knowledge graph operation module includes:
[0096] The operation request storage submodule is used to store operation requests to the Kafka message queue.
[0097] The operation request retrieval submodule is used to retrieve operation requests from the Kafka message queue through the server cluster and operate on dense nodes in the knowledge graph based on the node identifier in the operation request.
[0098] Optionally, in this embodiment, the operation request further includes: a four-hop relationship; and operating dense nodes in the knowledge graph based on node identifiers through a server cluster, including:
[0099] The transit node query submodule is used to query transit nodes with two-hop relationships from the knowledge graph by starting from the node corresponding to the node identifier in the server cluster.
[0100] The target node query submodule is used to query the target node with a two-hop relationship from the knowledge graph, starting from the intermediate node in the server cluster.
[0101] It should be understood that this device corresponds to the knowledge graph operation method embodiment described above and is capable of executing the various steps involved in the above method embodiment. The specific functions of this device can be found in the description above, and detailed descriptions are omitted here to avoid repetition. The device includes at least one software functional module that can be stored in memory or embedded in the device's operating system (OS) in the form of software or firmware.
[0102] Please see Figure 4 The diagram shows a structural schematic of an electronic device provided in an embodiment of this application. An electronic device 300 provided in this application includes a processor 310 and a memory 320. The memory 320 stores machine-readable instructions executable by the processor 310. When the machine-readable instructions are executed by the processor 310, the method described above is performed.
[0103] This application embodiment also provides a computer-readable storage medium 330, on which a computer program is stored. This computer program is executed by a processor 310 to perform the methods described above. The computer-readable storage medium 330 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Read-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0104] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For apparatus embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0105] It should be understood that the disclosed apparatus and methods can also be implemented in other ways, as provided in the embodiments of this application. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in the flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the accompanying drawings. For example, two consecutive blocks may actually be executed substantially in parallel, or they may sometimes be executed in reverse order, depending primarily on the functions involved.
[0106] Furthermore, the functional modules of each embodiment in this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part. In addition, in the description of this specification, the reference to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., means that the specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. Furthermore, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification and the features of different embodiments or examples.
[0107] The above description is only an optional implementation of the embodiments of this application, but the protection scope of the embodiments of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the embodiments of this application should be covered within the protection scope of the embodiments of this application.
Claims
1. A method for operating a knowledge graph, characterized in that, include: Obtain an operation request, the operation request including: node identifier; Determine whether the node corresponding to the node identifier is a dense node; If so, the operation request is stored in the Kafka message queue; The operation request is obtained from the Kafka message queue through the server cluster, and the dense nodes in the knowledge graph are operated according to the node identifier in the operation request; Wherein, if the operation request is a four-hop relationship query request for the node, the step of operating on the dense nodes in the knowledge graph according to the node identifier in the operation request includes: Starting from the node corresponding to the node identifier, the server cluster queries the knowledge graph to find the transit node for the two-hop relationship; Starting from the relay node, the server cluster queries the knowledge graph again to find the target node with the two-hop relationship, thus completing the four-hop relationship query request.
2. The method according to claim 1, characterized in that, The step of determining whether the node corresponding to the node identifier is a dense node includes: Obtain the node attribute value corresponding to the node identifier, and obtain multiple node attribute values; Determine whether the multiple node attribute values include preset attribute tags; If so, the node corresponding to the node identifier is determined as a dense node; otherwise, the node corresponding to the node identifier is determined as a normal node.
3. The method according to claim 2, characterized in that, Before determining whether the plurality of node attribute values include preset attribute tags, the method further includes: Query the cluster vertices that have a number of edges traversed from the node corresponding to the node identifier that is less than or equal to a preset edge threshold; Determine whether the total number of cluster vertices is greater than a preset threshold. If so, the node attribute value corresponding to the node identifier is set to the preset attribute label.
4. The method according to claim 3, characterized in that, Setting the node attribute value corresponding to the node identifier to the preset attribute label includes: The Spark task program sets the node attribute value corresponding to the node identifier to the preset attribute label.
5. The method according to claim 1, characterized in that, The step of determining whether the node corresponding to the node identifier is a dense node includes: Query the cluster vertices that have a number of edges traversed from the node corresponding to the node identifier that is less than or equal to a preset edge threshold; Determine whether the total number of cluster vertices is greater than a preset threshold. If so, the node corresponding to the node identifier is determined as a dense node; otherwise, the node corresponding to the node identifier is determined as a normal node.
6. A knowledge graph manipulation device, characterized in that, include: An operation request acquisition module is used to acquire operation requests, wherein the operation request includes: a node identifier; A dense node determination module is used to determine whether the node corresponding to the node identifier is a dense node; The knowledge graph operation module is used to store the operation request in a Kafka message queue if the node corresponding to the node identifier is a dense node; retrieve the operation request from the Kafka message queue through the server cluster, and operate on the dense nodes in the knowledge graph according to the node identifier in the operation request; wherein, if the operation request is a four-hop relationship query request for the node, the operation on the dense nodes in the knowledge graph according to the node identifier in the operation request includes: querying the knowledge graph for a two-hop relationship starting from the node corresponding to the node identifier through the server cluster; and querying the knowledge graph again for the target node of the two-hop relationship starting from the intermediate node through the server cluster, so as to complete the four-hop relationship query request.
7. An electronic device, characterized in that, include: A processor and a memory, the memory storing machine-readable instructions executable by the processor, which, when executed by the processor, perform the method as described in any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the method as described in any one of claims 1 to 5.