Madras1 commited on
Commit
446d368
verified
1 Parent(s): d7ca959

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -21
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
- 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 = []
 
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 = []