Skip to content

Commit 1cbfc95

Browse files
committed
remove camel case from relationship names
1 parent 4f934ee commit 1cbfc95

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

stix2/datastore/neo4j/neo4j.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22

33
from py2neo import Graph, Node, Relationship
4+
import re
45

56
import stix2
67
from stix2.base import _STIXBase
@@ -10,6 +11,8 @@
1011
from stix2.parsing import parse
1112

1213

14+
def convert_camel_case_to_snake_case(name):
15+
return re.sub(r'(?<!^)(?=[A-Z])', '_', name).lower()
1316
def remove_sro_from_list(sro, sro_list):
1417
for rel in sro_list:
1518
if (rel["source_ref"] == sro["source_ref"] and
@@ -237,7 +240,7 @@ def _insert_external_references(self, refs, parent_node):
237240
def _insert_extensions(self, extensions, parent_node):
238241
for ext in extensions:
239242
node_contents = dict()
240-
type_name = ext.__class__.__name__
243+
type_name = convert_camel_case_to_snake_case(ext.__class__.__name__)
241244
node_contents["type"] = type_name
242245
for key, value in ext.items():
243246
if not key.endswith("ref") and not key.endswith("refs"):
@@ -275,7 +278,7 @@ def _insert_sro(self, obj, recheck=False):
275278
if self._is_node_available(obj["source_ref"]) and self._is_node_available(obj["target_ref"]):
276279
cypher_string = f'MATCH (a),(b) WHERE a.id="{str(obj["source_ref"])}" AND b.id="{str(obj["target_ref"])}" CREATE (a)-[r:{reltype}]->(b) RETURN a,b'
277280
self.sgraph.run(cypher_string)
278-
print(f'Created {str(obj["source_ref"])} {reltype} {obj["target_ref"]}')
281+
# print(f'Created {str(obj["source_ref"])} {reltype} {obj["target_ref"]}')
279282
if recheck:
280283
remove_sro_from_list(obj, self.relationships_to_recheck)
281284
else:
@@ -299,7 +302,7 @@ def _insert_embedded_relationships(self, obj, id, recheck=False):
299302
# The "b to a" relationship is reversed in this cypher query to ensure the correct relationship direction in the graph
300303
cypher_string = f'MATCH (a),(b) WHERE a.id="{str(ref)}" AND b.id="{str(id)}" CREATE (b)-[r:{k}]->(a) RETURN a,b'
301304
self.sgraph.run(cypher_string)
302-
print(f'Created * {str(id)} {k} {str(ref)}')
305+
# print(f'Created * {str(id)} {k} {str(ref)}')
303306
if recheck:
304307
remove_sro_from_list(obj, self.relationships_to_recheck)
305308
else:

0 commit comments

Comments
 (0)