CREATE QUERY CompanyHolders(vertex<Company> company, uint step) FOR GRAPH EnterpriseGraph syntax v2 {
/**
* CompanyHolders query finds all key investors of a company within several steps.
* --- Dataset has been shrunk on Nov.20th,2020 ---
* Some interesting input parameters you can try:
* 1. company: Hospice Mocha Frame, step: 5
* 2. company: Psychoanalyst Purse Prior, step: 4
* 3. company: Hospice Loyalty Decongestant, step: 2
* 4. company: Discipline Base Perfume, step 1
* 5. company: Discipline Base Perfume, step 2
* 6. company: Discipline Base Perfume, step 3
* 7. company: Discipline Base Perfume, step 4
*/
// @visited is used to mark visited vertices
OrAccum @visited = false;
// @@edges is used to hold all touched edges
SetAccum<edge> @@edges;
int loopStep;
// limit the maximum traverse steps
IF (step > 8) THEN
loopStep = 8;
ELSE
loopStep = step;
END;
// Start from the input company
StartSet (any) = { company };
// VertexResults contains all vertices we touched during traversal
VertexResult = StartSet;
// Mark input company as visited
StartSet = SELECT s
FROM StartSet:s
ACCUM s.@visited = true;
// Traverse multiple steps
WHILE (true) LIMIT loopStep DO
// Find the investors (either people or companies) that is a key investor (control_type == "holding")
StartSet = SELECT tgt
FROM StartSet
-((PersonInvestCompany | <CompanyInvestCompany): e)-
(Person | Company): tgt
WHERE (e.control_type == "holding") AND tgt.@visited == FALSE
ACCUM @@edges += e
POST-ACCUM tgt.@visited = TRUE
;
// Merge touched vertices into the result
VertexResult = VertexResult union StartSet;
END;
// Print result as a graph
PRINT VertexResult;
PRINT @@edges;
}
CREATE QUERY KeyRelationship(vertex<Company> company, int step) FOR GRAPH EnterpriseGraph syntax v2 {
/**
* KeyRelationship query finds all key investors or leaders (CEO, VP, Director) of a company within several steps.
* --- Dataset has been shrunk on Nov.20th,2020 ---
* Some interesting input parameters you can try:
* 1. company: Hospice Mocha Frame, step: 5
* 2. company: Psychoanalyst Purse Prior, step: 4
* 3. company: Hospice Loyalty Decongestant, step: 2
* 4. company: Discipline Base Perfume, step 1
* 5. company: Discipline Base Perfume, step 2
* 6. company: Discipline Base Perfume, step 3
* 7. company: Discipline Base Perfume, step 4
*/
OrAccum @visited = false;
SetAccum<edge> @@edges;
int loopStep;
// limit the maximum traverse steps
IF (step > 8) THEN
loopStep = 8;
ELSE
loopStep = step;
END;
StartSet (any) = { company };
VertexResult = StartSet;
StartSet = SELECT s
FROM StartSet:s
ACCUM s.@visited = true;
WHILE (true) LIMIT loopStep DO
StartSet = SELECT tgt
FROM StartSet
-((WorkFor | PersonInvestCompany | reverse_CompanyInvestCompany>) : e)-
(Person | Company): tgt
WHERE (
(
e.type == "WorkFor"
AND
(e.title == "Director" OR e.title == "CEO" OR e.title == "Vice President")
)
OR
e.control_type == "holding"
)
AND
tgt.@visited == FALSE
ACCUM @@edges += e
POST-ACCUM tgt.@visited = TRUE
;
VertexResult = VertexResult union StartSet;
END;
PRINT VertexResult;
PRINT @@edges;
}
CREATE QUERY peopleWithKeyPositionsInAtLeastTwoCompanies() FOR GRAPH EnterpriseGraph API("v2") SYNTAX v2 {
/**
Find all the people who are a CEO, Director or Vice President in at least two different companies
*/
SetAccum<edge> @@FinalEdgeSet_4;
SetAccum<edge> @@FinalEdgeSet_5;
SetAccum<vertex<Company>> @@FinalVertexSet_1;
SetAccum<vertex<Person>> @@FinalVertexSet_2;
SetAccum<vertex<Company>> @@FinalVertexSet_3;
VertexSet_1 =
SELECT c2
FROM Person:alias_schema_2 -(WorkFor:alias_schema_4)- Company:c2,
Person:alias_schema_2 -(WorkFor:alias_schema_5)- Company:c1
WHERE (c2 != c1) AND
((alias_schema_4.title == "CEO") OR ((alias_schema_4.title == "Director") OR (alias_schema_4.title == "Vice President"))) AND
((alias_schema_5.title == "CEO") OR ((alias_schema_5.title == "Director") OR (alias_schema_5.title == "Vice President")))
ACCUM @@FinalEdgeSet_4 += alias_schema_4,
@@FinalEdgeSet_5 += alias_schema_5
POST-ACCUM @@FinalVertexSet_1 += c2
POST-ACCUM @@FinalVertexSet_2 += alias_schema_2
POST-ACCUM @@FinalVertexSet_3 += c1
;
PRINT @@FinalEdgeSet_4;
PRINT @@FinalEdgeSet_5;
VertexSet_1 = { @@FinalVertexSet_1 };
PRINT VertexSet_1[
VertexSet_1.registered_capital AS registered_capital
];
VertexSet_2 = { @@FinalVertexSet_2 };
PRINT VertexSet_2[
VertexSet_2.gender AS gender
];
VertexSet_3 = { @@FinalVertexSet_3 };
PRINT VertexSet_3[
VertexSet_3.registered_capital AS registered_capital
];
}