Spaces:
Sleeping
Sleeping
fix bug - cleaned data files have different layer names such as Patient_Segment_A
Browse files- MIND_utils.py +19 -6
MIND_utils.py
CHANGED
|
@@ -1,20 +1,33 @@
|
|
| 1 |
-
import numpy as np, pandas as pd, json
|
| 2 |
-
|
| 3 |
dimensions = ["A", "B-S", "B-O", "C-S", "C-O", "D"]
|
| 4 |
-
|
|
|
|
| 5 |
"B-S": "Segment Patient B-S",
|
|
|
|
| 6 |
"C-S": "Segment Patient C-S",
|
| 7 |
-
"D": "Segment Patient Desire (D)",
|
| 8 |
"C-O": "Segment Patient C-O",
|
| 9 |
-
"
|
| 10 |
-
"A": "Segment Patient Affect (A)",
|
| 11 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
def df_to_self_states_json(df, doc_name, annotator = None):
|
| 14 |
"""Convert a dataframe into a json object that can be more easily used for visualization."""
|
| 15 |
# df is the dataframe of annotations
|
| 16 |
# doc_name is the name of the document
|
| 17 |
# annotator is the name of the annotator (optional)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
def get_evidence_obj(evidence_df):
|
| 19 |
"Assume that the evidence_df is a partial dataframe including only annotation of a single evidence span."
|
| 20 |
evidence_obj = {k: v.value.iloc[0] for k, v in evidence_df.groupby("feature")}
|
|
|
|
|
|
|
|
|
|
| 1 |
dimensions = ["A", "B-S", "B-O", "C-S", "C-O", "D"]
|
| 2 |
+
dimension_to_layer_name_raw = { # in raw annotation files (Ayal's outputs)
|
| 3 |
+
"A": "Segment Patient Affect (A)",
|
| 4 |
"B-S": "Segment Patient B-S",
|
| 5 |
+
"B-O": "Segment Patient B-O",
|
| 6 |
"C-S": "Segment Patient C-S",
|
|
|
|
| 7 |
"C-O": "Segment Patient C-O",
|
| 8 |
+
"D": "Segment Patient Desire (D)",
|
|
|
|
| 9 |
}
|
| 10 |
+
dimension_to_layer_name_cleaned = { # in cleaned annotation files (Yael's outputs)
|
| 11 |
+
"A": "Segment_Patient_A",
|
| 12 |
+
"B-S": "Segment_Patient_B-S",
|
| 13 |
+
"B-O": "Segment_Patient_B-O",
|
| 14 |
+
"C-S": "Segment_Patient_C-S",
|
| 15 |
+
"C-O": "Segment_Patient_C-O",
|
| 16 |
+
"D": "Segment_Patient_D",
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
|
| 20 |
def df_to_self_states_json(df, doc_name, annotator = None):
|
| 21 |
"""Convert a dataframe into a json object that can be more easily used for visualization."""
|
| 22 |
# df is the dataframe of annotations
|
| 23 |
# doc_name is the name of the document
|
| 24 |
# annotator is the name of the annotator (optional)
|
| 25 |
+
# select dimension_to_layer_name
|
| 26 |
+
if 'Segment_Patient_A' in df.layer.unique():
|
| 27 |
+
dimension_to_layer_name = dimension_to_layer_name_cleaned
|
| 28 |
+
else:
|
| 29 |
+
dimension_to_layer_name = dimension_to_layer_name_raw
|
| 30 |
+
|
| 31 |
def get_evidence_obj(evidence_df):
|
| 32 |
"Assume that the evidence_df is a partial dataframe including only annotation of a single evidence span."
|
| 33 |
evidence_obj = {k: v.value.iloc[0] for k, v in evidence_df.groupby("feature")}
|