-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from smart-on-fhir/mikix/mentions
feat: add `mentions` command to show text for each label
- Loading branch information
Showing
10 changed files
with
364 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import argparse | ||
|
||
import rich | ||
import rich.box | ||
import rich.table | ||
import rich.text | ||
|
||
from chart_review import cli_utils, console_utils, types | ||
|
||
|
||
def make_subparser(parser: argparse.ArgumentParser) -> None: | ||
cli_utils.add_project_args(parser) | ||
cli_utils.add_output_args(parser) | ||
parser.set_defaults(func=print_mentions) | ||
|
||
|
||
def print_mentions(args: argparse.Namespace) -> None: | ||
""" | ||
Print Label Studio export's mentions (text associated with the label). | ||
""" | ||
reader = cli_utils.get_cohort_reader(args) | ||
|
||
table = cli_utils.create_table("Annotator", "Chart ID", "Mention", "Label") | ||
|
||
for annotator in sorted(reader.annotations.original_text_mentions, key=str.casefold): | ||
table.add_section() | ||
mentions = reader.annotations.original_text_mentions[annotator] | ||
for note_id, labeled_texts in mentions.items(): | ||
for label_text in labeled_texts: | ||
for label in sorted(label_text.labels, key=str.casefold): | ||
if label in reader.annotations.labels: | ||
table.add_row(annotator, str(note_id), label_text.text, label) | ||
|
||
if args.csv: | ||
cli_utils.print_table_as_csv(table) | ||
else: | ||
rich.get_console().print(table) | ||
console_utils.print_ignored_charts(reader) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: Mentions Command | ||
parent: Chart Review | ||
nav_order: 8 | ||
# audience: lightly technical folks | ||
# type: how-to | ||
--- | ||
|
||
# The Mentions Command | ||
|
||
The `mentions` command prints each time a piece of text was labeled | ||
and with what label. | ||
|
||
## Example | ||
|
||
```shell | ||
$ chart-review mentions | ||
╭───────────┬──────────┬─────────┬──────────╮ | ||
│ Annotator │ Chart ID │ Mention │ Label │ | ||
├───────────┼──────────┼─────────┼──────────┤ | ||
│ jane │ 1 │ achoo │ Cough │ | ||
│ jane │ 1 │ sigh │ Headache │ | ||
│ jane │ 1 │ sigh │ Fatigue │ | ||
│ jane │ 4 │ sleepy │ Fatigue │ | ||
│ jane │ 4 │ pain │ Headache │ | ||
├───────────┼──────────┼─────────┼──────────┤ | ||
│ jill │ 1 │ achoo │ Cough │ | ||
│ jill │ 1 │ sigh │ Fatigue │ | ||
│ jill │ 2 │ ouch │ Fatigue │ | ||
│ jill │ 4 │ sleepy │ Fatigue │ | ||
│ jill │ 4 │ pain │ Cough │ | ||
├───────────┼──────────┼─────────┼──────────┤ | ||
│ john │ 1 │ achoo │ Cough │ | ||
│ john │ 1 │ sigh │ Fatigue │ | ||
│ john │ 2 │ ouch │ Headache │ | ||
│ john │ 4 │ sleepy │ Fatigue │ | ||
│ john │ 4 │ pain │ Headache │ | ||
╰───────────┴──────────┴─────────┴──────────╯ | ||
``` | ||
|
||
## Options | ||
|
||
### --csv | ||
|
||
Print the mentions in a machine-parseable CSV format. | ||
|
||
#### Examples | ||
```shell | ||
$ chart-review mentions --csv > mentions.csv | ||
``` | ||
|
||
```shell | ||
$ chart-review mentions --csv | ||
annotator,chart_id,mention,label | ||
jane,1,achoo,Cough | ||
jane,1,sigh,Headache | ||
jane,1,sigh,Fatigue | ||
jane,4,sleepy,Fatigue | ||
jane,4,pain,Headache | ||
jill,1,achoo,Cough | ||
jill,1,sigh,Fatigue | ||
jill,2,ouch,Fatigue | ||
jill,4,sleepy,Fatigue | ||
jill,4,pain,Cough | ||
john,1,achoo,Cough | ||
john,1,sigh,Fatigue | ||
john,2,ouch,Headache | ||
john,4,sleepy,Fatigue | ||
john,4,pain,Headache | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.