Class: Openphar::Exporters::Neo4j::ModelRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/openphar/exporters/neo4j/model_registry.rb

Overview

Registry of all models that can be exported to Neo4j

Provides mapping from JSON-LD @type to:

  • Neo4j label(s)
  • Ruby model class
  • Serialization key mappings

This registry is the central source of truth for model-to-Neo4j mapping.

Constant Summary collapse

NODE_TYPES =

Node type mappings: JSON-LD @type => Neo4j labels

{
  'PharmacopoeiaMonograph' => 'Monograph',
  'CrudeDrugMonograph' => 'Monograph:CrudeDrug',
  'ChemicalDrugMonograph' => 'Monograph:ChemicalDrug',
  'FormulationMonograph' => 'Monograph:Formulation',
  'VitaminMonograph' => 'Monograph:Vitamin',
  'AminoAcidMonograph' => 'Monograph:AminoAcid',
  'MineralSubstanceMonograph' => 'Monograph:Mineral',
  'BiologicalSubstanceMonograph' => 'Monograph:Biological',
  # JP-specific types
  'KampoFormula' => 'Monograph:Formulation:Kampo',
  # Ph.Int.-specific types
  'RadiopharmaceuticalMonograph' => 'Monograph:Radiopharmaceutical',
  'DosageFormMonograph' => 'Monograph:DosageForm',
  'TestMethod' => 'TestMethod',
  'Reagent' => 'Reagent',
  'TestSolution' => 'Reagent:TestSolution',
  'VolumetricSolution' => 'Reagent:VolumetricSolution',
  'BufferSolution' => 'Reagent:BufferSolution',
  'ReferenceSubstance' => 'ReferenceSubstance',
  # Test specifications
  'TestSpecification' => 'TestSpec',
  'AssaySpecification' => 'TestSpec:Assay',
  'PuritySpecification' => 'TestSpec:Purity',
  'IdentificationSpecification' => 'TestSpec:Identity',
  'PhysicalSpecification' => 'TestSpec:Physical',
  # Other
  'Limit' => 'Limit',
  'Edition' => 'Edition',
  'Supplement' => 'Supplement',
  'Publisher' => 'Publisher'
}.freeze
RELATIONSHIP_TYPES =

Relationship types

{
  'sameSubstanceAs' => 'SAME_SUBSTANCE_AS',
  'hasEquivalentIn' => 'HAS_EQUIVALENT_IN',
  'similarTo' => 'SIMILAR_TO',
  'belongsToEdition' => 'BELONGS_TO_EDITION',
  'hasTestSpec' => 'HAS_TEST_SPEC',
  'referencesPreparation' => 'REFERENCES_PREPARATION',
  'referencesTCMProfile' => 'REFERENCES_TCM_PROFILE'
}.freeze
MODEL_CLASSES =

Model classes indexed by JSON-LD @type Uses lazy loading to avoid circular dependency issues

{
  # Core monograph types
  'CrudeDrugMonograph' => lambda { Openphar::Models::CrudeDrugMonograph },
  'ChemicalDrugMonograph' => lambda { Openphar::Models::ChemicalDrugMonograph },
  'Monograph' => lambda { Openphar::Models::Monograph },
  # Bibliographic
  'Edition' => lambda { Openphar::Models::Edition },
  'Supplement' => lambda { Openphar::Models::Supplement },
  # Test specifications
  'TestSpecification' => lambda { Openphar::Models::TestSpecification },
  'AssaySpecification' => lambda { Openphar::Models::AssaySpecification },
  'PuritySpecification' => lambda { Openphar::Models::PuritySpecification },
  'PhysicalSpecification' => lambda { Openphar::Models::PhysicalSpecification },
  # JP models (in JP namespace)
  'KampoFormula' => lambda { Openphar::Models::JP::KampoFormula },
  # Ph.Int. models (in PhInt namespace)
  'RadiopharmaceuticalMonograph' => lambda { Openphar::Models::PhInt::RadiopharmaceuticalMonograph },
  'DosageFormMonograph' => lambda { Openphar::Models::PhInt::DosageFormMonograph },
  'TestMethod' => lambda { Openphar::Models::PhInt::TestMethod },
  'Reagent' => lambda { Openphar::Models::PhInt::Reagent },
  'TestSolution' => lambda { Openphar::Models::PhInt::TestSolution },
  'VolumetricSolution' => lambda { Openphar::Models::PhInt::VolumetricSolution },
  'BufferSolution' => lambda { Openphar::Models::PhInt::BufferSolution },
  'ReferenceSubstance' => lambda { Openphar::Models::PhInt::ReferenceSubstance }
}.freeze

Instance Method Summary collapse

Instance Method Details

#all_node_typesArray<String>

Returns all known node types

Returns:

  • (Array<String>)

    List of Neo4j labels



88
89
90
# File 'lib/openphar/exporters/neo4j/model_registry.rb', line 88

def all_node_types
  NODE_TYPES.values.flat_map { |t| t.split(':') }.uniq
end

#model_class_for(jsonld_type) ⇒ Class?

Returns the Ruby model class for a given JSON-LD @type

Parameters:

  • jsonld_type (String)

    The @type from JSON-LD

Returns:

  • (Class, nil)

    The model class



72
73
74
75
# File 'lib/openphar/exporters/neo4j/model_registry.rb', line 72

def model_class_for(jsonld_type)
  entry = MODEL_CLASSES[jsonld_type]
  entry&.call
end

#monograph_type?(jsonld_type) ⇒ Boolean

Checks if a given type is a monograph type

Parameters:

  • jsonld_type (String)

    The @type from JSON-LD

Returns:

  • (Boolean)

    True if it's a monograph type



96
97
98
# File 'lib/openphar/exporters/neo4j/model_registry.rb', line 96

def monograph_type?(jsonld_type)
  NODE_TYPES[jsonld_type]&.include?('Monograph')
end

#node_type_for(jsonld_type) ⇒ String

Returns Neo4j labels for a given JSON-LD @type

Parameters:

  • jsonld_type (String)

    The @type from JSON-LD

Returns:

  • (String)

    Neo4j label(s)



64
65
66
# File 'lib/openphar/exporters/neo4j/model_registry.rb', line 64

def node_type_for(jsonld_type)
  NODE_TYPES[jsonld_type] || 'Monograph'
end

#relationship_type_for(link_type) ⇒ String

Returns the Neo4j relationship type for a given link type

Parameters:

  • link_type (String)

    The relationship type from JSON-LD

Returns:

  • (String)

    Neo4j relationship type



81
82
83
# File 'lib/openphar/exporters/neo4j/model_registry.rb', line 81

def relationship_type_for(link_type)
  RELATIONSHIP_TYPES[link_type] || 'RELATED_TO'
end