Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support paneron glossarist attributes in localized concept #112

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions lib/glossarist/concept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,20 @@ def initialize(*args)
def uuid
@uuid ||= Glossarist::Utilities::UUID.uuid_v5(
Glossarist::Utilities::UUID::OID_NAMESPACE,
to_h.to_yaml,
to_h_no_uuid.to_yaml,
)
end

def id=(id)
# Some of the glossaries that are not generated using glossarist, contains ids that are integers
# Some of the glossaries that are not generated using glossarist, contains ids that are integers
# so adding a temporary check until every glossary is updated using glossarist.
if !id.nil? && (id.is_a?(String) || id.is_a?(Integer))
@id = id
else
raise(Glossarist::Error, "Expect id to be a String or Integer, Got #{id.class} (#{id})")
end
end

alias :termid= :id=
alias :identifier= :id=

Expand Down Expand Up @@ -119,6 +120,7 @@ def designations=(designations)
def preferred_designations
@designations.select(&:preferred?)
end

alias :preferred_terms :preferred_designations

def dates=(dates)
Expand All @@ -141,7 +143,22 @@ def authoritative_source=(sources)
end
end

def to_h
def date_accepted=(date)
date_hash = {
"type" => "accepted",
"date" => date,
}

@dates ||= []
@dates << ConceptDate.new(date_hash)
end

def date_accepted
return nil unless @dates
@dates.find { |date| date.accepted? }
end

def to_h_no_uuid
{
"data" => {
"dates" => dates&.map(&:to_h),
Expand All @@ -154,10 +171,18 @@ def to_h
"sources" => sources.empty? ? nil : sources&.map(&:to_h),
"terms" => (terms&.map(&:to_h) || []),
"related" => related&.map(&:to_h),
"domain" => domain,
}.compact,

"date_accepted" => date_accepted&.date,

}.compact
end

def to_h
to_h_no_uuid.merge("id" => uuid)
end

# @deprecated For legacy reasons only.
# Implicit conversion (i.e. {#to_hash} alias) will be removed soon.
alias :to_hash :to_h
Expand Down
17 changes: 9 additions & 8 deletions lib/glossarist/localized_concept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class LocalizedConcept < Concept
# Temporary fields
# @todo Need to remove these once the isotc211-glossary is fixed
attr_accessor *%i[
review_date
review_decision_date
review_decision_event
review_type
]
review_date
review_decision_date
review_decision_event
review_type
]

def language_code=(language_code)
if language_code.is_a?(String) && language_code.length == 3
Expand All @@ -41,11 +41,10 @@ def language_code=(language_code)
end
end

def to_h # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def to_h_no_uuid # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
hash = super

hash["data"].merge!({
"domain" => domain,
"language_code" => language_code,
"entry_status" => entry_status,
"sources" => sources.empty? ? nil : sources&.map(&:to_h),
Expand All @@ -56,14 +55,16 @@ def to_h # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
"review_decision_event" => review_decision_event,
}.compact).merge!(@extension_attributes)

hash["status"] = entry_status if entry_status

hash
end

def self.from_h(hash)
terms = hash["terms"]&.map { |h| Designation::Base.from_h(h) } || []
sources = hash["authoritative_source"]&.each { |source| source.merge({ "type" => "authoritative" }) }

super(hash.merge({"terms" => terms, "sources" => sources}))
super(hash.merge({ "terms" => terms, "sources" => sources }))
end

# @deprecated For legacy reasons only.
Expand Down
2 changes: 1 addition & 1 deletion spec/features/v1_serialization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
localized_concept_path = File.join(localized_concepts_folder, "#{id}.yaml")
localized_concept = load_yaml_file(localized_concept_path)

expect(localized_concept["data"]).to eq(concept.localizations[lang].to_h["data"])
expect(localized_concept["data"]).to eq(concept.localizations[lang].to_h_no_uuid["data"])
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/features/v2_serialization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
localized_concept_path = File.join(localized_concepts_folder, "#{id}.yaml")
localized_concept = load_yaml_file(localized_concept_path)

expect(localized_concept["data"]).to eq(concept.localizations[lang].to_h["data"])
expect(localized_concept["data"]).to eq(concept.localizations[lang].to_h_no_uuid["data"])
end
end

Expand Down Expand Up @@ -59,7 +59,7 @@
localized_concept_path = File.join(localized_concepts_folder, "#{id}.yaml")
localized_concept = load_yaml_file(localized_concept_path)

