From 8e07df6bcd3ca1271e6cbf35aac07f3d75254684 Mon Sep 17 00:00:00 2001 From: Imad Bourouche Date: Fri, 14 Feb 2025 07:47:27 +0100 Subject: [PATCH] add metrics to artefacts and distributions --- lib/ontologies_linked_data/models/base.rb | 2 +- lib/ontologies_linked_data/models/metric.rb | 16 +++++++ .../models/mod/semantic_artefact.rb | 43 +++++++++++++------ .../mod/semantic_artefact_distribution.rb | 24 ++++++++--- 4 files changed, 64 insertions(+), 21 deletions(-) diff --git a/lib/ontologies_linked_data/models/base.rb b/lib/ontologies_linked_data/models/base.rb index 9c2b330d..8f3652b0 100644 --- a/lib/ontologies_linked_data/models/base.rb +++ b/lib/ontologies_linked_data/models/base.rb @@ -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 diff --git a/lib/ontologies_linked_data/models/metric.rb b/lib/ontologies_linked_data/models/metric.rb index e3950efb..53dc1903 100644 --- a/lib/ontologies_linked_data/models/metric.rb +++ b/lib/ontologies_linked_data/models/metric.rb @@ -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 diff --git a/lib/ontologies_linked_data/models/mod/semantic_artefact.rb b/lib/ontologies_linked_data/models/mod/semantic_artefact.rb index 14f5aaa1..92666fcd 100644 --- a/lib/ontologies_linked_data/models/mod/semantic_artefact.rb +++ b/lib/ontologies_linked_data/models/mod/semantic_artefact.rb @@ -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 @@ -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 diff --git a/lib/ontologies_linked_data/models/mod/semantic_artefact_distribution.rb b/lib/ontologies_linked_data/models/mod/semantic_artefact_distribution.rb index 03583c66..5a7e6389 100644 --- a/lib/ontologies_linked_data/models/mod/semantic_artefact_distribution.rb +++ b/lib/ontologies_linked_data/models/mod/semantic_artefact_distribution.rb @@ -46,9 +46,9 @@ 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 } @@ -56,8 +56,18 @@ def attribute_mapped(name, **options) 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 @@ -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