Skip to content

import_kg

Command

Bases: BaseCommand

Source code in datasets/management/commands/import_kg.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class Command(BaseCommand):
    def add_arguments(self, parser):
        parser.add_argument('file', type=str)

    def handle(self, file, *args, **options):

        datasets = LinkedOpenDataCloudApi.fetch_all_datasets()
        downloadable = [d for d in datasets if len(d.downloads()) > 0]
        print(f'{len(downloadable)} datasets are downloadable')
        defdownloadable = [d for d in datasets if any(do.is_kg for do in d.downloads())]
        print(f'{len(defdownloadable)} datasets are definitely kg')

        downs = defaultdict(list)
        for d in defdownloadable:
            for do in d.downloads():
                if do.is_kg:
                    downs[do.guess_format()].append(do)

        import_kg(Path(file).absolute())

add_arguments(parser)

Source code in datasets/management/commands/import_kg.py
11
12
def add_arguments(self, parser):
    parser.add_argument('file', type=str)

handle(file, *args, **options)

Source code in datasets/management/commands/import_kg.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def handle(self, file, *args, **options):

    datasets = LinkedOpenDataCloudApi.fetch_all_datasets()
    downloadable = [d for d in datasets if len(d.downloads()) > 0]
    print(f'{len(downloadable)} datasets are downloadable')
    defdownloadable = [d for d in datasets if any(do.is_kg for do in d.downloads())]
    print(f'{len(defdownloadable)} datasets are definitely kg')

    downs = defaultdict(list)
    for d in defdownloadable:
        for do in d.downloads():
            if do.is_kg:
                downs[do.guess_format()].append(do)

    import_kg(Path(file).absolute())