duongthienz commited on
Commit
98eb7e8
·
verified ·
1 Parent(s): 14b0f84

Update state.py

Browse files
Files changed (1) hide show
  1. state.py +10 -12
state.py CHANGED
@@ -108,24 +108,22 @@ def build_all_csv_zip():
108
  annotation, _ = result
109
  currDF, _ = su.annotationToSimpleDataFrame(annotation)
110
 
111
- # Apply speaker renames
112
- renames = st.session_state.speakerRenames.get(fname, {})
113
- currDF = currDF.copy()
114
- if "Resource" in currDF.columns:
115
- currDF["Resource"] = currDF["Resource"].apply(
116
- lambda s: renames.get(s, s)
117
- )
118
-
119
- # Add Role column (raw speaker -> role, before rename applied above,
120
- # so look up by renamed value since we already applied renames)
121
  raw_to_role = {
122
- renames.get(token.split(": ", 1)[1], token.split(": ", 1)[1]):
123
- st.session_state.categories[i]
124
  for i, tokens in enumerate(st.session_state.categorySelect)
125
  for token in tokens
126
  if token.startswith(f"{fname}: ")
127
  }
 
128
  currDF["Role"] = currDF["Resource"].map(raw_to_role).fillna("")
 
 
 
 
 
 
 
129
  currDF = currDF.drop(columns=["Task"], errors="ignore")
130
  currDF = currDF.rename(columns={"Resource": "Speaker"})
131
  if "Start" in currDF.columns:
 
108
  annotation, _ = result
109
  currDF, _ = su.annotationToSimpleDataFrame(annotation)
110
 
111
+ # Add Role column against raw SPEAKER_## labels BEFORE renames
 
 
 
 
 
 
 
 
 
112
  raw_to_role = {
113
+ token.split(": ", 1)[1]: st.session_state.categories[i]
 
114
  for i, tokens in enumerate(st.session_state.categorySelect)
115
  for token in tokens
116
  if token.startswith(f"{fname}: ")
117
  }
118
+ currDF = currDF.copy()
119
  currDF["Role"] = currDF["Resource"].map(raw_to_role).fillna("")
120
+
121
+ # Apply speaker renames after Role is set
122
+ renames = st.session_state.speakerRenames.get(fname, {})
123
+ if "Resource" in currDF.columns:
124
+ currDF["Resource"] = currDF["Resource"].apply(
125
+ lambda s: renames.get(s, s)
126
+ )
127
  currDF = currDF.drop(columns=["Task"], errors="ignore")
128
  currDF = currDF.rename(columns={"Resource": "Speaker"})
129
  if "Start" in currDF.columns: