wikibase-cli 15.16.9 → 16.0.1

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-search CHANGED
@@ -5,6 +5,7 @@ program
5
5
  .option('-p, --properties <properties>', 'request additional properties (separated by a comma) (implies verbose mode)')
6
6
  .option('-t, --type <type>', 'customize type: i|item, p|property, l|lexeme, f|form, s|sense (Default: item)')
7
7
  .option('-n, --limit <num>', 'set a custom limit (defaults to 10)')
8
+ .option('--cirrus', 'use Cirrus search')
8
9
  .process('search')
9
10
 
10
11
  // Accept several words without requiring those to be joined by quotes
@@ -12,8 +13,9 @@ const search = program.args.join(' ')
12
13
 
13
14
  if (!(search && search.length > 0)) program.helpAndExit(0)
14
15
 
15
- let { lang: language, json, verbose, properties, limit, type } = program
16
+ let { lang: language, json, verbose, properties, limit, type, cirrus } = program
16
17
  limit = limit || 20
18
+ if (typeof limit === 'string') limit = parseInt(limit)
17
19
 
18
20
  if (properties) program.verbose = verbose = true
19
21
 
@@ -25,40 +27,63 @@ if (!valide.lang(language)) {
25
27
  }
26
28
 
27
29
  require('../lib/exit_on_missing').instance(program.instance)
28
- const { searchEntities } = require('../lib/wbk')(program)
30
+ const { searchEntities, cirrusSearchPages } = require('../lib/wbk')(program)
29
31
  const { get } = require('../lib/request')
30
32
  const parseEntityType = require('../lib/parse_entity_type')
31
33
  const { padEnd } = require('lodash')
32
34
 
33
35
  type = parseEntityType(type)
34
36
 
35
- const url = searchEntities({
36
- search,
37
- language,
38
- // Fetch more in case we need to filter-out some results
39
- limit: limit + 10,
40
- type
41
- })
37
+ let url
38
+ if (cirrus) {
39
+ url = cirrusSearchPages({
40
+ search,
41
+ srprop: 'snippet|titlesnippet|sectiontitle',
42
+ limit,
43
+ })
44
+ } else {
45
+ url = searchEntities({
46
+ search,
47
+ language,
48
+ // Fetch more in case we need to filter-out some results
49
+ limit: limit + 10,
50
+ type
51
+ })
52
+ }
53
+
54
+ const dropMarkup = str => {
55
+ return str
56
+ .replace(/<span class="searchmatch">/g, '')
57
+ .replace(/<\/span>/g, '')
58
+ }
42
59
 
43
60
  get(url)
44
61
  .then(body => {
45
- const { error, search } = body
62
+ const { error, search, query } = body
46
63
 
47
64
  if (error) {
48
65
  console.error('API error response: ' + error.info)
49
66
  process.exit(1)
50
67
  }
51
68
 
52
- let results = search
69
+ let results = search || query.search
53
70
 
54
71
  results = results.slice(0, limit)
55
72
 
73
+ if (cirrus) {
74
+ results.forEach(result => {
75
+ result.id = result.title
76
+ result.label = dropMarkup(result.titlesnippet)
77
+ result.description = dropMarkup(result.snippet.split('\n')[0])
78
+ })
79
+ }
80
+
56
81
  if (json) {
57
82
  console.log(JSON.stringify(results, null, 2))
58
83
  return
59
84
  }
60
85
 
61
- const ids = results.map(result => result.id)
86
+ const ids = results.map(result => result.id || result.title)
62
87
 
63
88
  if (ids.length === 0) {
64
89
  console.error('no result')
@@ -74,9 +99,22 @@ get(url)
74
99
  // in the summary verbose format, only in the normal, short, summary format
75
100
  program.verbose = false
76
101
  entityDataParser({ ids, parser: summaryParser })
102
+ } else if (cirrus) {
103
+ results
104
+ .forEach(result => {
105
+ let { id, label, description } = result
106
+ // Known case: when search with haswbstatement
107
+ if (!label) {
108
+ label = description
109
+ description = ''
110
+ }
111
+ let text = padEnd(id, 11) + label
112
+ if (description && description.length > 0) text += ' ' + grey(description)
113
+ console.log(text)
114
+ })
77
115
  } else {
78
116
  results
79
- .forEach((result, index) => {
117
+ .forEach(result => {
80
118
  const { id, label, description } = result
81
119
  let text = padEnd(id, 11) + label
82
120
  if (description && description.length > 0) text += ' ' + grey(description)
@@ -15,9 +15,10 @@ module.exports = {
15
15
  { args: 'Harry Potter --limit 25', comment: 'displays up to 25 results matching "Harry Potter"' },
16
16
  { args: 'Harry Potter --verbose', comment: 'display rich results (aka summaries)' },
17
17
  { args: 'Harry Potter --properties P577,P935', comment: 'request additional properties (separated by a comma) to be added to the results summaries' },
18
- { args: 'date --type property', comment: "Search properties (but `wb props` might be doing a better job)" },
19
- { args: 'date --type lexeme', comment: "Search lexemes" },
20
- { args: 'code --type form', comment: "Search forms" },
21
- { args: 'test --type sense', comment: "Searching senses doesn't seem to work currently (2020-04-17)" }
18
+ { args: 'date --type property', comment: 'Search properties (but `wb props` might be doing a better job)' },
19
+ { args: 'date --type lexeme', comment: 'Search lexemes' },
20
+ { args: 'code --type form', comment: 'Search forms' },
21
+ { args: 'test --type sense', comment: "Searching senses doesn't seem to work currently (2020-04-17)" },
22
+ { args: '--cirrus "porte haswbstatement:P31=Q5"', comment: 'Use Cirrus search to find humans (Q5) matching "porte"' },
22
23
  ]
23
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikibase-cli",
3
- "version": "15.16.9",
3
+ "version": "16.0.1",
4
4
  "description": "A command-line interface to Wikibase",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -50,8 +50,8 @@
50
50
  "shell-quote": "^1.7.3",
51
51
  "split": "^1.0.1",
52
52
  "through": "^2.3.8",
53
- "wikibase-edit": "^4.16.1",
54
- "wikibase-sdk": "^7.14.4",
53
+ "wikibase-edit": "^5.0.0",
54
+ "wikibase-sdk": "^8.0.0",
55
55
  "wikidata-lang": "^2.0.11"
56
56
  },
57
57
  "devDependencies": {
@@ -67,6 +67,6 @@
67
67
  "should": "^13.2.3"
68
68
  },
69
69
  "engines": {
70
- "node": ">= 7.6.0"
70
+ "node": ">= 10.0.0"
71
71
  }
72
72
  }