Advertisement
Filip_Markoski

NER Clustering

May 25th, 2022
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. def organizations_store_clustering(organizations_store: Dict[int, Set[str]],
  2.                                    position_clusters: List[Set[int]],
  3.                                    organization_clusters: List[Set[str]]) -> Tuple[List[Set[int]], List[Set[str]]]:
  4.     position_clusters: List[Set[int]] = []
  5.     organization_clusters: List[Set[str]] = []
  6.  
  7.     for position, entry in organizations_store.items():
  8.         entry: Set[str] = set(entry)
  9.  
  10.         if len(entry) == 0:
  11.             create_cluster(position, entry, position_clusters, organization_clusters)
  12.             continue
  13.  
  14.         if len(position_clusters) == 0:
  15.             create_cluster(position, entry, position_clusters, organization_clusters)
  16.             continue
  17.         else:
  18.             is_intersected = False
  19.             for position_cluster, organization_cluster in zip(position_clusters, organization_clusters):
  20.                 if len(organization_cluster) > 0:
  21.                     if entry.issubset(organization_cluster):
  22.                         is_intersected = True
  23.                         position_cluster.add(position)
  24.                         organization_cluster.update(entry)
  25.                         print(f'{position_cluster} {organization_cluster} updated')
  26.                         break
  27.  
  28.             if not is_intersected:
  29.                 create_cluster(position, entry, position_clusters, organization_clusters)
  30.  
  31.     return position_clusters, organization_clusters
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement