lib/bolognese/utils.rb in bolognese-0.9.5 vs lib/bolognese/utils.rb in bolognese-0.9.6

- old
+ new

@@ -7,10 +7,204 @@ "http://creativecommons.org/licenses/by-nc/4.0/" => "Creative Commons Attribution Noncommercial 4.0 (CC-BY-NC 4.0)", "http://creativecommons.org/licenses/by-sa/4.0/" => "Creative Commons Attribution Share Alike 4.0 (CC-BY-SA 4.0)", "http://creativecommons.org/licenses/by-nc-nd/4.0/" => "Creative Commons Attribution Noncommercial No Derivatives 4.0 (CC-BY-NC-ND 4.0)" } + DC_TO_SO_TRANSLATIONS = { + "Audiovisual" => "VideoObject", + "Collection" => "Collection", + "Dataset" => "Dataset", + "Event" => "Event", + "Image" => "ImageObject", + "InteractiveResource" => nil, + "Model" => nil, + "PhysicalObject" => nil, + "Service" => "Service", + "Software" => "SoftwareSourceCode", + "Sound" => "AudioObject", + "Text" => "ScholarlyArticle", + "Workflow" => nil, + "Other" => "CreativeWork" + } + + DC_TO_CP_TRANSLATIONS = { + "Audiovisual" => "motion_picture", + "Collection" => nil, + "Dataset" => "dataset", + "Event" => nil, + "Image" => "graphic", + "InteractiveResource" => nil, + "Model" => nil, + "PhysicalObject" => nil, + "Service" => nil, + "Software" => "computer_program", + "Sound" => "song", + "Text" => "report", + "Workflow" => nil, + "Other" => nil + } + + CR_TO_CP_TRANSLATIONS = { + "proceedings" => nil, + "reference-book" => nil, + "journal-issue" => nil, + "proceedings-article" => "paper-conference", + "other" => nil, + "dissertation" => "thesis", + "dataset" => "dataset", + "edited-book" => "book", + "journal-article" => "article-journal", + "journal" => nil, + "report" => "report", + "book-series" => nil, + "report-series" => nil, + "book-track" => nil, + "standard" => nil, + "book-section" => "chapter", + "book-part" => nil, + "book" => "book", + "book-chapter" => "chapter", + "standard-series" => nil, + "monograph" => "book", + "component" => nil, + "reference-entry" => "entry-dictionary", + "journal-volume" => nil, + "book-set" => nil + } + + SO_TO_DC_TRANSLATIONS = { + "Article" => "Text", + "AudioObject" => "Sound", + "Blog" => "Text", + "BlogPosting" => "Text", + "Collection" => "Collection", + "CreativeWork" => "Other", + "DataCatalog" => "Dataset", + "Dataset" => "Dataset", + "Event" => "Event", + "ImageObject" => "Image", + "Movie" => "Audiovisual", + "PublicationIssue" => "Text", + "ScholarlyArticle" => "Text", + "Service" => "Service", + "SoftwareSourceCode" => "Software", + "VideoObject" => "Audiovisual", + "WebPage" => "Text", + "WebSite" => "Text" + } + + SO_TO_CP_TRANSLATIONS = { + "Article" => "", + "AudioObject" => "song", + "Blog" => "report", + "BlogPosting" => "post-weblog", + "Collection" => nil, + "CreativeWork" => nil, + "DataCatalog" => "dataset", + "Dataset" => "dataset", + "Event" => nil, + "ImageObject" => "graphic", + "Movie" => "motion_picture", + "PublicationIssue" => nil, + "ScholarlyArticle" => "article-journal", + "Service" => nil, + "SoftwareSourceCode" => "computer_program", + "VideoObject" => "broadcast", + "WebPage" => "webpage", + "WebSite" => "webpage" + } + + CP_TO_SO_TRANSLATIONS = { + "song" => "AudioObject", + "post-weblog" => "BlogPosting", + "dataset" => "Dataset", + "graphic" => "ImageObject", + "motion_picture" => "Movie", + "article-journal" => "ScholarlyArticle", + "computer_program" => "SoftwareSourceCode", + "broadcast" => "VideoObject", + "webpage" => "WebPage" + } + + SO_TO_RIS_TRANSLATIONS = { + "Article" => nil, + "AudioObject" => nil, + "Blog" => nil, + "BlogPosting" => "BLOG", + "Collection" => nil, + "CreativeWork" => "GEN", + "DataCatalog" => "CTLG", + "Dataset" => "DATA", + "Event" => nil, + "ImageObject" => "FIGURE", + "Movie" => "MPCT", + "PublicationIssue" => nil, + "ScholarlyArticle" => "JOUR", + "Service" => nil, + "SoftwareSourceCode" => "COMP", + "VideoObject" => "VIDEO", + "WebPage" => "ELEC", + "WebSite" => nil + } + + CR_TO_RIS_TRANSLATIONS = { + "proceedings" => "CONF", + "reference-book" => "BOOK", + "journal-issue" => nil, + "proceedings-article" => "CPAPER", + "other" => "GEN", + "dissertation" => "THES", + "dataset" => "DATA", + "edited-book" => "BOOK", + "journal-article" => "JOUR", + "journal" => nil, + "report" => nil, + "book-series" => nil, + "report-series" => nil, + "book-track" => nil, + "standard" => nil, + "book-section" => "CHAP", + "book-part" => "CHAP", + "book" => "BOOK", + "book-chapter" => "CHAP", + "standard-series" => nil, + "monograph" => "BOOK", + "component" => nil, + "reference-entry" => "DICT", + "journal-volume" => nil, + "book-set" => nil + } + + DC_TO_RIS_TRANSLATIONS = { + "Audiovisual" => "MPCT", + "Collection" => nil, + "Dataset" => "DATA", + "Event" => nil, + "Image" => "FIGURE", + "InteractiveResource" => nil, + "Model" => nil, + "PhysicalObject" => nil, + "Service" => nil, + "Software" => "COMP", + "Sound" => "SOUND", + "Text" => "RPRT", + "Workflow" => nil, + "Other" => nil + } + + CP_TO_RIS_TRANSLATIONS = { + "post-weblog" => "BLOG", + "dataset" => "DATA", + "graphic" => "FIGURE", + "book" => "BOOK", + "motion_picture" => "MPCT", + "article-journal" => "JOUR", + "computer_program" => "COMP", + "broadcast" => "MPCT", + "webpage" => "ELEC" + } + def find_from_format(id: nil, string: nil, ext: nil, filename: nil) if id.present? find_from_format_by_id(id) elsif string.present? find_from_format_by_string(string, ext: ext, filename: filename) @@ -65,22 +259,26 @@ when "bibtex" then Bibtex.new(string: string) when "ris" then Ris.new(string: string) else SchemaOrg.new(id: id) end - unless p.valid? + if p.errors.present? $stderr.puts p.errors.colorize(:red) end p end def write(id: nil, string: nil, from: nil, to: nil, **options) metadata = read(id: id, string: string, from: from, **options) return nil if metadata.nil? - puts metadata.send(to) + if to == "datacite" && metadata.datacite_errors.present? + $stderr.puts metadata.datacite_errors.colorize(:red) + else + puts metadata.send(to) + end end def generate(id: nil, string: nil, from: nil, to: nil, **options) metadata = read(id: id, string: string, from: from, **options) return nil if metadata.nil? @@ -307,8 +505,15 @@ get_date_from_parts(year, month, day) end def get_date_from_parts(year, month = nil, day = nil) [year.to_s.rjust(4, '0'), month.to_s.rjust(2, '0'), day.to_s.rjust(2, '0')].reject { |part| part == "00" }.join("-") + end + + def jsonlint(json) + error_array = [] + linter = JsonLint::Linter.new + linter.send(:check_data, json, error_array) + error_array end end end