Upload app.py
Browse files
app.py
CHANGED
|
@@ -335,19 +335,28 @@ def build_entity_to_entity_graph(entities_by_doc: List[List[Tuple[str, str]]]) -
|
|
| 335 |
# Construir nós (entidades com >= 2 docs)
|
| 336 |
nodes = []
|
| 337 |
entity_to_id = {}
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
| 339 |
if count >= 2:
|
| 340 |
-
entity_to_id[entity] =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
nodes.append({
|
| 342 |
-
"id":
|
| 343 |
"entity": entity[0],
|
| 344 |
"type": entity[1],
|
| 345 |
"docs": count,
|
| 346 |
-
|
| 347 |
-
"
|
| 348 |
-
"
|
| 349 |
-
"z": 0
|
| 350 |
})
|
|
|
|
| 351 |
|
| 352 |
# Construir arestas (co-ocorrências)
|
| 353 |
entity_edges = []
|
|
|
|
| 335 |
# Construir nós (entidades com >= 2 docs)
|
| 336 |
nodes = []
|
| 337 |
entity_to_id = {}
|
| 338 |
+
node_count = sum(1 for e, c in entity_doc_count.items() if c >= 2)
|
| 339 |
+
|
| 340 |
+
node_idx = 0
|
| 341 |
+
for entity, count in sorted(entity_doc_count.items(), key=lambda x: x[1], reverse=True):
|
| 342 |
if count >= 2:
|
| 343 |
+
entity_to_id[entity] = node_idx
|
| 344 |
+
|
| 345 |
+
# Posição em espiral 3D (melhor distribuição)
|
| 346 |
+
angle = 2 * np.pi * node_idx / max(node_count, 1) * 3 # 3 voltas na espiral
|
| 347 |
+
radius = 1.5 + (node_idx / max(node_count, 1)) * 2 # Raio aumenta
|
| 348 |
+
z_pos = (node_idx / max(node_count, 1) - 0.5) * 3 # Altura varia
|
| 349 |
+
|
| 350 |
nodes.append({
|
| 351 |
+
"id": node_idx,
|
| 352 |
"entity": entity[0],
|
| 353 |
"type": entity[1],
|
| 354 |
"docs": count,
|
| 355 |
+
"x": float(radius * np.cos(angle)),
|
| 356 |
+
"y": float(radius * np.sin(angle)),
|
| 357 |
+
"z": float(z_pos)
|
|
|
|
| 358 |
})
|
| 359 |
+
node_idx += 1
|
| 360 |
|
| 361 |
# Construir arestas (co-ocorrências)
|
| 362 |
entity_edges = []
|