function get_dbo_concepthouses_by_uid
Retrieves a single dbo_ConceptHouses node from a Neo4j graph database by matching its unique identifier (UID).
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
664 - 671
simple
Purpose
This function queries a Neo4j database to fetch a specific dbo_ConceptHouses node using its UID property. It's designed for retrieving individual concept house records from a knowledge graph, likely part of a DBpedia ontology implementation. The function returns the first matching node or None if no match is found.
Source Code
def get_dbo_concepthouses_by_uid(uid):
"""Get a dbo_ConceptHouses node by its UID"""
query = """
MATCH (n:dbo_ConceptHouses {UID: $uid})
RETURN n
"""
result = run_query(query, {"uid": uid})
return result[0] if result else None
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
uid |
- | - | positional_or_keyword |
Parameter Details
uid: The unique identifier (UID) of the dbo_ConceptHouses node to retrieve. Expected to be a string or value that matches the UID property stored in the Neo4j database. This should be a valid identifier that exists in the database's dbo_ConceptHouses nodes.
Return Value
Returns a dictionary or node object representing the matched dbo_ConceptHouses node if found, or None if no node with the specified UID exists. The returned object contains all properties of the matched node. The function uses indexing (result[0]) to return only the first match, assuming UIDs are unique.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
# Example run_query implementation:
from neo4j import GraphDatabase
driver = GraphDatabase.driver('bolt://localhost:7687', auth=('neo4j', 'password'))
def run_query(query, params):
with driver.session() as session:
result = session.run(query, params)
return [record['n'] for record in result]
# Using the function
uid_to_find = 'concept_house_12345'
node = get_dbo_concepthouses_by_uid(uid_to_find)
if node:
print(f'Found node: {node}')
else:
print('No node found with that UID')
Best Practices
- Ensure the UID parameter is properly validated before calling this function to avoid unnecessary database queries
- The function assumes UIDs are unique and returns only the first match; verify this assumption holds for your data model
- Consider adding error handling for database connection issues or query failures
- The run_query function must be properly implemented with connection management and error handling
- Consider adding type hints for better code documentation (e.g., def get_dbo_concepthouses_by_uid(uid: str) -> Optional[Dict])
- Ensure proper indexing on the UID property in Neo4j for optimal query performance
- Close database connections properly in the run_query implementation to avoid resource leaks
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_concepthouses_by_id 90.7% similar
-
function get_dbo_houses_by_uid 90.5% similar
-
function get_dbo_concepts_by_uid 87.2% similar
-
function get_dbo_houses_by_id 80.5% similar
-
function get_all_dbo_concepthouses 80.1% similar