def sample_describe_graph(): """this demonstrates use of cypher query and interpretation of result returned from the query""" rows, cols = db.cypher_query( "MATCH (t:TeamMember)-[p:PROFICIENCY_FOR]-(s:Skill) RETURN t, p, s") # cols {0: TeamMember, 1: Proficiency, 2: Skill} for r in rows: team_member = TeamMember.inflate(r[0]) proficiency = ProficiencyRel.inflate(r[1]) skill = Skill.inflate(r[2]) print( f"Team member {team_member.name} is proficient in skill {skill.name} with a score {proficiency.score} " f"in year {proficiency.year}\n")
def sample_queries(): """sample queries, using both techniques provided by neomodel and cypher query""" # use object graph mapping (OGM) to query for information print(f"Skill Python: {Skill.nodes.get_or_none(name='Python')}") print( f"Skill Java that doesn't exist: {Skill.nodes.get_or_none(name='Java')}" ) print("All team members name that starts with T:\n") team_members = TeamMember.nodes.filter(Q(first_name__startswith="T")) for n in team_members: print(f"\tTeam member: {n}\n") print( "All team members name that starts with T with proficiencies more than 3 in:\n" ) excellencies = team_members.skill.match(score__gt=4.0) for ex in excellencies: print(f"\t Skills: {ex}\n") # use cypher queries print("Current graph description:") sample_describe_graph() print( "The skills in which team member first name starting with T has score more than 3 in any year" ) rows, cols = db.cypher_query( "MATCH(t: TeamMember)-[p: PROFICIENCY_FOR]-(s:Skill) " "WHERE t.first_name STARTS WITH 'T' AND p.score > 3.0 " "RETURN DISTINCT (s)") # cols: {0: Skill} for r in rows: skill = Skill.inflate(r[0]) print(f"Skill name {skill.name}") print( "For each of the available skills, find out the list of team members who has proficiency in it\n" ) skills = Skill.nodes.all() for skill in skills: rows, cols = db.cypher_query( "MATCH (s:Skill)-[p:PROFICIENCY_FOR]-(t:TeamMember) " "WHERE s.name = $name RETURN DISTINCT (t)", params={"name": skill.name}) print(f"\nSkill name: {skill.name}") for r in rows: team_member = TeamMember.inflate(r[0]) # cols: {0: TeamMember} print(f"Team member name {team_member.name}") print("Queried sample queries ...")