-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5_GraphRefactor.cql
More file actions
56 lines (40 loc) · 1.35 KB
/
5_GraphRefactor.cql
File metadata and controls
56 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// GRAPH REFACORING EXAMPLES:
// Spill FailureType - refactor property to Node
// lets say we want to convert a property to a node:
MATCH (s:Spill)
where s.FailureType <> ''
CALL apoc.create.uuids(1) YIELD uuid as Uuid
MERGE (f:FailureType {Name:s.FailureType})
ON CREATE
set
f.Uuid = Uuid
MERGE (s)-[:HasFailureType]->(f)
REMOVE s.FailureType;
// TOO MANY IsInField->Spill links
// Refactor Field Center out of Fields
MATCH (f:Field)
where f.FieldCenter <> ''
CALL apoc.create.uuids(1) YIELD uuid as Uuid
MERGE (fc:FieldCenter:Card {Name:f.FieldCenter})
ON CREATE
set
f.Uuid = Uuid
MERGE (f)-[:IsCenteredIn]->(fc)
REMOVE f.FieldCenter;
// remap relationship with spill:
MATCH (s:Spill)-[d:IsInField]->(f:Field)
MATCH (fc:FieldCenter) where fc.Name=f.Name
MERGE (s)-[:IsInFieldCenter]->(fc);
// now delete the spill-Field relationship
MATCH (s:Spill)-[d:IsInField]->(f:Field)
DELETE d
// --- fuzzy name matching
// add phoneme string to spill node
match (s:Spill) with s limit 1
CALL apoc.text.phonetic(s.LicenseeName) YIELD value as phoneme WITH phoneme, s set s.PhonemeKey=phoneme return s
match (li:Licensee) with li limit 1
CALL apoc.text.phonetic(li.FullName) YIELD value as phoneme WITH phoneme, s set s.PhonemeKey=phoneme return li
// match up Facility and SPill based on LSD
MATCH (f:Facility)
MATCH (s:Spill)
Where f.LSD = s.LSD return f,s limit 100