-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
94 lines (86 loc) · 2.92 KB
/
helpers.js
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
import { sparqlEscapeDateTime, sparqlEscapeString, sparqlEscapeUri } from "mu";
import { querySudo as query } from "@lblod/mu-auth-sudo";
import { MASTER_GRAPH, PUBLIC_GRAPH, MIN_NB_OF_AGENDAITEMS } from "./config";
async function fetchMostRecentAgendas() {
const since = new Date();
since.setYear(since.getFullYear() - 1); // 1 year ago
const queryResult = await query(`
PREFIX besluitvorming: <https://data.vlaanderen.be/ns/besluitvorming#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
SELECT DISTINCT ?agendaId WHERE {
GRAPH <${MASTER_GRAPH}> {
?s a besluitvorming:Agenda ;
mu:uuid ?agendaId ;
dct:modified ?modified .
}
FILTER (?modified > ${sparqlEscapeDateTime(since)})
} ORDER BY DESC(?modified)
`);
return queryResult.results.bindings.map((b) => b["agendaId"].value);
}
async function fetchLargeAgendas() {
const queryResult = await query(`
PREFIX besluitvorming: <https://data.vlaanderen.be/ns/besluitvorming#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
SELECT ?agendaId ?count WHERE
{
{
SELECT DISTINCT ?agendaId (COUNT(?agendaitem) as ?count) {
GRAPH <${MASTER_GRAPH}> {
?agenda a besluitvorming:Agenda ;
mu:uuid ?agendaId ;
dct:hasPart ?agendaitem .
}
}
GROUP BY ?agendaId
}
FILTER (?count > ${MIN_NB_OF_AGENDAITEMS})
} ORDER BY DESC(?count)`);
return queryResult.results.bindings.map((b) => b["agendaId"].value);
}
async function fetchAgendaitemsFromAgenda(agendaId) {
const queryResult = await query(`
PREFIX besluitvorming: <https://data.vlaanderen.be/ns/besluitvorming#>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX mu: <http://mu.semte.ch/vocabularies/core/>
SELECT DISTINCT ?agendaitemId {
GRAPH <${MASTER_GRAPH}> {
?agenda a besluitvorming:Agenda ;
mu:uuid ${sparqlEscapeString(agendaId)};
dct:hasPart ?agendaitem .
?agendaitem mu:uuid ?agendaitemId .
}
}
`);
return queryResult.results.bindings.map((binding) => {
return binding.agendaitemId.value;
});
}
async function countConceptsForConceptScheme(conceptSchemeUri) {
const queryResult = await query(`
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT (COUNT(DISTINCT ?concept) AS ?count)
WHERE {
GRAPH <${PUBLIC_GRAPH}> {
?concept skos:inScheme ${sparqlEscapeUri(conceptSchemeUri)} .
}
}`);
if (queryResult.results.bindings.length) {
return queryResult.results.bindings[0].count.value;
}
}
function chunk(array, size) {
let chunked = [];
for (let i = 0; i < array.length; i += size)
chunked.push(array.slice(i, i + size));
return chunked;
};
export {
fetchMostRecentAgendas,
fetchLargeAgendas,
fetchAgendaitemsFromAgenda,
countConceptsForConceptScheme,
chunk,
};