Visual Pattern Examples

You have learnt all the basic concepts of the Visual Query Builder in the previous article. In this article we will walk you through building several visual patterns step by step, and then show you more graph analytics questions and how to solve them with visual patterns.‌

Example 1. Find all the departments with male employees

Click add pattern btnin the pattern list pattern, input the pattern name, and click add btn:

assets  lhvjxin4  6ba0t qmu  lvvuteg9eqbxemig3sx  lvvvsnl5eksscgabgze demo 2 name

Clickadd vertex typein the toolbar to add a vertex pattern:

assets  lhvjxin4  6ba0t qmu  lvvuteg9eqbxemig3sx  lvvxrsv4oqboqfdo5rn add 1st vertex pattern

In the config panel, change the vertex type to be department, and put it in result:

edit vertex pattern

Confirm the change by clickconfirm:

assets  lhvjxin4  6ba0t qmu  lvvuteg9eqbxemig3sx  lvvxyennhcuze3pjgew changed to department

Clickadd vertex typein the toolbar to add another vertex pattern:

assets  lhvjxin4  6ba0t qmu  lvvuteg9eqbxemig3sx  lvvyo9rsvkzoxl5ti45 2nd vertex pattern

Expand the Filter section in the config panel:

open filter

Clickadd buttonto add a filter:

add filter

Edit the filter to be (gender == "male"):

edit filter

Confirm the change:

assets  lhvjxin4  6ba0t qmu  lvvuteg9eqbxemig3sx  lvvaran9ybyvmp5ddmo apply filter

Clickadd edge typein the toolbar, then click the person vertex pattern in the working panel:

click person vp

Then click department vertex pattern in the working panel to create an edge pattern between the two vertex patterns:

assets  lhvjxin4  6ba0t qmu  lvvuteg9eqbxemig3sx  lvwcirpqnzwxjjmibcm click dep vp

In the config panel, change the edge type to be work_in:

edit etype

Apply the change, and drag the person vertex pattern to a better position:

assets  lhvjxin4  6ba0t qmu  lvvuteg9eqbxemig3sx  lvwcxjavy9gzmh4fyzv apply etype change

Click image in the toolbar to save the pattern, and click image in the toolbar to run the pattern:assets_-lhvjxin4__6ba0t-qmu_-lvvuteg9eqbxemig3sx_-lvwdbsyr4slvpf3q_x3_run-pattern.png[image]

You can also try to output the entire matched subgraphs. Click image in the toolbar to enter output toggle mode, then click the person vertex pattern and the work_in edge pattern:

image

Click image in the toolbar again to exit output toggle mode, then click image to run the pattern:

image

Example 2. Find all such people A, B, C: A and B are friends, A and C are friends, and B manages C.

Create a new visual pattern named FriendsManagerABC.

Click image in the console panel to switch to graph schema:

image

Click image in the toolbar, then click the friend edge type in the graph schema:

image

An edge pattern is added into the working panel:

image

Similarly, use image to add another friend edge pattern and a manage edge pattern into the working panel:

image

Adjust the vertex patterns' positions:

image

Hold Shift key and choose the two vertex patterns on the left, then click image in the toolbar to merge them together:

image

Then, merge the top two vertex patterns:

image

Then, merge the right two vertex patterns:

image

Now you have a triangle visual pattern representing the three people relationship!

image

Now, click image in the toolbar and put all the vertex patterns and edge patterns into result:

image

Click image again to exit output toggle mode, click image to save the pattern, and click image to run the pattern:

image

Example 3. Find the top 2 cities where the most number of companies of an industry are located in.

Create a new visual pattern named IndustryCenterCity. Click image in the console panel to switch to graph schema.

Use image in the toolbar to pick the company_locate_at edge type and belong_to edge type in graph schema:

image

Use Shift key to select the two company vertex patterns, and click image to merge them into one. Drag the vertex patterns to make their positions look good:

image

Click the industry vertex pattern, then click image in the toolbar (or double click the industry vertex pattern), now you are in edit mode:

image

Change the vertices to be from parameter, and give a parameter name ind. This annotates the industry as an input vertex set when running the pattern:

image

Confirm the change, and notice there is an id condition on the industry vertex pattern:

image

Click the company vertex pattern, then click image in the toolbar, and change the Name to C:

image

Confirm the change, and the label of company vertex pattern becomes company as C:

image

Click the city vertex pattern, then click image in the toolbar:

image

Expand the Aggregation section in the config panel, and add an aggregation:

image

Confirm the change:

image

Expand the Order section in the config panel, and add a descending order of aggregation result countCompany:

image

Confirm the change:

image

Expand the Limit section in the config panel, check the use limit checkbox, and change limit to 2:

image

Confirm the change:

image

Click image , then click the city vertex pattern, then click image again to exit output toggle mode, click image to save the pattern:

Click image . Because the pattern has one input parameter ind, the Pattern parameters section in the pattern list panel expands:

image

Click image to add one industry vertex, and input "big data" for vertex id, then click image :

image

Change the industry vertex id to be "internet", and run the pattern again:

image

Again, you can choose to output everything in the matched subgraphs:

image

Example 4. Find the people who either were born in Redwood City or attended Stanford university, but didn’t work for Hooli.

Expand Graph patterns section in the pattern list panel, then create a new visual pattern named SearchPeople. Create the following visual pattern following similar steps as above:

image

Click image in the toolbar, and choose Union:

image

Click the left two person vertex patterns respectively to add the union widget:

image

Click​imagein the toolbar, and choose Subtract:

image

Click the output person vertex pattern of the union widget, then click the right person vertex pattern, a subtract widget is added into the visual pattern:

image

Put the output person vertex pattern of the subtract widget into result:

image

Save and run the pattern:

image

Example 5. Find all the people that were born in a city with population no more than 100,000, worked for Graphlet, and have research skill.

A snowflake-like visual pattern is commonly used in this type of searching problems:

image

Example 6. Giving a person P, among all his direct friends and friends' friends who have programming skill, what are the top 5 other skills that most of these people have?

First, we get the friends and friends' friends of P. We use the programming skill to filter these friends, then we find the other skills that these people have. Then we count the number of people having these skills, and choose the top 5 skills as the result.

image