glossarist 2.6.6 → 2.6.7

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 (139) hide show
  1. checksums.yaml +4 -4
  2. data/README.adoc +90 -29
  3. data/glossarist.gemspec +2 -0
  4. data/lib/glossarist/citation.rb +26 -123
  5. data/lib/glossarist/cli/compare_command.rb +106 -0
  6. data/lib/glossarist/cli/export_command.rb +11 -14
  7. data/lib/glossarist/cli/validate_command.rb +111 -20
  8. data/lib/glossarist/cli.rb +18 -0
  9. data/lib/glossarist/collections/bibliography_collection.rb +4 -2
  10. data/lib/glossarist/collections/localization_collection.rb +2 -0
  11. data/lib/glossarist/comparison_result.rb +35 -0
  12. data/lib/glossarist/concept_collector.rb +44 -0
  13. data/lib/glossarist/concept_comparator.rb +72 -0
  14. data/lib/glossarist/concept_data.rb +16 -0
  15. data/lib/glossarist/concept_diff.rb +15 -0
  16. data/lib/glossarist/concept_document.rb +11 -0
  17. data/lib/glossarist/concept_manager.rb +19 -5
  18. data/lib/glossarist/concept_ref.rb +13 -0
  19. data/lib/glossarist/concept_validator.rb +6 -1
  20. data/lib/glossarist/context_configuration.rb +90 -0
  21. data/lib/glossarist/dataset_validator.rb +8 -4
  22. data/lib/glossarist/designation/prefix.rb +17 -0
  23. data/lib/glossarist/designation/suffix.rb +17 -0
  24. data/lib/glossarist/gcr_metadata.rb +7 -14
  25. data/lib/glossarist/gcr_package.rb +35 -23
  26. data/lib/glossarist/gcr_validator.rb +38 -17
  27. data/lib/glossarist/localized_concept.rb +8 -0
  28. data/lib/glossarist/managed_concept.rb +39 -6
  29. data/lib/glossarist/managed_concept_data.rb +2 -1
  30. data/lib/glossarist/rdf/ext/jsonld_transform_ext.rb +208 -0
  31. data/lib/glossarist/rdf/ext/mapping_ext.rb +37 -0
  32. data/lib/glossarist/rdf/ext/mapping_rule_ext.rb +27 -0
  33. data/lib/glossarist/rdf/ext/member_rule_ext.rb +34 -0
  34. data/lib/glossarist/rdf/ext/turtle_transform_ext.rb +222 -0
  35. data/lib/glossarist/rdf/ext.rb +39 -0
  36. data/lib/glossarist/rdf/gloss_citation.rb +36 -0
  37. data/lib/glossarist/rdf/gloss_concept.rb +58 -0
  38. data/lib/glossarist/rdf/gloss_concept_date.rb +24 -0
  39. data/lib/glossarist/rdf/gloss_concept_reference.rb +29 -0
  40. data/lib/glossarist/rdf/gloss_concept_source.rb +37 -0
  41. data/lib/glossarist/rdf/gloss_designation.rb +146 -0
  42. data/lib/glossarist/rdf/gloss_detailed_definition.rb +24 -0
  43. data/lib/glossarist/rdf/gloss_grammar_info.rb +57 -0
  44. data/lib/glossarist/rdf/gloss_locality.rb +25 -0
  45. data/lib/glossarist/rdf/gloss_localized_concept.rb +67 -0
  46. data/lib/glossarist/rdf/gloss_non_verbal_rep.rb +31 -0
  47. data/lib/glossarist/rdf/gloss_pronunciation.rb +32 -0
  48. data/lib/glossarist/rdf/gloss_reference.rb +55 -0
  49. data/lib/glossarist/rdf/namespaces/glossarist_namespace.rb +12 -0
  50. data/lib/glossarist/rdf/namespaces/iso_thes_namespace.rb +12 -0
  51. data/lib/glossarist/rdf/namespaces/owl_namespace.rb +12 -0
  52. data/lib/glossarist/rdf/namespaces/prov_namespace.rb +12 -0
  53. data/lib/glossarist/rdf/namespaces/rdf_namespace.rb +12 -0
  54. data/lib/glossarist/rdf/namespaces/skosxl_namespace.rb +12 -0
  55. data/lib/glossarist/rdf/namespaces.rb +8 -2
  56. data/lib/glossarist/rdf/relationships.rb +19 -0
  57. data/lib/glossarist/rdf/v3/configuration.rb +15 -0
  58. data/lib/glossarist/rdf/v3.rb +79 -0
  59. data/lib/glossarist/rdf.rb +22 -2
  60. data/lib/glossarist/reference_extractor.rb +12 -19
  61. data/lib/glossarist/reference_resolver.rb +3 -3
  62. data/lib/glossarist/related_concept.rb +2 -10
  63. data/lib/glossarist/schema_migration.rb +39 -0
  64. data/lib/glossarist/sts/term_mapper.rb +2 -2
  65. data/lib/glossarist/transforms/concept_to_gloss_transform.rb +355 -0
  66. data/lib/glossarist/transforms.rb +2 -2
  67. data/lib/glossarist/v1/concept.rb +17 -17
  68. data/lib/glossarist/v2/citation.rb +36 -0
  69. data/lib/glossarist/v2/concept_data.rb +46 -0
  70. data/lib/glossarist/v2/concept_document.rb +18 -0
  71. data/lib/glossarist/v2/concept_ref.rb +8 -0
  72. data/lib/glossarist/v2/concept_source.rb +16 -0
  73. data/lib/glossarist/v2/configuration.rb +13 -0
  74. data/lib/glossarist/v2/detailed_definition.rb +14 -0
  75. data/lib/glossarist/v2/localized_concept.rb +9 -0
  76. data/lib/glossarist/v2/managed_concept.rb +25 -0
  77. data/lib/glossarist/v2/managed_concept_data.rb +49 -0
  78. data/lib/glossarist/v2/related_concept.rb +15 -0
  79. data/lib/glossarist/v2.rb +28 -0
  80. data/lib/glossarist/v3/bibliography_entry.rb +19 -0
  81. data/lib/glossarist/v3/bibliography_file.rb +27 -0
  82. data/lib/glossarist/v3/citation.rb +30 -0
  83. data/lib/glossarist/v3/concept_data.rb +46 -0
  84. data/lib/glossarist/v3/concept_document.rb +18 -0
  85. data/lib/glossarist/v3/concept_ref.rb +8 -0
  86. data/lib/glossarist/v3/concept_source.rb +16 -0
  87. data/lib/glossarist/v3/configuration.rb +13 -0
  88. data/lib/glossarist/v3/detailed_definition.rb +14 -0
  89. data/lib/glossarist/v3/image_entry.rb +21 -0
  90. data/lib/glossarist/v3/image_file.rb +31 -0
  91. data/lib/glossarist/v3/localized_concept.rb +9 -0
  92. data/lib/glossarist/v3/managed_concept.rb +26 -0
  93. data/lib/glossarist/v3/managed_concept_data.rb +34 -0
  94. data/lib/glossarist/v3/related_concept.rb +15 -0
  95. data/lib/glossarist/v3.rb +36 -0
  96. data/lib/glossarist/validation/bibliography_index.rb +61 -30
  97. data/lib/glossarist/validation/rules/asciidoc_xref_rule.rb +2 -15
  98. data/lib/glossarist/validation/rules/authoritative_source_rule.rb +2 -15
  99. data/lib/glossarist/validation/rules/base.rb +5 -0
  100. data/lib/glossarist/validation/rules/bibliography_yaml_rule.rb +2 -3
  101. data/lib/glossarist/validation/rules/citation_completeness_rule.rb +5 -27
  102. data/lib/glossarist/validation/rules/dataset_context.rb +8 -3
  103. data/lib/glossarist/validation/rules/date_validity_rule.rb +1 -1
  104. data/lib/glossarist/validation/rules/designation_status_rule.rb +0 -1
  105. data/lib/glossarist/validation/rules/designation_type_rule.rb +1 -5
  106. data/lib/glossarist/validation/rules/domain_ref_rule.rb +37 -0
  107. data/lib/glossarist/validation/rules/domain_target_rule.rb +56 -0
  108. data/lib/glossarist/validation/rules/gcr_context.rb +12 -13
  109. data/lib/glossarist/validation/rules/image_reference_rule.rb +2 -17
  110. data/lib/glossarist/validation/rules/locality_completeness_rule.rb +58 -0
  111. data/lib/glossarist/validation/rules/localization_consistency_rule.rb +72 -0
  112. data/lib/glossarist/validation/rules/localization_presence_rule.rb +1 -1
  113. data/lib/glossarist/validation/rules/model_validity_rule.rb +71 -0
  114. data/lib/glossarist/validation/rules/orphaned_bibliography_rule.rb +1 -13
  115. data/lib/glossarist/validation/rules/orphaned_images_rule.rb +16 -11
  116. data/lib/glossarist/validation/rules/ref_shape_rule.rb +68 -0
  117. data/lib/glossarist/validation/rules/related_concept_cycle_rule.rb +1 -3
  118. data/lib/glossarist/validation/rules/related_concept_symmetry_rule.rb +1 -3
  119. data/lib/glossarist/validation/rules/related_concept_target_rule.rb +64 -0
  120. data/lib/glossarist/validation/rules/schema_version_rule.rb +41 -0
  121. data/lib/glossarist/validation/rules/source_type_rule.rb +1 -15
  122. data/lib/glossarist/validation/rules/source_urn_format_rule.rb +65 -0
  123. data/lib/glossarist/validation/rules/uuid_format_rule.rb +33 -0
  124. data/lib/glossarist/validation/rules.rb +10 -43
  125. data/lib/glossarist/validation/validation_issue.rb +14 -11
  126. data/lib/glossarist/validation_result.rb +12 -22
  127. data/lib/glossarist/version.rb +1 -1
  128. data/lib/glossarist.rb +9 -0
  129. data/memory/project-status.md +43 -0
  130. data/scripts/migrate_dataset.rb +180 -0
  131. data/scripts/migrate_isotc204_to_v3.rb +134 -0
  132. data/scripts/migrate_isotc211_to_v3.rb +153 -0
  133. data/scripts/migrate_osgeo_to_v3.rb +155 -0
  134. data/scripts/upgrade_dataset_to_v3.rb +47 -0
  135. metadata +111 -6
  136. data/TODO.integration/01-gcr-package-cli.md +0 -180
  137. data/lib/glossarist/rdf/skos_concept.rb +0 -43
  138. data/lib/glossarist/rdf/skos_vocabulary.rb +0 -25
  139. data/lib/glossarist/transforms/concept_to_skos_transform.rb +0 -131
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V2
5
+ class ManagedConceptData < Glossarist::ManagedConceptData
6
+ attribute :sources, V2::ConceptSource, collection: true
7
+ attribute :localizations, V2::LocalizedConcept,
8
+ collection: Collections::LocalizationCollection,
9
+ initialize_empty: true
10
+ attribute :related, V2::RelatedConcept, collection: true
11
+
12
+ key_value do
13
+ map %i[id identifier], to: :id,
14
+ with: { to: :id_to_yaml, from: :id_from_yaml }
15
+ map :uri, to: :uri
16
+ map %i[localized_concepts localizedConcepts], to: :localized_concepts
17
+ map %i[domains groups], to: :domains,
18
+ with: { from: :domains_from_yaml, to: :domains_to_yaml }
19
+ map :sources, to: :sources
20
+ map :localizations, to: :localizations,
21
+ with: { from: :localizations_from_yaml, to: :localizations_to_yaml }
22
+ map :related, to: :related,
23
+ with: { from: :related_from_yaml, to: :related_to_yaml }
24
+ end
25
+
26
+ def localizations_from_yaml(model, value)
27
+ value.each do |localized_concept_hash|
28
+ localized_concept = V2::LocalizedConcept.of_yaml(localized_concept_hash)
29
+ model.localizations.store(localized_concept.language_code,
30
+ localized_concept)
31
+ end
32
+ end
33
+
34
+ def localizations_to_yaml(model, doc); end
35
+
36
+ def related_from_yaml(model, value)
37
+ return unless value.is_a?(Array)
38
+
39
+ model.related = value.map { |r| V2::RelatedConcept.of_yaml(r) }
40
+ end
41
+
42
+ def related_to_yaml(model, doc)
43
+ return unless model.related&.any?
44
+
45
+ doc["related"] = model.related.map(&:to_hash)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V2
5
+ class RelatedConcept < Glossarist::RelatedConcept
6
+ attribute :ref, V2::ConceptRef
7
+
8
+ key_value do
9
+ map :content, to: :content
10
+ map :type, to: :type
11
+ map :ref, to: :ref
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "v2/configuration"
4
+ require_relative "v2/citation"
5
+ require_relative "v2/concept_source"
6
+ require_relative "v2/detailed_definition"
7
+ require_relative "v2/concept_ref"
8
+ require_relative "v2/related_concept"
9
+ require_relative "v2/concept_data"
10
+ require_relative "v2/localized_concept"
11
+ require_relative "v2/managed_concept_data"
12
+ require_relative "v2/managed_concept"
13
+ require_relative "v2/concept_document"
14
+
15
+ module Glossarist
16
+ module V2
17
+ Configuration.register_model(Citation, id: :citation)
18
+ Configuration.register_model(ConceptSource, id: :concept_source)
19
+ Configuration.register_model(DetailedDefinition, id: :detailed_definition)
20
+ Configuration.register_model(ConceptData, id: :concept_data)
21
+ Configuration.register_model(LocalizedConcept, id: :localized_concept)
22
+ Configuration.register_model(ConceptRef, id: :concept_ref)
23
+ Configuration.register_model(RelatedConcept, id: :related_concept)
24
+ Configuration.register_model(ManagedConceptData, id: :managed_concept_data)
25
+ Configuration.register_model(ManagedConcept, id: :managed_concept)
26
+ Configuration.register_model(ConceptDocument, id: :concept_document)
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class BibliographyEntry < Lutaml::Model::Serializable
6
+ attribute :id, :string
7
+ attribute :reference, :string
8
+ attribute :title, :string
9
+ attribute :link, :string
10
+
11
+ key_value do
12
+ map :id, to: :id
13
+ map :reference, to: :reference
14
+ map :title, to: :title
15
+ map :link, to: :link
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class BibliographyFile < Lutaml::Model::Collection
6
+ instances :entries, BibliographyEntry
7
+
8
+ key_value do
9
+ map_instances to: :entries
10
+ end
11
+
12
+ def self.from_file(path)
13
+ return nil unless File.exist?(path)
14
+
15
+ from_yaml(File.read(path))
16
+ end
17
+
18
+ def resolve?(anchor)
19
+ entries.any? { |e| e.id == anchor.to_s }
20
+ end
21
+
22
+ def [](key)
23
+ entries.find { |e| e.id == key.to_s }
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class Citation < Glossarist::Citation
6
+ key_value do
7
+ map :ref, to: :ref, with: { from: :ref_from_yaml, to: :ref_to_yaml }
8
+ end
9
+
10
+ def ref_from_yaml(model, value)
11
+ case value
12
+ when Hash
13
+ model.ref = Ref.new(value.transform_keys(&:to_sym))
14
+ when String
15
+ model.ref = Ref.new(source: value)
16
+ end
17
+ end
18
+
19
+ def ref_to_yaml(model, doc)
20
+ return unless model.ref
21
+
22
+ attrs = {}
23
+ attrs["source"] = model.ref.source if model.ref.source
24
+ attrs["id"] = model.ref.id if model.ref.id
25
+ attrs["version"] = model.ref.version if model.ref.version
26
+ doc["ref"] = attrs.empty? ? nil : attrs
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class ConceptData < Glossarist::ConceptData
6
+ attribute :sources, V3::ConceptSource,
7
+ collection: Collections::ConceptSourceCollection,
8
+ initialize_empty: true
9
+ attribute :definition, V3::DetailedDefinition,
10
+ collection: Collections::DetailedDefinitionCollection,
11
+ initialize_empty: true
12
+ attribute :examples, V3::DetailedDefinition,
13
+ collection: Collections::DetailedDefinitionCollection,
14
+ initialize_empty: true
15
+ attribute :notes, V3::DetailedDefinition,
16
+ collection: Collections::DetailedDefinitionCollection,
17
+ initialize_empty: true
18
+ attribute :related, V3::RelatedConcept, collection: true
19
+
20
+ key_value do
21
+ map :dates, to: :dates
22
+ map :definition, to: :definition
23
+ map :examples, to: :examples
24
+ map :id, to: :id
25
+ map %i[lineage_source_similarity lineageSourceSimilarity],
26
+ to: :lineage_source_similarity
27
+ map :notes, to: :notes
28
+ map :release, to: :release
29
+ map :sources, to: :sources
30
+ map :terms, to: :terms,
31
+ with: { from: :terms_from_yaml, to: :terms_to_yaml }
32
+ map :related, to: :related
33
+ map :references, to: :references
34
+ map :domain, to: :domain
35
+ map %i[language_code languageCode], to: :language_code
36
+ map :script, to: :script
37
+ map :system, to: :system
38
+ map %i[entry_status entryStatus], to: :entry_status
39
+ map %i[review_date reviewDate], to: :review_date
40
+ map %i[review_decision_date reviewDecisionDate], to: :review_decision_date
41
+ map %i[review_decision_event reviewDecisionEvent],
42
+ to: :review_decision_event
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class ConceptDocument < Glossarist::ConceptDocument
6
+ attribute :concept, V3::ManagedConcept
7
+ attribute :localizations, V3::LocalizedConcept, collection: true
8
+
9
+ yamls do
10
+ sequence do
11
+ map_document 0, to: :concept, type: V3::ManagedConcept
12
+ map_document 1.., to: :localizations, type: V3::LocalizedConcept,
13
+ collection: true
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class ConceptRef < Glossarist::ConceptRef
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class ConceptSource < Glossarist::ConceptSource
6
+ attribute :origin, V3::Citation
7
+
8
+ key_value do
9
+ map :origin, to: :origin
10
+ map :status, to: :status
11
+ map :type, to: :type
12
+ map :modification, to: :modification
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../context_configuration"
4
+
5
+ module Glossarist
6
+ module V3
7
+ module Configuration
8
+ extend Glossarist::ContextConfiguration
9
+
10
+ CONTEXT_ID = :glossarist_v3
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class DetailedDefinition < Glossarist::DetailedDefinition
6
+ attribute :sources, V3::ConceptSource, collection: true
7
+
8
+ key_value do
9
+ map :content, to: :content
10
+ map :sources, to: :sources
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class ImageEntry < Lutaml::Model::Serializable
6
+ attribute :id, :string
7
+ attribute :path, :string
8
+ attribute :type, :string, default: -> { "image" }
9
+ attribute :title, :string
10
+ attribute :alt, :string
11
+
12
+ key_value do
13
+ map :id, to: :id
14
+ map :path, to: :path
15
+ map :type, to: :type
16
+ map :title, to: :title
17
+ map :alt, to: :alt
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class ImageFile < Lutaml::Model::Collection
6
+ instances :entries, ImageEntry
7
+
8
+ key_value do
9
+ map_instances to: :entries
10
+ end
11
+
12
+ def self.from_file(path)
13
+ return nil unless File.exist?(path)
14
+
15
+ from_yaml(File.read(path))
16
+ end
17
+
18
+ def path_for_anchor(anchor)
19
+ entries.find { |e| e.id == anchor.to_s }&.path
20
+ end
21
+
22
+ def anchor_for_path(path)
23
+ entries.find { |e| e.path == path }&.id
24
+ end
25
+
26
+ def path?(path)
27
+ entries.any? { |e| e.path == path }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class LocalizedConcept < Glossarist::LocalizedConcept
6
+ attribute :data, V3::ConceptData, default: -> { V3::ConceptData.new }
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class ManagedConcept < Glossarist::ManagedConcept
6
+ attribute :data, V3::ManagedConceptData, default: -> { V3::ManagedConceptData.new }
7
+ attribute :related, V3::RelatedConcept, collection: true
8
+ attribute :sources, V3::ConceptSource, collection: true
9
+
10
+ key_value do
11
+ map :data, to: :data
12
+ map :id, with: { to: :identifier_to_yaml, from: :identifier_from_yaml }
13
+ map :identifier,
14
+ with: { to: :identifier_to_yaml, from: :identifier_from_yaml }
15
+ map :related, to: :related
16
+ map :dates, to: :dates
17
+ map %i[date_accepted dateAccepted],
18
+ with: { from: :date_accepted_from_yaml, to: :date_accepted_to_yaml }
19
+ map :status, to: :status
20
+ map :uuid, to: :uuid, with: { from: :uuid_from_yaml, to: :uuid_to_yaml }
21
+ map :schema_version, to: :schema_version
22
+ map :sources, to: :sources
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class ManagedConceptData < Glossarist::ManagedConceptData
6
+ attribute :sources, V3::ConceptSource, collection: true
7
+ attribute :localizations, V3::LocalizedConcept,
8
+ collection: Collections::LocalizationCollection,
9
+ initialize_empty: true
10
+
11
+ key_value do
12
+ map %i[id identifier], to: :id,
13
+ with: { to: :id_to_yaml, from: :id_from_yaml }
14
+ map :uri, to: :uri
15
+ map %i[localized_concepts localizedConcepts], to: :localized_concepts
16
+ map %i[domains groups], to: :domains,
17
+ with: { from: :domains_from_yaml, to: :domains_to_yaml }
18
+ map :sources, to: :sources
19
+ map :localizations, to: :localizations,
20
+ with: { from: :localizations_from_yaml, to: :localizations_to_yaml }
21
+ end
22
+
23
+ def localizations_from_yaml(model, value)
24
+ value.each do |localized_concept_hash|
25
+ localized_concept = V3::LocalizedConcept.of_yaml(localized_concept_hash)
26
+ model.localizations.store(localized_concept.language_code,
27
+ localized_concept)
28
+ end
29
+ end
30
+
31
+ def localizations_to_yaml(model, doc); end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Glossarist
4
+ module V3
5
+ class RelatedConcept < Glossarist::RelatedConcept
6
+ attribute :ref, V3::ConceptRef
7
+
8
+ key_value do
9
+ map :content, to: :content
10
+ map :type, to: :type
11
+ map :ref, to: :ref
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "v3/configuration"
4
+ require_relative "v3/citation"
5
+ require_relative "v3/concept_source"
6
+ require_relative "v3/detailed_definition"
7
+ require_relative "v3/concept_ref"
8
+ require_relative "v3/related_concept"
9
+ require_relative "v3/concept_data"
10
+ require_relative "v3/localized_concept"
11
+ require_relative "v3/managed_concept_data"
12
+ require_relative "v3/managed_concept"
13
+ require_relative "v3/concept_document"
14
+ require_relative "v3/bibliography_entry"
15
+ require_relative "v3/bibliography_file"
16
+ require_relative "v3/image_entry"
17
+ require_relative "v3/image_file"
18
+
19
+ module Glossarist
20
+ module V3
21
+ Configuration.register_model(Citation, id: :citation)
22
+ Configuration.register_model(ConceptSource, id: :concept_source)
23
+ Configuration.register_model(DetailedDefinition, id: :detailed_definition)
24
+ Configuration.register_model(ConceptData, id: :concept_data)
25
+ Configuration.register_model(LocalizedConcept, id: :localized_concept)
26
+ Configuration.register_model(ConceptRef, id: :concept_ref)
27
+ Configuration.register_model(RelatedConcept, id: :related_concept)
28
+ Configuration.register_model(ManagedConceptData, id: :managed_concept_data)
29
+ Configuration.register_model(ManagedConcept, id: :managed_concept)
30
+ Configuration.register_model(ConceptDocument, id: :concept_document)
31
+ Configuration.register_model(BibliographyEntry, id: :bibliography_entry)
32
+ Configuration.register_model(BibliographyFile, id: :bibliography_file)
33
+ Configuration.register_model(ImageEntry, id: :image_entry)
34
+ Configuration.register_model(ImageFile, id: :image_file)
35
+ end
36
+ end
@@ -3,9 +3,6 @@
3
3
  module Glossarist
