aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--skate/reduce.go8
-rw-r--r--skate/schema.go63
-rw-r--r--skate/schema_test.go4
3 files changed, 70 insertions, 5 deletions
diff --git a/skate/reduce.go b/skate/reduce.go
index b28d976..3bb2466 100644
--- a/skate/reduce.go
+++ b/skate/reduce.go
@@ -511,7 +511,13 @@ func matchedRefsExtend(matched []*BiblioRef, refs []*Ref, stats *statsAugment) [
bref.SourceReleaseStage = r.ReleaseStage
bref.SourceWorkIdent = r.WorkIdent
bref.SourceYear = fmt.Sprintf("%d", r.ReleaseYear)
- bref.TargetUnstructured = r.Biblio.Unstructured
+ if r.Biblio.Unstructured != "" {
+ bref.TargetUnstructured = r.Biblio.Unstructured
+ } else {
+ // TODO: create CSL subdoc
+ log.Printf("to-csl: %v", r)
+ bref.TargetCSL = nil
+ }
// Reuse fields for debugging, for now.
bref.MatchStatus = StatusUnmatched.Short()
bref.MatchReason = ReasonUnknown.Short()
diff --git a/skate/schema.go b/skate/schema.go
index dd088c2..afd9034 100644
--- a/skate/schema.go
+++ b/skate/schema.go
@@ -424,7 +424,66 @@ type BiblioRef struct {
MatchStatus string `json:"match_status,omitempty"`
MatchReason string `json:"match_reason,omitempty"`
TargetUnstructured string `json:"target_unstructured,omitempty"`
- TargetCSL string `json:"target_csl,omitempty"`
+ TargetCSL *CSL `json:"target_csl,omitempty"`
+}
+
+// CSL is a subset of citation style language schema.
+// https://github.com/citation-style-language/schema,
+// https://navneethg.github.io/jsonschemaviewer/. This is a subset only.
+type CSL struct {
+ Accessed CSLDate `json:"accessed,omitempty"`
+ Author []CSLAuthor `json:"author,omitempty"`
+ CollectionTitle string `json:"collection-title"`
+ ContainerTitle string `json:"container-title,omitempty"`
+ ContainerTitleShort string `json:"container-title-short,omitempty"`
+ DOI string `json:"DOI,omitempty"`
+ ID string `json:"id,omitempty"`
+ ISBN string `json:"ISBN,omitempty"`
+ ISSN string `json:"ISSN,omitempty"`
+ Issue string `json:"issue,omitempty"`
+ Issued CSLDate `json:"issued,omitempty"`
+ JounralAbbreviation string `json:"journalAbbreviation"`
+ Language string `json:"language"`
+ NumberOfPages string `json:"number-of-pages,omitempty"`
+ OriginalTitle string `json:"original-title,omitempty"`
+ PMCID string `json:"PMCID,omitempty"`
+ PMID string `json:"PMID,omitempty"`
+ Page string `json:"page,omitempty"`
+ PageFirst string `json:"page-first,omitempty"`
+ Publisher string `json:"publisher,omitempty"`
+ Source string `json:"source,omitempty"`
+ Status string `json:"status,omitempty"`
+ Title string `json:"title,omitempty"`
+ TitleShort string `json:"title-short,omitempty"`
+ Type string `json:"type,omitempty"`
+ URL string `json:"URL,omitempty"`
+ Volume string `json:"volume,omitempty"`
+ VolumeTitle string `json:"volume-title,omitempty"`
+ VolumeTitleShort string `json:"volume-title-short,omitempty"`
+ YearSuffix string `json:"year-suffix,omitempty"`
+}
+
+// A date field is a complex field that expresses a date or a range of dates.
+// An example date field in CSL is issued, which identifies the date an item
+// was issued or published. Date fields can be expressed in two different
+// formats. The first format is an array format (note the double-nesting of the
+// array). To express a date range in this format, the ending date would be set
+// as a second array. The second date format is a raw string. The recommended
+// encoding is a string that represents the date in a numberic year-month-day
+// format.
+type CSLDate struct {
+ Raw string `json:"raw,omitempty"`
+ Parts [][]int `json:"date-parts,omitempty"`
+}
+
+// Some personal names are represented by a single field (e.g. mononyms such as
+// “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.
+type CSLAuthor struct {
+ Family string `json:"family,omitempty"`
+ Given string `json:"given,omitempty"`
+ Literal string `json:"literal,omitempty"`
}
func (b *BiblioRef) Reset() {
@@ -447,7 +506,7 @@ func (b *BiblioRef) Reset() {
b.MatchStatus = ""
b.MatchReason = ""
b.TargetUnstructured = ""
- b.TargetCSL = ""
+ b.TargetCSL = nil
}
// Hash returns a string that will be the same, if source and target are
diff --git a/skate/schema_test.go b/skate/schema_test.go
index cb1cf83..d70c001 100644
--- a/skate/schema_test.go
+++ b/skate/schema_test.go
@@ -220,11 +220,11 @@ func TestLinkHash(t *testing.T) {
}{
{
bref: BiblioRef{},
- linkHash: "e39b4dd927dbfb19c8aa78b10f684b0a5c35fcca",
+ linkHash: "042db9d756488070ce841d1369f8d877b3982c40",
},
{
bref: BiblioRef{SourceReleaseIdent: "123"},
- linkHash: "6d244189489b57c8f70ac7a835f1bacfee00c42a",
+ linkHash: "1a31cc64bd5f6080dd81edc91079bdc41a95bcfe",
},
{
bref: BiblioRef{