async def get_path(goblin_app, source_label, source_id, target_label, target_id): session = await goblin_app.session() traversal = (session.g.V().has( source_label, f"{source_label}_id", source_id).repeat(__.bothE().otherV().simplePath()).until( __.has( target_label, f"{target_label}_id", target_id).or_().loops().is_(6)).has( target_label, f"{target_label}_id", target_id).limit(1).path().index().map(__.unfold().filter( __.unfold().tail().math("_ % 2").is_(1)).limit( Scope.local, 1).project("source", "edge", "target").by( project_vertex(__.outV())).by( __.project("id", "label", "values").by( __.id()).by(__.label()).by( __.valueMap())).by( project_vertex( __.inV())).fold())) result = await traversal.toList() if not result: return None for path in result: for entry in path: cleanup_vertex(entry["source"], goblin_app) cleanup_vertex(entry["target"], goblin_app) cleanup_edge(entry["edge"]) return result
def get_locality_vertex_projection(): return (__.cap("vertices").unfold().dedup().project( "id", "kind", "label", "values", "total_edge_count", "child_count").by(__.id()).by(__.constant("vertex")).by(__.label()).by( __.valueMap()).by(__.bothE().count()).by( __.inE("relationship").has( "name", P.within("Member Of", "Subsidiary Of", "Subrelease Of")).count()))
def project_vertex(traversal, **extra_traversals): traversal = (traversal.project( "id", "label", "values", "total_edge_count", "child_count", "extra", "in_roles", "out_roles", *sorted(extra_traversals.keys()), ).by(__.id()).by(__.label()).by(__.valueMap()).by(__.bothE().count()).by( make_child_count_traversal()).by(make_track_extras_traversal()).by( __.inE("relationship").groupCount().by("name")).by( __.outE("relationship").groupCount().by("name"))) for _, extra_traversal in sorted(extra_traversals.items()): traversal = traversal.by(extra_traversal) return traversal
async def _get_vertex_properties(self, vid, label): projection = self._g.V(vid).properties() \ .project('id', 'key', 'value', 'meta') \ .by(__.id()).by(__.key()).by(__.value()) \ .by(__.valueMap()) props = await projection.toList() new_props = {'label': label, 'id': vid} for prop in props: key = prop['key'] val = prop['value'] # print('val_type', type(val)) meta = prop['meta'] new_props.setdefault(key, []) if meta: meta['key'] = key meta['value'] = val meta['id'] = prop['id'] val = meta new_props[key].append(val) return new_props
def get_locality_edge_projection(): return (__.cap("filteredEdges").unfold().project( "id", "kind", "label", "source", "target", "values").by(__.id()).by(__.constant("edge")).by(__.label()).by( __.outV().id()).by(__.inV().id()).by(__.valueMap()))