diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-03-30 02:16:16 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-03-30 02:16:16 +0200 |
commit | dfc258b352d6d3a7f5b56ffdadebfb8a13260966 (patch) | |
tree | e63aec0da0cf8c139234c2ead707141e49a0dc29 | |
parent | e8ed1ff2a60b694b242669a50c5a37346f3b6d79 (diff) | |
download | refcat-dfc258b352d6d3a7f5b56ffdadebfb8a13260966.tar.gz refcat-dfc258b352d6d3a7f5b56ffdadebfb8a13260966.zip |
wp: id list parser
-rw-r--r-- | skate/cmd/skate-biblioref-from-wikipedia/main.go | 7 | ||||
-rw-r--r-- | skate/schema.go | 48 |
2 files changed, 54 insertions, 1 deletions
diff --git a/skate/cmd/skate-biblioref-from-wikipedia/main.go b/skate/cmd/skate-biblioref-from-wikipedia/main.go index 552b625..61b590e 100644 --- a/skate/cmd/skate-biblioref-from-wikipedia/main.go +++ b/skate/cmd/skate-biblioref-from-wikipedia/main.go @@ -25,7 +25,12 @@ func main() { if err := json.Unmarshal(p, &w); err != nil { return nil, err } - return nil, nil + b, err := json.Marshal(w.ParseIDList()) + if err != nil { + return nil, err + } + b = append(b, bytesNewline...) + return b, nil }) pp.NumWorkers = *numWorkers pp.BatchSize = *batchSize diff --git a/skate/schema.go b/skate/schema.go index ff59b61..6a0d1c2 100644 --- a/skate/schema.go +++ b/skate/schema.go @@ -3,6 +3,7 @@ package skate import ( "fmt" "strconv" + "strings" ) // RefToRelease converts a ref to a release. Set a extra.skate.status flag to @@ -261,3 +262,50 @@ type MinimalCitations struct { Title string `json:"Title"` TypeOfCitation string `json:"type_of_citation"` } + +// IDList with commonly used identifier from wikipedia citations. +type IDList struct { + ISBN string `json:isbn,omitempty"` + DOI string `json:doi,omitempty"` + PMID string `json:pmid,omitempty"` + ISSN string `json:issn,omitempty"` + JSTOR string `json:jstor,omitempty"` + PMC string `json:pmc,omitempty"` + ARXIV string `json:arxiv,omitempty"` + OL string `json:ol,omitempty"` +} + +func (c *MinimalCitations) ParseIDList() (result IDList) { + if len(c.IDList) < 3 { + return result + } + s := c.IDList[1 : len(c.IDList)-1] + parts := strings.Split(s, ",") + for _, part := range parts { + pair := strings.Split(part, "=") + if len(pair) != 2 { + continue + } + switch pair[0] { + case "ISBN": + result.ISBN = pair[1] + case "DOI": + result.DOI = pair[1] + case "PMID": + result.PMID = pair[1] + case "ISSN": + result.ISSN = pair[1] + case "PMC": + result.PMC = pair[1] + case "JSTOR": + result.JSTOR = pair[1] + case "ARXIV": + result.ARXIV = pair[1] + case "OL": + result.OL = pair[1] + default: + continue + } + } + return result +} |