diff --git a/mapknowledge/competency/__init__.py b/mapknowledge/competency/__init__.py index 38da091..d7657e7 100644 --- a/mapknowledge/competency/__init__.py +++ b/mapknowledge/competency/__init__.py @@ -138,6 +138,7 @@ def __delete_source_from_tables(self, cursor, source: KnowledgeSource): cursor.execute('DELETE FROM path_nodes WHERE source_id=%s', (source_id, )) cursor.execute('DELETE FROM feature_types WHERE source_id=%s', (source_id, )) cursor.execute('DELETE FROM feature_expert_consultants WHERE source_id=%s', (source_id, )) + cursor.execute('DELETE FROM feature_relationship WHERE source_id=%s', (source_id, )) cursor.execute('DELETE FROM feature_terms WHERE source_id=%s', (source_id, )) def __update_anatomical_types(self, cursor): @@ -258,7 +259,6 @@ def __update_connectivity(self, cursor, knowledge: KnowledgeList, show_progress= def __update_features(self, cursor, knowledge: KnowledgeList): #============================================================= source_id = knowledge.source.source_id - cursor.execute('DELETE FROM feature_terms WHERE source_id=%s', (source_id, )) for record in knowledge.knowledge: if source_id == clean_knowledge_source(record.get('source', '')): @@ -272,6 +272,13 @@ def __update_features(self, cursor, knowledge: KnowledgeList): if (term_type:=record.get('type')) is not None: copy.write_row([source_id, record['id'], term_type]) + # Feature relationships + with cursor.copy("COPY feature_relationship (source_id, feature_0, feature_1, relationship) FROM STDIN") as copy: + for record in knowledge.knowledge: + if source_id == clean_knowledge_source(record.get('source', '')): + for descendant in record.get('descendants', []): + copy.write_row([source_id, descendant, record['id'], 'descendant-ancestor']) + def __update_knowledge_source(self, cursor, source: KnowledgeSource): #==================================================================== cursor.execute('''INSERT INTO knowledge_sources (source_id, sckan_id, description)