Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataset handle mismatches #10

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion elpis/datasets/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def from_dict(cls, data: Dict[str, Any]) -> Dataset:
elan_options=elan_options,
)

@property
def valid_transcriptions(self):
return (
self._transcript_files()
.difference(self.mismatched_files())
.difference(self.colliding_files())
)

def to_batches(self) -> List[ProcessingBatch]:
"""Converts a valid dataset to a list of processing jobs, matching
transcript and audio files.
Expand All @@ -164,7 +172,7 @@ def to_batches(self) -> List[ProcessingBatch]:
cleaning_options=self.cleaning_options,
elan_options=self.elan_options,
)
for transcription_file in self._transcript_files()
for transcription_file in self.valid_transcriptions
]

def to_dict(self) -> Dict[str, Any]:
Expand Down
12 changes: 11 additions & 1 deletion tests/datasets/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ def test_serialize_dataset_options():
FILES_WITHOUT_ELAN = ["1.txt", "1.wav"]
MISMATCHED_FILES = ["1.eaf", "1.wav", "2.wav", "3.txt"]
COLLIDING_FILES = ["1.eaf", "1.wav", "1.txt"]

MESSY_FILES = ["1.eaf", "1.wav", "2.eaf", "2.txt", "2.wav", "3.eaf", "4.wav"]

DATASET_DICT = {
"name": "dataset",
"files": FILES_WITH_ELAN,
"cleaning_options": CLEANING_OPTIONS_DICT,
}
MESSY_DATASET_DICT = {
"name": "dataset",
"files": MESSY_FILES,
"cleaning_options": CLEANING_OPTIONS_DICT,
}

DATASET_DICT_ELAN = DATASET_DICT | {"elan_options": ELAN_OPTIONS_DICT}

Expand Down Expand Up @@ -124,6 +129,11 @@ def test_duplicate_files():
assert set(dataset.colliding_files()) == {Path("1.eaf"), Path("1.txt")}


def test_valid_transcriptions():
dataset = Dataset.from_dict(MESSY_DATASET_DICT)
assert len(dataset.valid_transcriptions) == 1


def test_dataset_batching():
dataset = Dataset.from_dict(DATASET_DICT)
batch = dataset.to_batches()
Expand Down
Loading