Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get(self, key, value):
""" Fetch a list of all entities from the index which are associated
with the `key`:`value` pair supplied::
# obtain a reference to the "People" node index and
# get all nodes where `family_name` equals "Smith"
people = graph.get_or_create_index(neo4j.Node, "People")
smiths = people.get("family_name", "Smith")
..
"""
return [
self.graph.hydrate(assembled(result))
for i, result in grouped(self._searcher.expand(key=key, value=value).get())
]
alice = contacts.get_or_create("name", "SMITH, Alice", {
"given_name": "Alice Jane", "family_name": "Smith",
"phone": "01234 567 890", "mobile": "07890 123 456"
})
# obtain a reference to the "Friendships" relationship index and
# ensure that Alice and Bob's friendship is registered (`alice`
# and `bob` refer to existing nodes)
friendships = graph.get_or_create_index(neo4j.Relationship, "Friendships")
alice_and_bob = friendships.get_or_create(
"friends", "Alice & Bob", (alice, "KNOWS", bob)
)
..
"""
return self.graph.hydrate(assembled(self._create_unique(key, value, abstract)))
def _execute_spatial_request(self, resource, spatial_payload):
try:
json_stream = resource.post(spatial_payload)
except GraphError as exc:
if 'NullPointerException' in exc.full_name:
# no results leads to a NullPointerException.
# this is probably a bug on the Java side, but this
# happens with some resources and must be managed.
return []
raise
if json_stream.status_code == 204:
# no content
return []
geometry_nodes = map(Node.hydrate, assembled(json_stream))
nodes = self._get_data_nodes(geometry_nodes)
return nodes
def relationship_types(self):
""" The set of relationship types currently defined within the graph.
"""
resource = self._subresource("relationship_types")
return set(_hydrated(assembled(resource._get())))
def create_layer(self, layer_name):
""" Create a Layer to add geometries to. If a Layer with the
name property value of ``layer_name`` already exists, nothing
happens.
"""
resource = self.resources['addEditableLayer']
spatial_data = dict(layer=layer_name, **EXTENSION_CONFIG)
raw = resource.post(spatial_data)
layer = assembled(raw)
return layer
def __iter__(self):
hydration_cache = {}
for key, section in grouped(self._buffered):
if key[0] == "data":
for i, row in grouped(section):
yield self._producer.produce(_hydrated(assembled(row),
hydration_cache))
def get_properties(self):
""" Fetch all properties.
:return: dictionary of properties
"""
if not self.is_abstract:
self._properties = assembled(self._properties_resource._get()) or {}
return self._properties
def find(self, label, property_key=None, property_value=None):
""" Iterate through a set of labelled nodes, optionally filtering
by property key and value
"""
uri = URI(self).resolve("/".join(["label", label, "nodes"]))
if property_key:
uri = uri.resolve("?" + percent_encode({property_key: json.dumps(property_value, ensure_ascii=False)}))
try:
for i, result in grouped(Resource(uri)._get()):
yield _hydrated(assembled(result))
except ClientError as err:
if err.status_code != NOT_FOUND:
raise