-
Notifications
You must be signed in to change notification settings - Fork 2
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: add lutaml model #118
Conversation
lib/glossarist.rb
Outdated
@@ -30,6 +31,7 @@ | |||
|
|||
require_relative "glossarist/collections" | |||
|
|||
require_relative "glossarist/lutaml_models" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HassanAkbar why do we have to use a special namespace for these? Why not just replace the classes in the original namespace?
end | ||
|
||
|
||
def data_hash(model) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need *_hash
methods? We want to just use default lutaml-model methods?
# skip, will be handled in ref | ||
end | ||
|
||
def ref_hash(model = self) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need a special method to convert into hash? We should just use the default lutaml-model methods.
@sources.select { |source| source.type == "authoritative" } | ||
end | ||
|
||
def related=(related) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use attribute :related, RelatedConcept, collection: true
?
|
||
def localized_concept_path(id) | ||
localized_concept_possible_dir = { | ||
"localized_concept" => File.join( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can implement map [ 'localized_concept', 'localized-concept' ], to: :localized_concept
in lutaml-model to accept more than one mapping?
|
||
def date_accepted_from_yaml(model, value) | ||
model.dates ||= [] | ||
model.dates << ConceptDate.of_yaml({ "date" => value, "type" => "accepted" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too custom. We want to use lutaml-model functionality?
end | ||
|
||
def identifier=(val) | ||
@identifier = val |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If id
is just a shorthand for the identifier
attribute, why not just this?
alias :id, :identifier
alias :id=, :identifier=
@uuid ||= Glossarist::Utilities::UUID.uuid_v5(Glossarist::Utilities::UUID::OID_NAMESPACE, to_yaml(except: [:uuid])) | ||
end | ||
|
||
def data_hash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very weird. We should just use the default functionality from lutaml-model?
map :ref, with: { from: :ref_from_yaml, to: :ref_to_yaml } | ||
end | ||
|
||
def ref_to_yaml(model, doc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if we remove these custom methods?
lib/glossarist/concept.rb
Outdated
attribute :subject, :string | ||
attribute :definition, DetailedDefinition, collection: true | ||
attribute :non_verb_rep, :string | ||
attribute :notes, DetailedDefinition, default: -> { Glossarist::Collections::Collection.new(klass: DetailedDefinition) }, collection: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@HassanAkbar does this mean that we should support "attribute collections" using custom "collection" Ruby class/types instead of just Ruby Array
s?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the answer is yes... we need to either provide a Lutaml::Model::Collection
base class as an interface (e.g. support some methods from Ruby's Enum
: insert, delete, iterate, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ronaldtse Sure I'll look into it, I've created an issue for it here -> lutaml/lutaml-model#215
lib/glossarist/citation.rb
Outdated
def ref_to_hash(model, doc) | ||
doc["ref"] = if model.structured? | ||
ref_hash(model) | ||
else | ||
model.text | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a custom method because ref
can be a string or a hash.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to dictate only one behavior? Because to support both it’s quite strange.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ronaldtse Sure, Which one do we need to support here?
ref can be like
ref: 'ISO 19107:2019'
OR
ref:
id: 1234
source: 'ISO 19107:2019'
version: 1.3
I think we can only support the second format and convert the first one to
ref:
source: 'ISO 19107:2019'
def designations | ||
data.terms | ||
end | ||
alias :terms :designations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods like this are just to call the delegated methods.
May be we should add a delegate
key with attribute
in lutaml-model
to add methods like this i.e
class Concept < Lutaml::Model::Serializable
attribute :terms, delegate: :data
end
@ronaldtse What do you suggest?
9967eb9
to
11b30cc
Compare
59afd87
to
2e63816
Compare
Moved
glossarist-ruby
tolutaml-model
We will need to merge following PRs for this PR to work properly
closes #107