glossarist 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.rubocop_todo.yml +65 -0
  4. data/README.adoc +2 -2
  5. data/config.yml +1 -1
  6. data/exe/glossarist +5 -3
  7. data/glossarist.gemspec +1 -0
  8. data/lib/glossarist/asset.rb +4 -9
  9. data/lib/glossarist/citation.rb +73 -41
  10. data/lib/glossarist/collection.rb +2 -11
  11. data/lib/glossarist/collections/asset_collection.rb +0 -3
  12. data/lib/glossarist/collections/bibliography_collection.rb +1 -1
  13. data/lib/glossarist/concept.rb +66 -206
  14. data/lib/glossarist/concept_data.rb +66 -0
  15. data/lib/glossarist/concept_date.rb +7 -11
  16. data/lib/glossarist/concept_manager.rb +19 -29
  17. data/lib/glossarist/concept_set.rb +6 -4
  18. data/lib/glossarist/concept_source.rb +15 -58
  19. data/lib/glossarist/config.rb +4 -4
  20. data/lib/glossarist/designation/abbreviation.rb +15 -16
  21. data/lib/glossarist/designation/base.rb +16 -15
  22. data/lib/glossarist/designation/expression.rb +18 -26
  23. data/lib/glossarist/designation/grammar_info.rb +27 -45
  24. data/lib/glossarist/designation/graphical_symbol.rb +12 -8
  25. data/lib/glossarist/designation/letter_symbol.rb +13 -11
  26. data/lib/glossarist/designation/symbol.rb +11 -13
  27. data/lib/glossarist/designation.rb +3 -3
  28. data/lib/glossarist/detailed_definition.rb +6 -24
  29. data/lib/glossarist/error.rb +4 -4
  30. data/lib/glossarist/glossary_definition.rb +6 -3
  31. data/lib/glossarist/localized_concept.rb +17 -62
  32. data/lib/glossarist/managed_concept.rb +73 -146
  33. data/lib/glossarist/managed_concept_collection.rb +15 -24
  34. data/lib/glossarist/managed_concept_data.rb +47 -0
  35. data/lib/glossarist/non_verb_rep.rb +10 -13
  36. data/lib/glossarist/related_concept.rb +14 -21
  37. data/lib/glossarist/utilities/uuid.rb +10 -5
  38. data/lib/glossarist/utilities.rb +0 -2
  39. data/lib/glossarist/version.rb +1 -1
  40. data/lib/glossarist.rb +10 -9
  41. metadata +23 -13
  42. data/lib/glossarist/model.rb +0 -40
  43. data/lib/glossarist/utilities/boolean_attributes.rb +0 -35
  44. data/lib/glossarist/utilities/enum/class_methods.rb +0 -99
  45. data/lib/glossarist/utilities/enum/enum_collection.rb +0 -45
  46. data/lib/glossarist/utilities/enum/instance_methods.rb +0 -55
  47. data/lib/glossarist/utilities/enum.rb +0 -21
  48. data/lib/glossarist/v1_reader.rb +0 -28
@@ -1,35 +1,36 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Glossarist
4
2
  module Designation
5
- class Base < Model
6
- include Glossarist::Utilities::Enum
7
-
8
- # @note This is not entirely aligned with agreed schema and may be
9
- # changed.
10
- attr_accessor :designation
3
+ class Base < Lutaml::Model::Serializable
4
+ attribute :designation, :string
5
+ attribute :geographical_area, :string
6
+ attribute :normative_status, :string,
7
+ values: Glossarist::GlossaryDefinition::DESIGNATION_BASE_NORMATIVE_STATUSES
8
+ attribute :type, :string
11
9
 
12
- attr_accessor :geographical_area
13
- register_enum :normative_status, Glossarist::GlossaryDefinition::DESIGNATION_BASE_NORMATIVE_STATUSES
10
+ yaml do
11
+ map :type, to: :type
12
+ map %i[normative_status normativeStatus], to: :normative_status
13
+ map %i[geographical_area geographicalArea], to: :geographical_area
14
+ map :designation, to: :designation
15
+ end
14
16
 
