aboutsummaryrefslogtreecommitdiffstats
path: root/skate/zippy.go
diff options
context:
space:
mode:
Diffstat (limited to 'skate/zippy.go')
-rw-r--r--skate/zippy.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/skate/zippy.go b/skate/zippy.go
index f2dca98..194b8ba 100644
--- a/skate/zippy.go
+++ b/skate/zippy.go
@@ -159,6 +159,53 @@ func ZippyVerifyRefs(releases, refs io.Reader, w io.Writer) error {
return zipper.Run()
}
+// ZippyRefsOpenLibrary takes a release and refs reader (tsv, with ident, key, doc)
+// and will execute gf for each group found.
+func ZippyRefsOpenLibrary(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. Here, we do verification and write out the generated
+ // biblioref.
+ var (
+ enc = json.NewEncoder(w)
+ keyer = makeKeyFunc("\t", 1)
+ grouper = func(g *zipkey.Group) error {
+ var (
+ re, pivot *Release
+ err error
+ )
+ if len(g.G0) == 0 || len(g.G1) == 0 {
+ return nil
+ }
+ if pivot, err = stringToRelease(cut(g.G0[0], "\t", 2)); err != nil {
+ return err
+ }
+ for _, line := range g.G1 {
+ if re, err = stringToRelease(cut(line, "\t", 2)); err != nil {
+ return err
+ }
+ result := Verify(pivot, re)
+ switch result.Status {
+ case StatusExact, StatusStrong:
+ if result.Reason == ReasonDOI {
+ continue
+ }
+ br := generateBiblioRef(re, pivot, result, "fuzzy")
+ if err := enc.Encode(br); err != nil {
+ return err
+ }
+ default:
+ // XXX: We want to add unmatched pieces as well; here? We
+ // probably want to do a single final pass to complete the
+ // dataset.
+ }
+ }
+ return nil
+ }
+ )
+ zipper := zipkey.New(olr, refs, keyer, grouper)
+ return zipper.Run()
+}
+
// makeKeyFunc creates a function that can be used as keyFunc, selecting a
// column from fields separated by sep; column is 1-indexed.
func makeKeyFunc(sep string, column int) func(string) (string, error) {