wikibase-cli 18.3.2 → 18.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/wb-claims.js +5 -3
- package/lib/execute_function.js +2 -2
- package/lib/log_claims.js +16 -4
- package/lib/reset_properties.js +4 -2
- package/lib/summary_parser.js +1 -1
- package/package.json +1 -1
package/bin/wb-claims.js
CHANGED
|
@@ -59,11 +59,13 @@ const run = async () => {
|
|
|
59
59
|
return output(ids)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const simplifiedClaims = simplifyClaims(entity[statementsKey], { keepNonTruthy })
|
|
62
|
+
const simplifiedClaims = simplifyClaims(entity[statementsKey], { keepNonTruthy, keepTypes: true })
|
|
63
63
|
if (!prop) return logClaims({ program, simplifiedClaims, pattern, resort: true })
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
if (simplifiedClaims[prop] != null) {
|
|
66
|
+
const values = simplifiedClaims[prop].map(({ value }) => value)
|
|
67
|
+
return output(values)
|
|
68
|
+
}
|
|
67
69
|
|
|
68
70
|
const label = await getEntityLabel(prop)
|
|
69
71
|
console.log(yellow('no statement found'), label)
|
package/lib/execute_function.js
CHANGED
|
@@ -12,8 +12,6 @@ export async function executeFunction (absoluePath, inputArgs) {
|
|
|
12
12
|
fn = module.default
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
if (typeof fn !== 'function') throw new Error('function not found')
|
|
16
|
-
|
|
17
15
|
let metadata
|
|
18
16
|
|
|
19
17
|
if (fn && fn.template) {
|
|
@@ -21,6 +19,8 @@ export async function executeFunction (absoluePath, inputArgs) {
|
|
|
21
19
|
fn = fn.template
|
|
22
20
|
}
|
|
23
21
|
|
|
22
|
+
if (typeof fn !== 'function') throw new Error('function not found')
|
|
23
|
+
|
|
24
24
|
validateFunctionArgs(fn, inputArgs, metadata)
|
|
25
25
|
|
|
26
26
|
try {
|
package/lib/log_claims.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { chain, max, padEnd } from 'lodash-es'
|
|
2
|
-
import { isEntityId } from 'wikibase-sdk'
|
|
1
|
+
import { chain, compact, max, padEnd, uniq } from 'lodash-es'
|
|
3
2
|
import { bgMagenta, grey } from '#lib/chalk'
|
|
4
3
|
import filterClaimsProperties from '#lib/filter_claims_properties'
|
|
5
4
|
import getClaimsTexts from '#lib/get_claims_texts'
|
|
@@ -9,6 +8,7 @@ import getPropertiesData from './get_properties_data.js'
|
|
|
9
8
|
export default async ({ program, simplifiedClaims, extraData = {}, pattern, resort }) => {
|
|
10
9
|
const { lang } = program
|
|
11
10
|
const ids = collectEntityIds(simplifiedClaims, extraData)
|
|
11
|
+
simplifiedClaims = furtherSimplify(simplifiedClaims)
|
|
12
12
|
const labels = await getEntitiesLabels(ids, lang)
|
|
13
13
|
|
|
14
14
|
const propertiesIds = Object.keys(simplifiedClaims)
|
|
@@ -39,14 +39,17 @@ const collectEntityIds = (claims, extraData) => {
|
|
|
39
39
|
const claimIds = chain(claims)
|
|
40
40
|
.values()
|
|
41
41
|
.flatten()
|
|
42
|
-
.filter(
|
|
42
|
+
.filter(isEntityClaim)
|
|
43
|
+
.map(getClaimValue)
|
|
43
44
|
.value()
|
|
44
45
|
|
|
45
46
|
const extraDataIds = Object.values(extraData)
|
|
46
47
|
|
|
47
|
-
return claimIds.concat(extraDataIds)
|
|
48
|
+
return uniq(compact(claimIds.concat(extraDataIds)))
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
const isEntityClaim = claim => claim.type.split('-')[0] === 'wikibase'
|
|
52
|
+
|
|
50
53
|
const propClaimsText = targetLength => claimsTextData => {
|
|
51
54
|
const { propText, valuesText } = claimsTextData
|
|
52
55
|
return harmonizedLength(propText, targetLength) + valuesText
|
|
@@ -63,3 +66,12 @@ const logExtraData = (extraData, labels) => {
|
|
|
63
66
|
console.log(bgMagenta(key), labels[id], grey(id))
|
|
64
67
|
}
|
|
65
68
|
}
|
|
69
|
+
|
|
70
|
+
function furtherSimplify (simplifiedClaims) {
|
|
71
|
+
for (const [ property, propertyClaims ] of Object.entries(simplifiedClaims)) {
|
|
72
|
+
simplifiedClaims[property] = propertyClaims.map(getClaimValue)
|
|
73
|
+
}
|
|
74
|
+
return simplifiedClaims
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const getClaimValue = claim => claim.value
|
package/lib/reset_properties.js
CHANGED
|
@@ -5,8 +5,10 @@ import { getCacheFolderPath } from '#lib/get_cache_folder_path'
|
|
|
5
5
|
export default () => {
|
|
6
6
|
return getCacheFolderPath('props')
|
|
7
7
|
.then(propsDir => {
|
|
8
|
-
//
|
|
9
|
-
|
|
8
|
+
// -f: ignore if there are no more files to delete
|
|
9
|
+
// Use `-f` rather than `--force` to make it work on BusyBox
|
|
10
|
+
// cf https://www.wikidata.org/wiki/User_talk:Maxlath#Small_fix and https://paste.toolforge.org/view/f40c24e5
|
|
11
|
+
exec(`rm -f ${propsDir}/*.json`, (err, res) => {
|
|
10
12
|
if (err) console.error('reset properties failed', err)
|
|
11
13
|
else console.log(green('properties reset'))
|
|
12
14
|
})
|
package/lib/summary_parser.js
CHANGED
|
@@ -69,7 +69,7 @@ const parseEntity = async (entity, params) => {
|
|
|
69
69
|
if (instanceMainProps) properties = instanceMainProps
|
|
70
70
|
}
|
|
71
71
|
claims = program.verbose ? claims : pick(claims, properties)
|
|
72
|
-
const simplifiedClaims = simplify.claims(claims)
|
|
72
|
+
const simplifiedClaims = simplify.claims(claims, { keepTypes: true })
|
|
73
73
|
|
|
74
74
|
const extraData = {}
|
|
75
75
|
if (type === 'lexeme') {
|