From b2e4e4242c9d8d4fbdc026a80dfefa86697a5649 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sat, 24 Jul 2021 18:13:33 -0700 Subject: schema: have issued+accessed (CSLDate) actually omitempty Similar to TargetCSL, these should be pointer types so they don't get encoded as empty objects when not set. --- skate/reduce.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'skate/reduce.go') diff --git a/skate/reduce.go b/skate/reduce.go index e2fa130..356ed25 100644 --- a/skate/reduce.go +++ b/skate/reduce.go @@ -598,7 +598,7 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [ Title: r.Biblio.Title, URL: r.Biblio.Url, Volume: r.Biblio.Volume, - Issued: CSLDate{ + Issued: &CSLDate{ Raw: year, }, } -- cgit v1.2.3 From e038bfb6be24994ae9972d08f85c1cb1506a06b4 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sun, 25 Jul 2021 12:46:00 -0700 Subject: skate: use date-parts for year, not 'raw' --- skate/reduce.go | 13 +++++++------ skate/schema_test.go | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'skate/reduce.go') diff --git a/skate/reduce.go b/skate/reduce.go index 356ed25..4cd604a 100644 --- a/skate/reduce.go +++ b/skate/reduce.go @@ -574,7 +574,7 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [ var ( authors []CSLAuthor isbn string - year string + issued *CSLDate ) for _, name := range r.Biblio.ContribRawNames { authors = append(authors, CSLAuthor{Name: name}) @@ -582,8 +582,11 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [ if len(r.Biblio.Extra.ISBN) > 0 { isbn = r.Biblio.Extra.ISBN[0] } - if r.Biblio.Year > 1500 && r.Biblio.Year < 2022 { - year = fmt.Sprintf("%d", r.Biblio.Year) + // TODO: need to update this "max year" number frequently? + if r.Biblio.Year > 1500 && r.Biblio.Year <= 2025 { + issued = &CSLDate{Parts: [][]int{{int(r.Biblio.Year)}}} + } else { + issued = &CSLDate{} } bref.TargetCSL = &CSL{ Author: authors, @@ -598,9 +601,7 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [ Title: r.Biblio.Title, URL: r.Biblio.Url, Volume: r.Biblio.Volume, - Issued: &CSLDate{ - Raw: year, - }, + Issued: issued, } } // Reuse fields for debugging, for now. diff --git a/skate/schema_test.go b/skate/schema_test.go index 7616001..4489bed 100644 --- a/skate/schema_test.go +++ b/skate/schema_test.go @@ -263,10 +263,10 @@ func TestSchemaMarshal(t *testing.T) { var csl = CSL{ Title: "test-doc", Issued: &CSLDate{ - Raw: "2012", + Parts: [][]int{{2012}}, }, } - var csl_json = []byte(`{"issued":{"raw":"2012"},"title":"test-doc"}`) + var csl_json = []byte(`{"issued":{"date-parts":[[2012]]},"title":"test-doc"}`) var csl_encoded, _ = json.Marshal(csl) if bytes.Compare(csl_json, csl_encoded) != 0 { t.Fatalf("got:\n%v\nwant:\n%v\n", string(csl_json[:]), string(csl_encoded[:])) -- cgit v1.2.3 From a2cae69110df162b12b4a4aad33785fa35f6e5e8 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sun, 25 Jul 2021 13:01:38 -0700 Subject: schema: switch from '.name' to '.raw_name' for un-parsed CSL name field --- skate/reduce.go | 4 ++-- skate/schema.go | 4 ++-- skate/schema_test.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) (limited to 'skate/reduce.go') diff --git a/skate/reduce.go b/skate/reduce.go index 4cd604a..361d7ba 100644 --- a/skate/reduce.go +++ b/skate/reduce.go @@ -576,8 +576,8 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [ isbn string issued *CSLDate ) - for _, name := range r.Biblio.ContribRawNames { - authors = append(authors, CSLAuthor{Name: name}) + for _, raw_name := range r.Biblio.ContribRawNames { + authors = append(authors, CSLAuthor{RawName: raw_name}) } if len(r.Biblio.Extra.ISBN) > 0 { isbn = r.Biblio.Extra.ISBN[0] diff --git a/skate/schema.go b/skate/schema.go index 50f52d6..f36815f 100644 --- a/skate/schema.go +++ b/skate/schema.go @@ -481,12 +481,12 @@ type CSLDate struct { // family element. Institutional names may be delivered in the same way, but it // is preferred to set them instead as a literal element. // -// We include Name, for holding unparsed name, which is not a literal. +// We include RawName, for holding unparsed name, which is not a literal. type CSLAuthor struct { Family string `json:"family,omitempty"` Given string `json:"given,omitempty"` Literal string `json:"literal,omitempty"` - Name string `json:"name,omitempty"` + RawName string `json:"raw_name,omitempty"` } func (b *BiblioRef) Reset() { diff --git a/skate/schema_test.go b/skate/schema_test.go index 4489bed..59b1f58 100644 --- a/skate/schema_test.go +++ b/skate/schema_test.go @@ -221,11 +221,11 @@ func TestLinkHash(t *testing.T) { }{ { bref: BiblioRef{}, - linkHash: "7cae9fc61f167bc26cc3839f15457fe87b2be4e1", + linkHash: "8b8c3f74dd1472aa8869ee3a58295b70c7064aa8", }, { bref: BiblioRef{SourceReleaseIdent: "123"}, - linkHash: "a0969f96c14cb42d298117e1927bd409873173a2", + linkHash: "23d0f9e279ec533f46a6b220f7a5758ec0c9d9af", }, { bref: BiblioRef{ -- cgit v1.2.3 From 3d6ea95540d1e5b225b2507808d5318ecea05b6b Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Sun, 25 Jul 2021 15:38:31 -0700 Subject: skate: pass-through match_provenance in more situations --- skate/reduce.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'skate/reduce.go') diff --git a/skate/reduce.go b/skate/reduce.go index 361d7ba..76b511e 100644 --- a/skate/reduce.go +++ b/skate/reduce.go @@ -408,6 +408,7 @@ func ZippyWayback(refs, cdx io.Reader, w io.Writer) error { cdx.Summary.Ok, cdx.Line) } } + bref.MatchProvenance = ref.RefSource bref.MatchStatus = StatusExact.Short() bref.MatchReason = ReasonURLMatch.Short() if err := enc.Encode(bref); err != nil { @@ -605,6 +606,7 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [ } } // Reuse fields for debugging, for now. + bref.MatchProvenance = r.RefSource bref.MatchStatus = StatusUnmatched.Short() bref.MatchReason = ReasonUnknown.Short() matched = append(matched, &bref) -- cgit v1.2.3