diff options
author | Martin Czygan <martin.czygan@gmail.com> | 2021-05-05 15:55:39 +0200 |
---|---|---|
committer | Martin Czygan <martin.czygan@gmail.com> | 2021-05-05 15:55:39 +0200 |
commit | 634b7b7d910ddb20c5af0722de41ef5ccded7358 (patch) | |
tree | d83f5fb36dc4c98035511059202fc51dc676ee54 /skate/cmd/skate-from-unstructured | |
parent | a380bffa5fb0cf20ee84ede6fa590bf38e3675f8 (diff) | |
parent | 134752c2a160986c13d6c2b9428cb2720ed382d0 (diff) | |
download | refcat-634b7b7d910ddb20c5af0722de41ef5ccded7358.tar.gz refcat-634b7b7d910ddb20c5af0722de41ef5ccded7358.zip |
Merge branch 'master' of git.archive.org:martin/cgraph
* 'master' of git.archive.org:martin/cgraph: (24 commits)
update notes
make: run go mod tidy after build
add test for ParseUnstructured
remove stub file
tweaks; move parsing out of command
skate-map: a bit more help output
update docs
set: some tweaks
update README
update deps
start overview docs
update README
update docs
map is a reference type
fix a typo
implement a few flags as mapper middleware
update ignore files
update deps
rename skate-ref-to-release to skate-conv
update README
...
Diffstat (limited to 'skate/cmd/skate-from-unstructured')
-rw-r--r-- | skate/cmd/skate-from-unstructured/main.go | 61 |
1 files changed, 1 insertions, 60 deletions
diff --git a/skate/cmd/skate-from-unstructured/main.go b/skate/cmd/skate-from-unstructured/main.go index c2015e2..179057d 100644 --- a/skate/cmd/skate-from-unstructured/main.go +++ b/skate/cmd/skate-from-unstructured/main.go @@ -6,9 +6,7 @@ import ( "flag" "log" "os" - "regexp" "runtime" - "strings" "git.archive.org/martin/cgraph/skate" "git.archive.org/martin/cgraph/skate/parallel" @@ -19,11 +17,6 @@ var ( numWorkers = flag.Int("w", runtime.NumCPU(), "number of workers") batchSize = flag.Int("b", 100000, "batch size") bytesNewline = []byte("\n") - - PatDOI = regexp.MustCompile(`10[.][0-9]{1,8}/[^ ]*[\w]`) - PatDOINoHyphen = regexp.MustCompile(`10[.][0-9]{1,8}/[^ -]*[\w]`) - PatArxivPDF = regexp.MustCompile(`http://arxiv.org/pdf/([0-9]{4,4}[.][0-9]{1,8})(v[0-9]{1,2})?(.pdf)?`) - PatArxivAbs = regexp.MustCompile(`http://arxiv.org/abs/([0-9]{4,4}[.][0-9]{1,8})(v[0-9]{1,2})?(.pdf)?`) ) func main() { @@ -32,7 +25,7 @@ func main() { if err := json.Unmarshal(p, &ref); err != nil { return nil, err } - if err := parseUnstructured(&ref); err != nil { + if err := skate.ParseUnstructured(&ref); err != nil { return nil, err } return skate.JsonMarshalLine(&ref) @@ -43,55 +36,3 @@ func main() { log.Fatal(err) } } - -// parseUnstructured will in-place augment missing DOI, arxiv id and so on. -func parseUnstructured(ref *skate.Ref) error { - uns := ref.Biblio.Unstructured - var ( - v string - vs []string - ) - // Handle things like: 10.1111/j.1550-7408.1968.tb02138.x-BIB5|cit5, - // 10.1111/j.1558-5646.1997.tb02431.x-BIB0008|evo02431-cit-0008, ... - if strings.Contains(strings.ToLower(ref.Key), "-bib") && ref.Biblio.DOI == "" { - parts := strings.Split(strings.ToLower(ref.Key), "-bib") - ref.Biblio.DOI = parts[0] - } - // DOI - v = PatDOI.FindString(uns) - if v != "" && ref.Biblio.DOI == "" { - ref.Biblio.DOI = v - } - // DOI in Key - v = PatDOINoHyphen.FindString(ref.Key) - if v != "" && ref.Biblio.DOI == "" { - ref.Biblio.DOI = v - } - // DOI in URL - prefixes := []string{ - "http://doi.org/", - "https://doi.org/", - "http://dx.doi.org/", - "https://dx.doi.org/", - } - for _, prefix := range prefixes { - if ref.Biblio.DOI != "" && strings.HasPrefix(ref.Biblio.Url, prefix) { - ref.Biblio.DOI = strings.Replace(ref.Biblio.Url, prefix, "", -1) - } - } - v = PatDOINoHyphen.FindString(ref.Key) - if v != "" && ref.Biblio.DOI == "" { - ref.Biblio.DOI = v - } - // Arxiv - vs = PatArxivPDF.FindStringSubmatch(uns) - if len(vs) != 0 && ref.Biblio.ArxivId == "" { - ref.Biblio.ArxivId = vs[1] - } else { - vs = PatArxivAbs.FindStringSubmatch(uns) - if len(vs) != 0 && ref.Biblio.ArxivId == "" { - ref.Biblio.ArxivId = vs[1] - } - } - return nil -} |