<commit_before>========
Cookbook
========

Creating a Simple Graph
=======================

Listed below are a couple of short examples on how to create a simple graph.

Using the Regular REST API
--------------------------

::

    from py2neo import neo4j

    graph_db = neo4j.GraphDatabaseService()
    a, b, ab = graph_db.create(node(name="Alice"), node(name="Bob"), rel(0, "KNOWS", 1))

Using Cypher
------------

::

    from py2neo import neo4j

    graph_db = neo4j.GraphDatabaseService()
    query = neo4j.CypherQuery(db, "CREATE (a {name:{name_a}})-[ab:KNOWS]->(b {name:{name_b}})"
                                  "RETURN a, b, ab")
    a, b, ab = query.execute(name_a="Alice", name_b="Bob").data[0]

Batch Insertion using Index
===========================

::

    # some example source data
    records = [(101, "Alice"), (102, "Bob"), (103, "Carol")]

    graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
    batch = neo4j.WriteBatch(graph_db)  # batch is linked to graph database

    for emp_no, name in records:
        # get_or_create_indexes_node is one of many batch methods available
        batch.get_or_create_indexed_node("Employees", "emp_no", emp_no, {
            "emp_no": emp_no, "name": name
        })

    nodes = batch.submit()  # will return `Node` objects for the nodes created

Default URI
-----------

A default Neo4j instance will listen on port 7474. Therefore, for such a
default installation, the ``DEFAULT_URI`` can be used:

.. autoattribute:: py2neo.neo4j.DEFAULT_URI

This default will be used if the URI is omitted from construction of a new
``GraphDatabaseService`` instance::

    graph_db = neo4j.GraphDatabaseService()

Authentication
--------------

.. autofunction:: py2neo.neo4j.authenticate

URI Rewriting
-------------

.. autofunction:: py2neo.neo4j.rewrite<commit_msg>fixes #172<commit_after>========
Cookbook
========

Creating a Simple Graph
=======================

Listed below are a couple of short examples on how to create a simple graph.

Using the Regular REST API
--------------------------

::

    from py2neo import neo4j

    graph_db = neo4j.GraphDatabaseService()
    a, b, ab = graph_db.create(node(name="Alice"), node(name="Bob"), rel(0, "KNOWS", 1))

Using Cypher
------------

::

    from py2neo import neo4j

    graph_db = neo4j.GraphDatabaseService()
    query = neo4j.CypherQuery(db, "CREATE (a {name:{name_a}})-[ab:KNOWS]->(b {name:{name_b}})"
                                  "RETURN a, b, ab")
    a, b, ab = query.execute(name_a="Alice", name_b="Bob").data[0]

Batch Insertion using Index
===========================

::

    # some example source data
    records = [(101, "Alice"), (102, "Bob"), (103, "Carol")]

    graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
    batch = neo4j.WriteBatch(graph_db)  # batch is linked to graph database

    for emp_no, name in records:
        # get_or_create_indexes_node is one of many batch methods available
        batch.get_or_create_indexed_node("Employees", "emp_no", emp_no, {
            "emp_no": emp_no, "name": name
        })

    nodes = batch.submit()  # will return `Node` objects for the nodes created

Default URI
===========

A default Neo4j instance will listen on port 7474. Therefore, for such a
default installation, the ``DEFAULT_URI`` can be used:

.. autoattribute:: py2neo.neo4j.DEFAULT_URI

This default will be used if the URI is omitted from construction of a new
``GraphDatabaseService`` instance::

    graph_db = neo4j.GraphDatabaseService()

Authentication
==============

.. autofunction:: py2neo.neo4j.authenticate

URI Rewriting
=============

.. autofunction:: py2neo.neo4j.rewrite

Logging
=======

To enable logging, simply import the ``logging`` module and provide a
configuration, e.g.::

    import logging
    logging.basicConfig(level=logging.DEBUG)
{'fraction_non_alphanumeric': 0.17897727272727273, 'fraction_numerical': 0.019886363636363636, 'mean_word_length': 3.2420591456736036, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3576659', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1178, 'n_words': 353}