Class: Suma::TermClassification

Inherits:
Object
  • Object
show all
Defined in:
lib/suma/term_classification.rb

Overview

Term-extractor-specific classification of an EXPRESS schema.

Bridges ExpressSchema::Type (the canonical classification shared across the codebase) and the Glossarist-specific labels TermExtractor emits: the domain string ("application module" / "resource") that goes into a concept's domain field, and the entity-type URN term used in generated concept definitions.

The mapping is data — a frozen Hash keyed by ExpressSchema::Type symbol — so adding a new schema type is a one-line addition to BY_TYPE (open/closed principle). The previous implementation switched on string keys in three separate places; this consolidates them into one source of truth.

Constant Summary collapse

BY_TYPE =
{
  ExpressSchema::Type::RESOURCE => new(
    type: ExpressSchema::Type::RESOURCE,
    domain_label: "resource",
    entity_term: "express-language.entity_data_type",
    entity_display: "entity data type",
  ),
  ExpressSchema::Type::MODULE_ARM => new(
    type: ExpressSchema::Type::MODULE_ARM,
    domain_label: "application module",
    entity_term: "general.application_object",
    entity_display: "application object",
  ),
  ExpressSchema::Type::MODULE_MIM => new(
    type: ExpressSchema::Type::MODULE_MIM,
    domain_label: "application module",
    entity_term: "express-language.entity_data_type",
    entity_display: "entity data type",
  ),
  ExpressSchema::Type::BUSINESS_OBJECT_MODEL => new(
    type: ExpressSchema::Type::BUSINESS_OBJECT_MODEL,
    domain_label: "resource",
    entity_term: "express-language.entity_data_type",
    entity_display: "entity data type",
  ),
  ExpressSchema::Type::CORE_MODEL => new(
    type: ExpressSchema::Type::CORE_MODEL,
    domain_label: "resource",
    entity_term: "express-language.entity_data_type",
    entity_display: "entity data type",
  ),
  ExpressSchema::Type::STANDALONE => new(
    type: ExpressSchema::Type::STANDALONE,
    domain_label: "resource",
    entity_term: "express-language.entity_data_type",
    entity_display: "entity data type",
  ),
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, domain_label:, entity_term:, entity_display:) ⇒ TermClassification

Returns a new instance of TermClassification.



20
21
22
23
24
25
26
# File 'lib/suma/term_classification.rb', line 20

def initialize(type:, domain_label:, entity_term:, entity_display:)
  @type = type
  @domain_label = domain_label
  @entity_term = entity_term
  @entity_display = entity_display
  freeze
end

Instance Attribute Details

#domain_labelObject (readonly)

Returns the value of attribute domain_label.



18
19
20
# File 'lib/suma/term_classification.rb', line 18

def domain_label
  @domain_label
end

#entity_displayObject (readonly)

Returns the value of attribute entity_display.



18
19
20
# File 'lib/suma/term_classification.rb', line 18

def entity_display
  @entity_display
end

#entity_termObject (readonly)

Returns the value of attribute entity_term.



18
19
20
# File 'lib/suma/term_classification.rb', line 18

def entity_term
  @entity_term
end

#typeObject (readonly)

Returns the value of attribute type.



18
19
20
# File 'lib/suma/term_classification.rb', line 18

def type
  @type
end

Class Method Details

.for_schema(id:, path:) ⇒ Object



71
72
73
74
75
76
# File 'lib/suma/term_classification.rb', line 71

def self.for_schema(id:, path:)
  type = ExpressSchema::Type.classify(id: id, path: path)
  BY_TYPE.fetch(type) do |t|
    raise Error, "[suma] no term classification for type #{t.inspect}"
  end
end

Instance Method Details

#domain_for(schema_id) ⇒ Object



28
29
30
# File 'lib/suma/term_classification.rb', line 28

def domain_for(schema_id)
  "#{domain_label}: #{schema_id}"
end