Skip to content

Instantly share code, notes, and snippets.

View halftermeyer's full-sized avatar

Pierre Halftermeyer halftermeyer

View GitHub Profile
@halftermeyer
halftermeyer / query_v5.cypher
Last active September 22, 2023 20:23
cypher v5.9+ fraud detection query
// Anchoring the following QPP to a first transaction
MATCH (a:Account)<-[f:FROM]-(first_tx:Transaction)
// matching a Neo4j 5.9+ QPP with + cardinality (1 or more)
MATCH path=(a)<-[f]-(first_tx)
(
(tx_i:Transaction)-[:TO]->(a_i:Account)<-[:FROM]-(tx_j:Transaction)
// inner-qpp locally-defined rules filtering
WHERE tx_i.date < tx_j.date
AND tx_i.amount >= tx_j.amount >= 0.80 * tx_i.amount
@halftermeyer
halftermeyer / query_v4.cypher
Last active September 20, 2023 14:14
Cypher pre-v5 fraud ring detection query
// Produce any 2-to-6-hop-long path
MATCH path=(a:Account)-[rel:TRANSACTION*2..6]->(a)
// Then filter to keep only
// - non-node-repeating paths (using some APOC magic)
WHERE size(apoc.coll.toSet(nodes(path))) = size(nodes(path)) - 1
// - and, at each step…
AND ALL(idx in range(0, size(rel)-2)
// … date-consistent
WHERE (rel[idx]).date < (rel[idx+1]).date
// … and 20%-rule compliant paths