diff --git a/src/rdf-mappings/map-tblBranch.py b/src/rdf-mappings/map-tblBranch.py index 8c9aff7a7a5a7bdacb69ebb1cf230fad77333484..143cdc06b8c7c63dd95f5c39f6968b350475d981 100644 --- a/src/rdf-mappings/map-tblBranch.py +++ b/src/rdf-mappings/map-tblBranch.py @@ -48,10 +48,10 @@ def create_owl_class_from_string(new_class_name, sub_class_of=None, create_prope new_class_name = new_class_name.replace(':', '') - if mapping_config['create_research_dataset'] == True and '(' in new_class_name: + if (mapping_config['create_research_dataset'] == True or mapping_config['create_test_dataset'] == True) and '(' in new_class_name: new_class_name = new_class_name.split('(')[0] - if mapping_config['create_research_dataset'] == True and '[' in new_class_name: + if (mapping_config['create_research_dataset'] == True or mapping_config['create_test_dataset'] == True) and '[' in new_class_name: new_class_name = new_class_name.split('[')[0] if new_class_name != '' and ( new_class_name[-1] == '.' or new_class_name[-1] == ')' ): @@ -157,14 +157,32 @@ def add_modifier(charge_node, charge, modifier_number): def create_visual_link(source_node, target_node=None, direction='current_to_next', charge_number=0): """ - Creates a link between two nodes from a column named with the scheme 'Charge#_relation_to_Charge#' (where # is a number). - The relation is defined as a sub property of dho:hasVisualRelation. + Creates a link between two nodes to describe the visual positioning of something on a shield. + (1) Link from a column named with the scheme 'Charge#_relation_to_Charge#' (where # is a number). + The relation is defined as a sub property of dho:hasSpatialRelation. Target node is newly created and returned, if not given and if the visual link is created. If the visual link is not created, `None` is returned. + (2) Define an topological relation between something and how it is positioned absolutely on a shield (e.g. something is placed in base) """ valid_directions = {'current_to_next', 'previous_to_current', 'current_to_previous', 'field_relation_to_Layer1'} + topological_keywords = [ + 'dx', + 'sn', + 'in base', + 'in chf', + 'in chf dx', + 'issant', + 'issant sn', + 'isst sn', + 'overall', + 'over all', + 'from dx base', + 'enhanced', + 'from dx corner' + ] + if direction == 'current_to_next': relation_column_name = 'Charge' + str(charge_number) + '_relation_to_Charge' + str(charge_number + 1) elif direction == 'previous_to_current': @@ -180,8 +198,14 @@ def create_visual_link(source_node, target_node=None, direction='current_to_next target_node = URIRef(dho_blazon_n + str(uuid.uuid4())) if relation_column_name in df_tblBranch.columns and not pd.isnull(row[relation_column_name]): - relation_property = create_owl_property_from_string(row[relation_column_name], sub_property_of=dho_n.hasVisualRelation) - g.add((source_node, relation_property, target_node)) + # Decide if the visal link is to be defined as an absolute topological relation (with regard to the whole shield) or as a spatial + # relation (with regard to the visual relation between two elements) + if row[relation_column_name] in topological_keywords: + direction_class = create_owl_class_from_string(row[relation_column_name], sub_class_of=dho_n.Direction) + g.add((source_node, dho_n.hasTopologicalRelation, direction_class)) + else: + relation_property = create_owl_property_from_string(row[relation_column_name], sub_property_of=dho_n.hasSpatialRelation) + g.add((source_node, relation_property, target_node)) return target_node else: @@ -336,8 +360,8 @@ def add_layer(layer_number, layer_content, field_node, previous_layer_node=None, # Create visual link to field if charge + '_relation_to_field' in df_tblBranch.columns and not pd.isnull(row[charge + '_relation_to_field']): - visual_relation = create_owl_property_from_string(row[charge + '_relation_to_field'], sub_property_of=dho_n.hasVisualRelation) - g.add((charge_node, visual_relation, field_node)) + direction_class = create_owl_class_from_string(row[charge + '_relation_to_field'], sub_class_of=dho_n.Direction) + g.add((charge_node, dho_n.hasTopologicalRelation, direction_class)) # Create visual link from current Charge to next Charge if next Charge is part of the same Layer if charge != layer_charge_list[-1]: