Skip to content

Commit

Permalink
implement submission class children function
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Oct 30, 2024
1 parent 4f0c628 commit 4efb558
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
7 changes: 3 additions & 4 deletions lib/ontologies_linked_data/models/class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,9 @@ def hasChildren()



def load_has_children()
if !instance_variable_get("@intlHasChildren").nil?
return
end
def load_has_children
return @intlHasChildren unless instance_variable_get("@intlHasChildren").nil?

graphs = [self.submission.id.to_s]
query = has_children_query(self.id.to_s,graphs.first)
has_c = false
Expand Down
36 changes: 34 additions & 2 deletions lib/ontologies_linked_data/models/ontology_submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class OntologySubmission < LinkedData::Models::Base
FLAT_ROOTS_LIMIT = 1000

model :ontology_submission, scheme: File.join(__dir__, '../../../config/schemes/ontology_submission.yml'),
name_with: ->(s) { submission_id_generator(s) }
name_with: ->(s) { submission_id_generator(s) }

attribute :submissionId, type: :integer, enforce: [:existence]

Expand Down Expand Up @@ -124,7 +124,7 @@ class OntologySubmission < LinkedData::Models::Base
attribute :openSearchDescription, namespace: :void, type: :uri, default: -> (s) { open_search_default(s) }
attribute :source, namespace: :dct, type: :list
attribute :endpoint, namespace: :sd, type: %i[uri list],
default: ->(s) { default_sparql_endpoint(s) }
default: ->(s) { default_sparql_endpoint(s) }
attribute :includedInDataCatalog, namespace: :schema, type: %i[list uri]

# Relations
Expand Down Expand Up @@ -741,6 +741,38 @@ def roots(extra_include = [], page = nil, pagesize = nil, concept_schemes: [], c
classes
end

def children(cls, includes_param: [], concept_schemes: [], concept_collections: [], page: 1, size: 50)
ld = LinkedData::Models::Class.goo_attrs_to_load(includes_param)
unmapped = ld.delete(:properties)

ld += LinkedData::Models::Class.concept_is_in_attributes if skos?

page_data_query = LinkedData::Models::Class.where(parents: cls).in(self).include(ld)
aggregates = LinkedData::Models::Class.goo_aggregates_to_load(ld)
page_data_query.aggregate(*aggregates) unless aggregates.empty?
page_data = page_data_query.page(page, size).all
LinkedData::Models::Class.in(self).models(page_data).include(:unmapped).all if unmapped

page_data.delete_if { |x| x.id.to_s == cls.id.to_s }
if ld.include?(:hasChildren) || ld.include?(:isInActiveScheme) || ld.include?(:isInActiveCollection)
page_data.each do |c|
c.load_computed_attributes(to_load: ld,
options: { schemes: concept_schemes, collections: concept_collections })
end
end

unless concept_schemes.empty?
page_data.delete_if { |c| Array(c.isInActiveScheme).empty? && !c.load_has_children }
if (page_data.size < size) && page_data.next_page
page_data += children(cls, includes_param: includes_param, concept_schemes: concept_schemes,
concept_collections: concept_collections,
page: page_data.next_page, size: size)
end
end

page_data
end

def skos?
self.bring :hasOntologyLanguage if bring? :hasOntologyLanguage
self.hasOntologyLanguage&.skos?
Expand Down

0 comments on commit 4efb558

Please sign in to comment.