Upload app.py
Browse files
app.py
CHANGED
|
@@ -332,31 +332,42 @@ def build_entity_to_entity_graph(entities_by_doc: List[List[Tuple[str, str]]]) -
|
|
| 332 |
pair = tuple(sorted([unique_entities[i], unique_entities[j]], key=str))
|
| 333 |
cooccurrence[pair] += 1
|
| 334 |
|
| 335 |
-
# Construir n贸s (entidades com >= 2 docs)
|
| 336 |
nodes = []
|
| 337 |
entity_to_id = {}
|
| 338 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
node_idx = 0
|
| 341 |
-
for entity, count in
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
# Construir arestas (co-ocorr锚ncias)
|
| 362 |
entity_edges = []
|
|
|
|
| 332 |
pair = tuple(sorted([unique_entities[i], unique_entities[j]], key=str))
|
| 333 |
cooccurrence[pair] += 1
|
| 334 |
|
| 335 |
+
# Construir n贸s (entidades com >= 2 docs, limitado a top 50)
|
| 336 |
nodes = []
|
| 337 |
entity_to_id = {}
|
| 338 |
+
|
| 339 |
+
# Filtrar e ordenar por frequ锚ncia
|
| 340 |
+
valid_entities = [(e, c) for e, c in entity_doc_count.items() if c >= 2]
|
| 341 |
+
valid_entities.sort(key=lambda x: x[1], reverse=True)
|
| 342 |
+
valid_entities = valid_entities[:50] # Limitar a 50 n贸s principais
|
| 343 |
+
|
| 344 |
+
node_count = len(valid_entities)
|
| 345 |
|
| 346 |
node_idx = 0
|
| 347 |
+
for entity, count in valid_entities:
|
| 348 |
+
entity_to_id[entity] = node_idx
|
| 349 |
+
|
| 350 |
+
# Layout em esfera 3D (melhor para muitos n贸s)
|
| 351 |
+
# Golden angle para distribui莽茫o uniforme
|
| 352 |
+
golden_angle = np.pi * (3 - np.sqrt(5))
|
| 353 |
+
theta = node_idx * golden_angle
|
| 354 |
+
phi = np.arccos(1 - 2 * (node_idx + 0.5) / max(node_count, 1))
|
| 355 |
+
|
| 356 |
+
radius = 3.0 # Raio fixo maior
|
| 357 |
+
x = radius * np.sin(phi) * np.cos(theta)
|
| 358 |
+
y = radius * np.sin(phi) * np.sin(theta)
|
| 359 |
+
z = radius * np.cos(phi)
|
| 360 |
+
|
| 361 |
+
nodes.append({
|
| 362 |
+
"id": node_idx,
|
| 363 |
+
"entity": entity[0],
|
| 364 |
+
"type": entity[1],
|
| 365 |
+
"docs": count,
|
| 366 |
+
"x": float(x),
|
| 367 |
+
"y": float(y),
|
| 368 |
+
"z": float(z)
|
| 369 |
+
})
|
| 370 |
+
node_idx += 1
|
| 371 |
|
| 372 |
# Construir arestas (co-ocorr锚ncias)
|
| 373 |
entity_edges = []
|