package graph import ( "github.com/neo4j/neo4j-go-driver/v5/neo4j" ) // NodeConverter converts Neo4j nodes and relationships to domain types type NodeConverter struct{} // NewNodeConverter creates a new node converter func NewNodeConverter() *NodeConverter { return &NodeConverter{} } // ConvertNode converts a Neo4j node to PathNode func (nc *NodeConverter) ConvertNode(node neo4j.Node) PathNode { return PathNode{ ID: getStringProp(node.Props, "id"), Labels: node.Labels, Properties: node.Props, } } // ConvertRelationship converts a Neo4j relationship to PathRelationship func (nc *NodeConverter) ConvertRelationship(rel neo4j.Relationship) PathRelationship { return PathRelationship{ ID: rel.ElementId, Type: rel.Type, Properties: rel.Props, } } // ConvertNodes converts a slice of Neo4j nodes to PathNodes func (nc *NodeConverter) ConvertNodes(nodes []interface{}) []PathNode { result := make([]PathNode, 0, len(nodes)) for _, node := range nodes { if n, ok := node.(neo4j.Node); ok { result = append(result, nc.ConvertNode(n)) } } return result } // ConvertRelationships converts a slice of Neo4j relationships to PathRelationships func (nc *NodeConverter) ConvertRelationships(rels []interface{}) []PathRelationship { result := make([]PathRelationship, 0, len(rels)) for _, rel := range rels { if r, ok := rel.(neo4j.Relationship); ok { result = append(result, nc.ConvertRelationship(r)) } } return result } // Helper functions for property extraction func getStringProp(props map[string]interface{}, key string) string { if val, ok := props[key]; ok && val != nil { if str, ok := val.(string); ok { return str } } return "" } func getFloat64Prop(props map[string]interface{}, key string) float64 { if val, ok := props[key]; ok && val != nil { switch v := val.(type) { case float64: return v case int64: return float64(v) case int: return float64(v) } } return 0.0 } func getStringValue(val interface{}) string { if val == nil { return "" } if str, ok := val.(string); ok { return str } return "" } func getFloat64Value(val interface{}) float64 { if val == nil { return 0.0 } switch v := val.(type) { case float64: return v case int64: return float64(v) case int: return float64(v) } return 0.0 } func getIntValue(val interface{}) int { if val == nil { return 0 } switch v := val.(type) { case int64: return int(v) case int: return v case float64: return int(v) } return 0 }