-
Notifications
You must be signed in to change notification settings - Fork 14
/
valid_claims.js
31 lines (27 loc) · 963 Bytes
/
valid_claims.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
const wdk = require('wikidata-sdk')
const haveAMatch = require('./have_a_match')
module.exports = (claims, filterByClaimData) => {
if (!filterByClaimData) return true
const { P, Q, negatedProp, filterByClaimValue } = filterByClaimData
// filter-out this entity unless it has claims of the desired property
var propClaims = claims[P]
if (propClaims && propClaims.length > 0) {
if (negatedProp && !filterByClaimValue) return false
} else {
if (!negatedProp) return false
}
// let the possibility to let the claim value unspecified
// ex: wikidata-filter --claim P184
if (filterByClaimValue) {
const Qs = Q.split(',')
// filter-out this entity unless it has a claim
// of the desired property with the desired value
propClaims = wdk.simplifyPropertyClaims(propClaims)
if (haveAMatch(Qs, propClaims)) {
if (negatedProp) return false
} else {
if (!negatedProp) return false
}
}
return true
}