当前位置:网站首页>Figure data * reconstruction subgraph

Figure data * reconstruction subgraph

2022-06-13 03:19:00 Tnoy. Ma


Here’s the table of contents:

Figure data * Reconstruct subgraph

     Subgraph reconstruction It usually occurs in the data operation and maintenance stage . When the data is wrong or the data model is adjusted, you need to Modifying data when , The graph data nodes or relationships need to be reconstructed in batch . The method of data reconstruction avoids the reorganization and import of data , Save resources and carry out rapid batch operation at the same time .
     Here is an introduction to Node mode Subgraph reconstruction method under , This method is to merge nodes and migrate their association relationship at the same time . You need to specify the merged target node , And the merged target nodes , And specify the merge operation mode of its attributes in an optional mode .

One 、 Find the concepts that need to be merged

     First , Find two target nodes that need to be merged , I'm going to use it here Polyolefin materials Crystalline silicon furnace , Two keyword nodes ( What is established here is the inclusion relation graph between keywords and documents , A word may appear in many different documents ).

MATCH (kw: key word ) WHERE kw.name IN [' Polyolefin materials ',' Crystalline silicon furnace '] RETURN kw

 Please add a picture description

Two 、 Expand the concept to view one-time relationships

     below Brown Represents a document , Red Indicates the keyword . The following query can be used to correlate Polyolefin materials Crystalline silicon furnace The two keywords all once contain relation .

MATCH p=(kw: key word )--() WHERE kw.name IN [' Polyolefin materials ',' Crystalline silicon furnace '] RETURN p

 Insert picture description here

3、 ... and 、 Create a new node

     In the future Polyolefin materials and Crystalline silicon furnace Two keyword nodes , And their one degree networks are merged into this new node .

CREATE (kw: Concept  {name:' Industrial manufacturing '}) RETURN ID(kw) AS idN

Four 、 Merge the node list into the first node

4.1 Nodes to be operated

     This query shows , Three nodes to be operated , among green For the new node just created , Its label is Concept .

MATCH (n) WHERE ID(n) IN [2133617,34934,213289] RETURN n

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-jA3PyXa9-1633961951749)(vx_images/1415041182489.png =512x)]

4.2 Extend all the node relationships

     Concept The node currently has no association , In the next operation, I will put the above Keyword subgraph Merge into On the concept node .

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-PM8b6KLl-1633961951753)(vx_images/167734207973.png =512x)]

4.3 Perform refactoring analysis

     Such as Nodes to be operated in ,ID The first node in the list is a new node Industrial manufacturing Concept node , Other nodes after the first node and their associated relationships will be merged into the first node . The merged nodes , It will be deleted after execution .

     Three options are supported for attribute operation during merging :overwrite、discard、combine.overwrite Will override the attributes of the merged entity ;discard No action will be performed when the attribute is repeated ;combine When the attribute is repeated , Will be stored in an array .

 Insert picture description here

     When the relationship between the merged node and the merged node is duplicate, a new node will be created , have access to apoc.refactor.mergeRelationships Then merge the relationship ;apoc.refactor.mergeRelationships When merging relationships, you need to pay attention to , The start and end nodes of the relationship must be the same , Configurable properties and apoc.refactor.mergeNodes It's the same .

4.4 Set not to operate on node attributes during refactoring

     The default operation : If the relationship on the node is repeated , Will the new , That is, the edges may repeat ; The labels of the nodes are merged into the first node .

MATCH (n) WHERE ID(n) IN [2133617,34934,213289] WITH COLLECT(n) AS nodes
CALL apoc.refactor.mergeNodes(nodes,{properties:'discard'}) YIELD node RETURN node

4.5 The effect of reconstruction

     Three nodes become one node , Three subgraphs become one subgraph .

 Insert picture description here

Four 、 summary

     This paper introduces , Data reconstruction method in node mode . It is very practical in the actual data production operation , Refactoring in relational mode is similar to this approach . During refactoring, data is generally operated in batches , In support of ACID In order to avoid the frequent occurrence of life and death lock problems in the database , Concurrent operation of data is not supported in stored procedures .

原网站

版权声明
本文为[Tnoy. Ma]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280531435731.html