mgbam commited on
Commit
85d173c
·
verified ·
1 Parent(s): 6799b1d

Update visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +9 -7
visualization.py CHANGED
@@ -5,17 +5,19 @@ from pyvis.network import Network
5
 
6
  def extract_key_terms(text: str):
7
  """
8
- A naive approach to extract key terms by matching capitalized words.
 
9
  """
10
  return re.findall(r"\b[A-Z][a-zA-Z]+\b", text)
11
 
12
  def create_medical_graph(query: str, docs: list) -> str:
13
  """
14
- Builds a PyVis network:
15
- - A central "QUERY" node.
16
- - A node for each retrieved document.
17
- - Sub-nodes for extracted key terms.
18
- Returns the full HTML of the generated graph.
 
19
  """
20
  net = Network(height="600px", width="100%", directed=False)
21
  net.add_node("QUERY", label=f"Query: {query}", color="red", shape="star")
@@ -31,7 +33,7 @@ def create_medical_graph(query: str, docs: list) -> str:
31
  net.add_node(term_id, label=term, color="green")
32
  net.add_edge(doc_id, term_id)
33
 
34
- # Write the network HTML to a temporary file and return its content
35
  with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmp:
36
  temp_filename = tmp.name
37
  net.show(temp_filename)
 
5
 
6
  def extract_key_terms(text: str):
7
  """
8
+ A simple method to extract key terms by matching capitalized words.
9
+ In a clinical context, this may highlight important entities.
10
  """
11
  return re.findall(r"\b[A-Z][a-zA-Z]+\b", text)
12
 
13
  def create_medical_graph(query: str, docs: list) -> str:
14
  """
15
+ Creates an interactive knowledge graph using PyVis:
16
+ - A central node for the query.
17
+ - One node per abstract.
18
+ - Sub-nodes for key terms extracted from each abstract.
19
+
20
+ Returns the HTML content of the graph.
21
  """
22
  net = Network(height="600px", width="100%", directed=False)
23
  net.add_node("QUERY", label=f"Query: {query}", color="red", shape="star")
 
33
  net.add_node(term_id, label=term, color="green")
34
  net.add_edge(doc_id, term_id)
35
 
36
+ # Write the graph to a temporary HTML file and return its content.
37
  with tempfile.NamedTemporaryFile(delete=False, suffix=".html") as tmp:
38
  temp_filename = tmp.name
39
  net.show(temp_filename)