python-eigen-ingenuity 0.5.29b1__py3-none-any.whl → 0.5.30b2__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.
@@ -134,20 +134,33 @@ class CSVContentsManager:
134
134
  def get_property_values_dict(self, row_number, column_numbers, allow_blank_property_list, default_key='', prefix='', blank_override='', allow_split=True):
135
135
  this_row = self.data_list[row_number]
136
136
  if allow_split:
137
- split_values = [this_row[column].split('::') for column in column_numbers]
137
+ split_values = [this_row[column].split('::', 2) for column in column_numbers]
138
138
  else:
139
139
  split_values = [[this_row[column]] for column in column_numbers]
140
140
  split_keys = [(value[0] + ':').split(':') for value in split_values]
141
141
  this_list = {prefix + (self.mapped_keys[column] or default_key): Neo4jProperty(prefix + (self.mapped_keys[column] or default_key), this_row[column], self.formats[column], blank_override=blank_override) if len(split_values[count]) == 1 else {prefix + (split_keys[count][0] or default_key): Neo4jProperty(prefix + (split_keys[count][0] or default_key), split_values[count][1], split_keys[count][1] or self.formats[column], blank_override=blank_override)} for count, column in enumerate(column_numbers) if this_row[column] or self.mapped_keys[column] in allow_blank_property_list or allow_blank_property_list == []}
142
142
  return this_list
143
143
 
144
+ def parse_property_value_with_labels(self, raw_value, default_key, override_key, format_value):
145
+ match_labels = ''
146
+ value_parts = raw_value.split('$$', 1)
147
+ value = value_parts[0]
148
+ if len(value_parts) > 1:
149
+ match_labels = value_parts[1]
150
+
151
+ if '::' in value:
152
+ key_value_parts = value.split('::', 1)
153
+ key = key_value_parts[0] or default_key
154
+ value = key_value_parts[1]
155
+ else:
156
+ key = override_key or default_key
157
+
158
+ return Neo4jProperty(key, value, format_value, match_labels=match_labels)
159
+
144
160
  def get_property_values_list(self, row_number, column_numbers, default_key='', override_key='', allow_split=True, override_format=None):
145
161
  this_row = self.data_list[row_number]
146
162
  if allow_split:
147
- split_values = [this_row[column].split('::') for column in column_numbers]
163
+ this_list = [self.parse_property_value_with_labels(this_row[column], self.mapped_keys[column] or default_key, override_key or self.mapped_keys[column] if self.types[column] == '' else self.mapped_keys[column] or default_key, override_format or self.formats[column]) for column in column_numbers if this_row[column]]
148
164
  else:
149
- split_values = [[this_row[column]] for column in column_numbers]
150
- split_keys = [(value[0]+':').split(':') for value in split_values]
151
- these_keys = [override_key or self.mapped_keys[column] if self.types[column] == '' else self.mapped_keys[column] or default_key for column in column_numbers]
152
- this_list = [Neo4jProperty(these_keys[count], this_row[column], override_format or self.formats[column]) if len(split_values[count]) == 1 else Neo4jProperty(split_values[count][0] or default_key, split_values[count][1], override_format or split_keys[count][1] or self.formats[column]) for count, column in enumerate(column_numbers) if this_row[column]]
165
+ this_list = [Neo4jProperty(override_key or self.mapped_keys[column] if self.types[column] == '' else self.mapped_keys[column] or default_key, this_row[column], override_format or self.formats[column]) for column in column_numbers if this_row[column]]
153
166
  return this_list
@@ -50,6 +50,16 @@ class NodeFileProcessor:
50
50
  last_row = min(num_rows, self.last_row)
51
51
  return last_row
52
52
 
53
+ def get_inline_merge_labels(self, label_string):
54
+ # For node MERGE, only colon-separated labels are directly supported.
55
+ # OR expressions (label1|label2) are ignored here because MERGE cannot express label OR.
56
+ if not label_string:
57
+ return []
58
+ if '|' in label_string:
59
+ messages.warning_message('Unsupported inline node label expression: ', f'{label_string} (ignoring OR labels for MERGE)')
60
+ return []
61
+ return lm.validate_label_string_to_list(label_string)
62
+
53
63
  def process_node_file(self):
54
64
 
