Module: Bolognese::Readers::CiteprocReader

Included in:
Metadata
Defined in:
lib/bolognese/readers/citeproc_reader.rb

Constant Summary collapse

CP_TO_SO_TRANSLATIONS =
{
  "song" => "AudioObject",
  "post-weblog" => "BlogPosting",
  "dataset" => "Dataset",
  "graphic" => "ImageObject",
  "motion_picture" => "Movie",
  "article-journal" => "ScholarlyArticle",
  "broadcast" => "VideoObject",
  "webpage" => "WebPage"
}
CP_TO_RIS_TRANSLATIONS =
{
  "post-weblog" => "BLOG",
  "dataset" => "DATA",
  "graphic" => "FIGURE",
  "book" => "BOOK",
  "motion_picture" => "MPCT",
  "article-journal" => "JOUR",
  "broadcast" => "MPCT",
  "webpage" => "ELEC"
}

Instance Method Summary collapse

Instance Method Details

#read_citeproc(string: nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/bolognese/readers/citeproc_reader.rb', line 26

def read_citeproc(string: nil)
  errors = jsonlint(string)
  return { "errors" => errors } if errors.present?

  meta = string.present? ? Maremma.from_json(string) : {}

  citeproc_type = meta.fetch("type", nil)
  type = CP_TO_SO_TRANSLATIONS[citeproc_type] || "CreativeWork"
  doi = normalize_doi(meta.fetch("DOI", nil))
  author = get_authors(from_citeproc(Array.wrap(meta.fetch("author", nil))))
  editor = get_authors(from_citeproc(Array.wrap(meta.fetch("editor", nil))))
  date_published = get_date_from_date_parts(meta.fetch("issued", nil))
  container_title = meta.fetch("container-title", nil)
  is_part_of = if container_title.present?
                 { "type" => "Periodical",
                   "title" => container_title,
                   "issn" => meta.fetch("ISSN", nil) }.compact
               else
                 nil
               end

  { "id" => normalize_id(meta.fetch("id", nil)),
    "type" => type,
    "additional_type" => meta.fetch("additionalType", nil),
    "citeproc_type" => citeproc_type,
    "bibtex_type" => Bolognese::Utils::SO_TO_BIB_TRANSLATIONS[type] || "misc",
    "ris_type" => CP_TO_RIS_TRANSLATIONS[type] || "GEN",
    "resource_type_general" => Bolognese::Utils::SO_TO_DC_TRANSLATIONS[type],
    "doi" => doi_from_url(doi),
    "url" => normalize_id(meta.fetch("URL", nil)),
    "title" => meta.fetch("title", nil),
    "author" => author,
    "container_title" => container_title,
    "publisher" => meta.fetch("publisher", nil),
    "is_part_of" => is_part_of,
    "date_published" => date_published,
    "volume" => meta.fetch("volume", nil),
    #{}"pagination" => meta.pages.to_s.presence,
    "description" => meta.fetch("abstract", nil).present? ? { "text" => sanitize(meta.fetch("abstract")) } : nil,
    #{ }"license" => { "id" => meta.field?(:copyright) && meta.copyright.to_s.presence },
    "version" => meta.fetch("version", nil),
    "keywords" => Array.wrap(meta.fetch("categories", nil)).split(", ")
  }
end