aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2021-05-28 00:00:35 +0200
committerMartin Czygan <martin.czygan@gmail.com>2021-05-28 00:00:39 +0200
commit56653efe99c699f93c123f07c39bc7e6ccd8c3eb (patch)
tree87b6bb4bbb5bb272e2292079b21e0388e64fcca6
parent83e6e6576294f0eb0416d7e6d852c7d7fa219a35 (diff)
downloadrefcat-56653efe99c699f93c123f07c39bc7e6ccd8c3eb.tar.gz
refcat-56653efe99c699f93c123f07c39bc7e6ccd8c3eb.zip
include OL work id
-rw-r--r--skate/cmd/skate-conv/main.go9
-rw-r--r--skate/cmd/skate-reduce/main.go2
-rw-r--r--skate/schema.go6
-rw-r--r--skate/xio/util.go9
-rw-r--r--skate/zippy.go10
5 files changed, 22 insertions, 14 deletions
diff --git a/skate/cmd/skate-conv/main.go b/skate/cmd/skate-conv/main.go
index 850d0d5..f861cd0 100644
--- a/skate/cmd/skate-conv/main.go
+++ b/skate/cmd/skate-conv/main.go
@@ -46,13 +46,8 @@ func main() {
case "oled":
f = openLibraryEditionToRelease
if *extraOpenLibraryAuthorMapping != "" {
- log.Printf("loading author mapping ...")
- f, err := os.Open(*extraOpenLibraryAuthorMapping)
- if err != nil {
- log.Fatal(err)
- }
- defer f.Close()
- m, err := xio.TabsToMap(f, "\t", 1, 2)
+ log.Printf("loading author mapping from %v ...", *extraOpenLibraryAuthorMapping)
+ m, err := xio.TabsToMapFile(*extraOpenLibraryAuthorMapping, "\t", 1, 2)
if err != nil {
log.Fatal(err)
}
diff --git a/skate/cmd/skate-reduce/main.go b/skate/cmd/skate-reduce/main.go
index 3cd15c8..74053ef 100644
--- a/skate/cmd/skate-reduce/main.go
+++ b/skate/cmd/skate-reduce/main.go
@@ -143,7 +143,7 @@ func main() {
log.Fatal(err)
}
// XXX: This is broken.
- if err := skate.ZippyVerifyRefsOnly(o, f, bw); err != nil {
+ if err := skate.ZippyVerifyRefsOpenLibrary(o, f, bw); err != nil {
log.Fatal(err)
}
default:
diff --git a/skate/schema.go b/skate/schema.go
index d885728..54f796a 100644
--- a/skate/schema.go
+++ b/skate/schema.go
@@ -217,7 +217,8 @@ type Release struct {
} `json:"rg,omitempty"`
} `json:"skate,omitempty"`
OpenLibrary struct {
- HasFulltext bool `json:"has_fulltext,omitempty"`
+ HasFulltext bool `json:"has_fulltext,omitempty"`
+ WorkID string `json:"work,omitempty"`
} `json:"ol,omitempty"`
} `json:"extra,omitempty"`
}
@@ -563,6 +564,9 @@ func OpenLibraryEditionToRelease(v *OpenLibraryEdition, authorMap map[string]str
}
contribs[i].RawName = name
}
+ if len(v.Works) > 0 {
+ release.Extra.OpenLibrary.WorkID = v.Works[0].Key
+ }
release.Contribs = contribs
release.Title = v.Title
release.ExtIDs.ISBN = v.Isbns()
diff --git a/skate/xio/util.go b/skate/xio/util.go
index 19651f4..8e1669d 100644
--- a/skate/xio/util.go
+++ b/skate/xio/util.go
@@ -19,6 +19,15 @@ func OpenTwo(f1, f2 string) (g1, g2 *os.File, err error) {
return g1, g2, nil
}
+func TabsToMapFile(filename, sep string, kCol, vCol int) (map[string]string, error) {
+ f, err := os.Open(filename)
+ if err != nil {
+ return nil, err
+ }
+ defer f.Close()
+ return TabsToMap(f, sep, kCol, vCol)
+}
+
// TabsToMap read from a reader and turns values from kCol, vCol columns into a
// mapping.
func TabsToMap(r io.Reader, sep string, kCol, vCol int) (map[string]string, error) {
diff --git a/skate/zippy.go b/skate/zippy.go
index b36af6c..146d2e7 100644
--- a/skate/zippy.go
+++ b/skate/zippy.go
@@ -159,9 +159,9 @@ func ZippyVerifyRefs(releases, refs io.Reader, w io.Writer) error {
return zipper.Run()
}
-// ZippyVerifyRefsOnly takes a release and refs reader (tsv, with ident, key, doc)
-// and will execute gf for each group found.
-func ZippyVerifyRefsOnly(releases, refs io.Reader, w io.Writer) error {
+// ZippyVerifyRefsOpenLibrary takes OL editions (as release) and refs (as
+// release) and emits biblioref.
+func ZippyVerifyRefsOpenLibrary(olr, refs io.Reader, w io.Writer) error {
// Define a grouper, working on one set of refs and releases with the same
// key at a time.
var (
@@ -174,6 +174,7 @@ func ZippyVerifyRefsOnly(releases, refs io.Reader, w io.Writer) error {
if len(g.G0) == 0 || len(g.G1) == 0 {
return nil
}
+ // We take a single edition from OL; XXX: might want to link to work.
if pivot, err = stringToRelease(cut(g.G0[0], "\t", 2)); err != nil {
return err
}
@@ -184,7 +185,6 @@ func ZippyVerifyRefsOnly(releases, refs io.Reader, w io.Writer) error {
// The refs have a container name, but not a title, but here we
// compare against titles from open library.
re.Title = re.ContainerName
-
result := Verify(pivot, re)
fmt.Printf("%s\t%s\t%s\t%s\t%s\n",
result.Status.Short(),
@@ -196,7 +196,7 @@ func ZippyVerifyRefsOnly(releases, refs io.Reader, w io.Writer) error {
return nil
}
)
- zipper := zipkey.New(releases, refs, keyer, grouper)
+ zipper := zipkey.New(olr, refs, keyer, grouper)
return zipper.Run()
}