aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-04-29 15:42:06 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-04-29 15:42:06 +0200
commitd1fd6dd6169134ae4e4b9131ba163a0cb9857974 (patch)
tree2f921256ee4d8e6e5477a8f588b635a54189d1ab /python
parent5e7543c3f4612dacd7f1d4e04c75cd48ecb67b0c (diff)
downloadrefcat-d1fd6dd6169134ae4e4b9131ba163a0cb9857974.tar.gz
refcat-d1fd6dd6169134ae4e4b9131ba163a0cb9857974.zip
add OpenLibraryWorks
Diffstat (limited to 'python')
-rw-r--r--python/conf/settings.ini2
-rw-r--r--python/refcat/tasks.py28
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)
+
+