-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (29 loc) · 880 Bytes
/
index.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
const bySubjectCount = require('./bySubjectCount')
const current = require('./current')
class SimpleIriFinder {
init (context, iri, graph, options) {
SimpleIriFinder.assignIri(this, null, options.iriFinders)
}
static assignIri (simple, iris, finders) {
const iri = SimpleIriFinder.findIri(simple, iris, finders)
if (iri) {
simple._core.iri = iri
}
}
static findIri (simple, iris, finders) {
return SimpleIriFinder.findIris(simple, iris, finders).shift()
}
static findIris (simple, iris, finders) {
finders = finders || SimpleIriFinder.defaults.iriFinders
return finders.reduce((iris, finder) => {
if (iris.length === 1) {
return iris
}
return finder(simple, iris)
}, iris || [])
}
}
SimpleIriFinder.defaults = {
iriFinders: [current(), bySubjectCount()]
}
module.exports = SimpleIriFinder