Skip to content

Commit

Permalink
Parse cre_dep object from neo4j Node
Browse files Browse the repository at this point in the history
  • Loading branch information
john681611 committed Sep 14, 2023
1 parent 713b4c0 commit caea284
Showing 1 changed file with 76 additions and 2 deletions.
78 changes: 76 additions & 2 deletions application/database/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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]]:
Expand Down

0 comments on commit caea284

Please sign in to comment.