🔍 Code Extractor

function get_dbo_interventionprotocolflocks_with_references_flocks_dbo_flocks

Maturity: 42

Queries a Neo4j graph database to retrieve dbo_Flocks nodes that are connected to a specific dbo_InterventionProtocolFlocks node through a REFERENCES_FLOCKS relationship.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
2025 - 2032
Complexity:
simple

Purpose

This function is designed to traverse a graph database relationship between intervention protocol flocks and their associated flocks. It's useful for retrieving all flock entities that are referenced by a particular intervention protocol, which could be used in agricultural, veterinary, or livestock management systems to understand which flocks are affected by specific intervention protocols.

Source Code

def get_dbo_interventionprotocolflocks_with_references_flocks_dbo_flocks(source_id, limit=100):
    """Get dbo_Flocks nodes connected to a dbo_InterventionProtocolFlocks via REFERENCES_FLOCKS"""
    query = """
    MATCH (source:dbo_InterventionProtocolFlocks {id: $source_id})-[r:REFERENCES_FLOCKS]->(target:dbo_Flocks)
    RETURN target
    LIMIT $limit
    """
    return run_query(query, {"source_id": source_id, "limit": limit})

Parameters

Name Type Default Kind
source_id - - positional_or_keyword
limit - 100 positional_or_keyword

Parameter Details

source_id: The unique identifier (id property) of the dbo_InterventionProtocolFlocks node from which to start the traversal. This should be a string or integer value that matches an existing node's id in the database.

limit: Maximum number of dbo_Flocks nodes to return. Defaults to 100. This parameter helps control query performance and result set size. Must be a positive integer.

Return Value

Returns the result of run_query() function, which typically returns a list of Neo4j records containing the target dbo_Flocks nodes. Each record represents a dbo_Flocks node with all its properties. The exact return type depends on the run_query() implementation, but it's likely a list of dictionaries or Neo4j Record objects. Returns an empty list if no matching relationships are found.

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query is defined and Neo4j connection is configured
from neo4j import GraphDatabase

# Define or import run_query function
def run_query(query, params):
    driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
    with driver.session() as session:
        result = session.run(query, params)
        return [record['target'] for record in result]
    driver.close()

# Use the function to get flocks for a specific intervention protocol
intervention_protocol_id = 'protocol_123'
flocks = get_dbo_interventionprotocolflocks_with_references_flocks_dbo_flocks(intervention_protocol_id, limit=50)

# Process the results
for flock in flocks:
    print(f"Flock ID: {flock['id']}, Name: {flock.get('name', 'N/A')}")

Best Practices

  • Ensure the source_id parameter matches an existing dbo_InterventionProtocolFlocks node to avoid empty results
  • Use appropriate limit values to prevent performance issues with large datasets
  • Handle the case where no relationships exist (empty result set) in calling code
  • Ensure proper Neo4j connection management in the run_query() function implementation
  • Consider adding error handling for database connection failures
  • Validate that the run_query() function is properly defined before calling this function
  • Consider adding pagination if working with large result sets beyond the limit parameter
  • Ensure proper indexing on the id property of dbo_InterventionProtocolFlocks nodes for optimal query performance

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function get_dbo_interventionprotocolflocks_with_references_interventionprotocols_dbo_interventionprotocols 94.5% similar

    Queries a Neo4j graph database to retrieve dbo_InterventionProtocols nodes that are connected to a specific dbo_InterventionProtocolFlocks node via a REFERENCES_INTERVENTIONPROTOCOLS relationship.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_dbo_interventionprotocolflocks 89.0% similar

    Queries a Neo4j graph database to retrieve all nodes labeled as 'dbo_InterventionProtocolFlocks' with a configurable limit on the number of results returned.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_interventionprotocolflocks_by_id 87.1% similar

    Retrieves a single dbo_InterventionProtocolFlocks node from a Neo4j graph database by its unique ID.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_dbo_interventionprotocolflocks_by_uid 83.3% similar

    Retrieves a single dbo_InterventionProtocolFlocks node from a Neo4j graph database by matching its unique identifier (UID).

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_references_flocks_relationship_v1 82.5% similar

    Creates a REFERENCES_FLOCKS relationship in a Neo4j graph database between an InterventionProtocolFlocks node and a Flocks node, with optional properties on the relationship.

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