forked from resource-watch/graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Endpoints.txt
96 lines (79 loc) · 3.78 KB
/
Endpoints.txt
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// 1. SEARCH endpoint (Explore)
// FILTER 1
MATCH (c:CONCEPT)<-[:TAGGED_WITH {application: 'appname'}]-(d:DATASET)
WHERE c.id IN ['water']
WITH COLLECT(d.id) AS datasets
OPTIONAL MATCH (c:CONCEPT)<-[:PART_OF|:IS_A|:QUALITY_OF*1..15]-(c2:CONCEPT)<-[:TAGGED_WITH {application: 'appname'}]-(d:DATASET)
WHERE (c.id IN ['water'])
WITH COLLECT(d.id) + datasets AS datasets
// FILTER 2
MATCH (c:CONCEPT)<-[:TAGGED_WITH {application: 'appname'}]-(d:DATASET)
WHERE c.id IN ['raster'] AND d.id IN datasets
WITH COLLECT(d.id) AS tempSet, datasets
OPTIONAL MATCH (c:CONCEPT)<-[:PART_OF|:IS_A|:QUALITY_OF*1..15]-(c2:CONCEPT)<-[:TAGGED_WITH {application: 'appname'}]-(d:DATASET)
WHERE (c.id IN ['raster']) AND d.id IN datasets
WITH COLLECT(d.id) + tempSet AS datasets
// FILTER 3
MATCH (c:CONCEPT)<-[:TAGGED_WITH {application: 'appname'}]-(d:DATASET)
WHERE c.id IN ['nitrogen'] AND d.id IN datasets
WITH COLLECT(d.id) AS tempSet, datasets
OPTIONAL MATCH (c:CONCEPT)<-[:PART_OF|:IS_A|:QUALITY_OF*1..15]-(c2:CONCEPT)<-[:TAGGED_WITH {application: 'appname'}]-(d:DATASET)
WHERE (c.id IN ['nitrogen']) AND d.id IN datasets
WITH COLLECT(d.id) + tempSet AS datasets
RETURN DISTINCT datasets
// 2. SIMILAR DATASETS
// GET SIMILAR DATASETS 1 (datasets tagged with at least one of the concepts related to the dataset provided)
MATCH p=(d:DATASET)-[:TAGGED_WITH {application: 'appname'}]->(c:TOPIC)<-[:TAGGED_WITH {application: 'appname'}]-(d2:DATASET)
WHERE d.id IN ['dataset_ids']
WITH length(COLLECT(c.id)) AS number_of_shared_concepts, COLLECT(c.id) AS shared_concepts, d2
RETURN d2.id, shared_concepts, number_of_shared_concepts
ORDER BY number_of_shared_concepts DESC
// 2. SIMILAR DATASETS Including descendants tags
// We're taking into account only topics
MATCH (d:DATASET)-[:TAGGED_WITH {application: 'appname'}]->(c:TOPIC)
WHERE d.id IN ['dataset_ids']
WITH COLLECT(c.id) AS main_tags, d
MATCH (d2:DATASET)-[:TAGGED_WITH {application: 'appname'}]->(c1:TOPIC)-[:PART_OF|:IS_A|:QUALITY_OF*1..15]->(c2:TOPIC)
WHERE (c1.id IN main_tags OR c2.id IN main_tags) AND d2.id <> d.id
WITH COLLECT(DISTINCT c1.id) AS dataset_tags, d2.id AS dataset
WITH size(dataset_tags) AS number_of_ocurrences, dataset_tags, dataset
RETURN dataset, dataset_tags, number_of_ocurrences
ORDER BY number_of_ocurrences DESC
// 3. GET LIST OF CONCEPTS
MATCH (c:CONCEPT)
WITH c
OPTIONAL MATCH (c)<-[:TAGGED_WITH {application: 'appname'}]-(d:DATASET)
WITH COLLECT(d.id) AS datasets, c, COUNT(d) as number_of_datasets_tagged
RETURN c.id, c.label, c.synonyms, labels(c) AS labels, number_of_datasets_tagged, datasets
ORDER BY number_of_datasets_tagged DESC
// 4. GET CONCEPTS INFERRED FROM LIST
MATCH (c:CONCEPT)-[:PART_OF|:IS_A|:QUALITY_OF*]->(c2:CONCEPT)
WHERE c.id IN ['xxxx', 'yyyy', 'zzzz']
WITH collect(DISTINCT c.id) + collect(DISTINCT c2.id) as results
MATCH (c:CONCEPT)
WHERE c.id IN results
RETURN c.id, c.label, c.synonyms, labels(c) as labels
// 5. DIRECT ANCESTORS OF SET OF CONCEPTS
MATCH (c:CONCEPT)-[:PART_OF|:IS_A|:QUALITY_OF]->(c2:CONCEPT)
WHERE c.id IN ['xxx', 'yyy']
WITH collect(DISTINCT c2.id) as results
MATCH (c:CONCEPT)
WHERE c.id IN results
RETURN c.id, c.label, c.synonyms, labels(c) as labels
// 6. MOST LIKED/FAVORITED DATASETS
MATCH (u:USER)-[:FAVOURITE {application: 'appname'}]->(d:DATASET)
RETURN d.id, COUNT(d) AS number_of_favorites
ORDER BY number_of_favorites DESC
// 7. MOST VIEWED DATASETS
MATCH (d:DATASET)
RETURN d.id, d.views
ORDER BY d.views DESC
// 8. MOST VIEWED DATASETS (per user)
MATCH (d:DATASET)<-[v:VIEWED {application: 'appname'}]-(u:USER {id: 'xxxx'})
RETURN d.id, v.views
ORDER BY v.views DESC
// 9. SEARCH BY LABEL-SYNONYMS
MATCH (d:DATASET)-[:TAGGED_WITH {application: 'appname'}]->(c:CONCEPT)
WHERE toLower(c.label) CONTAINS toLower('string_value')
OR size(filter(x IN c.synonyms WHERE toLower(x) CONTAINS toLower('string_value'))) > 0
RETURN d.id