function get_dbo_concepthouses_with_references_concepts_dbo_concepts
Queries a Neo4j graph database to retrieve dbo_Concepts nodes that are connected to a specific dbo_ConceptHouses node through a REFERENCES_CONCEPTS relationship.
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
1673 - 1680
simple
Purpose
This function is designed to traverse a knowledge graph stored in Neo4j, specifically to find concept nodes referenced by a concept house. It's useful for exploring semantic relationships in a database where concept houses organize or categorize multiple concepts. The function supports pagination through a limit parameter to control result set size.
Source Code
def get_dbo_concepthouses_with_references_concepts_dbo_concepts(source_id, limit=100):
"""Get dbo_Concepts nodes connected to a dbo_ConceptHouses via REFERENCES_CONCEPTS"""
query = """
MATCH (source:dbo_ConceptHouses {id: $source_id})-[r:REFERENCES_CONCEPTS]->(target:dbo_Concepts)
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_ConceptHouses node from which to start the traversal. This should be a string or value that matches the 'id' property of a ConceptHouses node in the Neo4j database.
limit: Maximum number of target dbo_Concepts nodes to return. Defaults to 100. This parameter controls pagination and prevents overwhelming result sets. Must be a positive integer.
Return Value
Returns the result of the run_query function, which typically contains a list or collection of dbo_Concepts nodes that match the query criteria. The exact return type depends on the run_query implementation, but it likely returns a list of dictionaries or Neo4j Record objects containing the properties of the target concept nodes. Returns an empty collection 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 the run_query helper 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 concepts referenced by a concept house
concept_house_id = 'CH_12345'
concepts = get_dbo_concepthouses_with_references_concepts_dbo_concepts(concept_house_id, limit=50)
# Process the results
for concept in concepts:
print(f"Concept ID: {concept['id']}, Name: {concept.get('name', 'N/A')}")
Best Practices
- Ensure the source_id parameter matches an existing dbo_ConceptHouses node in the database to avoid empty results
- Use appropriate limit values to balance between performance and completeness of results
- Handle cases where no relationships exist (empty result set) in calling code
- Consider implementing error handling for database connection failures
- Validate that the run_query function properly manages Neo4j driver sessions and connections
- For large result sets, consider implementing pagination by calling the function multiple times with different offsets
- Ensure proper indexing on the 'id' property of dbo_ConceptHouses nodes for optimal query performance
- Close Neo4j driver connections properly to avoid resource leaks
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_concepthouses_with_references_houses_dbo_houses 95.8% similar
-
function get_all_dbo_concepthouses 87.3% similar
-
function get_dbo_concepthouses_by_id 83.6% similar
-
function create_references_concepts_relationship 82.5% similar
-
function create_references_houses_relationship_v1 78.8% similar