aboutsummaryrefslogtreecommitdiffstats
path: root/skate/reduce.go
diff options
context:
space:
mode:
Diffstat (limited to 'skate/reduce.go')
-rw-r--r--skate/reduce.go39
1 files changed, 21 insertions, 18 deletions
diff --git a/skate/reduce.go b/skate/reduce.go
index ade6a02..d093f5a 100644
--- a/skate/reduce.go
+++ b/skate/reduce.go
@@ -303,23 +303,8 @@ func ZippyVerifyRefsOpenLibraryTable(olr, refs io.Reader, w io.Writer) error {
// release) and writes biblioref.
func ZippyVerifyRefsOpenLibrary(olr, refs io.Reader, w io.Writer) error {
var (
- enc = json.NewEncoder(xio.NewSingleWriter(w))
- keyer = makeKeyFunc("\t", 1)
- cleanIdentifier = func(s string) string {
- // Turn ids like /books/OL31189321M into OL31189321M
- if s = strings.TrimSpace(s); len(s) == 0 {
- return ""
- }
- var (
- parts = strings.Split(s, "/")
- last = parts[len(parts)-1]
- )
- if strings.HasPrefix(last, "OL") {
- return last
- }
- log.Printf("warning: unexpected OL id: %s", s)
- return ""
- }
+ enc = json.NewEncoder(xio.NewSingleWriter(w))
+ keyer = makeKeyFunc("\t", 1)
grouper = func(g *zipkey.Group) error {
// TODO: For openlibrary and wayback matches, pass through either
// unstructured ref string, or CSL JSON
@@ -344,7 +329,7 @@ func ZippyVerifyRefsOpenLibrary(olr, refs io.Reader, w io.Writer) error {
result := Verify(pivot, ref)
switch result.Status {
case StatusExact, StatusStrong:
- openLibraryWorkID := cleanIdentifier(pivot.WorkID)
+ openLibraryWorkID := cleanOpenLibraryIdentifier(pivot.WorkID)
if openLibraryWorkID == "" {
continue
}
@@ -681,3 +666,21 @@ func parseBiblioref(s string) (r *BiblioRef, err error) {
err = json.Unmarshal([]byte(s), &r)
return
}
+
+// cleanOpenLibraryIdentifier turns OL ids like /books/OL31189321M into OL31189321M.
+func cleanOpenLibraryIdentifier(s string) string {
+ // XXX: This can be made faster; iterate from the end of the string
+ // and use a slice.
+ if s = strings.TrimSpace(s); len(s) == 0 {
+ return ""
+ }
+ var (
+ parts = strings.Split(s, "/")
+ last = parts[len(parts)-1]
+ )
+ if strings.HasPrefix(last, "OL") {
+ return last
+ }
+ log.Printf("warning: unexpected OL id: %s", s)
+ return ""
+}