wikibase-cli 16.3.2 → 17.0.0
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-add-alias.js +12 -0
- package/bin/wb-add-badge.js +12 -0
- package/bin/wb-add-claim.js +14 -0
- package/bin/wb-add-qualifier.js +14 -0
- package/bin/wb-add-reference.js +14 -0
- package/bin/wb-aliases.js +4 -0
- package/bin/wb-badges.js +18 -0
- package/bin/{wb-claims → wb-claims.js} +19 -14
- package/bin/{wb-config → wb-config.js} +8 -6
- package/bin/{wb-convert → wb-convert.js} +11 -12
- package/bin/wb-create-entity.js +10 -0
- package/bin/{wb-data → wb-data.js} +15 -11
- package/bin/wb-delete-entity.js +10 -0
- package/bin/wb-description.js +4 -0
- package/bin/wb-edit-entity.js +10 -0
- package/bin/{wb-generate-template → wb-generate-template.js} +24 -13
- package/bin/{wb-hub → wb-hub.js} +10 -8
- package/bin/{wb-id → wb-id.js} +14 -11
- package/bin/wb-label.js +4 -0
- package/bin/{wb-lang → wb-lang.js} +8 -8
- package/bin/wb-lemma.js +4 -0
- package/bin/{wb-merge-entity → wb-merge-entity.js} +6 -4
- package/bin/wb-move-claim.js +20 -0
- package/bin/wb-move-qualifier.js +21 -0
- package/bin/{wb-open → wb-open.js} +23 -22
- package/bin/{wb-props → wb-props.js} +8 -9
- package/bin/{wb-query → wb-query.js} +13 -9
- package/bin/wb-remove-alias.js +12 -0
- package/bin/wb-remove-badge.js +12 -0
- package/bin/wb-remove-claim.js +11 -0
- package/bin/wb-remove-description.js +16 -0
- package/bin/wb-remove-label.js +16 -0
- package/bin/wb-remove-qualifier.js +15 -0
- package/bin/wb-remove-reference.js +15 -0
- package/bin/wb-remove-sitelink.js +16 -0
- package/bin/{wb-revisions → wb-revisions.js} +15 -11
- package/bin/{wb-search → wb-search.js} +17 -15
- package/bin/wb-set-alias.js +12 -0
- package/bin/wb-set-description.js +12 -0
- package/bin/wb-set-label.js +12 -0
- package/bin/wb-set-sitelink.js +17 -0
- package/bin/{wb-sparql → wb-sparql.js} +16 -12
- package/bin/{wb-summary → wb-summary.js} +3 -3
- package/bin/{wb-update-claim → wb-update-claim.js} +9 -6
- package/bin/wb-update-qualifier.js +14 -0
- package/bin/wb.js +27 -0
- package/bin/{wd → wd.js} +2 -3
- package/index.js +7 -1
- package/lib/apply_env_and_config_default.js +7 -5
- package/lib/chalk.js +12 -0
- package/lib/command_with_template_custom_help.js +7 -7
- package/lib/common_command_args_parser.js +7 -10
- package/lib/common_errors.js +5 -7
- package/lib/common_options.js +23 -24
- package/lib/config/config.js +10 -5
- package/lib/config/credentials_config.js +7 -6
- package/lib/config/file_operations.js +9 -8
- package/lib/config/file_path.js +11 -8
- package/lib/config/parameters.js +11 -10
- package/lib/convert_ids.js +10 -8
- package/lib/copy.js +2 -2
- package/lib/drop_non_selected_subprops.js +3 -3
- package/lib/edit/assert_credentials.js +3 -3
- package/lib/edit/edit_command.js +19 -19
- package/lib/edit/init_credentials.js +11 -11
- package/lib/edit/parse_batch_line.js +2 -2
- package/lib/edit/parse_object_value.js +6 -5
- package/lib/edit/prompt.js +7 -5
- package/lib/edit/validate_instance_credentials.js +2 -2
- package/lib/entity_attribute_command.js +10 -10
- package/lib/entity_attribute_parser.js +8 -8
- package/lib/entity_data_parser.js +14 -11
- package/lib/errors.js +3 -3
- package/lib/execute_function.js +4 -4
- package/lib/exit_on_missing.js +11 -12
- package/lib/fetch_and_log_entity_revision.js +18 -15
- package/lib/fetch_and_log_guid_data.js +19 -11
- package/lib/fetch_and_log_ids_data.js +17 -16
- package/lib/fetch_and_log_property_claims_data.js +18 -10
- package/lib/fetch_lang_props.js +13 -12
- package/lib/filter_claims_properties.js +4 -4
- package/lib/format_properties_data.js +2 -2
- package/lib/format_statement_element_value.js +3 -3
- package/lib/fs.js +27 -25
- package/lib/generate_describe_sparql_query.js +3 -3
- package/lib/generate_sample_sparql_query.js +1 -1
- package/lib/generate_select_sparql_query.js +9 -6
- package/lib/get_cache_folder_path.js +5 -5
- package/lib/get_claims_texts.js +8 -7
- package/lib/get_entities.js +6 -5
- package/lib/get_entities_by_batches.js +12 -7
- package/lib/get_entities_labels.js +3 -5
- package/lib/get_entities_schemas.js +7 -7
- package/lib/get_folder_path.js +8 -6
- package/lib/get_lang_props.js +17 -16
- package/lib/get_pattern_filter.js +18 -9
- package/lib/get_properties_data.js +5 -5
- package/lib/get_redirected_sitelink_title.js +4 -4
- package/lib/get_sitelink_url.js +9 -8
- package/lib/get_stdin_input.js +1 -1
- package/lib/get_ttl_entities.js +8 -8
- package/lib/global_options_help.js +1 -1
- package/lib/hash_string.js +4 -2
- package/lib/json.js +5 -0
- package/lib/local_lang.js +2 -1
- package/lib/log_claims.js +12 -12
- package/lib/log_command_examples.js +3 -3
- package/lib/log_ndjson.js +1 -1
- package/lib/make_sparql_query.js +29 -25
- package/lib/matching_langs.js +4 -6
- package/lib/minimize_claims.js +3 -5
- package/lib/object_arg_parser.js +12 -17
- package/lib/open.js +7 -7
- package/lib/output.js +37 -35
- package/lib/output_templates.js +41 -31
- package/lib/parse_command_utils.js +14 -15
- package/lib/parse_entity_type.js +2 -2
- package/lib/parse_props.js +7 -4
- package/lib/parse_simplify_options.js +1 -1
- package/lib/path.js +3 -2
- package/lib/pluralize.js +2 -2
- package/lib/polymorphic_command_args_parser.js +11 -9
- package/lib/program.js +9 -9
- package/lib/properties.js +22 -23
- package/lib/queries/all_instances.js +2 -2
- package/lib/queries/all_properties.js +1 -1
- package/lib/read_ids_from_stdin.js +3 -3
- package/lib/request.js +22 -23
- package/lib/request_headers.js +8 -2
- package/lib/reset_properties.js +4 -4
- package/lib/sparql_query_command.js +10 -8
- package/lib/stringify_as_js_function.js +3 -3
- package/lib/summary_parser.js +43 -13
- package/lib/tabularize.js +7 -7
- package/lib/tolerant_id_parser.js +21 -18
- package/lib/types.js +4 -6
- package/lib/utils.js +11 -13
- package/lib/validate.js +2 -0
- package/lib/validate_function_args.js +2 -2
- package/lib/value_parsers.js +2 -2
- package/lib/wbk.js +4 -3
- package/lib/wellknown_queries.js +6 -5
- package/metadata/add-alias.js +6 -4
- package/metadata/add-badge.js +5 -3
- package/metadata/add-claim.js +5 -5
- package/metadata/add-qualifier.js +6 -4
- package/metadata/add-reference.js +6 -4
- package/metadata/aliases.js +6 -4
- package/metadata/badges.js +3 -3
- package/metadata/claims.js +4 -4
- package/metadata/config.js +5 -5
- package/metadata/convert.js +4 -4
- package/metadata/create-entity.js +8 -8
- package/metadata/data.js +4 -4
- package/metadata/delete-entity.js +7 -7
- package/metadata/description.js +6 -4
- package/metadata/edit-entity.js +10 -10
- package/metadata/generate-template.js +4 -4
- package/metadata/hub.js +3 -3
- package/metadata/id.js +4 -4
- package/metadata/label.js +5 -3
- package/metadata/lang.js +4 -4
- package/metadata/lemma.js +6 -4
- package/metadata/merge-entity.js +6 -6
- package/metadata/move-claim.js +6 -4
- package/metadata/move-qualifier.js +6 -4
- package/metadata/open.js +4 -4
- package/metadata/props.js +4 -4
- package/metadata/query.js +3 -3
- package/metadata/remove-alias.js +6 -4
- package/metadata/remove-badge.js +5 -3
- package/metadata/remove-claim.js +6 -4
- package/metadata/remove-description.js +5 -3
- package/metadata/remove-label.js +5 -3
- package/metadata/remove-qualifier.js +6 -4
- package/metadata/remove-reference.js +6 -4
- package/metadata/remove-sitelink.js +5 -3
- package/metadata/revisions.js +4 -4
- package/metadata/search.js +3 -3
- package/metadata/set-alias.js +6 -4
- package/metadata/set-description.js +6 -4
- package/metadata/set-label.js +6 -4
- package/metadata/set-sitelink.js +5 -3
- package/metadata/sparql.js +4 -4
- package/metadata/summary.js +5 -5
- package/metadata/update-claim.js +5 -5
- package/metadata/update-qualifier.js +6 -4
- package/package.json +24 -16
- package/bin/wb +0 -22
- package/bin/wb-add-alias +0 -9
- package/bin/wb-add-badge +0 -9
- package/bin/wb-add-claim +0 -11
- package/bin/wb-add-qualifier +0 -11
- package/bin/wb-add-reference +0 -11
- package/bin/wb-aliases +0 -2
- package/bin/wb-badges +0 -18
- package/bin/wb-create-entity +0 -5
- package/bin/wb-delete-entity +0 -7
- package/bin/wb-description +0 -2
- package/bin/wb-edit-entity +0 -5
- package/bin/wb-label +0 -2
- package/bin/wb-lemma +0 -2
- package/bin/wb-move-claim +0 -17
- package/bin/wb-move-qualifier +0 -18
- package/bin/wb-remove-alias +0 -9
- package/bin/wb-remove-badge +0 -9
- package/bin/wb-remove-claim +0 -8
- package/bin/wb-remove-description +0 -13
- package/bin/wb-remove-label +0 -13
- package/bin/wb-remove-qualifier +0 -12
- package/bin/wb-remove-reference +0 -12
- package/bin/wb-remove-sitelink +0 -13
- package/bin/wb-set-alias +0 -9
- package/bin/wb-set-description +0 -9
- package/bin/wb-set-label +0 -9
- package/bin/wb-set-sitelink +0 -14
- package/bin/wb-update-qualifier +0 -11
- package/lib/valide.js +0 -4
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { max, padEnd, values } from 'lodash-es'
|
|
2
|
+
import { grey, red } from '#lib/chalk'
|
|
3
|
+
import entityAttributeParser from './entity_attribute_parser.js'
|
|
4
|
+
import { entityDataParser } from './entity_data_parser.js'
|
|
5
|
+
import pluralize from './pluralize.js'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
export async function entityAttributeCommand (attribute, extraParams) {
|
|
8
8
|
let commandName, ids
|
|
9
9
|
if (extraParams) {
|
|
10
10
|
ids = extraParams.ids
|
|
@@ -15,13 +15,13 @@ module.exports = (attribute, extraParams) => {
|
|
|
15
15
|
const props = [ pluarlizedAttribute ]
|
|
16
16
|
|
|
17
17
|
const parser = async ({ lang, strictLang, output, entities }) => {
|
|
18
|
-
const entitiesList =
|
|
18
|
+
const entitiesList = values(entities)
|
|
19
19
|
const multiEntities = entitiesList.length > 1
|
|
20
|
-
const maxLength =
|
|
20
|
+
const maxLength = max(entitiesList.map(entity => entity.id.length)) + 1
|
|
21
21
|
entitiesList.forEach(logAttribute(attribute, lang, strictLang, multiEntities, maxLength, output))
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
entityDataParser({ commandName, props, parser, ids })
|
|
24
|
+
await entityDataParser({ commandName, props, parser, ids })
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
const logAttribute = (attribute, lang, strictLang, multiEntities, maxLength, output) => entity => {
|
|
@@ -38,7 +38,7 @@ const logAttribute = (attribute, lang, strictLang, multiEntities, maxLength, out
|
|
|
38
38
|
}
|
|
39
39
|
// Prefix value with the id if there are multiple entities
|
|
40
40
|
if (multiEntities) {
|
|
41
|
-
console.log(grey(
|
|
41
|
+
console.log(grey(padEnd(entity.id, maxLength)), value || grey('not found'))
|
|
42
42
|
} else {
|
|
43
43
|
output(value)
|
|
44
44
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { isArray, map, values } from 'lodash-es'
|
|
2
|
+
import errors_ from '#lib/errors'
|
|
3
|
+
import pluralize from './pluralize.js'
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
export default (entity, attribute, lang, strictLang) => {
|
|
6
6
|
if (entity.missing != null) return
|
|
7
7
|
const pluarlizedAttribute = pluralize(attribute)
|
|
8
8
|
const { id, type } = entity
|
|
@@ -12,9 +12,9 @@ module.exports = (entity, attribute, lang, strictLang) => {
|
|
|
12
12
|
const attrData = entity[pluarlizedAttribute]
|
|
13
13
|
let valueObj
|
|
14
14
|
if (strictLang != null) valueObj = attrData[strictLang]
|
|
15
|
-
else valueObj = attrData[lang] || attrData.en ||
|
|
16
|
-
if (
|
|
17
|
-
return
|
|
15
|
+
else valueObj = attrData[lang] || attrData.en || values(attrData)[0]
|
|
16
|
+
if (isArray(valueObj)) {
|
|
17
|
+
return map(valueObj, 'value').join(' | ')
|
|
18
18
|
} else {
|
|
19
19
|
return valueObj && valueObj.value
|
|
20
20
|
}
|
|
@@ -23,5 +23,5 @@ module.exports = (entity, attribute, lang, strictLang) => {
|
|
|
23
23
|
const attributesPerType = {
|
|
24
24
|
item: [ 'labels', 'descriptions', 'aliases' ],
|
|
25
25
|
property: [ 'labels', 'descriptions', 'aliases' ],
|
|
26
|
-
lexeme: [ 'lemmas' ]
|
|
26
|
+
lexeme: [ 'lemmas' ],
|
|
27
27
|
}
|
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import errors_ from '#lib/errors'
|
|
2
|
+
import { exitOnMissingInstance } from '#lib/exit_on_missing'
|
|
3
|
+
import { outputFactory } from '#lib/output'
|
|
4
|
+
import program from '#lib/program'
|
|
5
|
+
import { get } from '#lib/request'
|
|
6
|
+
import { tolerantIdParserFactory } from '#lib/tolerant_id_parser'
|
|
7
|
+
import wbk from '#lib/wbk'
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
const parseId = tolerantIdParserFactory()
|
|
10
|
+
|
|
11
|
+
export async function entityDataParser (params) {
|
|
7
12
|
const { commandName, parser, programOptions: options } = params
|
|
8
13
|
let { ids, props } = params
|
|
9
|
-
const program = require('../lib/program')
|
|
10
14
|
|
|
11
15
|
// If no commandName has been specified, assume that the options
|
|
12
16
|
// where already parsed and that program.process has already been called
|
|
13
17
|
if (commandName) {
|
|
14
18
|
if (options) options.forEach(option => program.option(...option))
|
|
15
|
-
program.process(commandName)
|
|
19
|
+
await program.process(commandName)
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
exitOnMissingInstance(program.instance)
|
|
19
23
|
|
|
20
|
-
const { getEntities } =
|
|
21
|
-
const output =
|
|
24
|
+
const { getEntities } = wbk(program)
|
|
25
|
+
const output = outputFactory(program)
|
|
22
26
|
|
|
23
27
|
const { args, lang, strictLang } = program
|
|
24
28
|
|
|
@@ -32,7 +36,6 @@ module.exports = async params => {
|
|
|
32
36
|
if (props && props[0] === 'lemmas') props = [ 'info' ]
|
|
33
37
|
|
|
34
38
|
const url = getEntities({ ids, props })
|
|
35
|
-
|
|
36
39
|
const body = await get(url)
|
|
37
40
|
const entities = parseEntities(ids, body)
|
|
38
41
|
return parser({ lang, strictLang, program, output, entities })
|
package/lib/errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { red } from '#lib/chalk'
|
|
2
2
|
|
|
3
3
|
const errors_ = {
|
|
4
4
|
new: (message, context) => {
|
|
@@ -25,7 +25,7 @@ const errors_ = {
|
|
|
25
25
|
bundle: (message, context) => {
|
|
26
26
|
const err = errors_.new(message, context)
|
|
27
27
|
errors_.exit(err)
|
|
28
|
-
}
|
|
28
|
+
},
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
export default errors_
|
package/lib/execute_function.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import errors_ from './errors.js'
|
|
2
|
+
import validateFunctionArgs from './validate_function_args.js'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
let fn =
|
|
4
|
+
export async function executeFunction (absoluePath, inputArgs) {
|
|
5
|
+
let { default: fn } = await import(absoluePath)
|
|
6
6
|
let metadata
|
|
7
7
|
|
|
8
8
|
if (fn && fn.template) {
|
package/lib/exit_on_missing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { red } from '#lib/chalk'
|
|
2
2
|
|
|
3
3
|
const missingInstance = `A Wikibase instance should be specificed.
|
|
4
4
|
|
|
@@ -16,15 +16,14 @@ This can be done in config, ex:
|
|
|
16
16
|
or with the -e,--sparql-endpoint command option:
|
|
17
17
|
$ wb sparql ./my_query.sparql -e https://query.wikidata.org/sparql`
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
19
|
+
export function exitOnMissingInstance (instance) {
|
|
20
|
+
if (instance) return
|
|
21
|
+
console.error(red(missingInstance))
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function exitOnMissingSparqlEndpoint (sparqlEndpoint) {
|
|
26
|
+
if (sparqlEndpoint) return
|
|
27
|
+
console.error(red(missingSparqlEndpoint))
|
|
28
|
+
process.exit(1)
|
|
30
29
|
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { values } from 'lodash-es'
|
|
2
|
+
import { simplifyEntity } from 'wikibase-sdk'
|
|
3
|
+
import { exitOnMissingInstance } from '#lib/exit_on_missing'
|
|
4
|
+
import optionsFactory from '#lib/parse_simplify_options'
|
|
5
|
+
import { get } from '#lib/request'
|
|
6
|
+
import wbk from '#lib/wbk'
|
|
7
|
+
import program from './program.js'
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
exitOnMissingInstance(program.instance)
|
|
10
|
+
|
|
11
|
+
export async function fetchAndLogEntityRevision (id, revision) {
|
|
12
|
+
const { getEntityRevision } = wbk(program)
|
|
13
|
+
const { simplify: simplifyOption } = program
|
|
14
|
+
const options = optionsFactory(program)
|
|
15
|
+
const url = getEntityRevision({ id, revision })
|
|
16
|
+
const body = await get(url)
|
|
17
|
+
let entity = values(body.entities)[0]
|
|
18
|
+
if (simplifyOption) entity = simplifyEntity(entity, options)
|
|
19
|
+
console.log(JSON.stringify(entity))
|
|
17
20
|
}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { values } from 'lodash-es'
|
|
2
|
+
import { getStatementsKey } from 'wikibase-edit/lib/parse_instance.js'
|
|
3
|
+
import { simplifyClaim } from 'wikibase-sdk'
|
|
4
|
+
import { exitOnMissingInstance } from '#lib/exit_on_missing'
|
|
5
|
+
import optionsFactory from '#lib/parse_simplify_options'
|
|
6
|
+
import { get } from '#lib/request'
|
|
7
|
+
import wbk from '#lib/wbk'
|
|
8
|
+
import { outputFactory } from './output.js'
|
|
9
|
+
import program from './program.js'
|
|
10
|
+
|
|
11
|
+
export async function fetchAndLogGuidData (guid) {
|
|
12
|
+
exitOnMissingInstance(program.instance)
|
|
13
|
+
const { getEntities } = wbk(program)
|
|
14
|
+
const options = optionsFactory(program)
|
|
15
|
+
const { simplify: simplifyOption } = program
|
|
16
|
+
const output = outputFactory(program)
|
|
9
17
|
|
|
10
|
-
module.exports = async guid => {
|
|
11
18
|
const id = guid.split('$')[0].toUpperCase()
|
|
12
19
|
const url = getEntities({ ids: id, props: 'claims' })
|
|
13
20
|
|
|
14
21
|
const { entities } = await get(url)
|
|
15
22
|
const entity = entities[id]
|
|
16
|
-
|
|
23
|
+
const statementsKey = getStatementsKey(program.instance)
|
|
24
|
+
let claim = findClaim(entity[statementsKey], guid)
|
|
17
25
|
if (!claim) throw new Error(`claim not found: ${guid}`)
|
|
18
|
-
if (simplifyOption) claim =
|
|
26
|
+
if (simplifyOption) claim = simplifyClaim(claim, options)
|
|
19
27
|
output(claim)
|
|
20
28
|
}
|
|
21
29
|
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { isEntitySchemaId, simplifyEntity } from 'wikibase-sdk'
|
|
2
|
+
import { exitOnMissingInstance } from '#lib/exit_on_missing'
|
|
3
|
+
import optionsFactory from '#lib/parse_simplify_options'
|
|
4
|
+
import dropNonSelectedSubprops from './drop_non_selected_subprops.js'
|
|
5
|
+
import { getEntitiesByBatches } from './get_entities_by_batches.js'
|
|
6
|
+
import { getEntitiesSchemas } from './get_entities_schemas.js'
|
|
7
|
+
import getTtlEntities from './get_ttl_entities.js'
|
|
8
|
+
import logNdjson from './log_ndjson.js'
|
|
9
|
+
import parseProps from './parse_props.js'
|
|
10
|
+
import program from './program.js'
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
export function fetchAndLogIdsData (ids) {
|
|
13
|
+
exitOnMissingInstance(program.instance)
|
|
14
|
+
const requestedPropsAndSubProps = parseProps(program.props)
|
|
15
|
+
const requestedProps = Object.keys(requestedPropsAndSubProps)
|
|
16
|
+
const options = optionsFactory(program)
|
|
17
|
+
const { simplify: simplifyFlag, format } = program
|
|
13
18
|
|
|
14
|
-
const options = require('../lib/parse_simplify_options')(program)
|
|
15
|
-
const { simplify: simplifyFlag, format } = program
|
|
16
|
-
|
|
17
|
-
module.exports = ids => {
|
|
18
19
|
if (format === 'ttl') return getTtlEntities(ids)
|
|
19
20
|
|
|
20
21
|
const entitiesSchemasIds = ids.filter(isEntitySchemaId)
|
|
@@ -24,7 +25,7 @@ module.exports = ids => {
|
|
|
24
25
|
const onResponse = entities => {
|
|
25
26
|
entities.forEach(entity => dropNonSelectedSubprops(entity, requestedPropsAndSubProps))
|
|
26
27
|
if (simplifyFlag) {
|
|
27
|
-
entities = entities.map(entity =>
|
|
28
|
+
entities = entities.map(entity => simplifyEntity(entity, options))
|
|
28
29
|
}
|
|
29
30
|
logNdjson(entities)
|
|
30
31
|
}
|
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { getStatementsKey } from 'wikibase-edit/lib/parse_instance.js'
|
|
2
|
+
import { simplifyPropertyClaims } from 'wikibase-sdk'
|
|
3
|
+
import { exitOnMissingInstance } from '#lib/exit_on_missing'
|
|
4
|
+
import optionsFactory from '#lib/parse_simplify_options'
|
|
5
|
+
import { get } from '#lib/request'
|
|
6
|
+
import wbk from '#lib/wbk'
|
|
7
|
+
import { outputFactory } from './output.js'
|
|
8
|
+
import program from './program.js'
|
|
9
|
+
|
|
10
|
+
export async function fetchAndLogPropertyClaimsData (propertyClaimsId) {
|
|
11
|
+
exitOnMissingInstance(program.instance)
|
|
12
|
+
const { getEntities } = wbk(program)
|
|
13
|
+
const options = optionsFactory(program)
|
|
14
|
+
const { simplify: simplifyOption } = program
|
|
15
|
+
const output = outputFactory(program)
|
|
8
16
|
|
|
9
|
-
module.exports = async propertyClaimsId => {
|
|
10
17
|
const [ entityId, propertyId ] = propertyClaimsId.toUpperCase().split('#')
|
|
11
18
|
const url = getEntities({ ids: entityId, props: 'claims' })
|
|
12
19
|
|
|
13
20
|
const { entities } = await get(url)
|
|
14
21
|
const entity = entities[entityId]
|
|
15
22
|
if (entity.missing != null) throw new Error(`entity not found: ${entityId}`)
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
const statementsKey = getStatementsKey(program.instance)
|
|
24
|
+
let claims = entity[statementsKey][propertyId] || []
|
|
25
|
+
if (simplifyOption) claims = simplifyPropertyClaims(claims, options)
|
|
18
26
|
output(claims)
|
|
19
27
|
}
|
package/lib/fetch_lang_props.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { simplifySparqlResults } from 'wikibase-sdk'
|
|
2
|
+
import { red, yellow } from '#lib/chalk'
|
|
3
|
+
import { get } from '#lib/request'
|
|
4
|
+
import { isValidLang } from '#lib/validate'
|
|
5
|
+
import wbk from '#lib/wbk'
|
|
6
|
+
import { exitOnMissingSparqlEndpoint } from './exit_on_missing.js'
|
|
7
|
+
import queryAllProperties from './queries/all_properties.js'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
export default async program => {
|
|
9
10
|
const { lang, sparqlEndpoint } = program
|
|
10
|
-
|
|
11
|
-
const { sparqlQuery
|
|
11
|
+
exitOnMissingSparqlEndpoint(program.sparqlEndpoint)
|
|
12
|
+
const { sparqlQuery } = wbk(program)
|
|
12
13
|
|
|
13
|
-
if (!
|
|
14
|
+
if (!isValidLang(lang)) throw Error(red(`invalid language: ${lang}`))
|
|
14
15
|
|
|
15
16
|
const sparql = queryAllProperties(lang)
|
|
16
17
|
const url = sparqlQuery(sparql)
|
|
17
18
|
|
|
18
19
|
try {
|
|
19
20
|
const body = await get(url)
|
|
20
|
-
return
|
|
21
|
+
return simplifySparqlResults(body).reduce(aggregator, {})
|
|
21
22
|
} catch (err) {
|
|
22
23
|
if (err.name === 'SyntaxError' || err.statusCode === 404) {
|
|
23
24
|
console.error(yellow(`Are you sure ${sparqlEndpoint} is a valid SPARQL endpoint?`))
|
|
@@ -36,7 +37,7 @@ const aggregator = (map, prop) => {
|
|
|
36
37
|
label: noLabelFound ? undefined : label,
|
|
37
38
|
type: type.split('#')[1],
|
|
38
39
|
description,
|
|
39
|
-
aliases
|
|
40
|
+
aliases,
|
|
40
41
|
}
|
|
41
42
|
return map
|
|
42
43
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { missingProperty } from './common_errors.js'
|
|
2
|
+
import getPatternFilter from './get_pattern_filter.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export default (propertiesData, claims, pattern) => {
|
|
5
5
|
const patternFilter = getPatternFilter(pattern, true)
|
|
6
6
|
|
|
7
7
|
const filteredClaims = {}
|
|
8
8
|
|
|
9
9
|
Object.keys(claims).forEach(property => {
|
|
10
10
|
const propData = propertiesData[property]
|
|
11
|
-
if (!propData) return
|
|
11
|
+
if (!propData) return missingProperty(property)
|
|
12
12
|
if (patternFilter(propData)) filteredClaims[property] = claims[property]
|
|
13
13
|
})
|
|
14
14
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { isPropertyId } from 'wikibase-sdk'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default (pattern, filter, includeAllDetails, includeTypes) => data => {
|
|
4
4
|
// Special case: when the pattern is a property id, just log the property
|
|
5
5
|
if (isPropertyId(pattern) && data[pattern] != null) {
|
|
6
6
|
const prop = pattern
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { isEntityId, isPropertyId } from 'wikibase-sdk'
|
|
2
|
+
import errors_ from '#lib/errors'
|
|
3
3
|
|
|
4
4
|
const prefixedProperty = prefix => value => {
|
|
5
5
|
if (isPropertyId(value)) return `${prefix}:${value}`
|
|
@@ -20,7 +20,7 @@ const object = value => {
|
|
|
20
20
|
return `"${value}"`.replace(/""/g, '"')
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
export default {
|
|
24
24
|
subject: value => {
|
|
25
25
|
if (isEntityId(value)) return `wd:${value}`
|
|
26
26
|
if (isUrlValue(value)) return formatUrlValue(value)
|
package/lib/fs.js
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import mkdirp from 'mkdirp'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
err ? reject(err) : resolve(res)
|
|
9
|
-
})
|
|
4
|
+
export const writeFile = (filepath, content) => {
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
fs.writeFile(filepath, content, (err, res) => {
|
|
7
|
+
err ? reject(err) : resolve(res)
|
|
10
8
|
})
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
9
|
+
})
|
|
10
|
+
}
|
|
11
|
+
export const exists = path => {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
fs.access(path, (err, res) => err ? reject(err) : resolve(res))
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
export const createFolder = path => {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
mkdirp(path, err => err ? reject(err) : resolve())
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
export const writeAccessSync = path => {
|
|
22
|
+
// Testing right to write
|
|
23
|
+
// cf https://nodejs.org/api/fs.html#fs_fs_access_path_mode_callback
|
|
24
|
+
// Will throw if failing
|
|
25
|
+
fs.accessSync(path, fs.constants.W_OK)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function getDirname (fileUrl) {
|
|
29
|
+
return new URL('.', fileUrl).pathname
|
|
28
30
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { isEntityId } from 'wikibase-sdk'
|
|
2
|
+
import errors_ from './errors.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export function generateDescribeSparqlQuery (describe) {
|
|
5
5
|
if (describe.startsWith('http')) return `DESCRIBE <${describe}>`
|
|
6
6
|
if (isEntityId(describe)) return `DESCRIBE wd:${describe}`
|
|
7
7
|
throw errors_.new('could not identify describe node type', 400, { describe })
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import formatStatementElementValue from './format_statement_element_value.js'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export function generateSelectSparqlQuery (program) {
|
|
4
4
|
let { count: countResults, labels: selectLabels, lang, qualifierProperty, qualifierObject } = program
|
|
5
5
|
|
|
6
6
|
const useSubSnaks = (qualifierProperty != null || qualifierObject != null)
|
|
@@ -56,9 +56,12 @@ module.exports = program => {
|
|
|
56
56
|
setElement('object')
|
|
57
57
|
|
|
58
58
|
if (selectLabels) {
|
|
59
|
-
if
|
|
60
|
-
|
|
61
|
-
lang =
|
|
59
|
+
// Include [AUTO_LANGUAGE], especially useful if program.open === true
|
|
60
|
+
if (lang === 'en') {
|
|
61
|
+
lang = 'en,[AUTO_LANGUAGE]'
|
|
62
|
+
} else {
|
|
63
|
+
// Include English as a fallback
|
|
64
|
+
lang = `${lang},[AUTO_LANGUAGE],en`
|
|
62
65
|
}
|
|
63
66
|
triple += `
|
|
64
67
|
SERVICE wikibase:label {
|
|
@@ -71,7 +74,7 @@ module.exports = program => {
|
|
|
71
74
|
let sparql = `SELECT ${select.trim()} WHERE {
|
|
72
75
|
${triple}
|
|
73
76
|
}`
|
|
74
|
-
if (limit) sparql +=
|
|
77
|
+
if (limit) sparql += `\nLIMIT ${limit}`
|
|
75
78
|
|
|
76
79
|
return sparql
|
|
77
80
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { exists, createFolder } from './fs.js'
|
|
2
|
+
import getFolderPath from './get_folder_path.js'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export default subfolder => {
|
|
5
5
|
const subfolderPath = getFolderPath('cache', subfolder)
|
|
6
|
-
return
|
|
6
|
+
return exists(subfolderPath)
|
|
7
7
|
.catch(err => {
|
|
8
8
|
if (err.code === 'ENOENT') {
|
|
9
|
-
return
|
|
9
|
+
return createFolder(subfolderPath)
|
|
10
10
|
} else {
|
|
11
11
|
throw err
|
|
12
12
|
}
|
package/lib/get_claims_texts.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import chalk from 'chalk'
|
|
2
|
+
import { isEntityId } from 'wikibase-sdk'
|
|
3
|
+
import { missingProperty } from './common_errors.js'
|
|
4
|
+
import getPropertiesData from './get_properties_data.js'
|
|
5
|
+
import { propTypes } from './properties.js'
|
|
6
|
+
|
|
2
7
|
const { grey, bgWhite, black } = chalk
|
|
3
|
-
const { isEntityId } = require('wikibase-sdk')
|
|
4
|
-
const { propTypes } = require('./properties')
|
|
5
|
-
const commonErrors = require('./common_errors')
|
|
6
|
-
const getPropertiesData = require('./get_properties_data')
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
export default async ({ labels, simplifiedClaims, resort, lang }) => {
|
|
9
10
|
const propertiesIds = Object.keys(simplifiedClaims)
|
|
10
11
|
const propertiesData = await getPropertiesData(propertiesIds, lang)
|
|
11
12
|
|
|
@@ -17,7 +18,7 @@ module.exports = async ({ labels, simplifiedClaims, resort, lang }) => {
|
|
|
17
18
|
|
|
18
19
|
const buildClaimsText = (labels, prop, values, propertiesData) => {
|
|
19
20
|
const propData = propertiesData[prop]
|
|
20
|
-
if (!propData) return
|
|
21
|
+
if (!propData) return missingProperty(prop)
|
|
21
22
|
|
|
22
23
|
const { label, type } = propData
|
|
23
24
|
const propColor = propTypes[type].color
|
package/lib/get_entities.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import wbk from '#lib/wbk'
|
|
2
|
+
import program from './program.js'
|
|
3
|
+
import { get } from './request.js'
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
export default async params => {
|
|
5
6
|
// JIT require to be sure program.process was already called
|
|
6
|
-
// and program.
|
|
7
|
-
const { getManyEntities } =
|
|
7
|
+
// and program.instance is set
|
|
8
|
+
const { getManyEntities } = wbk(program)
|
|
8
9
|
|
|
9
10
|
const urls = getManyEntities(params)
|
|
10
11
|
const allEntities = {}
|