Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from neomodel import StructuredNode, RelationshipTo, StringProperty
from .test_relationships import Country
class Cat(StructuredNode):
name = StringProperty()
# Relationship is defined using a relative class path
is_from = RelationshipTo('.test_relationships.Country', 'IS_FROM')
def test_relative_relationship():
a = Cat(name='snufkin').save()
assert a
c = Country(code='MG').save()
assert c
# connecting an instance of the class defined above
# the next statement will fail if there's a type mismatch
a.is_from.connect(c)
assert a.is_from.is_connected(c)
class HairDryer(StructuredNode):
version = IntegerProperty()
class ScrewDriver(StructuredNode):
version = IntegerProperty()
class Car(StructuredNode):
version = IntegerProperty()
class Monkey(StructuredNode):
name = StringProperty()
dryers = RelationshipTo('HairDryer', 'OWNS_DRYER', cardinality=ZeroOrMore)
driver = RelationshipTo('ScrewDriver', 'HAS_SCREWDRIVER', cardinality=ZeroOrOne)
car = RelationshipTo('Car', 'HAS_CAR', cardinality=OneOrMore)
toothbrush = RelationshipTo('ToothBrush', 'HAS_TOOTHBRUSH', cardinality=One)
class ToothBrush(StructuredNode):
name = StringProperty()
def test_cardinality_zero_or_more():
m = Monkey(name='tim').save()
assert m.dryers.all() == []
assert m.dryers.single() is None
h = HairDryer(version=1).save()
m.dryers.connect(h)
assert len(m.dryers.all()) == 1
from pytest import raises
from neomodel import (StructuredNode, RelationshipTo, RelationshipFrom, Relationship,
StringProperty, IntegerProperty, StructuredRel, One)
class PersonWithRels(StructuredNode):
name = StringProperty(unique_index=True)
age = IntegerProperty(index=True)
is_from = RelationshipTo('Country', 'IS_FROM')
knows = Relationship(u'PersonWithRels', 'KNOWS') # use unicode to check issue
@property
def special_name(self):
return self.name
def special_power(self):
return "I have no powers"
class Country(StructuredNode):
code = StringProperty(unique_index=True)
inhabitant = RelationshipFrom(PersonWithRels, 'IS_FROM')
president = RelationshipTo(PersonWithRels, 'PRESIDENT', cardinality=One)
INCOMING, DateTimeProperty, IntegerProperty, RelationshipFrom, RelationshipTo,
StringProperty, StructuredNode, StructuredRel
)
from neomodel.match import NodeSet, QueryBuilder, Traversal
from neomodel.exceptions import MultipleNodesReturned
class SupplierRel(StructuredRel):
since = DateTimeProperty(default=datetime.now)
courier = StringProperty()
class Supplier(StructuredNode):
name = StringProperty()
delivery_cost = IntegerProperty()
coffees = RelationshipTo('Coffee', 'COFFEE SUPPLIERS') # Space to check for escaping
class Coffee(StructuredNode):
name = StringProperty(unique_index=True)
price = IntegerProperty()
suppliers = RelationshipFrom(Supplier, 'COFFEE SUPPLIERS', model=SupplierRel)
def test_filter_exclude_via_labels():
Coffee(name='Java', price=99).save()
node_set = NodeSet(Coffee)
qb = QueryBuilder(node_set).build_ast()
results = qb._execute()
from neomodel import StructuredNode, StringProperty, RelationshipTo
class Humanbeing(StructuredNode):
name = StringProperty(unique_index=True)
has_a = RelationshipTo(['Location', 'Nationality'], 'HAS_A')
class Location(StructuredNode):
name = StringProperty(unique_index=True)
class Nationality(StructuredNode):
name = StringProperty(unique_index=True)
def test_multi_class_rels():
ne = Humanbeing(name='new news').save()
lo = Location(name='Belgium').save()
na = Nationality(name='British').save()
ne.has_a.connect(lo)
from neomodel import StructuredNode, RelationshipTo
class SomeModel(StructuredNode):
test = RelationshipTo('SomeModel', 'SELF')
def test_len_relationship():
t1 = SomeModel().save()
t2 = SomeModel().save()
t1.test.connect(t2)
l = len(t1.test.all())
assert l
assert l == 1
smiles = StringProperty(unique_index=True)
heavy_atom_count = IntegerProperty()
ring_atom_count = IntegerProperty()
ring_smiles = StringProperty()
# Annotations of price and molecule id
price = IntegerProperty()
mol_id = StringProperty()
class Compound(BaseMolecule):
"""
A molecule - a real purchasable molecule
"""
fragments = RelationshipTo("Fragment", "FRAG")
conformers = RelationshipTo("Conformer", "CONFEDGE")
parent_molecules = RelationshipTo("Compound", "PARENTEDGE")
class Fragment(BaseMolecule):
"""
A fragment - not a real molecule
"""
molecules = RelationshipFrom(Compound, "FRAG", model=F2Edge)
class Conformer(StructuredNode):
"""
The 3D conformer of a molecule - either Docked or imaginary
"""
# Going to go with uuid - seems as good as anything - this connects to the Django database for 3D information
unique_string = StringProperty(unique_index=True)
conformer = RelationshipFrom(Compound, "CONFEDGE")
RelationshipTo,
Relationship
)
from .nodeutils import NodeUtils
class Officer(StructuredNode, NodeUtils):
sourceID = StringProperty()
name = StringProperty()
country_codes = StringProperty()
valid_until = StringProperty()
countries = StringProperty()
node_id = StringProperty(index = True)
addresses = RelationshipTo('.address.Address', 'REGISTERED_ADDRESS')
entities = RelationshipTo('.entity.Entity', 'OFFICER_OF')
officers = Relationship('.officer.Officer', None)
@property
def serialize(self):
return {
'node_properties': {
'sourceID': self.sourceID,
'name': self.name,
'country_codes': self.country_codes,
'valid_until': self.valid_until,
'countries': self.countries,
'node_id': self.node_id,
},
}
StringProperty,
StructuredNode,
RelationshipTo,
Relationship
)
from .nodeutils import NodeUtils
class Other(StructuredNode, NodeUtils):
sourceID = StringProperty()
name = StringProperty()
valid_until = StringProperty()
node_id = StringProperty(index = True)
countries = StringProperty()
addresses = RelationshipTo('.address.Address', 'REGISTERED_ADDRESS')
officers = Relationship('.officer.Officer', None)
entities = Relationship('.entity.Entity', None)
@property
def serialize(self):
return{
'node_properties': {
'sourceID': self.sourceID,
'name': self.name,
'countries': self.countries,
'valid_until': self.valid_until,
'node_id': self.node_id,
},
}
id_str = neomodel.StringProperty(unique_index=True, required=True)
name = neomodel.StringProperty(required=False)
screen_name = neomodel.StringProperty(required=False)
followers_count = neomodel.IntegerProperty(required=False)
friends_count = neomodel.IntegerProperty(required=False)
modified = neomodel.DateTimeProperty(required=False)
created_at = neomodel.DateTimeProperty(required=False)
description = neomodel.StringProperty(required=False)
location = neomodel.StringProperty(required=False)
coordinates = neomodel.ArrayProperty(required=False, default=[])
time_zone = neomodel.StringProperty(required=False)
url = neomodel.StringProperty(required=False)
lang = neomodel.StringProperty(required=False)
follows = neomodel.RelationshipTo('User', 'FOLLOWS')
posts = neomodel.RelationshipTo('Tweet', 'POSTS')
def save(self):
self.modified = datetime.datetime.now()
super(User, self).save()
class Hashtag(neomodel.StructuredNode):
text = neomodel.StringProperty(unique_index=True, required=True)
class Link(neomodel.StructuredNode):
url = neomodel.StringProperty(unique_index=True, required=True)