jpcorb20 commited on
Commit
32246fa
·
verified ·
1 Parent(s): 2bf7301

Update SIMORD.py

Browse files
Files changed (1) hide show
  1. SIMORD.py +35 -31
SIMORD.py CHANGED
@@ -128,38 +128,42 @@ def _normalize_primock_id(stem: str) -> str:
128
  s = s.replace("consultation", "")
129
  return s
130
 
131
- def _build_primock_transcript_dict(root: str) -> Dict[str, dict]:
132
- """
133
- Mirror of read_primock_data post-conversion:
134
- reads *.txt in primock57-main/transcripts and applies the same tag normalization.
135
- """
136
- tdict: Dict[str, dict] = {}
137
- base = None
138
- for name in os.listdir(root):
139
- if name.startswith("primock57"):
140
- base = os.path.join(root, name)
141
- break
142
- if not base:
143
- return tdict
144
-
145
- tx_dir = os.path.join(base, "transcripts")
146
- if not os.path.isdir(tx_dir):
147
- # If transcripts haven't been generated yet by upstream script, we skip.
148
- return tdict
149
 
150
- for fn in os.listdir(tx_dir):
151
- if not fn.lower().endswith(".txt"):
152
- continue
153
- fp = os.path.join(tx_dir, fn)
154
- lines = [ln.strip() for ln in _read_text(fp).splitlines() if ln.strip()]
155
- norm = []
156
- for line in lines:
157
- line = line.replace("Doctor:", "[doctor]").replace("Patient:", "[patient]")
158
- norm.append(line)
159
- stem = os.path.splitext(fn)[0]
160
- primock_id = _normalize_primock_id(stem)
161
- tdict[primock_id] = {"transcript": "\n".join(norm)}
162
- return tdict
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
  def _load_annotations(path: str) -> List[dict]:
165
  # Expect a JSON array (list of dicts). If JSONL, we also handle it gracefully.
 
128
  s = s.replace("consultation", "")
129
  return s
130
 
131
+ def _build_primock_transcript_dict(primock_path):
132
+ # run primock txtgrid_to_transcript.py
133
+ script_path = os.path.join(primock_path, "primock57-main", "scripts", "textgrid_to_transcript.py")
134
+ if not os.path.exists(script_path):
135
+ print(f"Script {script_path} does not exist. Skipping Primock data.")
136
+ return
137
+ transcript_path = os.path.join(primock_path, "primock57-main", "transcripts")
138
+ primock_transcript_path = os.path.join(TMP_DIR, "primock_transcript")
139
+ os.system(f"python {script_path} --transcript_path {transcript_path} --output_path {primock_transcript_path}")
140
+ print(f"Primock data saved to {primock_transcript_path}")
 
 
 
 
 
 
 
 
141
 
142
+ # walk through the directory and find all json files
143
+ transcript_data = {}
144
+ for dirpath, _, files in os.walk(primock_transcript_path):
145
+ for filename in files:
146
+ if filename.endswith(".txt"):
147
+ file_path = os.path.join(dirpath, filename)
148
+ with open(file_path, 'r') as f:
149
+ primock_id = filename.replace(".txt", "")
150
+ primock_id = primock_id.replace("day", "primock57_")
151
+ primock_id = primock_id.replace("consultation0", "")
152
+ primock_id = primock_id.replace("consultation", "")
153
+
154
+ data = f.readlines()
155
+ data = [line.strip() for line in data if line.strip()]
156
+ transcript_lines = []
157
+ for line in data:
158
+ line = line.replace("Doctor:", "[doctor]")
159
+ line = line.replace("Patient:", "[patient]")
160
+ transcript_lines.append(line)
161
+ transcript_data[primock_id] = {
162
+ "transcript": "\n".join(transcript_lines)
163
+ }
164
+
165
+ print(f"Found {len(transcript_data)} transcripts in Primock data")
166
+ return transcript_data
167
 
168
  def _load_annotations(path: str) -> List[dict]:
169
  # Expect a JSON array (list of dicts). If JSONL, we also handle it gracefully.