How to use the py2neo.Node function in py2neo

To help you get started, we’ve selected a few py2neo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github technige / py2neo / test / integration / test_relationship.py View on Github external
def test_relationship_creation_on_existing_node(graph):
    a = Node()
    graph.create(a)
    b = Node()
    r = Relationship(a, "TO", b)
    graph.create(r)
    assert r.graph is a.graph is graph
    assert r.identity is not None
github technige / py2neo / test / test_deprecated.py View on Github external
def test_node_degree(self):
        alice = Node("Person", name="Alice")
        bob = Node("Person", name="Bob")
        carol = Node("Person", name="Carol")
        self.graph.create(alice)
        assert alice.degree() == 0
        self.graph.create(Path(alice, "KNOWS", bob))
        assert alice.degree() == 1
        self.graph.create(Path(alice, "KNOWS", carol))
        assert alice.degree() == 2
        self.graph.create(Path(carol, "KNOWS", alice))
        assert alice.degree() == 3
github technige / py2neo / test / integration / test_pull.py View on Github external
def test_relationship_property_pull_scenarios(graph):
    property_sets = [{}, {"name": "Alice"}, {"name": "Alice", "age": 33}, {"name": "Bob"}]
    for old_props in property_sets:
        for new_props in property_sets:
            a = Node()
            b = Node()
            relationship = Relationship(a, "TO", b, **old_props)
            graph.create(relationship)
            relationship_id = relationship.identity
            assert dict(relationship) == old_props
            graph.run("MATCH ()-[r]->() WHERE id(r)={x} SET r={y}",
                      x=relationship_id, y=new_props)
            graph.pull(relationship)
            assert dict(relationship) == new_props, \
                "Failed to pull new properties %r over old properties %r" % \
                (new_props, old_props)
github technige / py2neo / test_ext / batman / test_index.py View on Github external
def test_add_existing_node_to_index_with_odd_chars_in_key_and_value(self):
        alice = Node(name="Alice Smith")
        self.graph.create(alice)
        self.index.add("@!%#", "!\"$%^&*()", alice)
        entities = self.index.get("@!%#", "!\"$%^&*()")
        assert entities is not None
        assert isinstance(entities, list)
        assert len(entities) == 1
        assert entities[0] == alice
        self.graph.delete(alice)
github technige / py2neo / test / integration / test_relationship.py View on Github external
def test_cannot_get_relationship_by_id_when_id_does_not_exist(graph):
    a = Node()
    b = Node()
    r = Relationship(a, "TO", b)
    graph.create(r)
    rel_id = r.identity
    graph.delete(r)
    with raises(KeyError):
        _ = graph.relationships[rel_id]
github technige / py2neo / test / integration / test_push.py View on Github external
def test_should_push_multiple_labels_with_overlap(graph):
    node = Node("A", "B")
    graph.create(node)
    node_id = node.identity
    assert_has_labels(graph, node_id, {"A", "B"})
    node.remove_label("A")
    node.add_label("C")
    graph.push(node)
    assert_has_labels(graph, node_id, {"B", "C"})
github marksibrahim / knowledge_search / tools / neo4j_play / write_json_to_neo.py View on Github external
import json

results_path = "/Users/mark/Desktop/wiki_v4/"
with open(results_path + "sample_fln.json") as f:
        fln_dict = json.load(f)

# initialize graph db
g = Graph()
tx = g.begin()


# write to graph db

for article, fl in fln_dict.iteritems():
    article_node = Node("Article", title=article)
    fl_node = Node("Article", title=fl)
    relation = Relationship(article_node, "LINKS_TO", fl_node)

    tx.create(article_node)
    tx.create(fl_node)
    tx.create(relation)

tx.commit()


"""
g = Graph()
tx = g.begin()

a = Node("Person", name="Alice")
tx.create(a)
github mspreitz / MobileSandbox / Neo4J / msneo.py View on Github external
print 'ERROR: Found more than 1 Certificate nodes with Sha1Thumbprint {}'.format(certdict['Sha1Thumbprint'].upper())
        tx.commit()
        return

    # NOTE: It is currently presumed that static analysis occurs before dynamic analysis
    if count == 1:
        print 'Neo4J: Found Certificate Node with Sha1Thumbprint: {}'.format(certdict['Sha1Thumbprint'])

        # Create SIGNED_WITH Relationship between Android Application and Certificate. Then Abort
        r = Relationship(na, 'SIGNED_WITH', nc)
        tx.create(r)
        tx.commit()
        return

    # Create Certificate Node with its distinguishable and boolean attributes
    nc = Node('Certificate')
    add_attribute(nc, certdict, 'CertVersion')
    add_attribute(nc, certdict, 'Expired')
    add_attribute(nc, certdict, 'ForClientAuthentication')
    add_attribute(nc, certdict, 'ForCodeSigning')
    add_attribute(nc, certdict, 'ForSecureEmail')
    add_attribute(nc, certdict, 'ForServerAuthentication')
    add_attribute(nc, certdict, 'ForTimeStamping')
    add_attribute(nc, certdict, 'IsRoot')
    add_attribute(nc, certdict, 'IssuerDN')
    add_attribute(nc, certdict, 'Revoked')
    add_attribute(nc, certdict, 'SelfSigned')
    add_attribute(nc, certdict, 'SignatureVerified')
    add_attribute(nc, certdict, 'SubjectDN')
    add_attribute(nc, certdict, 'SerialNumber')
    add_attribute(nc, certdict, 'SubjectKeyId')
    add_attribute(nc, certdict, 'Sha1Thumbprint', regex=r_sha1, upper=True)
github Mirantis / solar / solar / solar / interfaces / db / neo4j.py View on Github external
def create(self, name, properties={}, collection=BaseGraphDB.DEFAULT_COLLECTION):
        log.log.debug(
            'Creating %s, name %s with properties %s',
            collection.name,
            name,
            properties
        )

        properties = deepcopy(properties)
        properties['name'] = name

        n = py2neo.Node(collection.name, **properties)
        return self._r.create(n)[0]
github okfn-brasil / serenata-de-amor / research / develop / 2017-02-12-marcusrehm-neo4j-guide.py View on Github external
# ## Nodes
# 
# Create nodes with the `Node` class. The first argument is the node's label. The remaining arguments are an arbitrary amount of node properties or key-value pairs.

# In[17]:

from py2neo import Node

nicole = Node("Person", name="Nicole", age=24)
drew = Node("Person", name="Drew", age=20)

mtdew = Node("Drink", name="Mountain Dew", calories=9000)
cokezero = Node("Drink", name="Coke Zero", calories=0)

coke = Node("Manufacturer", name="Coca Cola")
pepsi = Node("Manufacturer", name="Pepsi")

graph.create(nicole | drew | mtdew | cokezero | coke | pepsi)


# ## Relationships
# 
# Create relationships between nodes with the `Relationship` class.

# In[18]:

from py2neo import Relationship

graph.create(Relationship(nicole, "LIKES", cokezero))
graph.create(Relationship(nicole, "LIKES", mtdew))
graph.create(Relationship(drew, "LIKES", mtdew))