diff --git a/NEO4J/Readme.md b/NEO4J/Readme.md index 3078b93d..3d10d11d 100644 --- a/NEO4J/Readme.md +++ b/NEO4J/Readme.md @@ -42,6 +42,9 @@ Requirements: NOTE: the database load will fail if these requirements are not met. +#####ADDENDUM: +In order to support python version 3.9 and neo4j version 5.x, it is necessary to install the latest version of p2neo (2021.2.3) and make sure to have a symbolic link from python to python3 + ##### Syntax to create the NEO4J database from an RF2 release using the python scripts from this project: ``` diff --git a/NEO4J/snomed_g_graphdb_cypher_add_assoc_refset.template b/NEO4J/snomed_g_graphdb_cypher_add_assoc_refset.template index a59a389b..edc48465 100755 --- a/NEO4J/snomed_g_graphdb_cypher_add_assoc_refset.template +++ b/NEO4J/snomed_g_graphdb_cypher_add_assoc_refset.template @@ -10,9 +10,11 @@ // Create edges for association refset RETURN 'Creating ASSOCIATION REFSET edges between ObjectConcept nodes'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>assoc_refset_new.csv" as line -with line -MATCH (s:ObjectConcept { sctid: line.referencedComponentId }), (d:ObjectConcept { sctid: line.targetComponentId }) -WITH s,d,line -CREATE UNIQUE (s)-[:HAS_ASSOCIATION {association: line.association, refsetId: line.refsetId, active: line.active, effectiveTime: line.effectiveTime, referencedComponentId: line.referencedComponentId, targetComponentId: line.targetComponentId, moduleId: line.moduleId, id: line.id } ]->(d); +CALL { + with line + MATCH (s:ObjectConcept { sctid: line.referencedComponentId }), (d:ObjectConcept { sctid: line.targetComponentId }) + WITH s,d,line + CREATE UNIQUE (s)-[:HAS_ASSOCIATION {association: line.association, refsetId: line.refsetId, active: line.active, effectiveTime: line.effectiveTime, referencedComponentId: line.referencedComponentId, targetComponentId: line.targetComponentId, moduleId: line.moduleId, id: line.id } ]->(d) +} IN TRANSACTIONS OF 200 ROWS; + diff --git a/NEO4J/snomed_g_graphdb_cypher_create.template b/NEO4J/snomed_g_graphdb_cypher_create.template index 0cbef2bd..7e7638f5 100755 --- a/NEO4J/snomed_g_graphdb_cypher_create.template +++ b/NEO4J/snomed_g_graphdb_cypher_create.template @@ -11,26 +11,26 @@ // NEXT STEP -- create INDEXES -CREATE CONSTRAINT ON (c:ObjectConcept) ASSERT c.id IS UNIQUE; -CREATE CONSTRAINT ON (c:ObjectConcept) ASSERT c.sctid IS UNIQUE; +CREATE CONSTRAINT FOR (c:ObjectConcept) REQUIRE c.id IS UNIQUE; +CREATE CONSTRAINT FOR (c:ObjectConcept) REQUIRE c.sctid IS UNIQUE; // id,sctid index created, requiring uniqueness // Note: Can't have "FSN is UNIQUE"" constraint, can have dups (inactive concepts) // for example -- "retired procedure" is FSN of multiple inactive concepts -CREATE CONSTRAINT ON (c:Description) ASSERT c.id IS UNIQUE; -CREATE INDEX ON :Description(sctid); +CREATE CONSTRAINT FOR (c:Description) REQUIRE c.id IS UNIQUE; +CREATE INDEX FOR (x:Description) ON (x.sctid); // need index so setting HAS_DESCRIPTION edges doesn't stall // there can be more than one description for the same sctid, sctid not unique, but id is unique // ROLE_GROUP nodes. Index needed for defining relationship assignment. -CREATE INDEX ON :RoleGroup(sctid); +CREATE INDEX FOR (x:RoleGroup) ON (x.sctid); // NEXT STEP -- create CONCEPT nodes RETURN 'Creating NEW ObjectConcept nodes'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>concept_new.csv" as line -with line -CREATE (:ObjectConcept +CALL { + with line + CREATE (n:ObjectConcept { nodetype: 'concept', id: line.id, sctid: line.id, @@ -39,14 +39,17 @@ CREATE (:ObjectConcept moduleId: line.moduleId, definitionStatusId: line.definitionStatusId, FSN: line.FSN, - history: line.history} ); + history: line.history} ) + +} IN TRANSACTIONS OF 200 ROWS; // NEXT STEP -- create DESCRIPTION nodes (info from Language+Description file) RETURN 'Creating NEW Description nodes'; -USING PERIODIC COMMIT 200 + LOAD csv with headers from "<<>><<>>descrip_new.csv" as line -with line -CREATE (:Description +CALL { + with line + CREATE (n:Description { nodetype:'description', id: line.id, sctid: line.sctid, @@ -61,26 +64,31 @@ CREATE (:Description refsetId: line.refsetId, caseSignificanceId: line.caseSignificanceId, languageCode: line.languageCode, - history: line.history} ); + history: line.history} ) + +} IN TRANSACTIONS OF 200 ROWS; // NEXT STEP - create DESCRIPTION edges RETURN 'Creating HAS_DESCRIPTION edges for new Description nodes related to ObjectConcept nodes'; -USING PERIODIC COMMIT 200 + LOAD csv with headers from "<<>><<>>descrip_new.csv" as line -with line -MATCH (c:ObjectConcept { sctid: line.sctid }), (f:Description { id: line.id }) -MERGE (c)-[:HAS_DESCRIPTION]->(f); +CALL { + with line + MATCH (c:ObjectConcept { sctid: line.sctid }), (f:Description { id: line.id }) + MERGE (c)-[:HAS_DESCRIPTION]->(f) +} IN TRANSACTIONS OF 200 ROWS; // -------------------------------------------------------------------------------------- // NEXT STEP -- create ISA relationships // -------------------------------------------------------------------------------------- RETURN 'Creating NEW ISA edges'; -USING PERIODIC COMMIT 200 + LOAD csv with headers from "<<>><<>>isa_rel_new.csv" as line -with line -MATCH (c1:ObjectConcept { id: line.sourceId }), (c2:ObjectConcept { id: line.destinationId }) -MERGE (c1)-[:ISA { id: line.id, +CALL { + with line + MATCH (c1:ObjectConcept { id: line.sourceId }), (c2:ObjectConcept { id: line.destinationId }) + MERGE (c1)-[:ISA { id: line.id, active: line.active, effectiveTime: line.effectiveTime, moduleId: line.moduleId, @@ -89,27 +97,31 @@ MERGE (c1)-[:ISA { id: line.id, characteristicTypeId: line.characteristicTypeId, sourceId: line.sourceId, destinationId: line.destinationId, - history: line.history }]->(c2); + history: line.history }]->(c2) + } IN TRANSACTIONS OF 200 ROWS; // -------------------------------------------------------------------------------------- // NEXT STEP -- create RoleGroup nodes // -------------------------------------------------------------------------------------- RETURN 'Creating RoleGroup nodes'; -USING PERIODIC COMMIT 500 LOAD csv with headers from "<<>><<>>rolegroups.csv" as line -with line -MERGE (rg:RoleGroup +CALL { + with line + MERGE (rg:RoleGroup { nodetype:'rolegroup', sctid: line.sctid, - rolegroup: line.rolegroup}); + rolegroup: line.rolegroup}) +} IN TRANSACTIONS OF 500 ROWS; // Add edge in 2nd step, Java memory issue RETURN 'Creating HAS_ROLE_GROUP edges'; -USING PERIODIC COMMIT 500 LOAD csv with headers from "<<>><<>>rolegroups.csv" as line -with line -MATCH (c:ObjectConcept { sctid: line.sctid }), (rg:RoleGroup { sctid: line.sctid, rolegroup: line.rolegroup }) -MERGE (c)-[:HAS_ROLE_GROUP]->(rg); +CALL { + with line + MATCH (c:ObjectConcept { sctid: line.sctid }), (rg:RoleGroup { sctid: line.sctid, rolegroup: line.rolegroup }) + MERGE (c)-[:HAS_ROLE_GROUP]->(rg) +} IN TRANSACTIONS OF 500 ROWS; + // -------------------------------------------------------------------------------------- // NEXT STEP -- create Defining relationships diff --git a/NEO4J/snomed_g_graphdb_cypher_refset_assoc_create.template b/NEO4J/snomed_g_graphdb_cypher_refset_assoc_create.template index 436cacc8..475c2731 100755 --- a/NEO4J/snomed_g_graphdb_cypher_refset_assoc_create.template +++ b/NEO4J/snomed_g_graphdb_cypher_refset_assoc_create.template @@ -10,12 +10,12 @@ // Create edges for association refset RETURN 'Creating ASSOCIATION REFSET edges between ObjectConcept nodes'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>assoc_refset_new.csv" as line -with line -MATCH (s:ObjectConcept { sctid: line.referencedComponentId }), (d:ObjectConcept { sctid: line.targetComponentId }) -WITH s,d,line -MERGE (s)-[:HAS_ASSOCIATION {id: line.id, +CALL { + with line + MATCH (s:ObjectConcept { sctid: line.referencedComponentId }), (d:ObjectConcept { sctid: line.targetComponentId }) + WITH s,d,line + MERGE (s)-[:HAS_ASSOCIATION {id: line.id, association: line.association, refsetId: line.refsetId, active: line.active, @@ -23,4 +23,6 @@ MERGE (s)-[:HAS_ASSOCIATION {id: line.id, referencedComponentId: line.referencedComponentId, targetComponentId: line.targetComponentId, moduleId: line.moduleId, - history: line.history } ]->(d); + history: line.history } ]->(d) + } IN TRANSACTIONS OF 200 ROWS; + diff --git a/NEO4J/snomed_g_graphdb_cypher_rmv_problem_edges.template b/NEO4J/snomed_g_graphdb_cypher_rmv_problem_edges.template index 9c597c9e..8fa4d62a 100755 --- a/NEO4J/snomed_g_graphdb_cypher_rmv_problem_edges.template +++ b/NEO4J/snomed_g_graphdb_cypher_rmv_problem_edges.template @@ -13,13 +13,17 @@ // -------------------------------------------------------------------- RETURN 'Removing defining-relationships (DRs) that changed source/destination';' -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>defining_rel_chg.csv" as line -MATCH (rg:RoleGroup)-[r {id: line.id}]->(c:ObjectConcept) -DELETE r; +CALL { + MATCH (rg:RoleGroup)-[r {id: line.id}]->(c:ObjectConcept) + DELETE r; +} IN TRANSACTIONS OF 200 ROWS + RETURN 'Removing ISA relationships that changed the source or destination.'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>defining_rel_chg.csv" as line -MATCH (b:ObjectConcept)-[r {id: line.id}]->(c:ObjectConcept) -DELETE r; +CALL { + MATCH (b:ObjectConcept)-[r {id: line.id}]->(c:ObjectConcept) + DELETE r +} IN TRANSACTIONS OF 200 ROWS; + diff --git a/NEO4J/snomed_g_graphdb_cypher_update.template b/NEO4J/snomed_g_graphdb_cypher_update.template index 40271f42..3e00e84c 100755 --- a/NEO4J/snomed_g_graphdb_cypher_update.template +++ b/NEO4J/snomed_g_graphdb_cypher_update.template @@ -31,17 +31,19 @@ RETURN 'Removing defining-relationships (DRs) edges for DRs which changed role-g RETURN 'A CREATE operation later in the update will insert the replacement edge.'; RETURN 'Note: Cant simply modify the endpoint of the existing edge to point to a'; RETURN 'different role-group. An edge removal+recreation is required by NEO4J.'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>defining_rel_edge_rem.csv" as line -MATCH (rg:RoleGroup { sctid: line.sourceId, rolegroup: line.rolegroup })-[r {id: line.id}]->(c:ObjectConcept { sctid: line.destinationId }) -DELETE r; +CALL { + MATCH (rg:RoleGroup { sctid: line.sourceId, rolegroup: line.rolegroup })-[r {id: line.id}]->(c:ObjectConcept { sctid: line.destinationId }) + DELETE r +} IN TRANSACTIONS OF 200 ROWS; + // NEXT STEP -- Concept modifications -- new and updated RETURN 'Creating NEW ObjectConcept nodes'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>concept_new.csv" as line -CREATE (:ObjectConcept +CALL { + CREATE (:ObjectConcept { nodetype: 'concept', id: line.id, sctid: line.id, @@ -50,13 +52,14 @@ CREATE (:ObjectConcept moduleId: line.moduleId, definitionStatusId: line.definitionStatusId, FSN: line.FSN, - history: line.history} ); + history: line.history} ) + } IN TRANSACTIONS OF 200 ROWS; RETURN 'Modifying existing ObjectConcept nodes which were updated'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>concept_chg.csv" as line -MATCH (n:ObjectConcept { sctid:line.id }) -set n = { nodetype: 'concept', +CALL { + MATCH (n:ObjectConcept { sctid:line.id }) + set n = { nodetype: 'concept', id: line.id, sctid: line.id, active: line.active, @@ -64,13 +67,15 @@ set n = { nodetype: 'concept', moduleId: line.moduleId, definitionStatusId: line.definitionStatusId, FSN: line.FSN, - history: line.history}; + history: line.history} + } IN TRANSACTIONS OF 200 ROWS; + // Combined Language+Description file ==> defines Descriptions RETURN 'Creating NEW Description nodes'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>descrip_new.csv" as line -CREATE (:Description +CALL { + CREATE (:Description { nodetype:'description', id: line.id, sctid: line.sctid, @@ -85,13 +90,15 @@ CREATE (:Description refsetId: line.refsetId, caseSignificanceId: line.caseSignificanceId, languageCode: line.languageCode, - history: line.history} ); + history: line.history} ) +} IN TRANSACTIONS OF 200 ROWS; + RETURN 'Modifying existing Description nodes which were updated'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>descrip_chg.csv" as line -MATCH (n:Description { id:line.id }) -SET n = { nodetype:'description', +CALL { + MATCH (n:Description { id:line.id }) + SET n = { nodetype:'description', id: line.id, sctid: line.sctid, active: line.active, @@ -105,30 +112,36 @@ SET n = { nodetype:'description', refsetId: line.refsetId, caseSignificanceId: line.caseSignificanceId, languageCode: line.languageCode, - history: line.history }; + history: line.history } +} IN TRANSACTIONS OF 200 ROWS; + // Description edges for new and modified descriptions RETURN 'Creating HAS_DESCRIPTION edges for new Description nodes related to ObjectConcept nodes'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>descrip_new.csv" as line -MATCH (c:ObjectConcept { sctid: line.sctid }), (f:Description { id: line.id }) -MERGE (c)-[:HAS_DESCRIPTION]->(f); +CALL { + MATCH (c:ObjectConcept { sctid: line.sctid }), (f:Description { id: line.id }) + MERGE (c)-[:HAS_DESCRIPTION]->(f) +} IN TRANSACTIONS OF 200 ROWS; + RETURN 'Updating existing HAS_DESCRIPTION edges for updated Description nodes related to ObjectConcept nodes'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>descrip_chg.csv" as line -MATCH (c:ObjectConcept { sctid: line.sctid }), (f:Description { id: line.id }) -MERGE (c)-[:HAS_DESCRIPTION]->(f); +CALL { + MATCH (c:ObjectConcept { sctid: line.sctid }), (f:Description { id: line.id }) + MERGE (c)-[:HAS_DESCRIPTION]->(f) +} IN TRANSACTIONS OF 200 ROWS; + // -------------------------------------------------------------------------------------- // NEXT STEP -- ISA relationships // -------------------------------------------------------------------------------------- RETURN 'Creating NEW ISA edges'; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>isa_rel_new.csv" as line -MATCH (c1:ObjectConcept { id: line.sourceId }), (c2:ObjectConcept { id: line.destinationId }) -MERGE (c1)-[:ISA +CALL { + MATCH (c1:ObjectConcept { id: line.sourceId }), (c2:ObjectConcept { id: line.destinationId }) + MERGE (c1)-[:ISA { id: line.id, active: line.active, effectiveTime: line.effectiveTime, @@ -138,17 +151,18 @@ MERGE (c1)-[:ISA characteristicTypeId: line.characteristicTypeId, sourceId: line.sourceId, destinationId: line.destinationId, - history: line.history }]->(c2); + history: line.history }]->(c2) + } IN TRANSACTIONS OF 200 ROWS; RETURN 'Modifying existing ISA edges which were updated'; MATCH (a:SNOMED_G_ISA_UPDATE_ISSUE) delete a; -USING PERIODIC COMMIT 200 LOAD csv with headers from "<<>><<>>isa_rel_chg.csv" as line -OPTIONAL MATCH (c1:ObjectConcept { id: line.sourceId })-[r:ISA { id: line.id }]->(c2:ObjectConcept { id: line.destinationId }) -FOREACH (o IN (CASE WHEN r IS NOT NULL THEN [1] ELSE [] END) | -set r = { id: line.id, +CALL { + OPTIONAL MATCH (c1:ObjectConcept { id: line.sourceId })-[r:ISA { id: line.id }]->(c2:ObjectConcept { id: line.destinationId }) + FOREACH (o IN (CASE WHEN r IS NOT NULL THEN [1] ELSE [] END) | + set r = { id: line.id, active: line.active, effectiveTime: line.effectiveTime, moduleId: line.moduleId, @@ -158,9 +172,9 @@ set r = { id: line.id, sourceId: line.sourceId, destinationId: line.destinationId, history: line.history } -) -FOREACH (o IN (CASE WHEN r IS NULL THEN [1] ELSE [] END) | -CREATE (a:SNOMED_G_ISA_UPDATE_ISSUE + ) + FOREACH (o IN (CASE WHEN r IS NULL THEN [1] ELSE [] END) | + CREATE (a:SNOMED_G_ISA_UPDATE_ISSUE { snomedct_object:"ISA", id: line.id, active: line.active, @@ -172,32 +186,37 @@ CREATE (a:SNOMED_G_ISA_UPDATE_ISSUE sourceId: line.sourceId, destinationId: line.destinationId, history: line.history }) -); + ); + + match(a:SNOMED_G_ISA_UPDATE_ISSUE) + create (b:SNOMED_G_UPDATE_FAILURE); -match(a:SNOMED_G_ISA_UPDATE_ISSUE) -create (b:SNOMED_G_UPDATE_FAILURE); + match(a:SNOMED_G_ISA_UPDATE_ISSUE) + match (b:ObjectConcept)-[r:ISA {id: a.id}]->(c:ObjectConcept) + delete a,r +} IN TRANSACTIONS OF 200 ROWS; -match(a:SNOMED_G_ISA_UPDATE_ISSUE) -match (b:ObjectConcept)-[r:ISA {id: a.id}]->(c:ObjectConcept) -delete a,r; // -------------------------------------------------------------------------------------- // NEXT STEP -- Create RoleGroup nodes // -------------------------------------------------------------------------------------- RETURN 'Creating RoleGroup nodes'; -USING PERIODIC COMMIT 500 LOAD csv with headers from "<<>><<>>rolegroups.csv" as line -MERGE (rg:RoleGroup +CALL { + MERGE (rg:RoleGroup { nodetype:'rolegroup', sctid: line.sctid, - rolegroup: line.rolegroup}); + rolegroup: line.rolegroup}) +} IN TRANSACTIONS OF 500 ROWS; + // Add edge in 2nd step, Java memory issue RETURN 'Creating HAS_ROLE_GROUP edges'; -USING PERIODIC COMMIT 500 LOAD csv with headers from "<<>><<>>rolegroups.csv" as line -MATCH (c:ObjectConcept { sctid: line.sctid }), (rg:RoleGroup { sctid: line.sctid, rolegroup: line.rolegroup }) -MERGE (c)-[:HAS_ROLE_GROUP]->(rg); +CALL { + MATCH (c:ObjectConcept { sctid: line.sctid }), (rg:RoleGroup { sctid: line.sctid, rolegroup: line.rolegroup }) + MERGE (c)-[:HAS_ROLE_GROUP]->(rg) +} IN TRANSACTIONS OF 200 ROWS; // -------------------------------------------------------------------------------------- // NEXT STEP -- Modify existing defining relationships @@ -207,11 +226,11 @@ RETURN 'Modify updated Defining relationships'; MATCH (a:SNOMED_G_DEFREL_UPDATE_ISSUE) delete a; -USING PERIODIC COMMIT 200 LOAD CSV with headers from "<<>><<>>defining_rel_chg.csv" as line -OPTIONAL MATCH (rg:RoleGroup { sctid: line.sctid, rolegroup: line.rolegroup })-[r { id: line.id} ]->(c:ObjectConcept { sctid: line.destinationId }) -FOREACH (o IN (CASE WHEN r IS NOT NULL THEN [r] ELSE [] END) | -SET r = { id: line.id, +CALL { + OPTIONAL MATCH (rg:RoleGroup { sctid: line.sctid, rolegroup: line.rolegroup })-[r { id: line.id} ]->(c:ObjectConcept { sctid: line.destinationId }) + FOREACH (o IN (CASE WHEN r IS NOT NULL THEN [r] ELSE [] END) | + SET r = { id: line.id, active: line.active, sctid: line.sctid, typeId: line.typeId, @@ -221,9 +240,9 @@ SET r = { id: line.id, characteristicTypeId: line.characteristicTypeId, modifierId: line.modifierId, history: line.history } -) -FOREACH (o IN (CASE WHEN r IS NULL THEN [1] ELSE [] END) | -CREATE (a:SNOMED_G_DEFREL_UPDATE_ISSUE + ) + FOREACH (o IN (CASE WHEN r IS NULL THEN [1] ELSE [] END) | + CREATE (a:SNOMED_G_DEFREL_UPDATE_ISSUE { snomedct_object:"DEFINING_REL", id: line.id, active: line.active, @@ -235,14 +254,16 @@ CREATE (a:SNOMED_G_DEFREL_UPDATE_ISSUE characteristicTypeId: line.characteristicTypeId, modifierId: line.modifierId, history: line.history }) -); + ); + + match(a:SNOMED_G_DEFREL_UPDATE_ISSUE) + create (b:SNOMED_G_UPDATE_FAILURE); -match(a:SNOMED_G_DEFREL_UPDATE_ISSUE) -create (b:SNOMED_G_UPDATE_FAILURE); + match(a:SNOMED_G_DEFREL_UPDATE_ISSUE) + match (b:RoleGroup)-[r {id: a.id}]->(c:ObjectConcept) + delete a,r +} IN TRANSACTIONS OF 200 ROWS; -match(a:SNOMED_G_DEFREL_UPDATE_ISSUE) -match (b:RoleGroup)-[r {id: a.id}]->(c:ObjectConcept) -delete a,r; // -------------------------------------------------------------------------------------- // NEXT STEP -- Create new defining relationships diff --git a/NEO4J/snomed_g_lib_neo4j.py b/NEO4J/snomed_g_lib_neo4j.py index 5444cd1e..1a4a98eb 100755 --- a/NEO4J/snomed_g_lib_neo4j.py +++ b/NEO4J/snomed_g_lib_neo4j.py @@ -12,7 +12,7 @@ def db_data_prep(v): class Neo4j_Access: def __init__(self, base64pw): # NEO4J init - self.graph_db = py2neo.Graph(password=base64pw) # 'http://localhost:7474/db/data/transaction/commit' + self.graph_db = py2neo.Graph("bolt://localhost:7687", auth=("neo4j", base64pw)) # 'http://localhost:7474/db/data/transaction/commit' def lookup_elements_by_id(self,query_template,query_target_variable,id_field_name,id_list,chunk_size): matches = {} diff --git a/NEO4J/snomed_g_neo4j_tools.py b/NEO4J/snomed_g_neo4j_tools.py index cd9544c0..aeb16e58 100755 --- a/NEO4J/snomed_g_neo4j_tools.py +++ b/NEO4J/snomed_g_neo4j_tools.py @@ -41,7 +41,7 @@ def parse_command(arglist): opts, args = parse_command(arglist) n4jpw = opts.neopw try: - graph_db = py2neo.Graph(password=n4jpw) # 'http://localhost:7474/db/data/transaction/commit') + graph_db = py2neo.Graph("bolt://localhost:7687", auth=("neo4j", n4jpw)) # 'http://localhost:7474/db/data/transaction/commit') except Exception as e: print('*** Failed to make connection to NEO4J database ***') print('Exception: %s' % type(e).__name__) diff --git a/NEO4J/snomed_g_template_tools.py b/NEO4J/snomed_g_template_tools.py index 809e3dac..22af4473 100755 --- a/NEO4J/snomed_g_template_tools.py +++ b/NEO4J/snomed_g_template_tools.py @@ -104,26 +104,28 @@ def instantiate(arglist): print('// %s defining relationships' % rolename,file=fout) print('''RETURN 'NEW Defining relationships of type %s';''' % rolename,file=fout) print(file=fout) - print('USING PERIODIC COMMIT 200',file=fout) load_csv_line = ('LOAD CSV with headers from "%s%sDR_%s_new.csv" as line' % (('file:///' if sys.platform in ['cygwin','win32','darwin'] else 'file:'),output_dir,typeId)).replace('file:////','file:///') print(load_csv_line,file=fout) - print('with line, line.sctid as source_id, line.destinationId as dest_id, line.rolegroup as rolegroup_id',file=fout) - print('MERGE (rg:RoleGroup { sctid: source_id, rolegroup: rolegroup_id });',file=fout) + print('CALL {',file=fout) + print(' with line ',file=fout) + print(' MERGE (rg:RoleGroup { sctid: line.sctid, rolegroup: line.rolegroup })',file=fout) + print(' } IN TRANSACTIONS OF 200 ROWS;',file=fout) print(file=fout) print('// Add defining relationship edge in 2nd step, Java memory issue',file=fout) - print('USING PERIODIC COMMIT 200',file=fout) load_csv_line = ('LOAD CSV with headers from "%s%sDR_%s_new.csv" as line' % (('file:///' if sys.platform in ['cygwin','win32','darwin'] else 'file:'),output_dir,typeId)).replace('file:////','file:///') print(load_csv_line,file=fout) - print('with line, line.sctid as source_id, line.destinationId as dest_id, line.rolegroup as rolegroup_id',file=fout) - print('MATCH (rg:RoleGroup { sctid: source_id, rolegroup: rolegroup_id })',file=fout) - print('WITH line,rg,source_id,dest_id,rolegroup_id',file=fout) - print('MATCH (c:ObjectConcept { sctid: dest_id })',file=fout) - print('MERGE (rg)-[:%s { id: line.id, active: line.active, sctid: source_id,' % rolename,file=fout) + print('CALL {',file=fout) + print(' with line ',file=fout) + print(' MATCH (rg:RoleGroup { sctid: line.sctid, rolegroup: line.rolegroup })',file=fout) + print( 'WITH line,rg ',file=fout) + print(' MATCH (c:ObjectConcept { sctid: line.destinationId })',file=fout) + print(' MERGE (rg)-[:%s { id: line.id, active: line.active, sctid: line.sctid,' % rolename,file=fout) print(' typeId: line.typeId,',file=fout) - print(' rolegroup: rolegroup_id, effectiveTime: line.effectiveTime,',file=fout) + print(' rolegroup: line.rolegroup, effectiveTime: line.effectiveTime,',file=fout) print(' moduleId: line.moduleId, characteristicTypeId: line.characteristicTypeId,',file=fout) print(' modifierId: line.modifierId,',file=fout) - print(' history: line.history }]->(c);',file=fout) + print(' history: line.history }]->(c)',file=fout) + print(' } IN TRANSACTIONS OF 200 ROWS;',file=fout) # close CSV, wrap up print('// Finito',file=fout) fout.close()