-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4df276a
commit d05dc19
Showing
5 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
|
||
class CompositeDataset(object): | ||
""" | ||
A dataset composed of two or more others | ||
Args: | ||
datasets (list of datasets): One or more other datasets | ||
Examples: | ||
>>> from zounds import InternetArchive, CompositeDataset, ingest | ||
>>> dataset1 = InternetArchive('beethoven_ingigong_850') | ||
>>> dataset2 = InternetArchive('The_Four_Seasons_Vivaldi-10361') | ||
>>> composite = CompositeDataset(dataset1, dataset2) | ||
>>> ingest(composite, Sound) # ingest data from both datasets | ||
""" | ||
|
||
def __init__(self, *datasets): | ||
super(CompositeDataset, self).__init__() | ||
self.datasets = datasets | ||
|
||
def __iter__(self): | ||
for dataset in self.datasets: | ||
for meta in dataset: | ||
yield meta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import unittest2 | ||
from predownload import PreDownload | ||
from composite import CompositeDataset | ||
from zounds.soundfile import AudioMetaData | ||
|
||
|
||
class DatasetA(object): | ||
def __init__(self): | ||
super(DatasetA, self).__init__() | ||
|
||
def __iter__(self): | ||
yield AudioMetaData(uri=PreDownload('', 'http://example.com/1')) | ||
yield AudioMetaData(uri=PreDownload('', 'http://example.com/2')) | ||
|
||
|
||
class DatasetB(object): | ||
def __init__(self): | ||
super(DatasetB, self).__init__() | ||
|
||
def __iter__(self): | ||
yield AudioMetaData(uri=PreDownload('', 'http://example.com/3')) | ||
yield AudioMetaData(uri=PreDownload('', 'http://example.com/4')) | ||
|
||
|
||
class CompositeDatasetTests(unittest2.TestCase): | ||
|
||
def test_composite_iterates_over_multiple_datasets(self): | ||
composite = CompositeDataset(DatasetA(), DatasetB()) | ||
items = [x.uri.url for x in composite] | ||
self.assertEqual(4, len(items)) | ||
self.assertIn('http://example.com/1', items) | ||
self.assertIn('http://example.com/2', items) | ||
self.assertIn('http://example.com/3', items) | ||
self.assertIn('http://example.com/4', items) |