LibreCat/LibreCat

View on GitHub
fixes/crossref_mapping.fix

Summary

Maintainability
Test Coverage
# mapping data from CrossRef to the local repository

retain(message)
move(message, '')

add('r.status','new')

# look up publication type
move(type, r.type)
lookup(r.type, fixes/lookup/cr_type_mapping.csv, default: journal_article)

#title
move(title, r.title)
join(r.title,' ')
trim(r.title)

#year
move(issued.date-parts.0.0, r.year)
move(deposited.date-parts.0.0, r.year)
move(created.date-parts.0.0, r.year)
trim(r.year)

# identifier
move(DOI, r.doi)
move(ISSN, r.publication_identifier.issn)
move(ISBN, r.publication_identifier.isbn)
replace_all(r.publication_identifier.isbn.*, '^http://id.crossref.org/isbn/(.*)',$1)

# authors
do list (path => author, var:loop)
  do identity ()
    move(loop.given, tmp.first_name)
    move(loop.family, tmp.last_name)
    move(tmp,r.author.$append)
  end
end

# editors
do list (path => editor, var:loop)
  do identity ()
    move(loop.given, tmp.first_name)
    move(loop.family, tmp.last_name)
    move(tmp,r.editor.$append)
  end
end

add(r.publication_status, published)

move(volume, r.volume)
move(issue, r.issue)
move(publisher, r.publisher)
move(subtitle, r.alternative_title)
move(subject, r.keyword)
join(r.keyword,' ; ')
trim(r.keyword)

# type mapping
if all_match(r.type, 'journal_article')
    move(container-title.0, r.publication)
    if any_match(page, '-')
      move(page, r.page)
    else
      move(page, r.article_number)
    end
    move(article-number, r.article_number)
end

# book
if all_match(r.type, 'book')
    move(publisher-location, r.place)
    if exists(r.editor)
      set(r.type, book_editor)
    end
end

if all_match(r.type, 'book_chapter')
    move(container-title.0, r.publication)
    move(container-title.1, r.series_title)
end

if all_match(r.type, 'conference')
    move(container-title.0, r.publication)
end

if all_match(r.type, preprint)
# CHP registers DOIs for bioRxiv via Crossref, eg 10.1101/005538
  if all_match(member, '246')
    set(r.publication, bioRxiv)
  end
end

move(abstract, r.abstract)
if exists(r.abstract)
  unless is_array(r.abstract)
    move(r.abstract, r.abstract.0.text)
    add(r.abstract.0.lang, eng)
  end
end

# fix language and map to iso
move(language, r.language.0.iso)
lookup(r.language.0.iso, fixes/lookup/cr_lang_iso.csv, default: eng)

retain(r)
move(r, .)

vacuum()