🔍 Code Extractor

function create_dbo_concepts

Maturity: 46

Creates a new node with the label 'dbo_Concepts' in a Neo4j graph database with the specified properties.

File:
/tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
Lines:
712 - 721
Complexity:
simple

Purpose

This function is designed to insert a new concept node into a Neo4j database using the DBpedia Ontology (dbo) schema. It dynamically constructs a Cypher CREATE query based on the provided properties dictionary, executes the query, and returns the created node. This is useful for populating knowledge graphs with concept entities from structured data sources.

Source Code

def create_dbo_concepts(properties):
    """Create a new dbo_Concepts node"""
    props_list = ', '.join([f"n.{prop} = ${prop}" for prop in properties.keys()])
    query = f"""
    CREATE (n:dbo_Concepts)
    SET {props_list}
    RETURN n
    """
    result = run_query(query, properties)
    return result[0] if result else None

Parameters

Name Type Default Kind
properties - - positional_or_keyword

Parameter Details

properties: A dictionary containing key-value pairs representing the properties to be set on the new dbo_Concepts node. Keys should be valid property names (strings) and values can be any data type supported by Neo4j (strings, numbers, booleans, lists, etc.). Example: {'name': 'Artificial Intelligence', 'category': 'Technology', 'year': 1956}

Return Value

Returns the created Neo4j node object (typically a dictionary-like object with node properties and metadata) if the creation was successful. Returns None if the query execution fails or returns no results. The returned node includes all properties that were set plus any default properties added by Neo4j (like internal ID).

Dependencies

  • neo4j

Required Imports

from neo4j import GraphDatabase

Usage Example

# Assuming run_query function is defined and Neo4j is configured

# Example 1: Create a concept node with basic properties
properties = {
    'name': 'Machine Learning',
    'description': 'A subset of artificial intelligence',
    'category': 'Computer Science',
    'created_date': '2024-01-15'
}

node = create_dbo_concepts(properties)
if node:
    print(f"Created node: {node}")
else:
    print("Failed to create node")

# Example 2: Create a concept with multiple property types
properties = {
    'name': 'Neural Networks',
    'popularity_score': 95,
    'is_active': True,
    'related_topics': ['Deep Learning', 'AI', 'Data Science']
}

node = create_dbo_concepts(properties)
if node:
    print(f"Node created with ID: {node.get('id')}")

Best Practices

  • Validate the properties dictionary before passing it to ensure all keys are valid property names (no special characters that could break the Cypher query)
  • Be cautious of Cypher injection vulnerabilities - the function uses parameterized queries which is good, but ensure property keys come from trusted sources
  • Handle the None return value appropriately in calling code to detect creation failures
  • Consider adding error handling around the function call to catch Neo4j connection or query execution errors
  • Ensure the run_query function properly handles database connections and transactions
  • Use consistent property naming conventions across all dbo_Concepts nodes for easier querying
  • Consider adding constraints or indexes on frequently queried properties in the Neo4j database
  • The function does not check for duplicate nodes - implement uniqueness constraints at the database level if needed

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function create_dbo_concepthouses 87.0% similar

    Creates a new node with label 'dbo_ConceptHouses' in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_dbo_tnv 78.4% similar

    Creates a new node with label 'dbo_TNV' in a Neo4j graph database with specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function get_all_dbo_concepts 76.6% similar

    Retrieves a limited set of nodes labeled as 'dbo_Concepts' from a Neo4j graph database.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_dbo_product 76.0% similar

    Creates a new dbo_Product node in a Neo4j graph database with the specified properties and returns the created node.

    From: /tf/active/vicechatdev/neo4j_schema/neo4j_python_snippets.py
  • function create_references_concepts_relationship 74.9% similar

    Creates a REFERENCES_CONCEPTS relationship in a Neo4j graph database between a dbo_ConceptHouses node and a dbo_Concepts node, with optional properties on the relationship.

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