diff options
Diffstat (limited to 'skate')
-rw-r--r-- | skate/reduce.go | 35 | ||||
-rw-r--r-- | skate/reduce_test.go | 32 | ||||
-rw-r--r-- | skate/schema.go | 9 | ||||
-rw-r--r-- | skate/schema_test.go | 4 |
4 files changed, 72 insertions, 8 deletions
diff --git a/skate/reduce.go b/skate/reduce.go index 01df50f..f8694c1 100644 --- a/skate/reduce.go +++ b/skate/reduce.go @@ -521,9 +521,38 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [ if r.Biblio.Unstructured != "" { bref.TargetUnstructured = r.Biblio.Unstructured } else { - // TODO: create CSL subdoc - log.Printf("to-csl: %#v", r) - bref.TargetCSL = nil + // Unmatched and no unstructured field: generate CSL. + var ( + authors []CSLAuthor + isbn string + year string + ) + for _, name := range r.Biblio.ContribRawNames { + authors = append(authors, CSLAuthor{Name: name}) + } + 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) + } + bref.TargetCSL = &CSL{ + Author: authors, + ContainerTitle: r.Biblio.ContainerName, + DOI: r.Biblio.DOI, + ISBN: isbn, + Issue: r.Biblio.Issue, + PMCID: r.Biblio.PMCID, + PMID: r.Biblio.PMID, + Page: r.Biblio.Pages, + Publisher: r.Biblio.Publisher, + Title: r.Biblio.Title, + URL: r.Biblio.Url, + Volume: r.Biblio.Volume, + Issued: CSLDate{ + Raw: year, + }, + } } // Reuse fields for debugging, for now. bref.MatchStatus = StatusUnmatched.Short() diff --git a/skate/reduce_test.go b/skate/reduce_test.go index da4e21e..ddbca08 100644 --- a/skate/reduce_test.go +++ b/skate/reduce_test.go @@ -198,6 +198,38 @@ func TestMatchedRefsExtend(t *testing.T) { MatchStatus: StatusUnmatched.Short(), MatchReason: ReasonUnknown.Short(), SourceYear: "0", + TargetCSL: &CSL{ + Accessed: CSLDate{}, + Author: nil, + CollectionTitle: "", + ContainerTitle: "", + ContainerTitleShort: "", + DOI: "", + ID: "", + ISBN: "", + ISSN: "", + Issue: "", + Issued: CSLDate{}, + JournalAbbreviation: "", + Language: "", + NumberOfPages: "", + OriginalTitle: "", + PMCID: "", + PMID: "", + Page: "", + PageFirst: "", + Publisher: "", + Source: "", + Status: "", + Title: "Title", + TitleShort: "", + Type: "", + URL: "", + Volume: "", + VolumeTitle: "", + VolumeTitleShort: "", + YearSuffix: "", + }, }, }, }, diff --git a/skate/schema.go b/skate/schema.go index afd9034..a3f261d 100644 --- a/skate/schema.go +++ b/skate/schema.go @@ -433,7 +433,7 @@ type BiblioRef struct { type CSL struct { Accessed CSLDate `json:"accessed,omitempty"` Author []CSLAuthor `json:"author,omitempty"` - CollectionTitle string `json:"collection-title"` + CollectionTitle string `json:"collection-title,omitempty"` ContainerTitle string `json:"container-title,omitempty"` ContainerTitleShort string `json:"container-title-short,omitempty"` DOI string `json:"DOI,omitempty"` @@ -442,8 +442,8 @@ type CSL struct { ISSN string `json:"ISSN,omitempty"` Issue string `json:"issue,omitempty"` Issued CSLDate `json:"issued,omitempty"` - JounralAbbreviation string `json:"journalAbbreviation"` - Language string `json:"language"` + JournalAbbreviation string `json:"journalAbbreviation,omitempty"` + Language string `json:"language,omitempty"` NumberOfPages string `json:"number-of-pages,omitempty"` OriginalTitle string `json:"original-title,omitempty"` PMCID string `json:"PMCID,omitempty"` @@ -480,10 +480,13 @@ type CSLDate struct { // “Prince” or “Plato”). In such cases, the name can be delivered as a lone // 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. type CSLAuthor struct { Family string `json:"family,omitempty"` Given string `json:"given,omitempty"` Literal string `json:"literal,omitempty"` + Name string `json:"name,omitempty"` } func (b *BiblioRef) Reset() { diff --git a/skate/schema_test.go b/skate/schema_test.go index d70c001..3267072 100644 --- a/skate/schema_test.go +++ b/skate/schema_test.go @@ -220,11 +220,11 @@ func TestLinkHash(t *testing.T) { }{ { bref: BiblioRef{}, - linkHash: "042db9d756488070ce841d1369f8d877b3982c40", + linkHash: "7cae9fc61f167bc26cc3839f15457fe87b2be4e1", }, { bref: BiblioRef{SourceReleaseIdent: "123"}, - linkHash: "1a31cc64bd5f6080dd81edc91079bdc41a95bcfe", + linkHash: "a0969f96c14cb42d298117e1927bd409873173a2", }, { bref: BiblioRef{ |