4
4
  module Validation
5
5
  class BibliographyIndex
6
- BIB_ENTRY_KEYS = %w[id ref text anchor].freeze
7
- private_constant :BIB_ENTRY_KEYS
8
-
9
6
  attr_reader :entries
10
7
 
11
8
  def initialize
@@ -28,14 +25,22 @@ module Glossarist
28
25
  @entries.each_value(&block)
29
26
  end
30
27
 
31
- def self.build_from_concepts(concepts, dataset_path: nil,
32
- bibliography_yaml: nil)
28
+ def self.build_from_concepts(concepts, dataset_path: nil)
33
29
  index = new
34
30
 
35
31
  concepts.each { |concept| index_concept_sources(index, concept) }
32
+ index_bibliography_file(index, dataset_path)
33
+ index_images_file(index, dataset_path)
34
+
35
+ index
36
+ end
37
+
38
+ def self.build_from_yaml(concepts, bibliography_yaml: nil, images_yaml: nil)
39
+ index = new
36
40
 
37
- yaml = bibliography_yaml || read_bibliography_file(dataset_path)
38
- index_bibliography_yaml(index, yaml) if yaml
41
+ concepts.each { |concept| index_concept_sources(index, concept) }
42
+ index_bib_from_yaml_string(index, bibliography_yaml)
43
+ index_images_from_yaml_string(index, images_yaml)
39
44
 
