Skip to content

Commit 4d3a40c

Browse files
committed
tools: Tidy up flatmap_diagnostic.py.
1 parent fa7e54e commit 4d3a40c

1 file changed

Lines changed: 22 additions & 19 deletions

File tree

‎tools/flatmap_diagnostic.py‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,20 @@ def __init__(self, manifest_file, sckan_knowledge):
231231
# property info
232232
with open(manifest_file.with_name(self.__manifest['properties']), 'r') as fp:
233233
self.__properties = json.load(fp)
234+
self.__properties['points'] = [
235+
p
236+
for network in self.__properties.get('networks', [])
237+
for nt in ['centrelines', 'no-centrelines'] if nt in network
238+
for c in network[nt]
239+
for point in c.get('connects', [])
240+
for p in point.split('/')
241+
]
234242
self.__properties['networks'] = {
235243
c['id']: c
236244
for network in self.__properties.get('networks', [])
237245
for nt in ['centrelines', 'no-centrelines'] if nt in network
238246
for c in network[nt]
239247
}
240-
self.__properties['points'] = [
241-
p
242-
for network in self.__properties.get('networks', {}).values()
243-
for point in network['connects']
244-
for p in point.split('/')
245-
]
246248
self.__properties['terms'] = defaultdict(list)
247249
self.__properties['a_classes'] = defaultdict(list)
248250
for feature_id, feature in self.__properties.get('features', {}).items():
@@ -281,10 +283,10 @@ def __is_node_or_term_in_property_or_proxy(self, node_or_term):
281283
if isinstance(node_or_term, str):
282284
return node_or_term in self.__properties['terms'] or node_or_term in self.__have_proxies
283285
elif isinstance(node_or_term, tuple):
284-
for term in [node_or_term[0]] + list(node_or_term[1]):
285-
if term not in self.__properties['terms'] and term not in self.__have_proxies:
286-
return False
287-
return True
286+
terms_to_check = [node_or_term[0]] + list(node_or_term[1])
287+
props_terms = self.__properties['terms']
288+
proxies = self.__have_proxies
289+
return all(term in props_terms or term in proxies for term in terms_to_check)
288290

289291
def __get_term_by_id(self, id):
290292
if id in (dt:=self.__properties['features']) or id in (dt:=self.__properties['networks']):
@@ -347,11 +349,12 @@ def __anatomical_map_validation(self):
347349
def __properties_validation(self):
348350
# validating classes in properties
349351
for k, v in self.__properties['classes'].items():
350-
if (k in self.__anatomical_map or v.get('models')) and (k in self.__svg_tags['class'] or k in self.__properties['a_classes']):
351-
continue
352-
if k not in self.__svg_tags['class'] and k not in self.__properties['a_classes']:
352+
in_anat_or_models = k in self.__anatomical_map or v.get('models')
353+
in_svg_or_props = k in self.__svg_tags['class'] or k in self.__properties['a_classes']
354+
355+
if not in_svg_or_props:
353356
self.__record_issue('class', k, 'Properties', 'Properties class not in SVG and property features')
354-
elif k not in self.__anatomical_map and not v.get('models'):
357+
elif not in_anat_or_models:
355358
self.__record_issue('class', k, 'Properties', 'Properties class not in anatomical map and has no models')
356359

357360
# validating anatomical classes in properties
@@ -373,10 +376,11 @@ def __properties_validation(self):
373376
for k in self.__properties['features']:
374377
if k not in self.__svg_tags['id']:
375378
self.__record_issue('id', k, 'Properties', 'Properties feature id not in SVG')
376-
if not self.__properties['features'][k].get('models') and self.__anatomical_map.get(self.__properties['features'][k].get('class'), {}).get('term') is None:
379+
feature = self.__properties['features'][k]
380+
if not feature.get('models') and self.__anatomical_map.get(feature.get('class'), {}).get('term') is None:
377381
self.__record_issue('id', k, 'Properties', 'Properties feature id has no models and its class has no term in anatomical map')
378382

379-
def analize(self):
383+
def analyze(self):
380384
self.__svg_validation()
381385
self.__alias_validation()
382386
self.__proxy_validation()
@@ -420,12 +424,12 @@ def analyse_flatmap_source(manifest_files, sckan_knowledge, output_dir='.'):
420424
# Path to the file
421425
file_path = tmp_path / file_relative
422426
sv = SourceValidation(file_path, sckan_knowledge)
423-
sv.analize()
427+
sv.analyze()
424428
svs.append(sv)
425429
else:
426430
# local file
427431
sv = SourceValidation(manifest_file, sckan_knowledge)
428-
sv.analize()
432+
sv.analyze()
429433
svs.append(sv)
430434

431435
sources = [sv.get_manifest_id() for sv in svs]
@@ -461,7 +465,6 @@ def identify_missing_nodes(sckan_knowledge, log_data_list, map_type, g_rdf, outp
461465
missing_nodes[node_key]['map'] += (log_data['map'],)
462466
elif (missings:=log_data.get('missing')):
463467
for node_key in ast.literal_eval(missings):
464-
print(sckan_knowledge['terms'])
465468
missing_nodes[node_key] = {
466469
'name': '/'.join(sckan_knowledge['terms'].get(term) for term in [node_key[0]]+list(node_key[1])),
467470
'map': tuple()

0 commit comments

Comments
 (0)