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: add lutaml model #118

Merged
merged 8 commits into from
Dec 26, 2024
Merged

feat: add lutaml model #118

merged 8 commits into from
Dec 26, 2024

Conversation

HassanAkbar
Copy link
Member

@HassanAkbar HassanAkbar commented Dec 17, 2024

Moved glossarist-ruby to lutaml-model

We will need to merge following PRs for this PR to work properly

closes #107

@HassanAkbar HassanAkbar marked this pull request as draft December 17, 2024 14:58
@@ -30,6 +31,7 @@

require_relative "glossarist/collections"

require_relative "glossarist/lutaml_models"
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

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)
Copy link
Member

@ronaldtse ronaldtse Dec 17, 2024

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(
Copy link
Member

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" })
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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?

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
Copy link
Member

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 Arrays?

Copy link
Member

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.)

Copy link
Member Author

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

Comment on lines 51 to 57
def ref_to_hash(model, doc)
doc["ref"] = if model.structured?
ref_hash(model)
else
model.text
end
end
Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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'

Comment on lines +30 to +33
def designations
data.terms
end
alias :terms :designations
Copy link
Member Author

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?

@HassanAkbar HassanAkbar marked this pull request as ready for review December 23, 2024 12:48
@HassanAkbar HassanAkbar merged commit 4eba00b into main Dec 26, 2024
13 of 14 checks passed
@HassanAkbar HassanAkbar deleted the adding_lutaml_model branch December 26, 2024 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Change Glossarist gem to use lutaml-model
2 participants