def undecided_user_audience_check(g, transient_id, website_url, thank_you_page_url, since, min_visited_count): """ Given transient id, check whether it belongs to an audience. It's simple yes, no question. User belongs to an audience whenever all of the following criteria are met: * visited some website url at least X times since specific timestamp * did not visit thank you page url since specific timestamp """ return (g.V(transient_id).hasLabel("transientId").in_("has_identity").out( "has_identity").outE("visited").has("ts", P.gt(since)).choose( has("visited_url", website_url), groupCount("visits").by(constant("page_visits"))).choose( has("visited_url", thank_you_page_url), groupCount("visits").by( constant("thank_you_page_vists"))).cap("visits").coalesce( and_( coalesce(select("thank_you_page_vists"), constant(0)).is_(0), select("page_visits").is_( P.gt(min_visited_count))).choose( count().is_(1), constant(True)), constant(False)))
def test_P(self): # verify that the order of operations is respected assert "and(eq(a),lt(b))" == str(P.eq("a").and_(P.lt("b"))) assert "and(or(lt(b),gt(c)),neq(d))" == str( P.lt("b").or_(P.gt("c")).and_(P.neq("d"))) assert "and(or(lt(b),gt(c)),or(neq(d),gte(e)))" == str( P.lt("b").or_(P.gt("c")).and_(P.neq("d").or_(P.gte("e"))))
def test_bytecode(self): g = Graph().traversal() bytecode = g.V().out("created").bytecode assert 0 == len(bytecode.bindings.keys()) assert 0 == len(bytecode.source_instructions) assert 2 == len(bytecode.step_instructions) assert "V" == bytecode.step_instructions[0][0] assert "out" == bytecode.step_instructions[1][0] assert "created" == bytecode.step_instructions[1][1] assert 1 == len(bytecode.step_instructions[0]) assert 2 == len(bytecode.step_instructions[1]) ## bytecode = g.withSack(1).E().groupCount().by("weight").bytecode assert 0 == len(bytecode.bindings.keys()) assert 1 == len(bytecode.source_instructions) assert "withSack" == bytecode.source_instructions[0][0] assert 1 == bytecode.source_instructions[0][1] assert 3 == len(bytecode.step_instructions) assert "E" == bytecode.step_instructions[0][0] assert "groupCount" == bytecode.step_instructions[1][0] assert "by" == bytecode.step_instructions[2][0] assert "weight" == bytecode.step_instructions[2][1] assert 1 == len(bytecode.step_instructions[0]) assert 1 == len(bytecode.step_instructions[1]) assert 2 == len(bytecode.step_instructions[2]) ## bytecode = g.V(('a', [1, 2, 3])).out(('b', 'created')).where( __.in_(('c', 'created'), ('d', 'knows')).count().is_( ('e', P.gt(2)))).bytecode assert 'V' == bytecode.step_instructions[0][0] assert 'out' == bytecode.step_instructions[1][0] assert 'where' == bytecode.step_instructions[2][0] assert ('b', 'created') == bytecode.step_instructions[1][1] assert isinstance(hash(bytecode.step_instructions[1][1]), int)
def test_P(self): result = {'@type': 'g:P', '@value': { 'predicate': 'and', 'value': [{ '@type': 'g:P', '@value': { 'predicate': 'or', 'value': [{ '@type': 'g:P', '@value': {'predicate': 'lt', 'value': 'b'} }, {'@type': 'g:P', '@value': {'predicate': 'gt', 'value': 'c'}} ] } }, {'@type': 'g:P', '@value': {'predicate': 'neq', 'value': 'd'}}]}} assert result == json.loads( self.graphson_writer.writeObject(P.lt("b").or_(P.gt("c")).and_(P.neq("d")))) result = {'@type': 'g:P', '@value': {'predicate':'within','value': [{"@type": "g:Int32", "@value": 1},{"@type": "g:Int32", "@value": 2}]}} assert result == json.loads(self.graphson_writer.writeObject(P.within([1, 2]))) assert result == json.loads(self.graphson_writer.writeObject(P.within(1, 2))) result = {'@type': 'g:P', '@value': {'predicate':'within','value': [{"@type": "g:Int32", "@value": 1}]}} assert result == json.loads(self.graphson_writer.writeObject(P.within([1]))) assert result == json.loads(self.graphson_writer.writeObject(P.within(1)))
def test_traversal_modern_graph(modern_graph_data_dir): from gremlin_python.process.traversal import Order from gremlin_python.process.traversal import P gs_image, gie_manager_image = get_gs_image_on_ci_env() sess = graphscope.session( show_log=True, num_workers=1, k8s_gs_image=gs_image, k8s_gie_graph_manager_image=gie_manager_image, k8s_coordinator_cpu=0.5, k8s_coordinator_mem="2500Mi", k8s_vineyard_cpu=0.1, k8s_vineyard_mem="512Mi", k8s_engine_cpu=0.1, k8s_engine_mem="1500Mi", k8s_vineyard_shared_mem="2Gi", k8s_volumes=get_k8s_volumes(), ) graph = load_modern_graph(sess, modern_graph_data_dir) interactive = sess.gremlin(graph) g = interactive.traversal_source() assert g.V().has("name", "marko").count().toList()[0] == 1 assert g.V().has("person", "name", "marko").count().toList()[0] == 1 assert g.V().has("person", "name", "marko").outE("created").count().toList()[0] == 1 assert (g.V().has("person", "name", "marko").outE("created").inV().count().toList()[0] == 1) assert g.V().has("person", "name", "marko").out("created").count().toList()[0] == 1 assert (g.V().has( "person", "name", "marko").out("created").values("name").count().toList()[0] == 1) assert (g.V().hasLabel("person").has("age", P.gt(30)).order().by( "age", Order.desc).count().toList()[0] == 2)
def test_P(self): result = {'@type': 'g:P', '@value': { 'predicate': 'and', 'value': [{ '@type': 'g:P', '@value': { 'predicate': 'or', 'value': [{ '@type': 'g:P', '@value': {'predicate': 'lt', 'value': 'b'} }, {'@type': 'g:P', '@value': {'predicate': 'gt', 'value': 'c'}} ] } }, {'@type': 'g:P', '@value': {'predicate': 'neq', 'value': 'd'}}]}} assert result == json.loads( self.graphson_writer.writeObject(P.lt("b").or_(P.gt("c")).and_(P.neq("d")))) result = {'@type': 'g:P', '@value': {'predicate':'within','value': [{"@type": "g:Int32", "@value": 1},{"@type": "g:Int32", "@value": 2}]}} assert result == json.loads(self.graphson_writer.writeObject(P.within([1, 2]))) assert result == json.loads(self.graphson_writer.writeObject(P.within(1, 2))) result = {'@type': 'g:P', '@value': {'predicate':'within','value': [{"@type": "g:Int32", "@value": 1}]}} assert result == json.loads(self.graphson_writer.writeObject(P.within([1]))) assert result == json.loads(self.graphson_writer.writeObject(P.within(1)))
def query_users_active_in_n_days(g, n=30, today=datetime(2016, 6, 22, 23, 59), limit=1000): """Get users that were active in last 30 days.""" dt_condition = [has("ts", P.gt(today - timedelta(days=n)))] return query_users_active_in_given_date_intervals(g, dt_condition, limit)
def create_train_set(self, filename, username, quiet=False): repo_ids = self.g.V().has( TIME_PROCESSED, P.gt(0.0)).hasLabel(REPOSITORY).id().toList() print(f"{len(repo_ids)} ids downloaded...") for repo_id in tqdm(repo_ids, total=len(repo_ids), unit='repository', disable=quiet): self._create_repository_row(repo_id) self._save(filename, username)
def query_transient_nodes_for_website(g, website_id, limit=10000): return (g.V(website_id).in_("visited").limit(limit).project( "uid", "pid" ).by("uid").by(in_("has_identity").values("pid").fold()).group().by( coalesce( select("pid").unfold(), constant("transient-nodes-connected-to-website"))).by( select("uid").dedup().limit(100).fold()).unfold().project( "persistent-node-id", "transient-nodes").by( select(Column.keys)).by(select(Column.values)).where( select("transient-nodes").unfold().count().is_( P.gt(1)))).toList()
def test_bytecode(self): g = traversal().withGraph(Graph()) bytecode = g.V().out("created").bytecode assert 0 == len(bytecode.bindings.keys()) assert 0 == len(bytecode.source_instructions) assert 2 == len(bytecode.step_instructions) assert "V" == bytecode.step_instructions[0][0] assert "out" == bytecode.step_instructions[1][0] assert "created" == bytecode.step_instructions[1][1] assert 1 == len(bytecode.step_instructions[0]) assert 2 == len(bytecode.step_instructions[1]) ## bytecode = g.withSack(1).E().groupCount().by("weight").bytecode assert 0 == len(bytecode.bindings.keys()) assert 1 == len(bytecode.source_instructions) assert "withSack" == bytecode.source_instructions[0][0] assert 1 == bytecode.source_instructions[0][1] assert 3 == len(bytecode.step_instructions) assert "E" == bytecode.step_instructions[0][0] assert "groupCount" == bytecode.step_instructions[1][0] assert "by" == bytecode.step_instructions[2][0] assert "weight" == bytecode.step_instructions[2][1] assert 1 == len(bytecode.step_instructions[0]) assert 1 == len(bytecode.step_instructions[1]) assert 2 == len(bytecode.step_instructions[2]) ## bytecode = g.V(Bindings.of('a', [1, 2, 3])) \ .out(Bindings.of('b', 'created')) \ .where(__.in_(Bindings.of('c', 'created'), Bindings.of('d', 'knows')) \ .count().is_(Bindings.of('e', P.gt(2)))).bytecode assert 5 == len(bytecode.bindings.keys()) assert [1, 2, 3] == bytecode.bindings['a'] assert 'created' == bytecode.bindings['b'] assert 'created' == bytecode.bindings['c'] assert 'knows' == bytecode.bindings['d'] assert P.gt(2) == bytecode.bindings['e'] assert Binding('b', 'created') == bytecode.step_instructions[1][1] assert 'binding[b=created]' == str(bytecode.step_instructions[1][1]) assert isinstance(hash(bytecode.step_instructions[1][1]), int)
def test_bytecode(self): g = Graph().traversal() bytecode = g.V().out("created").bytecode assert 0 == len(bytecode.bindings.keys()) assert 0 == len(bytecode.source_instructions) assert 2 == len(bytecode.step_instructions) assert "V" == bytecode.step_instructions[0][0] assert "out" == bytecode.step_instructions[1][0] assert "created" == bytecode.step_instructions[1][1] assert 1 == len(bytecode.step_instructions[0]) assert 2 == len(bytecode.step_instructions[1]) ## bytecode = g.withSack(1).E().groupCount().by("weight").bytecode assert 0 == len(bytecode.bindings.keys()) assert 1 == len(bytecode.source_instructions) assert "withSack" == bytecode.source_instructions[0][0] assert 1 == bytecode.source_instructions[0][1] assert 3 == len(bytecode.step_instructions) assert "E" == bytecode.step_instructions[0][0] assert "groupCount" == bytecode.step_instructions[1][0] assert "by" == bytecode.step_instructions[2][0] assert "weight" == bytecode.step_instructions[2][1] assert 1 == len(bytecode.step_instructions[0]) assert 1 == len(bytecode.step_instructions[1]) assert 2 == len(bytecode.step_instructions[2]) ## bytecode = g.V(Bindings.of('a', [1,2,3])) \ .out(Bindings.of('b','created')) \ .where(__.in_(Bindings.of('c','created'), Bindings.of('d','knows')) \ .count().is_(Bindings.of('e',P.gt(2)))).bytecode assert 5 == len(bytecode.bindings.keys()) assert [1,2,3] == bytecode.bindings['a'] assert 'created' == bytecode.bindings['b'] assert 'created' == bytecode.bindings['c'] assert 'knows' == bytecode.bindings['d'] assert P.gt(2) == bytecode.bindings['e'] assert Binding('b','created') == bytecode.step_instructions[1][1] assert 'binding[b=created]' == str(bytecode.step_instructions[1][1]) assert isinstance(hash(bytecode.step_instructions[1][1]),int)
def undecided_users_audience(g, website_url, thank_you_page_url, since, min_visited_count): """ Given website url, get all the users that meet audience conditions. It returns list of transient identities uids. Audience is build from the users that met following criteria: * visited some website url at least X times since specific timestamp * did not visit thank you page url since specific timestamp """ return (g.V(website_url).hasLabel("website").inE("visited").has( "ts", P.gt(since)).outV().in_("has_identity").groupCount().unfold( ).dedup().where(select(Column.values).is_( P.gt(min_visited_count))).select(Column.keys).as_("pids").map( out("has_identity").outE("visited").has( "visited_url", thank_you_page_url).has("ts", P.gt(since)).outV().in_( "has_identity").dedup().values("pid").fold()).as_( "pids_that_visited").select("pids").not_( has("pid", where(P.within("pids_that_visited")))).out( "has_identity").values("uid"))
async def get_locality_traversal( session, vertex_id, vertex_label=None, limit=200, offset=0, countries=None, formats=None, formats_op="or", genres=None, labels=None, main_releases_only=True, roles=None, styles=None, styles_op="or", years=None, ): traversal = session.g.V(vertex_id) if vertex_label: traversal = session.g.V().has(vertex_label, f"{vertex_label}_id", vertex_id) traversal = traversal.aggregate("center") traversal = (traversal.aggregate("vertices").repeat( get_locality_loop_traversal( countries=countries, formats=formats, formats_op=formats_op, genres=genres, labels=labels, main_releases_only=main_releases_only, offset=offset, roles=roles, styles=styles, styles_op=styles_op, years=years, ), ).until( __.or_( __.cap("edges").unfold().count().is_(P.gt(limit)), __.loops().is_(10), )).cap("edges").unfold().limit(limit).aggregate("filteredEdges"). bothV().aggregate("vertices").barrier(0).inject(1).union( get_locality_edge_projection(), get_locality_vertex_projection(), get_locality_center_projection(), )) return await traversal.toList()
def recommend_similar_audience(g, website_url, categories_limit=3, search_time_limit_in_seconds=15): """Given website url, categories_limit, categories_coin recommend similar audience in n most popular categories. Similar audience - audience of users that at least once visited subpage of domain that contains IAB-category codes that are most popular across users of given website """ average_guy = (g.V(website_url).in_("visited").in_( "has_identity").dedup().hasLabel("persistentId").group().by().by( out("has_identity").out("visited").in_("links_to").groupCount().by( "categoryCode")).select( Column.values).unfold().unfold().group().by( Column.keys).by(select( Column.values).mean()).unfold().order().by( Column.values, Order.desc).limit(categories_limit)) most_popular_categories = dict( chain(*category.items()) for category in average_guy.toList()) guy_stats_subquery = (out("has_identity").out("visited").in_( "links_to").groupCount().by("categoryCode").project( *most_popular_categories.keys())) conditions_subqueries = [] for i in most_popular_categories: guy_stats_subquery = guy_stats_subquery.by( choose(select(i), select(i), constant(0))) conditions_subqueries.append( select(Column.values).unfold().select(i).is_( P.gt(int(most_popular_categories[i])))) return (g.V().hasLabel("websiteGroup").has( "categoryCode", P.within(list( most_popular_categories.keys()))).out("links_to").in_("visited"). dedup().in_("has_identity").dedup().hasLabel("persistentId").where( out("has_identity").out("visited").has( "url", P.neq(website_url))).timeLimit( search_time_limit_in_seconds * 1000).local( group().by().by(guy_stats_subquery).where( or_(*conditions_subqueries))).select( Column.keys).unfold().out( "has_identity").values("uid"))
def func(g): from gremlin_python.process.traversal import Order from gremlin_python.process.traversal import P assert g.V().has("name", "marko").count().toList()[0] == 1 assert g.V().has("person", "name", "marko").count().toList()[0] == 1 assert (g.V().has("person", "name", "marko").outE("created").count().toList()[0] == 1) assert (g.V().has( "person", "name", "marko").outE("created").inV().count().toList()[0] == 1) assert (g.V().has("person", "name", "marko").out("created").count().toList()[0] == 1) assert (g.V().has( "person", "name", "marko").out("created").values("name").count().toList()[0] == 1) assert (g.V().hasLabel("person").has("age", P.gt(30)).order().by( "age", Order.desc).count().toList()[0] == 2)
def test_P(self): result = {'@type': 'g:P', '@value': { 'predicate': 'and', 'value': [{ '@type': 'g:P', '@value': { 'predicate': 'or', 'value': [{ '@type': 'g:P', '@value': {'predicate': 'lt', 'value': 'b'} }, {'@type': 'g:P', '@value': {'predicate': 'gt', 'value': 'c'}} ] } }, {'@type': 'g:P', '@value': {'predicate': 'neq', 'value': 'd'}}]}} assert result == json.loads( self.graphson_writer.writeObject(P.lt("b").or_(P.gt("c")).and_(P.neq("d"))))
def test_traversal_modern_graph(gs_session, modern_graph_data_dir): from gremlin_python.process.traversal import Order from gremlin_python.process.traversal import P gs_image, gie_manager_image = get_gs_image_on_ci_env() graph = load_modern_graph(gs_session, modern_graph_data_dir) interactive = gs_session.gremlin(graph) g = interactive.traversal_source() assert g.V().has("name", "marko").count().toList()[0] == 1 assert g.V().has("person", "name", "marko").count().toList()[0] == 1 assert g.V().has("person", "name", "marko").outE("created").count().toList()[0] == 1 assert (g.V().has("person", "name", "marko").outE("created").inV().count().toList()[0] == 1) assert g.V().has("person", "name", "marko").out("created").count().toList()[0] == 1 assert (g.V().has( "person", "name", "marko").out("created").values("name").count().toList()[0] == 1) assert (g.V().hasLabel("person").has("age", P.gt(30)).order().by( "age", Order.desc).count().toList()[0] == 2)
def handler(event, context): graph = Graph() g = graph.traversal().withRemote( DriverRemoteConnection(myNeptuneEndpoint, "g")) toReturn = g.V().hasLabel("book").where(inE("purchased").count().is_(P.gt(0))).project("bookId","purchases","friendsPurchased") \ .by(id()).by(inE("purchased").count()).by(in_().id().fold()).order().by(select("purchases"),Order.decr).limit(5).toList() response = { "statusCode": 200, "headers": { "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Credentials": True }, "body": json.dumps(toReturn) } print(response) return response
r4 = g.V(c2).addE('ORDERS').to(p2).\ property('date',"2015-11-03").\ property('quantity',1).next() #Add edges for customers rating products r5 = g.V(c1).addE('RATES').to(p1).\ property('rating',4.8).next() r6 = g.V(c2).addE('RATES').to(p2).\ property('rating',4.5).next() #Print list of all vertices print(g.V().toList()) #Print list of all customers print(g.V().hasLabel('CUSTOMER').toList()) print(g.V().hasLabel('CUSTOMER').name.toList()) #Print list of all products print(g.V().hasLabel('PRODUCT').toList()) print(g.V().hasLabel('PRODUCT').title.toList()) #Print list of all customers from the country Greece print(g.V().hasLabel('CUSTOMER').\ has('country','Greece').toList()) #Print list of all products with price greater than 100 print(g.V().hasLabel('PRODUCT').\ has('price',P.gt(100)).\ order().by('price',Order.decr).toList())
def make_track_extras_traversal(): return __.choose( __.inE("relationship").has("name", "Includes").count().is_(P.gt(0)), __.inE("relationship").has("name", "Includes").otherV().valueMap(), __.constant(False), )
# -*- coding: utf-8 -*- """TinkerTop and Gremlin in a container """ from gremlin_python import statics from gremlin_python.process.anonymous_traversal import traversal from gremlin_python.process.graph_traversal import __ from gremlin_python.process.strategies import * from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection from gremlin_python.process.traversal import T from gremlin_python.process.traversal import Order from gremlin_python.process.traversal import Cardinality from gremlin_python.process.traversal import Column from gremlin_python.process.traversal import Direction from gremlin_python.process.traversal import Operator from gremlin_python.process.traversal import P from gremlin_python.process.traversal import Pop from gremlin_python.process.traversal import Scope from gremlin_python.process.traversal import Barrier from gremlin_python.process.traversal import Bindings from gremlin_python.process.traversal import WithOptions if __name__ == '__main__': g = traversal().withRemote( DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')) Ga = g.V().hasLabel('person').has('age', P.gt(30)).order().by( 'age', Order.desc).toList() print('\ndone')
def _create_main_dataframe(self): repo_id = self.g.V().has(TIME_PROCESSED, P.gt(0.0)).hasLabel(REPOSITORY).id().next() return pd.DataFrame( columns=self.g.V(repo_id).properties().label().toList())
def test_traversals(self, remote_connection): statics.load_statics(globals()) g = traversal().withRemote(remote_connection) assert long(6) == g.V().count().toList()[0] # # assert Vertex(1) == g.V(1).next() assert Vertex(1) == g.V(Vertex(1)).next() assert 1 == g.V(1).id_().next() assert Traverser(Vertex(1)) == g.V(1).nextTraverser() assert 1 == len(g.V(1).toList()) assert isinstance(g.V(1).toList(), list) results = g.V().repeat(__.out()).times(2).name results = results.toList() assert 2 == len(results) assert "lop" in results assert "ripple" in results # # assert 10 == g.V().repeat(__.both()).times(5)[0:10].count().next() assert 1 == g.V().repeat(__.both()).times(5)[0:1].count().next() assert 0 == g.V().repeat(__.both()).times(5)[0:0].count().next() assert 4 == g.V()[2:].count().next() assert 2 == g.V()[:2].count().next() # # results = g.withSideEffect( 'a', ['josh', 'peter' ]).V(1).out('created').in_('created').values('name').where( P.within('a')).toList() assert 2 == len(results) assert 'josh' in results assert 'peter' in results # # results = g.V().out().profile().toList() assert 1 == len(results) assert 'metrics' in results[0] assert 'dur' in results[0] # # results = g.V().has('name', 'peter').as_('a').out('created').as_('b').select( 'a', 'b').by(__.valueMap()).toList() assert 1 == len(results) assert 'peter' == results[0]['a']['name'][0] assert 35 == results[0]['a']['age'][0] assert 'lop' == results[0]['b']['name'][0] assert 'java' == results[0]['b']['lang'][0] assert 2 == len(results[0]['a']) assert 2 == len(results[0]['b']) # # results = g.V(1).inject(g.V(2).next()).values('name').toList() assert 2 == len(results) assert 'marko' in results assert 'vadas' in results # # results = g.V().has('person', 'name', 'marko').map( lambda: ("it.get().value('name')", "gremlin-groovy")).toList() assert 1 == len(results) assert 'marko' in results # # # this test just validates that the underscored versions of steps conflicting with Gremlin work # properly and can be removed when the old steps are removed - TINKERPOP-2272 results = g.V().filter_( __.values('age').sum_().and_(__.max_().is_(P.gt(0)), __.min_().is_(P.gt(0)))).range_( 0, 1).id_().next() assert 1 == results # # # test binding in P results = g.V().has('person', 'age', Bindings.of('x', P.lt(30))).count().next() assert 2 == results # # # test dict keys which can only work on GraphBinary and GraphSON3 which include specific serialization # types for dict if not isinstance(remote_connection._client._message_serializer, GraphSONSerializersV2d0): results = g.V().has( 'person', 'name', 'marko').elementMap("name").groupCount().next() assert { HashableDict.of({ T.id: 1, T.label: 'person', 'name': 'marko' }): 1 } == results if not isinstance(remote_connection._client._message_serializer, GraphSONSerializersV2d0): results = g.V().has('person', 'name', 'marko').both('knows').groupCount().by( __.values('name').fold()).next() assert {tuple(['vadas']): 1, tuple(['josh']): 1} == results
def test_P(self): assert """{"@type":"g:P","@value":{"predicate":"and","value":[{"@type":"g:P","@value":{"predicate":"or","value":[{"@type":"g:P","@value":{"predicate":"lt","value":"b"}},{"@type":"g:P","@value":{"predicate":"gt","value":"c"}}]}},{"@type":"g:P","@value":{"predicate":"neq","value":"d"}}]}}""" == self.graphson_writer.writeObject( P.lt("b").or_(P.gt("c")).and_(P.neq("d")))
def test_P(self): assert """{"@type":"g:P","@value":{"predicate":"and","value":[{"@type":"g:P","@value":{"predicate":"or","value":[{"@type":"g:P","@value":{"predicate":"lt","value":"b"}},{"@type":"g:P","@value":{"predicate":"gt","value":"c"}}]}},{"@type":"g:P","@value":{"predicate":"neq","value":"d"}}]}}""" == self.graphson_writer.writeObject( P.lt("b").or_(P.gt("c")).and_(P.neq("d")))
print(g.V().has('name', 'marko').out('knows').count().next()) print('\n') print("What are the names of the people that Marko knows?") print( "Using Marko node, out-going edge 'knows', in to the Vertices, get the name property ans list" ) print(g.V(1).outE('knows').inV().values('name').toList()) print('\n') print("Same as above with a slightly different syntax") print(g.V(1).out('knows').values('name').toList()) print('\n') print("Who does Marko know that is older than 30") print(g.V(1).out('knows').has('age', P.gt(30)).values('name').toList()) print('\n') print("list the people that are older than 30 from olders to youngest") print(g.V().hasLabel('person').has('age', P.gt(30)).order().by( 'age', Order.decr).values('name').toList()) # By importing the statics of Gremlin-Python, the class prefixes can be omitted. # for example P.gt because gt and Order.decr becomes decr, but the IDE has no idea and flags # them as an error - but it will execute. statics.load_statics(globals()) print('\n') print("Same as above but after loading static globals for better syntax") print(g.V().hasLabel('person').has('age', gt(30)).order().by( 'age', decr).values('name').toList())
def test_P(self): # verify that the order of operations is respected assert "and(eq(a),lt(b))" == str(P.eq("a").and_(P.lt("b"))) assert "and(or(lt(b),gt(c)),neq(d))" == str(P.lt("b").or_(P.gt("c")).and_(P.neq("d"))) assert "and(or(lt(b),gt(c)),or(neq(d),gte(e)))" == str( P.lt("b").or_(P.gt("c")).and_(P.neq("d").or_(P.gte("e"))))