Update SIMORD.py
Browse files
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(
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 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 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.
|