function get_dbo_concepts_by_uid
Retrieves a single dbo_Concepts node from a Neo4j graph database by matching its unique identifier (UID).
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
703 - 710
simple
Purpose
This function queries a Neo4j database to fetch a specific dbo_Concepts node using its UID property. It's designed for retrieving individual concept records from a knowledge graph or ontology structure, likely based on the DBpedia Ontology (dbo) schema. The function returns the first matching node or None if no match is found.
Source Code
def get_dbo_concepts_by_uid(uid):
"""Get a dbo_Concepts node by its UID"""
query = """
MATCH (n:dbo_Concepts {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_Concepts 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 dbo_Concepts nodes.
Return Value
Returns a dictionary-like object representing the matched dbo_Concepts node if found, containing all properties of that node. Returns None if no node with the specified UID exists. The exact structure depends on the properties stored in the dbo_Concepts nodes in the database.
Dependencies
neo4j
Required Imports
from neo4j import GraphDatabase
Usage Example
# Assuming run_query is defined and Neo4j connection is configured
# Example 1: Retrieve a concept by UID
uid_to_find = "concept_12345"
concept = get_dbo_concepts_by_uid(uid_to_find)
if concept:
print(f"Found concept: {concept}")
# Access node properties
# print(concept['n']['property_name'])
else:
print(f"No concept found with UID: {uid_to_find}")
# Example 2: Handle missing concepts
result = get_dbo_concepts_by_uid("nonexistent_uid")
if result is None:
print("Concept not found")
Best Practices
- Always check if the return value is None before accessing node properties to avoid AttributeError
- Ensure the run_query function is properly implemented with error handling and connection management
- Consider adding input validation for the uid parameter to ensure it's not None or empty
- The function assumes run_query returns a list; ensure this dependency behaves as expected
- For production use, consider adding logging for debugging failed queries
- Ensure proper Neo4j connection pooling and session management in the run_query function
- Consider adding a timeout parameter for long-running queries
- Index the UID property in Neo4j for optimal query performance
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_dbo_concepts_by_id 90.0% similar
-
function get_dbo_concepthouses_by_uid 87.2% similar
-
function get_all_dbo_concepts 79.2% similar
-
function get_dbo_usergroup_by_uid 77.6% similar
-
function get_dbo_concepthouses_by_id 76.7% similar