diff options
-rw-r--r-- | python/conf/settings.ini | 2 | ||||
-rw-r--r-- | python/refcat/tasks.py | 28 |
2 files changed, 30 insertions, 0 deletions
diff --git a/python/conf/settings.ini b/python/conf/settings.ini index e79153c..b6d42c9 100644 --- a/python/conf/settings.ini +++ b/python/conf/settings.ini @@ -39,3 +39,5 @@ RELEASE_EXPORT_EXPANDED_FILE = "/bigger/citations/release_export_expanded.json.z # MAG directory. MAG = "/magna/data/mag-2020-06-25" + +OL_DUMP = "/magna/data/open_library_2021-04-26.jsonl.zst" diff --git a/python/refcat/tasks.py b/python/refcat/tasks.py index df2245f..fd1df86 100644 --- a/python/refcat/tasks.py +++ b/python/refcat/tasks.py @@ -191,6 +191,10 @@ class WikipediaCitationsMinimalDataset(luigi.ExternalTask, Refcat): def output(self): return luigi.LocalTarget(path=os.path.join(settings.WIKIPEDIA_CITATIONS, "minimal_dataset.json")) +class OpenLibraryDump(luigi.ExternalTask, Refcat): + + def output(self): + return luigi.LocalTarget(path=settings.OL_DUMP, format=Zstd) # ----8< Derivations @@ -1449,3 +1453,27 @@ class WithISBN(Refcat): def output(self): return luigi.LocalTarget(path=self.path(ext="json.zst"), format=Zstd) + + +class OpenLibraryWorks(Refcat): + """ + Extract just the works. + """ + def requires(self): + return OpenLibraryDump() + + def run(self): + output = shellout(""" + zstdcat -T0 {input} | + parallel -j {n} --block 10M --pipe "jq -rc 'select(.type == \"work\")'" | + zstd -T0 -c > {output} + """, + n=self.n, + tmpdir=self.tmpdir, + input=self.input().path) + luigi.LocalTarget(output).move(self.output().path) + + def output(self): + return luigi.LocalTarget(path=self.path(ext="json.zst"), format=Zstd) + + |