15
- def self.from_h(hash)
17
+ def self.of_yaml(hash, options = {})
16
18
  type = hash["type"]
17
19
 
18
20
  if type.nil? || /\w/ !~ type
19
21
  raise ArgumentError, "designation type is missing"
20
22
  end
21
23
 
22
- designation_subclass = SERIALIZED_TYPES[type]
23
-
24
24
  if self == Base
25
25
  # called on Base class, delegate it to proper subclass
26
- SERIALIZED_TYPES[type].from_h(hash)
26
+ SERIALIZED_TYPES[type].of_yaml(hash)
27
27
  else
28
28
  # called on subclass, instantiate object
29
29
  unless SERIALIZED_TYPES[self] == type
30
30
  raise ArgumentError, "unexpected designation type: #{type}"
31
31
  end
32
- super(hash.reject { |k, _| k == "type" })
32
+
33
+ super(hash, options)
33
34
  end
34
35
  end
35
36
  end
@@ -1,24 +1,26 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative "base"
2
+ require_relative "grammar_info"
4
3
 
5
4
  module Glossarist
6
5
  module Designation
7
6
  class Expression < Base
8
- attr_accessor :prefix
9
- attr_accessor :usage_info
10
-
11
- # List of grammar info.
12
- # @return [Array<GrammarInfo>]
13
- attr_reader :grammar_info
14
-
15
- def grammar_info=(grammar_info)
16
- @grammar_info = grammar_info.map { |g| GrammarInfo.new(g) }
7
+ attribute :prefix, :string
8
+ attribute :usage_info, :string
9
+
10
+ attribute :gender, :string
11
+ attribute :plurality, :string
12
+ attribute :part_of_speech, :string
13
+ attribute :grammar_info, GrammarInfo, collection: true
14
+ attribute :type, :string, default: -> { "expression" }
15
+
16
+ yaml do
17
+ map :type, to: :type, render_default: true
18
+ map :prefix, to: :prefix
19
+ map %i[usage_info usageInfo], to: :usage_info
20
+ map %i[grammar_info grammarInfo], to: :grammar_info
17
21
  end
18
22
 
19
- # @todo Added to cater for current iev-data implementation,
20
- # might be removed in the future.
21
- def self.from_h(hash)
23
+ def self.of_yaml(hash, options = {})
22
24
  gender = hash.delete("gender") || hash.delete(:gender)
23
25
  number = hash.delete("plurality") || hash.delete(:plurality)
24
26
  part_of_speech = hash.delete("part_of_speech") || hash.delete(:part_of_speech)
@@ -31,19 +33,9 @@ module Glossarist
31
33
  }.compact]
32
34
  end
33
35
 
34
- super
35
- end
36
+ hash["type"] = "expression" unless hash["type"]
36
37
 
37
- def to_h
38
- {
39
- "type" => "expression",
40
- "prefix" => prefix,
41
- "normative_status" => normative_status,
42
- "usage_info" => usage_info,
43
- "designation" => designation,
44
- "geographical_area" => geographical_area,
45
- "grammar_info" => grammar_info&.map(&:to_h),
46
- }.compact
38
+ super(hash, options)
47
39
  end
48
40
  end
49
41
  end
@@ -1,57 +1,39 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../utilities"
4
-
5
1
  module Glossarist
6
2
  module Designation
