Skip to content

Commit

Permalink
add metrics to artefacts and distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
imadbourouche committed Feb 14, 2025
1 parent bc64d90 commit 8e07df6
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/ontologies_linked_data/models/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def self.goo_attrs_to_load(attributes = [], level = 0)
# Get attributes, either provided, all, or default
default_attrs = if !attributes.empty?
if attributes.first == :all
(self.attributes + hypermedia_settings[:serialize_default]).uniq
(self.attributes(:all) + hypermedia_settings[:serialize_default]).uniq
else
attributes - hypermedia_settings[:serialize_never]
end
Expand Down
16 changes: 16 additions & 0 deletions lib/ontologies_linked_data/models/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ class Metric < LinkedData::Models::Base
attribute :numberOfAxioms, namespace: :omv, type: :integer
attribute :entities, namespace: :void, type: :integer

attribute :numberOfNotes, namespace: :mod, type: :integer
attribute :numberOfUsingProjects, namespace: :mod, type: :integer
attribute :numberOfEnsorments, namespace: :mod, type: :integer
attribute :numberOfEvaluations, namespace: :mod, type: :integer
attribute :numberOfAgents, namespace: :mod, type: :integer
attribute :numberOfObjectProperties, namespace: :mod, type: :integer
attribute :numberOfDataProperties, namespace: :mod, type: :integer
attribute :numberOfLabels, namespace: :mod, type: :integer
attribute :numberOfDeprecated, namespace: :mod, type: :integer
attribute :classesWithNoLabel, namespace: :mod, type: :integer
attribute :classesWithNoFormalDefinition, namespace: :mod, type: :integer
attribute :classesWithNoAuthorMetadata, namespace: :mod, type: :integer
attribute :classesWithNoDateMetadata, namespace: :mod, type: :integer
attribute :numberOfMappings, namespace: :mod, type: :integer
attribute :numberOfUsers, namespace: :mod, type: :integer

cache_timeout 14400 # 4 hours

# Hypermedia links
Expand Down
43 changes: 29 additions & 14 deletions lib/ontologies_linked_data/models/mod/semantic_artefact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ def attribute_mapped(name, **options)
attribute_mapped :logo, namespace: :foaf, mapped_to: {model: :ontology_submission, attribute: :logo}
attribute_mapped :metrics, namespace: :mod, mapped_to: {model: :ontology_submission, attribute: :metrics}

attribute_mapped :numberOfNotes, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfNotes}
attribute_mapped :numberOfUsingProjects, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfUsingProjects}
attribute_mapped :numberOfEndorsements, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfEndorsements}
attribute_mapped :numberOfEvaluations, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfEvaluations}
attribute_mapped :numberOfUsers, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfUsers}
attribute_mapped :numberOfAgents, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfAgents}

attribute :ontology, type: :ontology

Expand Down Expand Up @@ -171,20 +177,29 @@ def bring(*attributes)
attributes = [attributes] unless attributes.is_a?(Array)
latest = @ontology.latest_submission(status: :ready)
attributes.each do |attr|
mapping = self.class.attribute_mappings[attr]
next if mapping.nil?

model = mapping[:model]
mapped_attr = mapping[:attribute]

case model
when :ontology
@ontology.bring(*mapped_attr)
self.send("#{attr}=", @ontology.send(mapped_attr)) if @ontology.respond_to?(mapped_attr)
when :ontology_submission
if latest
latest.bring(*mapped_attr)
self.send("#{attr}=", latest.send(mapped_attr))
if self.class.handler?(attr)
self.send(attr)
else
mapping = self.class.attribute_mappings[attr]
next if mapping.nil?

model = mapping[:model]
mapped_attr = mapping[:attribute]

case model
when :ontology
@ontology.bring(*mapped_attr)
self.send("#{attr}=", @ontology.send(mapped_attr)) if @ontology.respond_to?(mapped_attr)
when :ontology_submission
if latest
latest.bring(*mapped_attr)
self.send("#{attr}=", latest.send(mapped_attr))
end
when :metric
latest.bring(*[:metrics => [mapped_attr]])
if latest.metrics
self.send("#{attr}=", latest.metrics.send(mapped_attr)) if latest.metrics.respond_to?(mapped_attr)
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,28 @@ def attribute_mapped(name, **options)
attribute_mapped :obsoleteParent, namespace: :mod, mapped_to: { model: :ontology_submission, attribute: :obsoleteParent }
attribute_mapped :metadataVoc, namespace: :mod, mapped_to: { model: :ontology_submission, attribute: :metadataVoc }
attribute_mapped :metrics, namespace: :mod, mapped_to: { model: :ontology_submission, attribute: :metrics }
attribute_mapped :numberOfClasses, namespace: :mod, mapped_to: { model: :ontology_submission, attribute: :class_count }

# SAD attrs that map with metrics
attribute_mapped :numberOfClasses, namespace: :mod, mapped_to: { model: :metric, attribute: :classes }
attribute_mapped :numberOfAxioms, namespace: :mod, mapped_to: { model: :metric, attribute: :numberOfAxioms }
attribute_mapped :maxDepth, namespace: :mod, mapped_to: { model: :metric, attribute: :maxDepth }
attribute_mapped :maxChildCount, namespace: :mod, mapped_to: { model: :metric, attribute: :maxChildCount }
attribute_mapped :averageChildCount, namespace: :mod, mapped_to: { model: :metric, attribute: :averageChildCount }
attribute_mapped :classesWithOneChild, namespace: :mod, mapped_to: { model: :metric, attribute: :classesWithOneChild }
attribute_mapped :classesWithMoreThan25Children, namespace: :mod, mapped_to: { model: :metric, attribute: :classesWithMoreThan25Children }
attribute_mapped :classesWithNoDefinition, namespace: :mod, mapped_to: { model: :metric, attribute: :classesWithNoDefinition }


attribute_mapped :numberOfIndividuals, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :individuals}
attribute_mapped :numberOfProperties, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :properties}
attribute_mapped :numberOfObjectProperties, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfObjectProperties}
attribute_mapped :numberOfDataProperties, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfDataProperties}
attribute_mapped :numberOfLabels, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfLabels}
attribute_mapped :numberOfDeprecated, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfDeprecated}
attribute_mapped :classesWithNoFormalDefinition, namespace: :mod, mapped_to: { model: :metric, attribute: :classesWithNoFormalDefinition }
attribute_mapped :classesWithNoLabel, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :classesWithNoLabel}
attribute_mapped :classesWithNoAuthorMetadata, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :classesWithNoAuthorMetadata}
attribute_mapped :classesWithNoDateMetadata, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :classesWithNoDateMetadata}
attribute_mapped :numberOfMappings, namespace: :mod, enforce: [:integer], mapped_to: {model: :metric, attribute: :numberOfMappings}

# Attr special to SemanticArtefactDistribution
attribute :submission, type: :ontology_submission

Expand Down Expand Up @@ -102,9 +112,11 @@ def bring(*attributes)
when :ontology_submission
@submission.bring(*mapped_attr)
self.send("#{attr}=", @submission.send(mapped_attr)) if @submission.respond_to?(mapped_attr)
when :metrics
next
# TO-DO
when :metric
@submission.bring(*[:metrics => [mapped_attr]])
if @submission.metrics
self.send("#{attr}=", @submission.metrics.send(mapped_attr)) if @submission.metrics.respond_to?(mapped_attr)
end
end
end
end
Expand Down

0 comments on commit 8e07df6

Please sign in to comment.