lib/bolognese/schema_org.rb in bolognese-0.7.2 vs lib/bolognese/schema_org.rb in bolognese-0.8

- old
+ new

@@ -1,8 +1,17 @@ module Bolognese class SchemaOrg < Metadata + SO_TO_DC_RELATION_TYPES = { + "citation" => "References", + "sameAs" => "IsIdenticalTo", + "isPartOf" => "IsPartOf", + "hasPart" => "HasPart", + "isPredecessor" => "IsPreviousVersionOf", + "isSuccessor" => "IsNewVersionOf" + } + def initialize(id: nil, string: nil) id = normalize_id(id) if id.present? if string.present? @raw = string @@ -51,34 +60,34 @@ def bibtex_type Bolognese::Bibtex::SO_TO_BIB_TRANSLATIONS[type] || "misc" end - def name + def title metadata.fetch("name", nil) end def alternate_name metadata.fetch("alternateName", nil) end def author - arr = Array.wrap(metadata.fetch("author", nil)).map { |a| a.except("name") } - array_unwrap(arr) + authors = from_schema_org(Array.wrap(metadata.fetch("author", nil))) + get_authors(authors) end def editor - arr = Array.wrap(metadata.fetch("editor", nil)).map { |a| a.except("name") } - array_unwrap(arr) + editors = from_schema_org(Array.wrap(metadata.fetch("editor", nil))) + get_authors(editors) end def description - metadata.fetch("description", nil) + { "text" => metadata.fetch("description", nil) } end def license - metadata.fetch("license", nil) + { "id" => metadata.fetch("license", nil) } end def version metadata.fetch("version", nil) end @@ -97,31 +106,48 @@ def date_modified metadata.fetch("dateModified", nil) end - def related_identifiers(relation_type) - normalize_ids(metadata.fetch(relation_type, nil)) + def related_identifier + Array.wrap(is_identical_to) + + Array.wrap(is_part_of) + + Array.wrap(has_part) + + Array.wrap(is_previous_version_of) + + Array.wrap(is_new_version_of) + + Array.wrap(references) end - def same_as - related_identifiers("isIdenticalTo") + def get_related_identifier(relation_type: nil) + normalize_ids(metadata.fetch(relation_type, nil), SO_TO_DC_RELATION_TYPES[relation_type]) end + def is_identical_to + get_related_identifier(relation_type: "sameAs") + end + def is_part_of - related_identifiers("isPartOf") + get_related_identifier(relation_type: "isPartOf") end def has_part - related_identifiers("hasPart") + get_related_identifier(relation_type: "hasPart") end - def citation - related_identifiers("citation") + def is_previous_version_of + get_related_identifier(relation_type: "isPredecessor") end + def is_new_version_of + get_related_identifier(relation_type: "isSuccessor") + end + + def references + get_related_identifier(relation_type: "citation") + end + def publisher - metadata.fetch("publisher", nil) + metadata.dig("publisher", "name") end def container_title if publisher.is_a?(Hash) publisher.fetch("name", nil)