From caea2844095a54f14b9df24851ff1debbdf1b3f1 Mon Sep 17 00:00:00 2001 From: john681611 Date: Thu, 14 Sep 2023 10:17:35 +0100 Subject: [PATCH] Parse cre_dep object from neo4j Node --- application/database/db.py | 78 +++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/application/database/db.py b/application/database/db.py index ed9eeec11..31ce46be0 100644 --- a/application/database/db.py +++ b/application/database/db.py @@ -337,6 +337,7 @@ def format_path_record(rec): } def format_record(rec): + # self.parse_node(rec) return { "name": rec["name"], "sectionID": rec["section_id"], @@ -351,7 +352,7 @@ def format_record(rec): ] @classmethod - def standards(self): + def standards(self) -> List[str]: if not self.connected: return records, _, _ = self.driver.execute_query( @@ -360,6 +361,79 @@ def standards(self): ) return records[0][0] + @classmethod + def parse_node(self, node: neo4j.graph.Node) -> cre_defs.Document: + print(node) + name = node["name"] + id = node["id"] if "id" in node else None + description = node["description"] if "description" in node else None + links = [self.parse_link(link) for link in node["links"]] + tags = node["tags"] + metadata = node["metadata"] + if "Node" in node.labels: + return cre_defs.Node( + name=name, + id=id, + description=description, + links=links, + tags=tags, + metadata=metadata, + hyperlink=(node["hyperlink"] if "hyperlink" in node else None), + version=(node["version"] if "version" in node else None), + ) + if "Code" in node.labels: + return cre_defs.Code( + name=name, + id=id, + description=description, + links=links, + tags=tags, + metadata=metadata, + hyperlink=(node["hyperlink"] if "hyperlink" in node else None), + version=(node["version"] if "version" in node else None), + ) + if "Standard" in node.labels: + return cre_defs.Standard( + name=name, + id=id, + description=description, + links=links, + tags=tags, + metadata=metadata, + hyperlink=(node["hyperlink"] if "hyperlink" in node else None), + version=(node["version"] if "version" in node else None), + section=node['section'], + sectionID='sectionID', + subsection=(node["subsection"] if "subsection" in node else None), + ) + if "Tool" in node.labels: + return cre_defs.Tool( + name=name, + id=id, + description=description, + links=links, + tags=tags, + metadata=metadata, + hyperlink=(node["hyperlink"] if "hyperlink" in node else None), + version=(node["version"] if "version" in node else None), + section=node['section'], + sectionID='sectionID', + subsection=(node["subsection"] if "subsection" in node else None), + ) + if "CRE" in node.labels: + return cre_defs.CRE( + name=name, + id=id, + description=description, + links=links, + tags=tags, + metadata=metadata, + ) + + @classmethod + def parse_link(self, link): + return cre_defs.Link(ltype=link["ltype"], tags=link["tags"]) + class CRE_Graph: graph: nx.Graph = None @@ -1298,7 +1372,7 @@ def gap_analysis(self, node_names: List[str]): grouped_paths[key]["paths"][end_key] = path return grouped_paths - def standards(self): + def standards(self) -> List[str]: return self.neo_db.standards() def text_search(self, text: str) -> List[Optional[cre_defs.Document]]: