File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88 from tibert .bertcoref import CoreferenceDocument
99
1010
11+ RICH_COLORS = [
12+ "red" ,
13+ "green" ,
14+ "yellow" ,
15+ "blue" ,
16+ "magenta" ,
17+ "cyan" ,
18+ "bright_black" ,
19+ "bright_red" ,
20+ "bright_green" ,
21+ "bright_yellow" ,
22+ "bright_magenta" ,
23+ "bright_cyan" ,
24+ ]
25+
26+
27+ def get_cat_color (index : int ) -> str :
28+ """Get a categorical color from RICH_COLORS"""
29+ return RICH_COLORS [index % len (RICH_COLORS )]
30+
31+
1132T = TypeVar ("T" )
1233
1334
@@ -164,13 +185,15 @@ def pprint_coreference_document(doc: CoreferenceDocument):
164185
165186 for chain_i , start_i , _ in related_mentions :
166187 if token_i == start_i :
167- out .append (f"[red]({ chain_i } " )
188+ color = get_cat_color (chain_i )
189+ out .append (f"[{ color } ]({ chain_i } " )
168190
169191 out .append (token )
170192
171193 for chain_i , _ , end_i in related_mentions :
172194 if token_i == end_i - 1 :
173- out .append (f")[/red]" )
195+ color = get_cat_color (chain_i )
196+ out .append (f")[/{ color } ]" )
174197
175198 try :
176199 console .print (" " .join (out ))
You can’t perform that action at this time.
0 commit comments