Class: Glossarist::V3::HyperedgeIndex
- Inherits:
-
Object
- Object
- Glossarist::V3::HyperedgeIndex
- Defined in:
- lib/glossarist/v3/hyperedge_index.rb
Overview
HyperedgeIndex — derived reverse-lookup index over a flat list of hyperedges.
A hyperedge is directional: 1 comprehensive → N members. To answer the reverse query ("which hyperedges is X a member of?"), build a HyperedgeIndex on demand from the flat list and consult #for_member. The index is NOT stored on the concept — it's a derived view.
Use cases:
index.for_comprehensive("OIML:5.1")
# => 6 hyperedges (different criteria — the OIML pattern)
index.for_member("OIML:5.13")
# => hyperedges where 5.13 appears as a member
Instance Attribute Summary collapse
-
#by_comprehensive ⇒ Object
readonly
Returns the value of attribute by_comprehensive.
-
#by_member ⇒ Object
readonly
Returns the value of attribute by_member.
Instance Method Summary collapse
-
#all_concept_ids ⇒ Object
Every concept that appears anywhere in this hyperedge set (as comprehensive OR as a member), with its roles.
-
#for_comprehensive(qualified_id_or_ref) ⇒ Object
All hyperedges where the given concept is the comprehensive.
-
#for_member(qualified_id_or_ref) ⇒ Object
All hyperedges where the given concept is one of the members.
-
#initialize(hyperedges) ⇒ HyperedgeIndex
constructor
A new instance of HyperedgeIndex.
Constructor Details
#initialize(hyperedges) ⇒ HyperedgeIndex
Returns a new instance of HyperedgeIndex.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/glossarist/v3/hyperedge_index.rb', line 22 def initialize(hyperedges) @by_comprehensive = {} @by_member = {} Array(hyperedges).each do |h| register_comprehensive(h) register_members(h) end @by_comprehensive.freeze @by_member.freeze end |
Instance Attribute Details
#by_comprehensive ⇒ Object (readonly)
Returns the value of attribute by_comprehensive.
20 21 22 |
# File 'lib/glossarist/v3/hyperedge_index.rb', line 20 def by_comprehensive @by_comprehensive end |
#by_member ⇒ Object (readonly)
Returns the value of attribute by_member.
20 21 22 |
# File 'lib/glossarist/v3/hyperedge_index.rb', line 20 def by_member @by_member end |
Instance Method Details
#all_concept_ids ⇒ Object
Every concept that appears anywhere in this hyperedge set (as comprehensive OR as a member), with its roles.
51 52 53 |
# File 'lib/glossarist/v3/hyperedge_index.rb', line 51 def all_concept_ids (@by_comprehensive.keys | @by_member.keys).freeze end |
#for_comprehensive(qualified_id_or_ref) ⇒ Object
All hyperedges where the given concept is the comprehensive. Accepts either a qualified-id string ("VIM:1.2") or a ConceptRef.
37 38 39 40 |
# File 'lib/glossarist/v3/hyperedge_index.rb', line 37 def for_comprehensive(qualified_id_or_ref) key = resolve_key(qualified_id_or_ref) @by_comprehensive[key] || [] end |
#for_member(qualified_id_or_ref) ⇒ Object
All hyperedges where the given concept is one of the members. Accepts either a qualified-id string or a ConceptRef.
44 45 46 47 |
# File 'lib/glossarist/v3/hyperedge_index.rb', line 44 def for_member(qualified_id_or_ref) key = resolve_key(qualified_id_or_ref) @by_member[key] || [] end |