aboutsummaryrefslogtreecommitdiffstats
path: root/skate/schema.go
diff options
context:
space:
mode:
Diffstat (limited to 'skate/schema.go')
-rw-r--r--skate/schema.go48
1 files changed, 37 insertions, 11 deletions
diff --git a/skate/schema.go b/skate/schema.go
index 1dd02d9..a9b1e8a 100644
--- a/skate/schema.go
+++ b/skate/schema.go
@@ -4,6 +4,9 @@ import (
"fmt"
"strconv"
"strings"
+
+ "git.archive.org/martin/cgraph/skate/isbn"
+ "git.archive.org/martin/cgraph/skate/set"
)
// RefToRelease converts a ref to a release. Set a extra.skate.status flag to
@@ -81,15 +84,15 @@ type Release struct {
Role string `json:"role,omitempty"`
} `json:"contribs,omitempty"`
ExtIDs struct {
- DOI string `json:"doi,omitempty"`
- PMID string `json:"pmid,omitempty"`
- PMCID string `json:"pmcid,omitempty"`
- Arxiv string `json:"arxiv,omitempty"`
- Core string `json:"core,omitempty"`
- WikidataQID string `json:"wikidata_qid,omitempty"`
- Jstor string `json:"jstor,omitempty"`
- ISBN10 string `json:"isbn10,omitempty"`
- ISBN13 string `json:"isbn13,omitempty"`
+ Arxiv string `json:"arxiv,omitempty"`
+ Core string `json:"core,omitempty"`
+ DOI string `json:"doi,omitempty"`
+ ISBN []string `json:"isbn,omitempty"` // should be isbn13
+ Jstor string `json:"jstor,omitempty"`
+ OLID string `json:"olid,omitempty"`
+ PMCID string `json:"pmcid,omitempty"`
+ PMID string `json:"pmid,omitempty"`
+ WikidataQID string `json:"wikidata_qid,omitempty"`
} `json:"ext_ids,omitempty"`
Ident string `json:"ident,omitempty"`
Publisher string `json:"publisher,omitempty"`
@@ -140,6 +143,9 @@ type Release struct {
URL string `json:"url,omitempty"`
} `json:"rg,omitempty"`
} `json:"skate,omitempty"`
+ OpenLibrary struct {
+ HasFulltext bool `json:"has_fulltext,omitempty"`
+ } `json:"ol,omitempty"`
} `json:"extra,omitempty"`
}
@@ -356,6 +362,7 @@ func OpenLibraryToRelease(w *OpenLibraryWork) (*Release, error) {
RawName string `json:"raw_name,omitempty"`
Role string `json:"role,omitempty"`
}, len(w.AuthorName))
+ s = set.New()
)
for i, author := range w.AuthorName {
contribs[i].RawName = author
@@ -364,6 +371,25 @@ func OpenLibraryToRelease(w *OpenLibraryWork) (*Release, error) {
if len(w.PublishYear) > 0 {
release.ReleaseYearValue = w.FirstPublishYear
}
- // XXX: isbn normalization
- return nil, nil
+ for _, v := range w.Isbn {
+ switch {
+ case len(v) == 9 || len(v) == 10:
+ if w, err := isbn.To13(v); err == nil {
+ s.Add(w)
+ }
+ case len(v) == 12 || len(v) == 13:
+ if w, err := isbn.To13(v); err == nil {
+ s.Add(w)
+ }
+ default:
+ continue
+ }
+ }
+ if len(w.Publisher) > 0 {
+ release.Publisher = w.Publisher[0]
+ }
+ release.ExtIDs.ISBN = s.Slice()
+ release.ExtIDs.OLID = strings.Replace(w.Key, "/works/", "", 1)
+ release.Extra.OpenLibrary.HasFulltext = w.HasFulltext
+ return &release, nil
}