Skip to content

Instantly share code, notes, and snippets.

@toraritte
Last active September 7, 2017 22:56
Show Gist options
  • Select an option

  • Save toraritte/e038966c2693758d05f1b50a8d065e15 to your computer and use it in GitHub Desktop.

Select an option

Save toraritte/e038966c2693758d05f1b50a8d065e15 to your computer and use it in GitHub Desktop.
proof of concept using events as edges with properties
create
(:Timeline)-[:YEAR]->(y:Year {value: 2017})-[:MONTH]->(m9:Month {value: "9"})-[:DAY]->(:Day {value: "12"})-[:EVENT {description: "Called"}]->(sftb:Org {name: "SFTB"}),
(m9)-[:DAY]->(:Day {value: "19"})-[:EVENT {description: "Intake"}]->(:Education {name: "vmi"})-[:ORG]->(sftb),
(y)-[:MONTH]->(m10:Month {value: "10"})-[:DAY]->(:Day {value: "12"})-[:EVENT {description: "Started learning stuff"}]->(sftb),
(m10)-[:DAY]->(:Day {value: "19"})-[:EVENT {description: "donated $2"}]->(sftb);
match (:Timeline)-[]->(year),p=(year)-[*2]->()-[r:EVENT]->()
with p as event_paths, r as events
return nodes(event_paths), events;
// or
match (:Timeline)-[]->(year),
match p=(year)-[*2]->()-[r:EVENT]->()
with p as event_paths, r as events
return nodes(event_paths), events;
// continue this thought experiment tomorrow with a generic contact
// and one of our clients using the same terminology
// NOTE: for the sake of easier queries, it might easier to deal with
// an "event" node rather implementing it as an edge...
// modify to extract properties from path elements
MATCH path=(:P {name: 'A'})-[*]-(:N)
WITH filter(n in nodes(path) where not n:P) as p
UNWIND nodes(p) AS node
UNWIND extract(k in keys(node) | node[k]) AS node_value
RETURN reduce(acc="",s in collect(toString(node_value)) | acc + s);
//RETURN reduce(acc="", n in nodes(p) | acc + );
//IDEA the "reduce"-way will never really work, so why not encode a
// separator attribute into the nodes/edges themselves? dirty hack
// from here
match (:Timeline)-[]->(year),p=(year)-[*2]->()-[r:EVENT]->()
with p as event_paths, r as events
return event_paths;
╒══════════════════════════════════════════════════════════════════════╕
│"event_paths" │
╞══════════════════════════════════════════════════════════════════════╡
│[{"value":2017},{},{"value":"9"},{"value":"9"},{},{"value":"12"},{"val│
│ue":"12"},{"description":"Called"},{"name":"SFTB"}] │
├──────────────────────────────────────────────────────────────────────┤
│[{"value":2017},{},{"value":"9"},{"value":"9"},{},{"value":"19"},{"val│
│ue":"19"},{"description":"Intake"},{"name":"vmi"}] │
├──────────────────────────────────────────────────────────────────────┤
│[{"value":2017},{},{"value":"10"},{"value":"10"},{},{"value":"19"},{"v│
│alue":"19"},{"description":"donated $2"},{"name":"SFTB"}] │
├──────────────────────────────────────────────────────────────────────┤
│[{"value":2017},{},{"value":"10"},{"value":"10"},{},{"value":"12"},{"v│
│alue":"12"},{"description":"Started learning stuff"},{"name":"SFTB"}] │
└──────────────────────────────────────────────────────────────────────┘
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment