AD2000X commited on
Commit
6e321b6
·
verified ·
1 Parent(s): 3c98523

Update src/knowledge_graph.py

Browse files
Files changed (1) hide show
  1. src/knowledge_graph.py +7 -5
src/knowledge_graph.py CHANGED
@@ -360,9 +360,12 @@ class KnowledgeGraph:
360
  # Collect unique groups
361
  groups = set()
362
  for _, attrs in graph.nodes(data=True):
363
- if "group" in attrs:
364
  groups.add(attrs["group"])
365
 
 
 
 
366
  # Generate HTML for legend
367
  legend_html = """
368
  <div id="graph-legend" style="position: absolute; top: 10px; right: 10px; background-color: rgba(255,255,255,0.8);
@@ -372,7 +375,7 @@ class KnowledgeGraph:
372
  """
373
 
374
  # Add items for each group
375
- for group in sorted(groups):
376
  color = "#97c2fc" # Default color
377
  if group == "property":
378
  color = "#ffcc99"
@@ -831,9 +834,8 @@ class KnowledgeGraph:
831
  "count": count,
832
  "examples": examples
833
  })
834
-
835
- # Sort by frequency
836
- patterns.sort(key=lambda x: x["count"], reverse=True)
837
 
838
  return patterns
839
 
 
360
  # Collect unique groups
361
  groups = set()
362
  for _, attrs in graph.nodes(data=True):
363
+ if "group" in attrs and attrs["group"] is not None:
364
  groups.add(attrs["group"])
365
 
366
+ # 過濾並排序groups,確保沒有None值
367
+ sorted_groups = sorted([g for g in groups if g is not None])
368
+
369
  # Generate HTML for legend
370
  legend_html = """
371
  <div id="graph-legend" style="position: absolute; top: 10px; right: 10px; background-color: rgba(255,255,255,0.8);
 
375
  """
376
 
377
  # Add items for each group
378
+ for group in sorted_groups:
379
  color = "#97c2fc" # Default color
380
  if group == "property":
381
  color = "#ffcc99"
 
834
  "count": count,
835
  "examples": examples
836
  })
837
+
838
+ patterns.sort(key=lambda x: x["count"], reverse=True)
 
839
 
840
  return patterns
841