7
- class GrammarInfo
8
- include Glossarist::Utilities::Enum
9
- include Glossarist::Utilities::BooleanAttributes
10
- include Glossarist::Utilities::CommonFunctions
11
-
12
- register_enum :gender, Glossarist::GlossaryDefinition::GRAMMAR_INFO_GENDERS, multiple: true
13
- register_enum :number, Glossarist::GlossaryDefinition::GRAMMAR_INFO_NUMBERS, multiple: true
14
-
15
- register_boolean_attributes Glossarist::GlossaryDefinition::GRAMMAR_INFO_BOOLEAN_ATTRIBUTES
16
-
17
- def initialize(options = {})
18
- sanitized_options(options).each do |attr, value|
19
- public_send("#{attr}=", value)
3
+ class GrammarInfo < Lutaml::Model::Serializable
4
+ attribute :gender, :string,
5
+ values: Glossarist::GlossaryDefinition::GRAMMAR_INFO_GENDERS, collection: true
6
+ attribute :number, :string,
7
+ values: Glossarist::GlossaryDefinition::GRAMMAR_INFO_NUMBERS, collection: true
8
+ attribute :part_of_speech, :string,
9
+ values: Glossarist::GlossaryDefinition::GRAMMAR_INFO_BOOLEAN_ATTRIBUTES
10
+
11
+ yaml do
12
+ map :gender, to: :gender
13
+ map :number, to: :number
14
+
15
+ map %i[part_of_speech partOfSpeech], with: { to: :part_of_speech_to_yaml, from: :part_of_speech_from_yaml }
16
+ Glossarist::GlossaryDefinition::GRAMMAR_INFO_BOOLEAN_ATTRIBUTES.each do |bool_attr|
17
+ map bool_attr,
18
+ with: { to: :"part_of_speech_#{bool_attr}_to_yaml",
19
+ from: :"part_of_speech_#{bool_attr}_from_yaml" }
20
20
  end
21
21
  end
22
22
 
23
- def part_of_speech=(pos)
24
- public_send("#{pos}=", pos)
23
+ def part_of_speech_from_yaml(model, value)
24
+ model.part_of_speech = value
25
25
  end
26
26
 
27
- def to_h
28
- {
29
- "preposition" => preposition?,
30
- "participle" => participle?,
31
- "adj" => adj?,
32
- "verb" => verb?,
33
- "adverb" => adverb?,
34
- "noun" => noun?,
35
- "gender" => gender,
36
- "number" => number,
37
- }
38
- end
27
+ def part_of_speech_to_yaml(model, doc); end
39
28
 
40
- private
29
+ Glossarist::GlossaryDefinition::GRAMMAR_INFO_BOOLEAN_ATTRIBUTES.each do |bool_attr|
30
+ define_method(:"part_of_speech_#{bool_attr}_from_yaml") do |model, value|
31
+ model.public_send("#{bool_attr}=", value)
32
+ end
41
33
 
42
- def sanitized_options(options)
43
- hash = symbolize_keys(options)
44
- slice_keys(hash, [
45
- :gender,
46
- :number,
47
- :preposition,
48
- :participle,
49
- :adj,
50
- :verb,
51
- :adverb,
52
- :noun,
53
- :part_of_speech,
54
- ])
34
+ define_method(:"part_of_speech_#{bool_attr}_to_yaml") do |model, doc|
35
+ doc[bool_attr] = model.public_send("#{bool_attr}?")
36
+ end
55
37
  end
56
38
  end
57
39
  end
@@ -1,16 +1,20 @@
1
- # frozen_string_literal: true
1
+ require_relative "symbol"
2
2
 
3
3
  module Glossarist
4
4
  module Designation
5
5
  class GraphicalSymbol < Symbol
6
- attr_accessor :text
7
- attr_accessor :image
6
+ attribute :text, :string
7
+ attribute :image, :string
8
8
 
9
- def to_h
10
- super.merge(
11
- "text" => text,
12
- "image" => image,
13
- )
9
+ yaml do
10
+ map :text, to: :text
11
+ map :image, to: :image
12
+ end
13
+
14
+ def self.of_yaml(hash, options = {})
15
+ hash["type"] = "graphical_symbol"
16
+
17
+ super
14
18
  end
15
19
  end
16
20
  end
@@ -1,18 +1,20 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Glossarist
4
2
  module Designation
5
3
  class LetterSymbol < Symbol
6
- attr_accessor :text
7
- attr_accessor :language
8
- attr_accessor :script
4
+ attribute :text, :string
5
+ attribute :language, :string
6
+ attribute :script, :string
7
+
8
+ yaml do
9
+ map :text, to: :text
10
+ map :language, to: :language
11
+ map :script, to: :script
12
+ end
13
+
14
+ def self.of_yaml(hash, options = {})
15
+ hash["type"] = "letter_symbol"
9
16
 
