Class: Openphar::Exporters::Neo4j::RelationshipBuilder
- Inherits:
-
Object
- Object
- Openphar::Exporters::Neo4j::RelationshipBuilder
- Defined in:
- lib/openphar/exporters/neo4j/relationship_builder.rb
Overview
Builds Neo4j Cypher relationships between nodes
Handles:
- Edition relationships (monograph belongs to edition)
- Cross-publisher links (sameSubstanceAs, hasEquivalentIn, similarTo)
- Test specification relationships
Instance Attribute Summary collapse
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
Instance Method Summary collapse
-
#build_cross_publisher_relationship(source_id, target_id, rel_type) ⇒ String
Builds a Cypher relationship for cross-publisher links.
-
#build_edition_relationship(monograph_id, edition_id) ⇒ String
Builds a Cypher relationship for edition membership.
-
#build_test_spec_relationship(monograph_id, test_spec_id) ⇒ String
Builds a test specification relationship.
-
#initialize(registry = nil) ⇒ RelationshipBuilder
constructor
A new instance of RelationshipBuilder.
-
#map_link_type(link_type) ⇒ String
Maps a JSON-LD linkType to a Neo4j relationship type.
Constructor Details
#initialize(registry = nil) ⇒ RelationshipBuilder
Returns a new instance of RelationshipBuilder.
15 16 17 |
# File 'lib/openphar/exporters/neo4j/relationship_builder.rb', line 15 def initialize(registry = nil) @registry = registry || ModelRegistry.new end |
Instance Attribute Details
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
13 14 15 |
# File 'lib/openphar/exporters/neo4j/relationship_builder.rb', line 13 def registry @registry end |
Instance Method Details
#build_cross_publisher_relationship(source_id, target_id, rel_type) ⇒ String
Builds a Cypher relationship for cross-publisher links
38 39 40 41 42 43 44 |
# File 'lib/openphar/exporters/neo4j/relationship_builder.rb', line 38 def build_cross_publisher_relationship(source_id, target_id, rel_type) <<~CYPHER MATCH (a:Monograph {id: #{escape(source_id)}}) MATCH (b:Monograph {id: #{escape(target_id)}}) MERGE (a)-[:#{rel_type}]->(b); CYPHER end |
#build_edition_relationship(monograph_id, edition_id) ⇒ String
Builds a Cypher relationship for edition membership
24 25 26 27 28 29 30 |
# File 'lib/openphar/exporters/neo4j/relationship_builder.rb', line 24 def build_edition_relationship(monograph_id, edition_id) <<~CYPHER MATCH (m:Monograph {id: #{escape(monograph_id)}}) MATCH (e:Edition {id: #{escape(edition_id)}}) MERGE (m)-[:BELONGS_TO_EDITION]->(e); CYPHER end |
#build_test_spec_relationship(monograph_id, test_spec_id) ⇒ String
Builds a test specification relationship
64 65 66 67 68 69 70 |
# File 'lib/openphar/exporters/neo4j/relationship_builder.rb', line 64 def build_test_spec_relationship(monograph_id, test_spec_id) <<~CYPHER MATCH (m:Monograph {id: #{escape(monograph_id)}}) MATCH (t:TestSpec {id: #{escape(test_spec_id)}}) MERGE (m)-[:HAS_TEST_SPEC]->(t); CYPHER end |
#map_link_type(link_type) ⇒ String
Maps a JSON-LD linkType to a Neo4j relationship type
50 51 52 53 54 55 56 57 |
# File 'lib/openphar/exporters/neo4j/relationship_builder.rb', line 50 def map_link_type(link_type) case link_type when 'sameSubstanceAs' then 'SAME_SUBSTANCE_AS' when 'hasEquivalentIn' then 'HAS_EQUIVALENT_IN' when 'similarTo' then 'SIMILAR_TO' else 'RELATED_TO' end end |