python-eigen-ingenuity 0.5.35b3__py3-none-any.whl → 0.5.36b2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- eigeningenuity/__init__.py +16 -13
- eigeningenuity/alerts.py +444 -0
- eigeningenuity/util.py +32 -0
- modelbuilder/src/assetmodelutilities.py +2 -0
- modelbuilder/src/configmanager.py +5 -2
- modelbuilder/src/csvcontentsmanager.py +13 -2
- modelbuilder/src/filemanager.py +3 -3
- modelbuilder/src/processors/fileprocessors.py +67 -0
- modelbuilder/src/processors/labelmanager.py +11 -7
- modelbuilder/src/processors/nodefileprocessor.py +36 -83
- modelbuilder/src/processors/relationshipfileprocessor.py +96 -140
- modelbuilder/src/querymanager.py +130 -28
- {python_eigen_ingenuity-0.5.35b3.dist-info → python_eigen_ingenuity-0.5.36b2.dist-info}/METADATA +1 -1
- {python_eigen_ingenuity-0.5.35b3.dist-info → python_eigen_ingenuity-0.5.36b2.dist-info}/RECORD +17 -15
- {python_eigen_ingenuity-0.5.35b3.dist-info → python_eigen_ingenuity-0.5.36b2.dist-info}/WHEEL +1 -1
- {python_eigen_ingenuity-0.5.35b3.dist-info → python_eigen_ingenuity-0.5.36b2.dist-info}/entry_points.txt +0 -0
- {python_eigen_ingenuity-0.5.35b3.dist-info → python_eigen_ingenuity-0.5.36b2.dist-info}/top_level.txt +0 -0
|
@@ -89,13 +89,17 @@ def sort_labels(required_labels, labels):
|
|
|
89
89
|
|
|
90
90
|
|
|
91
91
|
def sort_node_labels(required_labels, input_labels):
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
merge_labels = []
|
|
93
|
+
new_labels = []
|
|
94
|
+
remove_labels = []
|
|
95
|
+
for inputs in input_labels:
|
|
96
|
+
wanted_label_list, unwanted_label_list, remove_label_list = sort_labels(required_labels, [inputs])
|
|
97
|
+
merge_list = [i for i in required_labels + wanted_label_list if (not ('!' + i in unwanted_label_list) and not (i.startswith('!')))]
|
|
98
|
+
merge_labels += [merge_list]
|
|
99
|
+
new_labels += [[i for i in wanted_label_list if i not in merge_list]]
|
|
100
|
+
remove_labels += [remove_label_list]
|
|
101
|
+
|
|
102
|
+
return merge_labels, new_labels, remove_labels
|
|
99
103
|
|
|
100
104
|
|
|
101
105
|
def sort_relationship_labels(required_labels, input_labels):
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from processors.fileprocessors import FileProcessor
|
|
1
2
|
import messages
|
|
2
3
|
from queries.cypherbuilder import QueryBuilder
|
|
3
4
|
import assetmodelutilities as amu
|
|
@@ -10,48 +11,16 @@ from property import Neo4jProperty
|
|
|
10
11
|
import copy
|
|
11
12
|
|
|
12
13
|
|
|
13
|
-
class NodeFileProcessor:
|
|
14
|
+
class NodeFileProcessor(FileProcessor):
|
|
14
15
|
|
|
15
16
|
def __init__(self, filename, config, contents, section, query_manager):
|
|
16
|
-
|
|
17
|
-
self.contents = contents
|
|
18
|
-
self.section = section
|
|
19
|
-
self.query_manager = query_manager
|
|
17
|
+
super().__init__(filename, config, contents, section, query_manager)
|
|
20
18
|
|
|
21
|
-
self.primary_property = config.get_primary_property()[section]
|
|
22
|
-
self.add_system_properties = not config.get_no_system_properties()
|
|
23
|
-
|
|
24
|
-
self.required_labels = config.get_required_labels()[section]
|
|
25
19
|
self.required_properties = config.get_required_properties_dict()[section]
|
|
26
20
|
self.unrequired_properties = config.get_unrequired_properties_list()[section]
|
|
27
|
-
self.merge_properties = config.get_merge_properties()[section]
|
|
28
|
-
self.unique_id_property = config.get_unique_id_property()[section]
|
|
29
|
-
self.creation_time_property = config.get_creation_time_property()[section]
|
|
30
|
-
self.update_time_property = config.get_update_time_property()[section]
|
|
31
|
-
|
|
32
21
|
self.label_alias = config.get_label_alias()[section]
|
|
33
22
|
self.node_alias = config.get_node_alias()[section]
|
|
34
23
|
|
|
35
|
-
self.validate_only = config.in_validation_mode()
|
|
36
|
-
self.summarise = config.in_summary_mode()
|
|
37
|
-
|
|
38
|
-
self.blank_property_list = config.get_blank_property_list()
|
|
39
|
-
self.blank_property_override = config.get_blank_property_override()
|
|
40
|
-
self.batch_rate = config.get_batch_rate()
|
|
41
|
-
self.start_from = config.get_start_from()
|
|
42
|
-
self.last_row = config.get_end_at()
|
|
43
|
-
|
|
44
|
-
self.node_types = amu.node_types
|
|
45
|
-
self.label_types = amu.label_types
|
|
46
|
-
self.all_types = amu.all_types
|
|
47
|
-
|
|
48
|
-
def get_last_row(self, num_rows):
|
|
49
|
-
if self.last_row < 0:
|
|
50
|
-
last_row = num_rows
|
|
51
|
-
else:
|
|
52
|
-
last_row = min(num_rows, self.last_row)
|
|
53
|
-
return last_row
|
|
54
|
-
|
|
55
24
|
def process_node_file(self):
|
|
56
25
|
|
|
57
26
|
# For each line in the file, build a cypher query to MERGE a node
|
|
@@ -71,19 +40,19 @@ class NodeFileProcessor:
|
|
|
71
40
|
property_ref_dot = property_ref + '.'
|
|
72
41
|
|
|
73
42
|
while this_row < last_row:
|
|
74
|
-
|
|
43
|
+
csv_labels = self.contents.get_column_values_list(this_row, label_columns)
|
|
75
44
|
row_properties = self.contents.get_property_values_dict(this_row, property_columns, self.blank_property_list, blank_override=self.blank_property_override, allow_split=False)
|
|
76
45
|
properties = pm.combine_properties(self.required_properties, row_properties)
|
|
77
46
|
# Remove any properties we don't want
|
|
78
47
|
for unwanted in self.unrequired_properties:
|
|
79
|
-
|
|
48
|
+
properties.pop(amu.validate(unwanted), None)
|
|
80
49
|
|
|
81
50
|
# Split out those properties that are dependent on others, so that we can add them in the right order
|
|
82
51
|
explicit_properties, calculated_properties = pm.split_out_functional_properties(properties)
|
|
83
52
|
|
|
84
53
|
for primary_property in self.contents.get_property_values_list(this_row, node_columns, self.primary_property, allow_split=True, override_format='str'):
|
|
85
54
|
primary_property_dict = {primary_property.key: primary_property}
|
|
86
|
-
param_primary_props, param_explicit_props, param_calc_props = self.query_manager.parameterise_nodes(primary_property_dict, explicit_properties, calculated_properties, self.section)
|
|
55
|
+
param_primary_props, param_labels, param_explicit_props, param_calc_props = self.query_manager.parameterise_nodes(primary_property_dict, csv_labels, explicit_properties, calculated_properties, self.section)
|
|
87
56
|
|
|
88
57
|
# Parameterisaton may have converted an explicit property into a calculated one, so check and re-assign any that have
|
|
89
58
|
new_calc_props = pm.check_for_functional_properties(param_explicit_props)
|
|
@@ -100,25 +69,19 @@ class NodeFileProcessor:
|
|
|
100
69
|
merge_props = []
|
|
101
70
|
set_props = []
|
|
102
71
|
for props in param_properties:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
merge_props_item[prop] = props[0][prop]
|
|
108
|
-
else:
|
|
109
|
-
set_props_item[prop] = props[0][prop]
|
|
110
|
-
merge_props.append(merge_props_item)
|
|
111
|
-
if set_props_item:
|
|
112
|
-
set_props.append(set_props_item)
|
|
72
|
+
merge_props_items, set_props_items = super().split_properties(props[0])
|
|
73
|
+
merge_props.append(merge_props_items)
|
|
74
|
+
if set_props_items:
|
|
75
|
+
set_props.append(set_props_items)
|
|
113
76
|
|
|
114
77
|
time_now = amu.get_formatted_time_now()
|
|
115
|
-
merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels,
|
|
116
|
-
node_labels = lm.merge_node_labels(merge_labels, primary_property.labels)
|
|
78
|
+
merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels, param_labels)
|
|
79
|
+
node_labels = lm.merge_node_labels(merge_labels[0], primary_property.labels)
|
|
117
80
|
for prop_counter in range(len(param_primary_props)):
|
|
118
81
|
# Build a simple MERGE query using queries
|
|
119
82
|
query_text = (QueryBuilder()
|
|
120
83
|
.merge()
|
|
121
|
-
.node(labels=
|
|
84
|
+
.node(labels=lm.merge_node_labels(merge_labels[prop_counter], primary_property.labels), ref_name=property_ref, properties=param_primary_props[prop_counter] | merge_props[prop_counter])
|
|
122
85
|
)
|
|
123
86
|
|
|
124
87
|
# Add in System properties if required
|
|
@@ -130,12 +93,12 @@ class NodeFileProcessor:
|
|
|
130
93
|
property_ref_dot + self.update_time_property + '=datetime("' + time_now + '")'
|
|
131
94
|
query_text = query_text.on_create().set_literal(create_time).set_literal(update_id)
|
|
132
95
|
|
|
133
|
-
if len(remove_labels) > 0:
|
|
134
|
-
query_text = query_text.remove_literal(f'{property_ref}:{":".join(remove_labels)}')
|
|
96
|
+
if len(remove_labels[prop_counter]) > 0:
|
|
97
|
+
query_text = query_text.remove_literal(f'{property_ref}:{":".join(remove_labels[prop_counter])}')
|
|
135
98
|
|
|
136
99
|
query_text_param = query_text
|
|
137
|
-
if len(new_labels) > 0:
|
|
138
|
-
query_text_param = query_text.set_labels(ref_name=property_ref, labels=new_labels)
|
|
100
|
+
if len(new_labels[prop_counter]) > 0:
|
|
101
|
+
query_text_param = query_text.set_labels(ref_name=property_ref, labels=new_labels[prop_counter])
|
|
139
102
|
if len(set_props) > 0:
|
|
140
103
|
query_text_param = query_text_param.set(properties=set_props[prop_counter], property_ref=property_ref_dot)
|
|
141
104
|
param_calc = param_properties[min(prop_counter, num_param_properties-1)][1]
|
|
@@ -188,20 +151,20 @@ class NodeFileProcessor:
|
|
|
188
151
|
creation_property = property_ref_dot + self.creation_time_property
|
|
189
152
|
|
|
190
153
|
while this_row < last_row:
|
|
191
|
-
|
|
154
|
+
csv_labels = self.contents.get_column_values_list(this_row, label_columns)
|
|
192
155
|
row_properties = self.contents.get_property_values_dict(this_row, property_columns, self.blank_property_list, blank_override=self.blank_property_override, allow_split=False)
|
|
193
156
|
|
|
194
157
|
for primary_property in self.contents.get_property_values_list(this_row, node_columns, self.primary_property, allow_split=True, override_format='str'):
|
|
195
|
-
merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels, validated_csv_labels)
|
|
196
|
-
node_labels = lm.merge_node_labels(merge_labels, primary_property.labels)
|
|
197
158
|
properties = pm.combine_properties(self.required_properties, row_properties)
|
|
198
159
|
# Remove any properties we don't want
|
|
199
160
|
for unwanted in self.unrequired_properties:
|
|
200
|
-
|
|
161
|
+
properties.pop(amu.validate(unwanted), None)
|
|
201
162
|
|
|
202
163
|
explicit_properties, calculated_properties = pm.split_out_functional_properties(properties)
|
|
203
164
|
primary_property_dict = {primary_property.key: primary_property}
|
|
204
|
-
param_primary_props, param_explicit_props, param_calc_props = self.query_manager.parameterise_nodes(primary_property_dict, explicit_properties, calculated_properties, self.section)
|
|
165
|
+
param_primary_props, param_labels, param_explicit_props, param_calc_props = self.query_manager.parameterise_nodes(primary_property_dict, csv_labels, explicit_properties, calculated_properties, self.section)
|
|
166
|
+
merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels, param_labels)
|
|
167
|
+
node_labels = lm.merge_node_labels(merge_labels[0], primary_property.labels)
|
|
205
168
|
|
|
206
169
|
# Parameterisaton may have converted an explicit property into a calculated one, so check and re-assign any that have
|
|
207
170
|
new_calc_props = pm.check_for_functional_properties(param_explicit_props)
|
|
@@ -209,7 +172,6 @@ class NodeFileProcessor:
|
|
|
209
172
|
for prop in new_calc_props[count]:
|
|
210
173
|
param_explicit_props[count].pop(prop.key)
|
|
211
174
|
param_calc_props[count][prop.key] = prop
|
|
212
|
-
query_data_list = []
|
|
213
175
|
|
|
214
176
|
merge_props = []
|
|
215
177
|
for props in param_explicit_props:
|
|
@@ -220,20 +182,20 @@ class NodeFileProcessor:
|
|
|
220
182
|
merge_props.append(merge_props_item)
|
|
221
183
|
|
|
222
184
|
for node_count in range(len(param_primary_props)):
|
|
223
|
-
query_data_list
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
185
|
+
query_data_list = [[pm.combine_properties(param_explicit_props[min(node_count, len(param_explicit_props)-1)], param_primary_props[node_count]), param_calc_props[min(node_count, len(param_calc_props)-1)], merge_props[0], time_now]]
|
|
186
|
+
|
|
187
|
+
# So now we know all about this particular update. Let's put it in the query dictionary
|
|
188
|
+
# We'll group these by unique combinations of labels and primary key type
|
|
189
|
+
# Have to use a list since a dictionary key can't be a dictionary
|
|
190
|
+
dictionary_key = [new_labels[node_count], node_labels, remove_labels[node_count], [primary_property.key], calculated_properties.keys(), merge_props[0]]
|
|
191
|
+
try:
|
|
192
|
+
dictionary_index = batch_keys.index(dictionary_key)
|
|
193
|
+
query_dictionary[dictionary_index] += query_data_list
|
|
194
|
+
except:
|
|
195
|
+
dictionary_index = len(batch_keys)
|
|
196
|
+
query_dictionary[dictionary_index] = query_data_list
|
|
197
|
+
batch_keys.append(dictionary_key)
|
|
198
|
+
dict_size += len(query_data_list)
|
|
237
199
|
|
|
238
200
|
this_row += 1
|
|
239
201
|
messages.message_no_cr(f'Analysing file... {100 * (this_row - self.start_from + 1) / num_rows:.0f}%{chr(13)}')
|
|
@@ -312,12 +274,3 @@ class NodeFileProcessor:
|
|
|
312
274
|
|
|
313
275
|
messages.message('', False)
|
|
314
276
|
return queries
|
|
315
|
-
|
|
316
|
-
def get_filename(self):
|
|
317
|
-
return self.filename
|
|
318
|
-
|
|
319
|
-
def get_section(self):
|
|
320
|
-
return self.section
|
|
321
|
-
|
|
322
|
-
def is_inline_query(self):
|
|
323
|
-
return False
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from processors.fileprocessors import FileProcessor
|
|
1
2
|
import messages
|
|
2
3
|
from queries.cypherbuilder import QueryBuilder
|
|
3
4
|
import assetmodelutilities as amu
|
|
@@ -10,18 +11,11 @@ from property import Neo4jProperty
|
|
|
10
11
|
import copy
|
|
11
12
|
|
|
12
13
|
|
|
13
|
-
class RelationshipFileProcessor:
|
|
14
|
+
class RelationshipFileProcessor(FileProcessor):
|
|
14
15
|
|
|
15
16
|
def __init__(self, filename, config, contents, section, query_manager):
|
|
16
|
-
|
|
17
|
-
self.contents = contents
|
|
18
|
-
self.section = section
|
|
19
|
-
self.query_manager = query_manager
|
|
17
|
+
super().__init__(filename, config, contents, section, query_manager)
|
|
20
18
|
|
|
21
|
-
self.primary_property = config.get_primary_property()[section]
|
|
22
|
-
self.add_system_properties = not config.get_no_system_properties()
|
|
23
|
-
|
|
24
|
-
self.required_labels = config.get_required_labels()[section]
|
|
25
19
|
self.required_properties = config.get_required_relationship_properties_dict()[section]
|
|
26
20
|
self.unrequired_properties = config.get_unrequired_relationship_properties_list()[section]
|
|
27
21
|
self.required_relationships = config.get_required_relationships_dict()[section]
|
|
@@ -30,8 +24,6 @@ class RelationshipFileProcessor:
|
|
|
30
24
|
self.to_property = config.get_to_properties_list()[section] or self.primary_property
|
|
31
25
|
self.from_required_labels = lm.validate_labels_to_list(config.get_from_required_labels_list()[section])
|
|
32
26
|
self.to_required_labels = lm.validate_labels_to_list(config.get_to_required_labels_list()[section])
|
|
33
|
-
self.creation_time_property = config.get_creation_time_property()[section]
|
|
34
|
-
self.update_time_property = config.get_update_time_property()[section]
|
|
35
27
|
|
|
36
28
|
self.from_node_alias = config.get_from_alias()[section]
|
|
37
29
|
self.from_label_alias = config.get_from_label_alias()[section]
|
|
@@ -39,27 +31,11 @@ class RelationshipFileProcessor:
|
|
|
39
31
|
self.to_label_alias = config.get_to_label_alias()[section]
|
|
40
32
|
self.relationship_alias = config.get_relationship_alias()[section]
|
|
41
33
|
|
|
42
|
-
self.validate_only = config.in_validation_mode()
|
|
43
|
-
self.summarise = config.in_summary_mode()
|
|
44
|
-
|
|
45
|
-
self.blank_property_override = config.get_blank_property_override()
|
|
46
|
-
self.blank_property_list = config.get_blank_property_list()
|
|
47
|
-
self.batch_rate = config.get_batch_rate()
|
|
48
|
-
self.start_from = config.get_start_from()
|
|
49
|
-
self.last_row = config.get_end_at()
|
|
50
|
-
|
|
51
34
|
self.from_types = amu.from_types
|
|
52
35
|
self.to_types = amu.to_types
|
|
53
36
|
self.relation_types = amu.relation_types
|
|
54
37
|
self.all_types = amu.all_types
|
|
55
38
|
|
|
56
|
-
def get_last_row(self, num_rows):
|
|
57
|
-
if self.last_row < 0:
|
|
58
|
-
last_row = num_rows
|
|
59
|
-
else:
|
|
60
|
-
last_row = min(num_rows, self.last_row)
|
|
61
|
-
return last_row
|
|
62
|
-
|
|
63
39
|
def process_relationship_file(self):
|
|
64
40
|
|
|
65
41
|
# For each line in the file, build a cypher query to MERGE a relationship
|
|
@@ -86,26 +62,26 @@ class RelationshipFileProcessor:
|
|
|
86
62
|
while this_row < last_row:
|
|
87
63
|
|
|
88
64
|
combined_relationships = {**self.required_relationships, **self.contents.get_column_values_dict(this_row, relation_columns)}
|
|
89
|
-
relationships =
|
|
90
|
-
|
|
65
|
+
relationships = [r.strip() for entry in combined_relationships.values() for rel in entry.split(':') for r in rel.split(',') if r]
|
|
66
|
+
param_relationships = self.query_manager.parameterise_relationship(relationships, self.section)
|
|
91
67
|
row_properties = self.contents.get_property_values_dict(this_row, property_columns, self.blank_property_list, blank_override=self.blank_property_override)
|
|
92
68
|
properties = pm.combine_properties(self.required_properties, row_properties)
|
|
93
69
|
for unwanted in self.unrequired_properties:
|
|
94
|
-
|
|
70
|
+
properties.pop(amu.validate(unwanted), None)
|
|
95
71
|
|
|
96
72
|
# Split out those properties that are dependent on others, so that we can add them in the right order
|
|
97
73
|
explicit_properties, calculated_properties = pm.split_out_functional_properties(properties)
|
|
98
74
|
# If there are multiple From or To nodes, create a relationship query for each combination
|
|
99
75
|
for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.from_property, override_format='str'):
|
|
100
|
-
|
|
101
|
-
from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels,
|
|
76
|
+
csv_from_labels = self.contents.get_column_values_list(this_row, from_label_columns)
|
|
77
|
+
from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels, csv_from_labels)
|
|
102
78
|
from_node_labels = lm.merge_node_labels(from_labels, from_node.labels)
|
|
103
79
|
for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.to_property, override_format='str'):
|
|
104
|
-
|
|
105
|
-
to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels,
|
|
80
|
+
csv_to_labels = self.contents.get_column_values_list(this_row, to_label_columns)
|
|
81
|
+
to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels, csv_to_labels)
|
|
106
82
|
to_node_labels = lm.merge_node_labels(to_labels, to_node.labels)
|
|
107
83
|
|
|
108
|
-
param_from_nodes, param_to_nodes, param_explicit_props, param_calc_props = self.query_manager.parameterise_relationships({'from_node': from_node}, {'to_node': to_node}, explicit_properties, calculated_properties, self.section)
|
|
84
|
+
param_from_nodes, param_to_nodes, param_from_labels, param_to_labels, param_explicit_props, param_calc_props = self.query_manager.parameterise_relationships({'from_node': from_node}, {'to_node': to_node}, from_node_labels, to_node_labels, explicit_properties, calculated_properties, self.section)
|
|
109
85
|
|
|
110
86
|
new_calc_props = pm.check_for_functional_properties(param_explicit_props)
|
|
111
87
|
for count in range(len(new_calc_props)):
|
|
@@ -114,50 +90,39 @@ class RelationshipFileProcessor:
|
|
|
114
90
|
param_calc_props[count][prop.key] = prop
|
|
115
91
|
|
|
116
92
|
# Build a MERGE query for the relationship(s)
|
|
117
|
-
for relationship in
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if len(set_props) > 0:
|
|
152
|
-
query_text = query_text.set(properties=set_props, property_ref=relation_ref_dot)
|
|
153
|
-
if len(calculated_properties) > 0:
|
|
154
|
-
query_text = query_text.set(properties=props[3], property_ref=relation_ref_dot)
|
|
155
|
-
|
|
156
|
-
query_text = query_text.toStr()
|
|
157
|
-
query = Neo4jQuery('relationship', query_text, time_now)
|
|
158
|
-
if self.validate_only and not self.summarise:
|
|
159
|
-
print(query_text)
|
|
160
|
-
queries.append(query)
|
|
93
|
+
for relationship in param_relationships:
|
|
94
|
+
|
|
95
|
+
time_now = amu.get_formatted_time_now()
|
|
96
|
+
for from_nodes, to_nodes, from_labels, to_labels, explicit_props, calc_props in zip(param_from_nodes, param_to_nodes, param_from_labels, param_to_labels, param_explicit_props, param_calc_props):
|
|
97
|
+
merge_props, set_props = self.split_properties(explicit_props)
|
|
98
|
+
|
|
99
|
+
query_text = (QueryBuilder()
|
|
100
|
+
.match()
|
|
101
|
+
.node(labels=lm.merge_node_labels([from_labels], []), ref_name=from_ref, properties=from_nodes)
|
|
102
|
+
.match()
|
|
103
|
+
.node(labels=lm.merge_node_labels([to_labels], []), ref_name=to_ref, properties=to_nodes)
|
|
104
|
+
.merge()
|
|
105
|
+
.node(ref_name=from_ref)
|
|
106
|
+
.related_to(label=relationship, ref_name=relation_ref, properties=merge_props, comparison_operator=":")
|
|
107
|
+
.node(ref_name=to_ref)
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
# Add in System properties
|
|
111
|
+
if self.add_system_properties:
|
|
112
|
+
create_time = relation_ref_dot + self.creation_time_property + '=datetime("' + time_now + '")'
|
|
113
|
+
update_time = relation_ref_dot + self.update_time_property + '=datetime("' + time_now + '")'
|
|
114
|
+
query_text = query_text.on_create().set_literal(create_time).set_literal(update_time)
|
|
115
|
+
|
|
116
|
+
if len(set_props) > 0:
|
|
117
|
+
query_text = query_text.set(properties=set_props, property_ref=relation_ref_dot)
|
|
118
|
+
if len(calculated_properties) > 0:
|
|
119
|
+
query_text = query_text.set(properties=calc_props, property_ref=relation_ref_dot)
|
|
120
|
+
|
|
121
|
+
query_text = query_text.toStr()
|
|
122
|
+
query = Neo4jQuery('relationship', query_text, time_now)
|
|
123
|
+
if self.validate_only and not self.summarise:
|
|
124
|
+
print(query_text)
|
|
125
|
+
queries.append(query)
|
|
161
126
|
|
|
162
127
|
this_row += 1
|
|
163
128
|
messages.message_no_cr(f'Generating queries... {100 * (this_row - self.start_from + 1) / num_rows:.0f}%{chr(13)}')
|
|
@@ -204,69 +169,69 @@ class RelationshipFileProcessor:
|
|
|
204
169
|
while this_row < last_row:
|
|
205
170
|
|
|
206
171
|
combined_relationships = {**self.required_relationships, **self.contents.get_column_values_dict(this_row, relation_columns)}
|
|
207
|
-
relationships =
|
|
208
|
-
|
|
172
|
+
relationships = [r.strip() for entry in combined_relationships.values() for rel in entry.split(':') for r in rel.split(',') if r]
|
|
173
|
+
param_relationships = self.query_manager.parameterise_relationship(relationships, self.section)
|
|
209
174
|
row_properties = self.contents.get_property_values_dict(this_row, property_columns, self.blank_property_list, blank_override=self.blank_property_override)
|
|
210
175
|
properties = pm.combine_properties(self.required_properties, row_properties)
|
|
211
176
|
for unwanted in self.unrequired_properties:
|
|
212
|
-
|
|
177
|
+
properties.pop(amu.validate(unwanted), None)
|
|
213
178
|
|
|
214
179
|
# If there are multiple From or To nodes, create a relationship query for each combination
|
|
215
180
|
for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.from_property, override_format='str'):
|
|
216
|
-
|
|
217
|
-
from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels,
|
|
181
|
+
csv_from_labels = self.contents.get_column_values_list(this_row, from_label_columns)
|
|
182
|
+
from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels, csv_from_labels)
|
|
218
183
|
from_node_labels = lm.merge_node_labels(from_labels, from_node.labels)
|
|
219
184
|
for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.to_property, override_format='str'):
|
|
220
|
-
|
|
221
|
-
to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels,
|
|
185
|
+
csv_to_labels = self.contents.get_column_values_list(this_row, to_label_columns)
|
|
186
|
+
to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels, csv_to_labels)
|
|
222
187
|
to_node_labels = lm.merge_node_labels(to_labels, to_node.labels)
|
|
223
188
|
|
|
224
189
|
# Build a MERGE query for the relationship(s)
|
|
225
|
-
for relationship in
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
190
|
+
for relationship in param_relationships:
|
|
191
|
+
|
|
192
|
+
explicit_properties, calculated_properties = pm.split_out_functional_properties(properties)
|
|
193
|
+
|
|
194
|
+
param_from_nodes, param_to_nodes, param_from_labels, param_to_labels, param_explicit_props, param_calc_props = self.query_manager.parameterise_relationships({'from_node': from_node}, {'to_node': to_node}, from_node_labels, to_node_labels, explicit_properties, calculated_properties, self.section)
|
|
195
|
+
new_calc_props = pm.check_for_functional_properties(param_explicit_props)
|
|
196
|
+
merge_props = []
|
|
197
|
+
set_props = []
|
|
198
|
+
for count in range(len(new_calc_props)):
|
|
199
|
+
merge_props_item = {}
|
|
200
|
+
set_props_item = {}
|
|
201
|
+
for prop in new_calc_props[count]:
|
|
202
|
+
param_explicit_props[count].pop(prop.key)
|
|
203
|
+
param_calc_props[count][prop.key] = prop
|
|
204
|
+
|
|
205
|
+
for prop in param_explicit_props[count]:
|
|
206
|
+
if prop in self.merge_properties:
|
|
207
|
+
merge_props_item[prop] = param_explicit_props[count][prop]
|
|
208
|
+
else:
|
|
209
|
+
set_props_item[prop] = param_explicit_props[count][prop]
|
|
210
|
+
merge_props.append(merge_props_item)
|
|
211
|
+
set_props.append(set_props_item)
|
|
212
|
+
|
|
213
|
+
new_labels_list = []
|
|
214
|
+
query_data_list = []
|
|
215
|
+
|
|
216
|
+
for count in range(len(param_from_nodes)):
|
|
217
|
+
from_labels = lm.merge_node_labels([param_from_labels[count]], [])
|
|
218
|
+
to_labels = lm.merge_node_labels([param_to_labels[count]], [])
|
|
219
|
+
merge_properties = {k: v.value for k, v in merge_props[count].items()}
|
|
220
|
+
new_labels_list += [[from_labels, to_labels, relationship, from_node.key, to_node.key, merge_properties, param_calc_props[count]]]
|
|
221
|
+
query_data_list += [[param_from_nodes[count]['from_node'].value.replace('\\\\n', '\n'), param_to_nodes[count]['to_node'].value.replace('\\\\n', '\n'), merge_props[count], set_props[count], param_calc_props[count], time_now]]
|
|
222
|
+
|
|
223
|
+
# So now we know all about this particular update. Let's put it in the query dictionary
|
|
224
|
+
q_count = 0
|
|
225
|
+
for count in range(len(new_labels_list)):
|
|
226
|
+
q_count += 1
|
|
227
|
+
try:
|
|
228
|
+
dictionary_index = batch_keys.index(new_labels_list[count])
|
|
229
|
+
query_dictionary[dictionary_index] += [query_data_list[count]]
|
|
230
|
+
except:
|
|
231
|
+
dictionary_index = len(batch_keys)
|
|
232
|
+
query_dictionary[dictionary_index] = [query_data_list[count]]
|
|
233
|
+
batch_keys.append(new_labels_list[count])
|
|
234
|
+
dict_size += len([query_data_list[count]])
|
|
270
235
|
|
|
271
236
|
this_row += 1
|
|
272
237
|
messages.message_no_cr(f'Analysing file... {100 * (this_row - self.start_from + 1) / num_rows:.0f}%{chr(13)}')
|
|
@@ -355,12 +320,3 @@ class RelationshipFileProcessor:
|
|
|
355
320
|
|
|
356
321
|
messages.message('', False)
|
|
357
322
|
return queries
|
|
358
|
-
|
|
359
|
-
def get_filename(self):
|
|
360
|
-
return self.filename
|
|
361
|
-
|
|
362
|
-
def get_section(self):
|
|
363
|
-
return self.section
|
|
364
|
-
|
|
365
|
-
def is_inline_query(self):
|
|
366
|
-
return False
|