40
45
  index
41
46
  end
@@ -49,13 +54,6 @@ bibliography_yaml: nil)
49
54
  class << self
50
55
  private
51
56
 
52
- def read_bibliography_file(dataset_path)
53
- return nil unless dataset_path
54
-
55
- bib_path = File.join(dataset_path, "bibliography.yaml")
56
- File.exist?(bib_path) ? File.read(bib_path) : nil
57
- end
58
-
59
57
  def index_concept_sources(index, concept)
60
58
  concept.localizations.each do |l10n|
61
59
  index_l10n_sources(index, l10n)
@@ -86,33 +84,66 @@ bibliography_yaml: nil)
86
84
  end
87
85
 
88
86
  def register_origin_text(index, origin)
89
- return unless origin.text && !origin.text.strip.empty?
87
+ ref = origin.ref
88
+ return unless ref && ref.source && !ref.source.strip.empty?
90
89
 
91
- index.register(origin.text, origin)
90
+ index.register(ref.source, origin)
92
91
  end
93
92
 
94
93
  def register_origin_ref(index, origin)
95
- return unless origin.source && origin.id
94
+ ref = origin.ref
95
+ return unless ref && ref.source && ref.id
96
96
 
97
- key = "#{origin.source} #{origin.id}"
97
+ key = "#{ref.source} #{ref.id}"
98
98
  index.register(key, origin)
