Skip to content

Commit

Permalink
target fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbie1977 authored Oct 23, 2024
1 parent afc8a35 commit 0fbd4d6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/uk/ac/ebi/vfb/neo4j/flybase2neo/fb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,31 @@ def cypher_escape(value):
# For numbers and booleans
return str(value).lower()

# **Preprocess the statement_template to remove spaces inside placeholders**
import re
statement_template = re.sub(r'{\s*([^}]+?)\s*}', r'{\1}', statement_template)

batch_size = 1000 # Adjust batch size as needed
for batch in chunks(dict_list, batch_size):
statements = []
for line in batch:
# Escape the values
# Escape and substitute values into the statement template
escaped_values = {key: cypher_escape(value) for key, value in line.items()}
# Create a new dictionary with 'line.' prefixed to keys
escaped_line = {'line.' + key: value for key, value in escaped_values.items()}

try:
statement = statement_template.format(**escaped_line)
statements.append(statement)
except KeyError as e:
warnings.warn(f"Missing key {e} in line: {line}")
continue # Skip this line if a key is missing

# Optionally, print the first statement for verification
if statements:
print("First Cypher command in the batch:")
print(statements[0])

# Now send the statements via commit_list
self.nc.commit_list(statements)

Expand Down

0 comments on commit 0fbd4d6

Please sign in to comment.