Handle comma-separated Last,First and Last,Jr,First format for names in bibtex, as well as "von", "de la" and "van de" separators.
This commit is contained in:
parent
558a8a5c64
commit
aee15712e5
|
@ -1,7 +1,8 @@
|
||||||
#lang at-exp racket/base
|
#lang at-exp racket/base
|
||||||
(require racket/function
|
(require racket/function
|
||||||
racket/match
|
racket/match
|
||||||
racket/list)
|
racket/list
|
||||||
|
racket/string)
|
||||||
|
|
||||||
(struct bibdb (raw bibs))
|
(struct bibdb (raw bibs))
|
||||||
|
|
||||||
|
@ -217,13 +218,23 @@
|
||||||
(and as
|
(and as
|
||||||
(apply authors
|
(apply authors
|
||||||
(for/list ([a (in-list (regexp-split #rx" +and *" as))])
|
(for/list ([a (in-list (regexp-split #rx" +and *" as))])
|
||||||
(match (regexp-split #rx" +" a)
|
(define (trim s)
|
||||||
[(list one) (org-author-name one)]
|
(string-trim (regexp-replace #rx" +" s " ")))
|
||||||
[(list one two) (author-name one two)]
|
(match a
|
||||||
[(list-rest first rest)
|
[(pregexp #px"^(.*),(.*),(.*)$" (list _ two suffix one))
|
||||||
(author-name (apply string-append (add-between (cons first (drop-right rest 1))
|
(author-name (trim one) (trim two) #:suffix (trim suffix))]
|
||||||
" "))
|
[(pregexp #px"^(.*),(.*)$" (list _ two one))
|
||||||
(last rest))])))))
|
(author-name (string-trim one) (string-trim two))]
|
||||||
|
[(pregexp #px"^(.*) (von|de la|van der) (.*)$" (list _ one von-like two))
|
||||||
|
(author-name (string-trim one) (string-append von-like " " (string-trim two)))]
|
||||||
|
[space-separated
|
||||||
|
(match (regexp-split #rx" +" space-separated)
|
||||||
|
[(list one) (org-author-name one)]
|
||||||
|
[(list one two) (author-name one two)]
|
||||||
|
[(list-rest first rest)
|
||||||
|
(author-name (apply string-append (add-between (cons first (drop-right rest 1))
|
||||||
|
" "))
|
||||||
|
(last rest))])])))))
|
||||||
|
|
||||||
(module+ test
|
(module+ test
|
||||||
(require rackunit)
|
(require rackunit)
|
||||||
|
@ -253,7 +264,69 @@
|
||||||
(authors (author-name "Edward L." "Deci")
|
(authors (author-name "Edward L." "Deci")
|
||||||
(author-name "Robert J." "Vallerand")
|
(author-name "Robert J." "Vallerand")
|
||||||
(author-name "Luc G." "Pelletier")
|
(author-name "Luc G." "Pelletier")
|
||||||
(author-name "Richard M." "Ryan"))))
|
(author-name "Richard M." "Ryan")))
|
||||||
|
|
||||||
|
(check
|
||||||
|
print-as-equal-string?
|
||||||
|
(parse-author "Lst, Fst")
|
||||||
|
(authors
|
||||||
|
(author-name "Fst" "Lst")))
|
||||||
|
|
||||||
|
(check
|
||||||
|
print-as-equal-string?
|
||||||
|
(parse-author "James, Earl Jones")
|
||||||
|
(authors
|
||||||
|
(author-name "Earl Jones" "James")))
|
||||||
|
|
||||||
|
(check
|
||||||
|
print-as-equal-string?
|
||||||
|
(parse-author "LstA LstB, Fst")
|
||||||
|
(authors
|
||||||
|
(author-name "Fst" "LstA LstB")))
|
||||||
|
|
||||||
|
(check
|
||||||
|
print-as-equal-string?
|
||||||
|
(parse-author "LstA LstB, FstA FstB")
|
||||||
|
(authors
|
||||||
|
(author-name "FstA FstB" "LstA LstB")))
|
||||||
|
|
||||||
|
(check
|
||||||
|
print-as-equal-string?
|
||||||
|
(parse-author "James, Jr, Earl Jones")
|
||||||
|
(authors
|
||||||
|
(author-name "Earl Jones" "James" #:suffix "Jr")))
|
||||||
|
|
||||||
|
(check
|
||||||
|
print-as-equal-string?
|
||||||
|
(parse-author "James, III, Earl Jones")
|
||||||
|
(authors
|
||||||
|
(author-name "Earl Jones" "James" #:suffix "III")))
|
||||||
|
|
||||||
|
(check
|
||||||
|
print-as-equal-string?
|
||||||
|
(parse-author "James Jack von Earl Jones")
|
||||||
|
(authors
|
||||||
|
(author-name "James Jack" "von Earl Jones")))
|
||||||
|
|
||||||
|
(check
|
||||||
|
print-as-equal-string?
|
||||||
|
(parse-author "James Jack de la Earl Jones")
|
||||||
|
(authors
|
||||||
|
(author-name "James Jack" "de la Earl Jones")))
|
||||||
|
|
||||||
|
(check
|
||||||
|
print-as-equal-string?
|
||||||
|
(parse-author "James Jack van der Earl Jones")
|
||||||
|
(authors
|
||||||
|
(author-name "James Jack" "van der Earl Jones")))
|
||||||
|
|
||||||
|
(check
|
||||||
|
print-as-equal-string?
|
||||||
|
(parse-author "Deci, Edward L. and Robert J. Vallerand and Pelletier, Luc G. and Ryan, Jr, Richard M.")
|
||||||
|
(authors (author-name "Edward L." "Deci")
|
||||||
|
(author-name "Robert J." "Vallerand")
|
||||||
|
(author-name "Luc G." "Pelletier")
|
||||||
|
(author-name "Richard M." "Ryan" #:suffix "Jr"))))
|
||||||
|
|
||||||
(define (parse-pages ps)
|
(define (parse-pages ps)
|
||||||
(match ps
|
(match ps
|
||||||
|
|
Loading…
Reference in New Issue
Block a user