Class: Openphar::Models::Chp::Monograph

Inherits:
Monograph show all
Defined in:
lib/openphar/models/chp/monograph.rb

Overview

Base class for all Chinese Pharmacopoeia monographs.

Adds ChP-specific identity fields (entryId from the network-edition API, bookId 1..4 for volumes I–IV, directoryTitle for the TOC node, pageNum for the printed-edition cross-reference, pinyin title) on top of the harmonized Openphar::Models::Monograph.

Concrete subclasses (TcmCrudeDrug, ChemicalSubstance, Biologic, GeneralChapter, etc.) declare their semantic @type via class methods. The classifier at Openphar::Migrators::Chp::Classifier is the single dispatch point — never use case/when on type elsewhere.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Monograph

#label

Methods inherited from BaseEntity

jsonld_context, neo4j_label, neo4j_labels_string, #to_cypher, #to_cypher_match, #to_jsonld, #to_neo4j_node, #to_neo4j_properties

Class Method Details

.harmonized_typeString?

Harmonized RDF type this ChP type maps to. Override in subclasses to declare the cross-publisher semantic type (e.g., 'CrudeDrug').

Returns:

  • (String, nil)


66
67
68
# File 'lib/openphar/models/chp/monograph.rb', line 66

def harmonized_type
  nil
end

.jsonld_typeObject



88
89
90
# File 'lib/openphar/models/chp/monograph.rb', line 88

def jsonld_type
  'ChpMonograph'
end

.jsonld_typesArray<String>

Array of types to emit in JSON-LD @type. Computed from jsonld_type + harmonized_type + the base 'Monograph'.

Returns:

  • (Array<String>)


74
75
76
77
78
79
# File 'lib/openphar/models/chp/monograph.rb', line 74

def jsonld_types
  types = ['Monograph']
  types << harmonized_type if harmonized_type
  types << jsonld_type unless jsonld_type == 'Monograph'
  types.uniq
end

.neo4j_labelsObject



81
82
83
84
85
86
# File 'lib/openphar/models/chp/monograph.rb', line 81

def neo4j_labels
  labels = %w[Monograph Chp]
  labels << harmonized_type if harmonized_type
  labels << name&.split('::')&.last
  labels.compact.uniq
end

.wire_keyString

Snake_case identifier used as the JSON-LD node-directory name and as the wire-key for type routing. Override in subclasses.

Returns:

  • (String)


58
59
60
# File 'lib/openphar/models/chp/monograph.rb', line 58

def wire_key
  'monograph'
end

Instance Method Details

#iriObject



105
106
107
108
# File 'lib/openphar/models/chp/monograph.rb', line 105

def iri
  edition_tag = (edition || 'unknown').to_s.downcase.gsub(/[^a-z0-9]/, '-')
  "#{Openphar.base_iri}/data/chp/#{edition_tag}/entry/#{entry_id}"
end

#jsonld_filenameObject



110
111
112
# File 'lib/openphar/models/chp/monograph.rb', line 110

def jsonld_filename
  "#{slug}.jsonld"
end

#slugObject



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/openphar/models/chp/monograph.rb', line 93

def slug
  base = (pinyin_title || title || "entry-#{entry_id}")
    .to_s
    .downcase
    .gsub(/\s+/, '-')
    .gsub(/[^\p{L}\p{N}\-]/, '')
    .gsub(/\-+/, '-')
    .gsub(/^\-|\-$/, '')
  base = "entry-#{entry_id}" if base.empty?
  "#{base}-#{entry_id}"
end