10
- def to_h
11
- super.merge(
12
- "text" => text,
13
- "language" => language,
14
- "script" => script,
15
- )
17
+ super
16
18
  end
17
19
  end
18
20
  end
@@ -1,20 +1,18 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "base"
4
-
5
1
  module Glossarist
6
2
  module Designation
7
3
  class Symbol < Base
8
- attr_accessor :international
4
+ attribute :international, :boolean
5
+ attribute :type, :string
6
+
7
+ yaml do
8
+ map :international, to: :international
9
+ map :type, to: :type, render_default: true
10
+ end
11
+
12
+ def self.of_yaml(hash, options = {})
13
+ hash["type"] = "symbol" unless hash["type"]
9
14
 
10
- def to_h
11
- {
12
- "type" => Glossarist::Designation::SERIALIZED_TYPES[self.class],
13
- "normative_status" => normative_status,
14
- "geographical_area" => geographical_area,
15
- "designation" => designation,
16
- "international" => international,
17
- }.compact
15
+ super
18
16
  end
19
17
  end
20
18
  end
@@ -3,9 +3,9 @@
3
3
  # (c) Copyright 2021 Ribose Inc.
4
4
  #
5
5
 
6
- require_relative "designation/abbreviation"
7
6
  require_relative "designation/base"
8
7
  require_relative "designation/expression"
8
+ require_relative "designation/abbreviation"
9
9
  require_relative "designation/grammar_info"
10
10
  require_relative "designation/symbol"
11
11
  require_relative "designation/graphical_symbol"
@@ -21,7 +21,7 @@ module Glossarist
21
21
  GraphicalSymbol => "graphical_symbol",
22
22
  LetterSymbol => "letter_symbol",
23
23
  }
24
- .tap { |h| h.merge!(h.invert) }
25
- .freeze
24
+ .tap { |h| h.merge!(h.invert) }
25
+ .freeze
26
26
  end
27
27
  end
@@ -1,31 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Glossarist
4
- class DetailedDefinition < Model
4
+ class DetailedDefinition < Lutaml::Model::Serializable
5
+ attribute :content, :string
6
+ attribute :sources, ConceptSource, collection: true
5
7
 
6
- def initialize(attributes = {})
7
- if attributes.is_a?(Hash)
8
- super
9
- else
10
- self.content = attributes
11
- end
12
- end
13
-
14
- # @return [String]
15
- attr_accessor :content
16
-
17
- # @return [Array<ConceptSource>]
18
- attr_reader :sources
19
-
20
- def sources=(sources)
21
- @sources = sources.map { |s| ConceptSource.new(s) }
22
- end
23
-
24
- def to_h
25
- {
26
- "content" => content,
27
- "sources" => sources&.map(&:to_h),
28
- }.compact
8
+ yaml do
9
+ map :content, to: :content
10
+ map :sources, to: :sources
29
11
  end
30
12
  end
31
13
  end
@@ -1,8 +1,8 @@
1
- require_relative "error/invalid_type_error"
2
- require_relative "error/invalid_language_code_error"
3
- require_relative "error/parse_error"
4
-
5
1
  module Glossarist
6
2
  class Error < StandardError
7
3
  end
8
4
  end
5
+
6
+ require_relative "error/invalid_type_error"
7
+ require_relative "error/invalid_language_code_error"
8
+ require_relative "error/parse_error"
@@ -4,7 +4,8 @@ require "yaml"
4
4
 
5
5
  module Glossarist
6
6
  module GlossaryDefinition
7
- config = YAML.load_file(File.expand_path("../../../config.yml", __FILE__)) || {}
7
+ config = YAML.load_file(File.expand_path("../../config.yml",
8
+ __dir__)) || {}
8
9
 
9
10
  CONCEPT_SOURCE_STATUSES = config.dig("concept_source", "status").freeze
10
11
 
@@ -14,13 +15,15 @@ module Glossarist
14
15
 
15
16
  ABBREVIATION_TYPES = config.dig("abbreviation", "type").freeze
16
17
 
17
- GRAMMAR_INFO_BOOLEAN_ATTRIBUTES = config.dig("grammar_info", "boolean_attribute").freeze
18
+ GRAMMAR_INFO_BOOLEAN_ATTRIBUTES = config.dig("grammar_info",
19
+ "boolean_attribute").freeze
18
20
 
