-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathreasoning.js
More file actions
107 lines (95 loc) · 2.78 KB
/
reasoning.js
File metadata and controls
107 lines (95 loc) · 2.78 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
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
96
97
98
99
100
101
102
103
104
105
106
107
const { httpBody } = require('../response-transforms');
const jsonify = res => {
res.headers.set('Content-Type', 'application/json; charset=utf-8');
return res;
};
const consistency = (conn, database, options = {}, params = {}) => {
const headers = conn.headers();
headers.set('Accept', 'text/boolean');
const suffix = `consistency${
options.namedGraph ? `?graph-uri=${options.namedGraph}` : ''
}`;
return fetch(conn.request(database, 'reasoning', suffix), {
headers,
}).then(httpBody);
};
// contentType - application/x-turtle, text/turtle, application/rdf+xml, text/plain, application/x-trig, text/x-nquads, application/trix
const explainInference = (conn, database, inference, config, params) => {
const headers = conn.headers();
headers.set('Content-Type', config.contentType);
headers.set('Accept', 'application/json');
return fetch(conn.request(database, 'reasoning', 'explain'), {
method: 'POST',
headers,
body: inference,
})
.then(jsonify)
.then(httpBody);
};
const explainInconsistency = (conn, database, options = {}, params = {}) => {
const headers = conn.headers();
headers.set('Accept', 'application/json');
const suffix = `inconsistency${
options.namedGraph ? `?graph-uri=${options.namedGraph}` : ''
}`;
return fetch(conn.request(database, 'reasoning', 'explain', suffix), {
method: 'POST',
headers,
})
.then(jsonify)
.then(httpBody);
};
// contentType - application/x-turtle, text/turtle, application/rdf+xml, text/plain, application/x-trig, text/x-nquads, application/trix
const explainInferenceInTransaction = (
conn,
database,
transactionId,
inference,
config,
params = {}
) => {
const headers = conn.headers();
headers.set('Content-Type', config.contentType);
if (config.encoding) {
headers.set('Content-Encoding', config.encoding);
}
return fetch(conn.request(database, 'reasoning', transactionId, 'explain'), {
method: 'POST',
headers,
body: inference,
}).then(httpBody);
};
const explainInconsistencyInTransaction = (
conn,
database,
transactionId,
options = {},
params = {}
) => {
const headers = conn.headers();
const suffix = `inconsistency${
options.namedGraph ? `?graph-uri=${options.namedGraph}` : ''
}`;
return fetch(
conn.request(database, 'reasoning', transactionId, 'explain', suffix),
{
method: 'POST',
headers,
}
).then(httpBody);
};
const schema = (conn, database, params = {}) => {
const headers = conn.headers();
headers.set('Accept', 'application/ld+json');
return fetch(conn.request(database, 'reasoning', 'schema'), {
headers,
}).then(httpBody);
};
module.exports = {
consistency,
explainInference,
explainInconsistency,
explainInferenceInTransaction,
explainInconsistencyInTransaction,
schema,
};