🔍 Code Extractor

function get_relationship_types

Maturity: 35

Retrieves a dictionary of relationship type constants from the RelTypes class, filtering out private attributes that start with underscore.

File:
/tf/active/vicechatdev/CDocs/db/schema_manager.py
Lines:
510 - 513
Complexity:
simple

Purpose

This function provides a programmatic way to access all public relationship type constants defined in the RelTypes class. It's useful for dynamically discovering available relationship types in a graph database schema, validating relationship types, or generating documentation. The function introspects the RelTypes class and returns only the public constants, making it ideal for runtime type checking or UI generation where relationship types need to be displayed or selected.

Source Code

def get_relationship_types() -> Dict[str, str]:
    """Get dictionary of relationship type constants."""
    return {key: value for key, value in vars(RelTypes).items() 
            if not key.startswith('_')}

Return Value

Type: Dict[str, str]

Returns a dictionary where keys are the attribute names from the RelTypes class (as strings) and values are the corresponding relationship type constant values (as strings). Only includes public attributes (those not starting with underscore). For example, if RelTypes has attributes like 'PARENT_OF' and 'CHILD_OF', the returned dictionary would be {'PARENT_OF': 'PARENT_OF', 'CHILD_OF': 'CHILD_OF'} or similar depending on the actual values stored in RelTypes.

Dependencies

  • typing

Required Imports

from typing import Dict

Usage Example

# Assuming RelTypes class is defined with relationship constants
# class RelTypes:
#     PARENT_OF = 'PARENT_OF'
#     CHILD_OF = 'CHILD_OF'
#     RELATED_TO = 'RELATED_TO'

rel_types = get_relationship_types()
print(rel_types)
# Output: {'PARENT_OF': 'PARENT_OF', 'CHILD_OF': 'CHILD_OF', 'RELATED_TO': 'RELATED_TO'}

# Use case: Validate a relationship type
if 'PARENT_OF' in rel_types:
    print(f"Valid relationship type: {rel_types['PARENT_OF']}")

# Use case: Get all available relationship types for a dropdown
available_types = list(rel_types.keys())

Best Practices

  • Ensure the RelTypes class is properly defined before calling this function, otherwise it will raise a NameError
  • The function assumes RelTypes attributes are string constants; if they are other types, the return type annotation may be misleading
  • This function creates a new dictionary on each call, so consider caching the result if called frequently
  • The filtering logic (not key.startswith('_')) excludes Python magic methods and private attributes, which is the intended behavior
  • If RelTypes is modified at runtime, subsequent calls to this function will reflect those changes

Similar Components

AI-powered semantic similarity - components with related functionality:

  • class RelTypes_v1 76.9% similar

    A constants class that defines string constants for relationship types used in a graph database (Neo4j) for a document management system.

    From: /tf/active/vicechatdev/CDocs single class/db/schema_manager.py
  • class RelTypes 76.9% similar

    A constants class that defines string literals representing relationship types used in a graph database (Neo4j) for document management and approval workflows.

    From: /tf/active/vicechatdev/CDocs/db/schema_manager.py
  • class _Relationship 52.4% similar

    A class representing a graph relationship (edge) with labels, properties, and an optional element ID, inheriting from PropertyDict to manage key-value properties.

    From: /tf/active/vicechatdev/neo4j_driver/neo4j_objects.py
  • function get_node_labels 51.7% similar

    Retrieves all non-private attributes from the NodeLabels class as a dictionary, filtering out attributes that start with underscore.

    From: /tf/active/vicechatdev/CDocs/db/schema_manager.py
  • function create_references_sampletypes_relationship 50.3% similar

    Creates a directed REFERENCES_SAMPLETYPES relationship in a Neo4j graph database from a LIMS_SampleTypeTests node to a LIMS_SampleTypes node, with optional properties on the relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
← Back to Browse