19
21
  GRAMMAR_INFO_GENDERS = config.dig("grammar_info", "gender").freeze
20
22
 
21
23
  GRAMMAR_INFO_NUMBERS = config.dig("grammar_info", "number").freeze
22
24
 
23
- DESIGNATION_BASE_NORMATIVE_STATUSES = config.dig("designation", "base", "normative_status").freeze
25
+ DESIGNATION_BASE_NORMATIVE_STATUSES = config.dig("designation", "base",
26
+ "normative_status").freeze
24
27
 
25
28
  CONCEPT_DATE_TYPES = config.dig("concept_date", "type").freeze
26
29
 
@@ -1,75 +1,30 @@
1
- # frozen_string_literal: true
2
-
3
- # (c) Copyright 2021 Ribose Inc.
4
- #
5
-
6
1
  module Glossarist
7
2
  class LocalizedConcept < Concept
8
- # ISO 639-2 code for terminology.
9
- # @see https://www.loc.gov/standards/iso639-2/php/code_list.php code list
10
- # @return [String]
11
- attr_reader :language_code
12
-
13
- # Must be one of the following:
14
- # +notValid+, +valid+, +superseded+, +retired+.
15
- # @todo Proper type checking.
16
- # @note Works with strings, but soon they may be replaced with symbols.
17
- # @return [String]
18
- attr_accessor :entry_status
19
- alias_method :status=, :entry_status=
20
-
21
- # Must be one of the following:
22
- # +preferred+, +admitted+, +deprecated+.
23
- # @todo Proper type checking.
24
- # @note Works with strings, but soon they may be replaced with symbols.
25
- # @return [String]
26
- attr_accessor :classification
27
-
28
- # Temporary fields
29
- # @todo Need to remove these once the isotc211-glossary is fixed
30
- attr_accessor *%i[
31
- review_date
32
- review_decision_date
33
- review_decision_event
34
- review_type
35
- ]
3
+ attribute :classification, :string
4
+ attribute :review_type, :string
5
+ attribute :entry_status, :string
36
6
 
37
- def language_code=(language_code)
38
- if language_code.is_a?(String) && language_code.length == 3
39
- @language_code = language_code
40
- else
41
- raise Glossarist::InvalidLanguageCodeError.new(code: language_code)
42
- end
7
+ yaml do
8
+ map :classification, to: :classification
9
+ map %i[review_type reviewType], to: :review_type
43
10
  end
44
11
 
45
- def to_h_no_uuid # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
46
- hash = super
47
-
48
- hash["data"].merge!({
49
- "language_code" => language_code,
50
- "entry_status" => entry_status,
51
- "sources" => sources.empty? ? nil : sources&.map(&:to_h),
52
- "classification" => classification,
53
- "dates" => dates&.map(&:to_h),
54
- "review_date" => review_date,
55
- "review_decision_date" => review_decision_date,
56
- "review_decision_event" => review_decision_event,
57
- }.compact).merge!(@extension_attributes)
58
-
59
- hash["status"] = entry_status if entry_status
12
+ alias_method :status=, :entry_status=
60
13
 
61
- hash
14
+ def language_code
15
+ data.language_code
62
16
  end
63
17
 
64
- def self.from_h(hash)
65
- terms = hash["terms"]&.map { |h| Designation::Base.from_h(h) } || []
66
- sources = hash["authoritative_source"]&.each { |source| source.merge({ "type" => "authoritative" }) }
18
+ def entry_status
19
+ data.entry_status
20
+ end
67
21
 
68
- super(hash.merge({ "terms" => terms, "sources" => sources }))
22
+ def language_code=(value)
23
+ data.language_code = value
69
24
  end
70
25
 
71
- # @deprecated For legacy reasons only.
72
- # Implicit conversion (i.e. {#to_hash} alias) will be removed soon.
73
- alias :to_hash :to_h
26
+ def entry_status=(value)
27
+ data.entry_status = value
28
+ end
74
29
  end
75
30
  end