Skip to content

Commit 374b123

Browse files
committed
colors for pprint_coreference_document
1 parent 74b9513 commit 374b123

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tibert/utils.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@
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+
1132
T = 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))

0 commit comments

Comments
 (0)