55
65
  # For each line in the file, build a cypher query to MERGE a node
@@ -70,7 +80,6 @@ class NodeFileProcessor:
70
80
 
71
81
  while this_row < last_row:
72
82
  validated_csv_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, label_columns))
73
- merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels, validated_csv_labels)
74
83
  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)
75
84
  properties = pm.combine_properties(self.required_properties, row_properties)
76
85
  # Remove any properties we don't want
@@ -82,6 +91,8 @@ class NodeFileProcessor:
82
91
 
83
92
  for primary_property in self.contents.get_property_values_list(this_row, node_columns, self.primary_property, allow_split=True, override_format='str'):
84
93
  time_now = amu.get_formatted_time_now()
94
+ inline_merge_labels = self.get_inline_merge_labels(primary_property.match_labels)
95
+ merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels, validated_csv_labels + inline_merge_labels)
85
96
 
86
97
  # Build a simple MERGE query using queries
87
98
  query_text = (QueryBuilder()
@@ -156,10 +167,11 @@ class NodeFileProcessor:
156
167
 
157
168
  while this_row < last_row:
158
169
  validated_csv_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, label_columns))
159
- merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels, validated_csv_labels)
160
170
  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)
161
171
 
162
172
  for primary_property in self.contents.get_property_values_list(this_row, node_columns, self.primary_property, allow_split=True, override_format='str'):
173
+ inline_merge_labels = self.get_inline_merge_labels(primary_property.match_labels)
174
+ merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels, validated_csv_labels + inline_merge_labels)
163
175
  properties = pm.combine_properties(self.required_properties, row_properties)
164
176
  # Remove any properties we don't want
165
177
  for unwanted in self.unrequired_properties:
@@ -58,6 +58,45 @@ class RelationshipFileProcessor:
58
58
  last_row = min(num_rows, self.last_row)
59
59
  return last_row
60
60
 
61
+ def get_inline_match_labels(self, node_ref, label_string):
62
+ # Supports:
63
+ # label1 -> node_ref:label1
64
+ # label1:label2 -> node_ref:label1 AND node_ref:label2
65
+ # label1|label2 -> node_ref:label1 OR node_ref:label2
66
+ # label1:label2|label3 -> (node_ref:label1 AND node_ref:label2) OR node_ref:label3
67
+ if not label_string:
68
+ return [], ''
69
+
70
+ # Grouped expression support:
71
+ # prefix:(a|b) -> required label 'prefix' + WHERE (node_ref:a OR node_ref:b)
72
+ # prefix1:prefix2:(a|b) -> required labels 'prefix1' and 'prefix2' + grouped OR
73
+ if label_string.endswith(')') and ':(' in label_string:
74
+ prefix, grouped = label_string.rsplit(':(', 1)
75
+ grouped = grouped[:-1]
76
+ if grouped and '|' in grouped:
77
+ required_labels = lm.validate_label_string_to_list(prefix)
78
+ option_literals = []
79
+ for option in grouped.split('|'):
80
+ these_labels = lm.validate_label_string_to_list(option)
81
+ if these_labels:
82
+ option_literals.append('(' + ' AND '.join([f'{node_ref}:{label}' for label in these_labels]) + ')')
83
+ if option_literals:
84
+ return required_labels, '(' + ' OR '.join(option_literals) + ')'
85
+
86
+ if '|' not in label_string:
87
+ return lm.validate_label_string_to_list(label_string), ''
88
+
89
+ option_literals = []
90
+ for option in label_string.split('|'):
91
+ these_labels = lm.validate_label_string_to_list(option)
92
+ if these_labels:
93
+ option_literals.append('(' + ' AND '.join([f'{node_ref}:{label}' for label in these_labels]) + ')')
94
+
95
+ if not option_literals:
96
+ return [], ''
97
+
98
+ return [], '(' + ' OR '.join(option_literals) + ')'
99
+
61
100
  def process_relationship_file(self):
62
101
 
63
102
  # For each line in the file, build a cypher query to MERGE a relationship
@@ -97,10 +136,12 @@ class RelationshipFileProcessor:
97
136
  # If there are multiple From or To nodes, create a relationship query for each combination
98
137
  for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.from_property, override_format='str'):
99
138
  validated_csv_from_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, from_label_columns))
100
- from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels, validated_csv_from_labels)
139
+ inline_from_labels, inline_from_where = self.get_inline_match_labels(from_ref, from_node.match_labels)
140
+ from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels, validated_csv_from_labels + inline_from_labels)
101
141
  for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.to_property, override_format='str'):
102
142
  validated_csv_to_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, to_label_columns))
103
- to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels, validated_csv_to_labels)
143
+ inline_to_labels, inline_to_where = self.get_inline_match_labels(to_ref, to_node.match_labels)
144
+ to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels, validated_csv_to_labels + inline_to_labels)
104
145
 
105
146
  # Build a MERGE query for the relationship(s)
106
147
  for relationship in relationships:
@@ -113,6 +154,13 @@ class RelationshipFileProcessor:
113
154
  .node(labels=from_labels, ref_name=from_ref, properties=from_node)
114
155
  .match()
115
156
  .node(labels=to_labels, ref_name=to_ref, properties=to_node)
157
+ )
158
+
159
+ where_literals = [i for i in [inline_from_where, inline_to_where] if i]
160
+ if where_literals:
161
+ query_text = query_text.where_literal(' AND '.join(where_literals))
162
+
163
+ query_text = (query_text
116
164
  .merge()
117
165
  .node(ref_name=from_ref)
118
166
  .related_to(label=relation, ref_name=relation_ref)
@@ -195,10 +243,12 @@ class RelationshipFileProcessor:
195
243
  # If there are multiple From or To nodes, create a relationship query for each combination
196
244
  for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.from_property, override_format='str'):
197
245
  validated_csv_from_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, from_label_columns))
198
- from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels, validated_csv_from_labels)
246
+ inline_from_labels, inline_from_where = self.get_inline_match_labels(from_ref, from_node.match_labels)
247
+ from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels, validated_csv_from_labels + inline_from_labels)
199
248
  for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.to_property, override_format='str'):
200
249
  validated_csv_to_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, to_label_columns))
201
- to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels, validated_csv_to_labels)
250
+ inline_to_labels, inline_to_where = self.get_inline_match_labels(to_ref, to_node.match_labels)
251
+ to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels, validated_csv_to_labels + inline_to_labels)
202
252
 
203
253
  # Build a MERGE query for the relationship(s)
204
254
  for relationship in relationships:
@@ -214,7 +264,7 @@ class RelationshipFileProcessor:
214
264
 
215
265
  query_data_list = []
216
266
  for count in range(max(len(param_from_nodes), len(param_to_nodes), len(param_explicit_props), len(param_calc_props))):
217
- new_labels_list = [[from_labels, to_labels, relation, from_node.key, to_node.key, param_calc_props[min(count, len(param_calc_props) - 1)]]]
267
+ new_labels_list = [[from_labels, to_labels, relation, from_node.key, to_node.key, inline_from_where, inline_to_where, param_calc_props[min(count, len(param_calc_props) - 1)]]]
218
268
  query_data_list += [[param_from_nodes[min(count, len(param_from_nodes) - 1)].value.replace('\\\\n', '\n'), param_to_nodes[min(count, len(param_to_nodes) - 1)].value.replace('\\\\n', '\n'), param_explicit_props[min(count, len(param_explicit_props) - 1)], param_calc_props[min(count, len(param_calc_props) - 1)], time_now]]
219
269
 
220
270
  # So now we know all about this particular update. Let's put it in the query dictionary
@@ -245,6 +295,8 @@ class RelationshipFileProcessor:
245
295
  relationship = batch_keys[from_to_labels][2]
246
296
  from_node = batch_keys[from_to_labels][3]
247
297
  to_node = batch_keys[from_to_labels][4]
298
+ from_where = batch_keys[from_to_labels][5]
299
+ to_where = batch_keys[from_to_labels][6]
248
300
  batch_num = 1
249
301
  while batch_num <= num_batches:
250
302
  if batch_num == num_batches:
@@ -285,6 +337,13 @@ class RelationshipFileProcessor:
285
337
  .node(labels=from_labels, ref_name=from_ref, properties_literal=from_keys)
286
338
  .match()
287
339
  .node(labels=to_labels, ref_name=to_ref, properties_literal=to_keys)
340
+ )
341
+
342
+ where_literals = [i for i in [from_where, to_where] if i]
343
+ if where_literals:
344
+ query_text = query_text.where_literal(' AND '.join(where_literals))
345
+
346
+ query_text = (query_text
288
347
  .merge()
289
348
  .node(ref_name=from_ref)
290
349
  .related_to(label=relationship, ref_name=relation_ref)
@@ -6,7 +6,7 @@ from querymanager import QueryManager
6
6
 
7
7
  class Neo4jProperty():
8
8
 
9
- def __init__(self, key, value = None, format = None, type = None, blank_override = False):
9
+ def __init__(self, key, value = None, format = None, type = None, blank_override = False, match_labels=''):
10
10
 
11
11
  self.key = pm.validate_property(key)
12
12
  # Sanitise the value
@@ -20,6 +20,8 @@ class Neo4jProperty():
20
20
  self.format = format
21
21
  # type is the kind of thing this is, such as ID, START_ID etc. See assetmodelutilities.py for the full list
22
22
  self.type = type
23
+ # Optional inline label selector used when matching nodes from csv values such as key::value::labelA|labelB
24
+ self.match_labels = match_labels
23
25
 
24
26
  # We'll format the value the first time someone wants it, so say it's not formatted yet
25
27
  self.formatted_values = {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-eigen-ingenuity
3
- Version: 0.5.29b1
3
+ Version: 0.5.30b2
4
4
  Summary: A python library used to query data from the Eigen Ingenuity system
5
5
  Home-page: https://www.eigen.co/
6
6
  Author: Murray Callander
@@ -41,12 +41,12 @@ modelbuilder/src/assetmodelbuilder.py,sha256=92Yu9CvmObPYDdqCpn8eBCaZ_KGBhm307Ys
41
41
  modelbuilder/src/assetmodelcsvwriter.py,sha256=GKNi_fw7AlY-UG2XhwFIS34Ff3XiVRss-o5MUzyJSV0,1071
42
42
  modelbuilder/src/assetmodelutilities.py,sha256=S_q5F7mVulk13zCeC1A8cLkJDXj_BR5_yFi3vTw3xUQ,1746
43
43
  modelbuilder/src/configmanager.py,sha256=PbqzYwav6rAm-3Wd8JegYuEEY44iugC_IQ45abUkGbI,30789
44
- modelbuilder/src/csvcontentsmanager.py,sha256=rVJmR6cPZMS851GeCsRgKzY7b6E_wdbM24rvS0c2feA,7838
44
+ modelbuilder/src/csvcontentsmanager.py,sha256=25JbbbmgnebAkjr_RvItBBZXK8Cq66a4Lcea9bWqcdk,8258
45
45
  modelbuilder/src/csvwriter.py,sha256=2Xc6kdV6cYwCjrVF6WaZfS6tVp8-oc0ksIHSOx6iqj8,14132
46
46
  modelbuilder/src/fileanalyser.py,sha256=L7x44NmOaD0spXO9GLAWrGTp-npM8T0xCqCYesMGHgU,4301
47
47
  modelbuilder/src/filemanager.py,sha256=nfRQlW-AIp8ICu1CO0MO55OyWMWDQJrW4Z8yRRhBs-k,26454
48
48
  modelbuilder/src/messages.py,sha256=6JnW-ke6nHGUA4hTEBvo_kVlNJTXoV4LWw8mNwMpBCQ,1325
49
- modelbuilder/src/property.py,sha256=MQ2jY3EKvPAIF-bWKrkrXj55I3AW1eujAnY4pkw_4IE,11441
49
+ modelbuilder/src/property.py,sha256=W67yx-vourlFDTsAcSgJOOlb4Q0exZFWf3gbNP2blJI,11615
50
50
  modelbuilder/src/querymanager.py,sha256=Wr0LcY7iCwmLyeSx8LcdbQT2xt1viltp6XFvP3Bg5v8,3270
51
51
  modelbuilder/src/versionmanager.py,sha256=B8mrYY5Der0sWi1GQjduyVGZ6BuAb6rTNVAZzQlP4k4,19148
52
52
  modelbuilder/src/connectors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -57,9 +57,9 @@ modelbuilder/src/connectors/httpsconnector.py,sha256=DOZyxRW3JQcaiaYtnx0_Jq2dBEh
57
57
  modelbuilder/src/processors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
58
  modelbuilder/src/processors/cypherfileprocessor.py,sha256=EmaLsBhC6gWQwvhyY7Ks2HEbGEzDoGAZfu2nBkh2hOs,2941
59
59
  modelbuilder/src/processors/labelmanager.py,sha256=b2xkIqMd2hptplm5Sp10zoc7LGOKTVZH2jDKN7brvYU,6619
60
- modelbuilder/src/processors/nodefileprocessor.py,sha256=-9vH1trZuYY6OFxfABCimJ2eEKCwGUnby-1ExDraQug,14561
60
+ modelbuilder/src/processors/nodefileprocessor.py,sha256=8D93Yy9HsOGMtbOnsodjgqGLGkoI0AC31PdxamnDjqA,15338
61
61
  modelbuilder/src/processors/propertymanager.py,sha256=zLr8S0HPZMXeUp1RUzVXWyNa64MxLufXrOqh5uL1mwU,6978
62
- modelbuilder/src/processors/relationshipfileprocessor.py,sha256=1osOMAaSKkVZTDZlk_XiZQyp8mGPAsmWgCMYm59ccdo,19143
62
+ modelbuilder/src/processors/relationshipfileprocessor.py,sha256=OvY5Lp0RcH9MhCCErCaAKZECwMeFH5tiFF8Y9XrdakQ,22342
63
63
  modelbuilder/src/processors/relationshipmanager.py,sha256=lDtE_5AdKzL3boq7VD8Gmpai8Uscq79vRxkzYQL8A9A,1105
64
64
  modelbuilder/src/queries/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
65
65
  modelbuilder/src/queries/cypherbuilder.py,sha256=VpUGuPo-Ba3skjCVBFjmxm4ORQBGgF5cDiQYnK67hLA,10418
@@ -88,8 +88,8 @@ regressiontests/eigeningenuity/historian-multi/test_getRawDatapoints.py,sha256=f
88
88
  regressiontests/eigeningenuity/historian-multi/test_listDataTags.py,sha256=TcceNSjCKoiK5SJcgTH2JXfKLYxIHdQdwZWlkpGnEVM,2006
89
89
  regressiontests/eigeningenuity/historian-multi/test_tagManagement.py,sha256=ylInBt453d1RaSih1eTTxGPZmb60UK4vMwI3UW-U1JY,4830
90
90
  regressiontests/eigeningenuity/historian-multi/test_writePoints.py,sha256=51tfUSLUqLKcCKJ1EyhjfzoC_4OP6n1oL3zgTSkXu4s,2696
91
- python_eigen_ingenuity-0.5.29b1.dist-info/METADATA,sha256=QPLpg6vx1IHUfMtVYc-rkpf6IaZBLeoILABSx9LwIXw,8124
92
- python_eigen_ingenuity-0.5.29b1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
93
- python_eigen_ingenuity-0.5.29b1.dist-info/entry_points.txt,sha256=G3LjFQX5xKaN4mqtqCL8uaC-gRbP5T5x9r0gBTJTXXA,70
94
- python_eigen_ingenuity-0.5.29b1.dist-info/top_level.txt,sha256=oDWOSmlNPKNBlIEKP8_JaV01O60jTcUIt2tDkq3OD18,56
95
- python_eigen_ingenuity-0.5.29b1.dist-info/RECORD,,
91
+ python_eigen_ingenuity-0.5.30b2.dist-info/METADATA,sha256=AbdsRsoYzLw_z-GD-s8R7ieHaFvVP50ljsDzE1qCyIE,8124
92
+ python_eigen_ingenuity-0.5.30b2.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
93
+ python_eigen_ingenuity-0.5.30b2.dist-info/entry_points.txt,sha256=G3LjFQX5xKaN4mqtqCL8uaC-gRbP5T5x9r0gBTJTXXA,70
94
+ python_eigen_ingenuity-0.5.30b2.dist-info/top_level.txt,sha256=oDWOSmlNPKNBlIEKP8_JaV01O60jTcUIt2tDkq3OD18,56
95
+ python_eigen_ingenuity-0.5.30b2.dist-info/RECORD,,