Class: Glossarist::ConceptRef

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/glossarist/concept_ref.rb

Overview

A typed reference to another concept, used inside n-ary relation members and other internal pointer shapes.

The base ConceptRef carries source, id, text, external, and ellipsis. The richer ConceptReference (in glossarist/concept_reference.rb) extends this with term, urn, version, ref_type for use in cross-vocabulary references and relevance contexts.

A ConceptRef is identified by source:id for external references or just id for local references. The qualified_id class method is the single SSOT for this string format — used by RelationLoader, the RDF transform, and ConceptRef-bearing data structures.

External concepts (parenthetical notation)

ISO 704:2022 uses parenthetical notation for external concepts — concepts referenced from this dataset but defined elsewhere. The external: true flag marks such a ref. External refs carry text (the parenthetical label) but NOT source/id.

Ellipsis (structural marker)

An ellipsis ref marks "further members exist but are not encoded." It is NOT a concept — it's a structural marker on the hyperedge. An ellipsis ref carries NO other fields (no source, id, text).

Direct Known Subclasses

V2::ConceptRef, V3::ConceptRef

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.qualified_id(ref) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/glossarist/concept_ref.rb', line 45

def self.qualified_id(ref)
  return nil unless ref.is_a?(ConceptRef)

  id_part = (ref.id.to_s.empty? ? nil : ref.id)
  text_part = (ref.text.to_s.empty? ? nil : ref.text)
  source_part = (ref.source.to_s.empty? ? nil : ref.source)

  if id_part
    source_part ? "#{source_part}:#{id_part}" : id_part
  elsif text_part
    source_part ? "#{source_part}:#{text_part}" : text_part
  end
end

Instance Method Details

#ellipsis?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/glossarist/concept_ref.rb', line 75

def ellipsis?
  ellipsis == true
end

#external?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/glossarist/concept_ref.rb', line 71

def external?
  external == true
end

#qualified_idObject



59
60
61
# File 'lib/glossarist/concept_ref.rb', line 59

def qualified_id
  self.class.qualified_id(self)
end

#resolved?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/glossarist/concept_ref.rb', line 67

def resolved?
  !source.to_s.empty? && !id.to_s.empty?
end

#same_concept?(other) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/glossarist/concept_ref.rb', line 63

def same_concept?(other)
  qualified_id == self.class.qualified_id(other)
end

#text_only?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/glossarist/concept_ref.rb', line 79

def text_only?
  !text.to_s.empty? && !resolved? && !external?
end

#validate_ref!Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/glossarist/concept_ref.rb', line 83

def validate_ref!
  if ellipsis? && (source || id || text || external?)
    raise ArgumentError,
          "ConceptRef with ellipsis: true must not carry any " \
          "other field (source, id, text, external)"
  end

  if external? && (source || id)
    raise ArgumentError,
          "ConceptRef with external: true must not carry " \
          "source/id — use text for the parenthetical label"
  end

  if !source && !id && !text && !external? && !ellipsis?
    raise ArgumentError,
          "ConceptRef must have at least one of: source+id, text, " \
          "external, or ellipsis"
  end

  self
end