99
- index.register(origin.id.to_s, origin)
99
+ index.register(ref.id.to_s, origin)
100
100
  end
101
101
 
102
- def index_bibliography_yaml(index, yaml_content)
103
- data = YAML.safe_load(yaml_content)
104
- return unless data.is_a?(Hash) || data.is_a?(Array)
102
+ def index_bibliography_file(index, dataset_path)
103
+ return unless dataset_path
105
104
 
106
- entries = data.is_a?(Hash) ? data.values : data
107
- entries.each do |entry|
108
- next unless entry.is_a?(Hash)
105
+ bib = V3::BibliographyFile.from_file(
106
+ File.join(dataset_path, "bibliography.yaml"),
107
+ )
108
+ return unless bib
109
109
 
110
- BIB_ENTRY_KEYS.each do |key|
111
- val = entry[key]
112
- index.register(val.to_s, entry) if val && !val.to_s.strip.empty?
113
- end
110
+ bib.entries.each do |entry|
111
+ index.register(entry.id, entry)
112
+ index.register(entry.reference, entry) if entry.reference
114
113
  end
115
- rescue Psych::SyntaxError, Psych::DisallowedClass
114
+ end
115
+
116
+ def index_images_file(index, dataset_path)
117
+ return unless dataset_path
118
+
119
+ images = V3::ImageFile.from_file(
120
+ File.join(dataset_path, "images.yaml"),
121
+ )
122
+ return unless images
123
+
124
+ images.entries.each do |entry|
125
+ index.register(entry.id, entry)
126
+ end
127
+ end
128
+
129
+ def index_bib_from_yaml_string(index, yaml_content)
130
+ return unless yaml_content
131
+
132
+ bib = V3::BibliographyFile.from_yaml(yaml_content)
133
+ bib.entries.each do |entry|
134
+ index.register(entry.id, entry)
135
+ index.register(entry.reference, entry) if entry.reference
136
+ end
137
+ rescue StandardError
138
+ nil
139
+ end
140
+
141
+ def index_images_from_yaml_string(index, yaml_content)
142
+ return unless yaml_content
143
+
144
+ images = V3::ImageFile.from_yaml(yaml_content)
145
+ images.entries.each { |entry| index.register(entry.id, entry) }
146
+ rescue StandardError
116
147
  nil