expect(localized_concept["data"]).to eq(concept.localizations[lang].to_h["data"])
expect(localized_concept["data"]).to eq(concept.localizations[lang].to_h_no_uuid["data"])
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
data:
identifier: 3.1.1.6
localized_concepts:
eng: b69609eb-0b27-50bf-86a0-634409e25872
id: '09767627-efa4-5d13-9503-b06ba3f18cda'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
data:
identifier: 3.1.1.5
localized_concepts:
eng: 285b90e7-2f7d-586a-bf5b-016dbfcdcf77
id: 17d42136-6e1f-58ec-8b20-64ec244dfe4c

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
data:
identifier: 3.1.1.1
localized_concepts:
eng: 2d05fd15-6c65-501b-b1e2-77389a1efd3a
groups:
- foo
- bar
id: 2be5e463-8e95-5a4d-9796-27fbd9eea33a

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
data:
identifier: 3.1.1.2
localized_concepts:
eng: 6660ed79-d78b-5940-887f-9c86597eed26
id: 4268ae1d-fbc6-5ce2-aec9-7b0065b9576d

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
data:
identifier: 3.1.1.4
localized_concepts:
eng: b90879f4-9627-5c09-a660-827b44f4fb24
id: a7c18f14-095c-51a6-9c60-5219d2937e5a

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
data:
identifier: 3.1.1.3
localized_concepts:
eng: dca5c779-33de-5621-a824-b8054ea26316
id: a9be0faa-aadc-5dbe-8128-f70708ee88cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ data:
designation: biological_entity
language_code: eng
entry_status: valid
status: valid
id: 285b90e7-2f7d-586a-bf5b-016dbfcdcf77
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
data:
dates:
- date: 2008-11-15 00:00:00.000000000 +08:00
- date: &1 2008-11-15 00:00:00.000000000 +08:00
type: accepted
definition:
- content: concrete or abstract thing that exists, did exist, or can possibly exist,
Expand All @@ -21,3 +21,6 @@ data:
designation: entity
language_code: eng
entry_status: valid
date_accepted: *1
status: valid
id: 2d05fd15-6c65-501b-b1e2-77389a1efd3a
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ data:
designation: immaterial_entity
language_code: eng
entry_status: valid
status: valid
id: 6660ed79-d78b-5940-887f-9c86597eed26
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ data:
designation: person
language_code: eng
entry_status: valid
status: valid
id: b69609eb-0b27-50bf-86a0-634409e25872
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ data:
designation: non-biological entity
language_code: eng
entry_status: valid
status: valid
id: b90879f4-9627-5c09-a660-827b44f4fb24
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ data:
designation: material entity
language_code: eng
entry_status: valid
status: valid
id: dca5c779-33de-5621-a824-b8054ea26316
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ data:
normative_status: preferred
designation: دلالة
language_code: ara
date_accepted: '2010-11-01T00:00:00.000Z'
id: '081154c5-89d6-5192-8147-373bd6060eaa'
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ data:
- type: expression
designation: ellipsoidal latitude
language_code: eng
date_accepted: '2003-02-15T00:00:00.000Z'
id: 27457e38-89b5-5694-8d19-0dd3973ec71d
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ data:
normative_status: preferred
designation: Intension
language_code: deu
date_accepted: '2010-11-01T00:00:00.000Z'
id: 527bd617-f471-5523-9b98-59bb181f3df8
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ data:
- type: expression
designation: Sistema de Coordenadas Cartesianas
language_code: spa
date_accepted: '2015-08-15T00:00:00.000Z'
id: becf3892-886d-5dab-8a7c-af303e576a8d
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ data:
normative_status: preferred
designation: intension
language_code: eng
date_accepted: '2010-11-01T00:00:00.000Z'
id: bf1691ef-6b21-590a-aef1-9e67ad54378e
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ data:
- type: expression
designation: ellipsoidal latitude
language_code: deu
date_accepted: '2003-02-15T00:00:00.000Z'
id: c2cc493d-bc21-50a5-96fc-6774f3d53496
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ data:
- type: expression
designation: Cartesian coordinate system
language_code: eng
date_accepted: '2015-08-15T00:00:00.000Z'
id: c87dfcd1-c38a-55f9-87bd-9da33bfede80
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ data:
designation: postal address component
domain: postal address
language_code: eng
date_accepted: '2017-11-15T00:00:00.000Z'
id: da24b782-1551-5128-a043-ba6135a25acf
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ data:
- type: expression
designation: ellipsoidal latitude
language_code: ara
date_accepted: '2003-02-15T00:00:00.000Z'
id: e4ee4f5c-07b0-577e-8bc0-37e0f98d7a2b
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ data:
- type: expression
designation: geodætisk bredde
language_code: dan
date_accepted: '2003-02-15T00:00:00.000Z'
id: eaea6d0f-c655-59c9-98f7-9affbdce7612
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ data:
normative_status: preferred
designation: دلالة
language_code: ara
date_accepted: '2010-11-01T00:00:00.000Z'
id: '081154c5-89d6-5192-8147-373bd6060eaa'
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ data:
- type: expression
designation: ellipsoidal latitude
language_code: eng
date_accepted: '2003-02-15T00:00:00.000Z'
id: 27457e38-89b5-5694-8d19-0dd3973ec71d
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ data:
normative_status: preferred
designation: Intension
language_code: deu
date_accepted: '2010-11-01T00:00:00.000Z'
id: 527bd617-f471-5523-9b98-59bb181f3df8
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ data:
- type: expression
designation: Sistema de Coordenadas Cartesianas
language_code: spa
date_accepted: '2015-08-15T00:00:00.000Z'
id: becf3892-886d-5dab-8a7c-af303e576a8d
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ data:
normative_status: preferred
designation: intension
language_code: eng
date_accepted: '2010-11-01T00:00:00.000Z'
id: bf1691ef-6b21-590a-aef1-9e67ad54378e
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ data:
- type: expression
designation: ellipsoidal latitude
language_code: deu
date_accepted: '2003-02-15T00:00:00.000Z'
id: c2cc493d-bc21-50a5-96fc-6774f3d53496
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ data:
- type: expression
designation: Cartesian coordinate system
language_code: eng
date_accepted: '2015-08-15T00:00:00.000Z'
id: c87dfcd1-c38a-55f9-87bd-9da33bfede80
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ data:
designation: postal address component
domain: postal address
language_code: eng
date_accepted: '2017-11-15T00:00:00.000Z'
id: da24b782-1551-5128-a043-ba6135a25acf
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ data:
- type: expression
designation: ellipsoidal latitude
language_code: ara
date_accepted: '2003-02-15T00:00:00.000Z'
id: e4ee4f5c-07b0-577e-8bc0-37e0f98d7a2b
Loading
Loading