117
148
  end
118
149
  end
@@ -21,12 +21,10 @@ module Glossarist
21
21
 
22
22
  concept.localizations.each do |l10n|
23
23
  lang = l10n.language_code || "unknown"
24
- texts = extract_texts(l10n)
25
24
 
26
- texts.each do |text|
25
+ l10n.text_content.each do |text|
27
26
  next unless text
28
- refs = extractor.extract_from_text(text)
29
- refs.each do |ref|
27
+ extractor.extract_from_text(text).each do |ref|
30
28
  next unless ref.is_a?(BibliographicReference)
31
29
  next if context.bibliography_index.resolve?(ref.anchor)
32
30
 
@@ -43,18 +41,7 @@ module Glossarist
43
41
 
44
42
  issues
45
43
  end
46
-
47
- private
48
-
49
- def extract_texts(l10n)
50
- texts = []
51
- (l10n.data&.definition || []).each { |d| texts << d.content if d.content }
52
- (l10n.data&.notes || []).each { |n| texts << n.content if n.content }
53
- (l10n.data&.examples || []).each { |e| texts << e.content if e.content }
54
- texts
55
- end
56
44
  end
57
45
  end
58
46
  end
59
47
  end
60
-
@@ -16,7 +16,8 @@ module Glossarist
16
16
  def check(context)
17
17
  concept = context.concept
18
18
  fname = context.file_name
19
- all_sources = gather_all_sources(concept)
19
+
20
+ all_sources = concept.localizations.flat_map(&:all_sources)
20
21
 
21
22
  return [] if all_sources.any? { |s| s.type == "authoritative" }
22
23
 
@@ -27,21 +28,7 @@ module Glossarist
27
28
  suggestion: "Add at least one source with type: authoritative",
28
29
  )]
29
30
  end
30
-
31
- private
32
-
33
- def gather_all_sources(concept)
34
- sources = []
35
- concept.localizations.each do |l10n|
36
- (l10n.data&.sources || []).each { |s| sources << s }
37
- (l10n.data&.definition || []).each { |d| (d.sources || []).each { |s| sources << s } }
38
- (l10n.data&.notes || []).each { |n| (n.sources || []).each { |s| sources << s } }
39
- (l10n.data&.examples || []).each { |e| (e.sources || []).each { |s| sources << s } }
40
- end
41
- sources
42
- end
43
31
  end
44
32
  end
45
33
  end
46
34
  end
47
-