Fix: fix #2183 by updating wikidata-sdk to latest wikibase-sdk
This commit is contained in:
parent
45fe5767e1
commit
021e5f2734
4 changed files with 54 additions and 24 deletions
39
package-lock.json
generated
39
package-lock.json
generated
|
@ -79,8 +79,7 @@
|
|||
"turndown": "^7.1.3",
|
||||
"vite-node": "^0.28.3",
|
||||
"vitest": "^0.28.3",
|
||||
"wikibase-sdk": "^7.14.0",
|
||||
"wikidata-sdk": "^7.14.0",
|
||||
"wikibase-sdk": "^10.1.1",
|
||||
"xml2js": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -20745,15 +20744,19 @@
|
|||
}
|
||||
},
|
||||
"node_modules/wikibase-sdk": {
|
||||
"version": "7.15.0",
|
||||
"license": "MIT",
|
||||
"version": "10.1.1",
|
||||
"resolved": "https://registry.npmjs.org/wikibase-sdk/-/wikibase-sdk-10.1.1.tgz",
|
||||
"integrity": "sha512-ePSfVhHeJ5ljAxde7O9ryzIBeNF54RB+LTn5naF+mUitDJeRkrgz2ZTxl89EMDzJeHUV4VnwVmLRWRcDqPA9Ng==",
|
||||
"engines": {
|
||||
"node": ">= 6.4"
|
||||
"node": ">= 12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/wikidata-sdk": {
|
||||
"version": "7.14.4",
|
||||
"license": "MIT",
|
||||
"resolved": "https://registry.npmjs.org/wikidata-sdk/-/wikidata-sdk-7.14.4.tgz",
|
||||
"integrity": "sha512-UAFBXWLxEWvB0Pn/c+ekc1voU8o0zR7T3kRt9xHLyfy2OiV7W1htk2iErwJdfisBPDb2a35HUgf2x1+ZAdrM8A==",
|
||||
"deprecated": "wikidata-sdk has been renamed wikibase-sdk",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"wikibase-sdk": "^7.14.4"
|
||||
},
|
||||
|
@ -20761,6 +20764,15 @@
|
|||
"node": ">= 6.4"
|
||||
}
|
||||
},
|
||||
"node_modules/wikidata-sdk/node_modules/wikibase-sdk": {
|
||||
"version": "7.15.0",
|
||||
"resolved": "https://registry.npmjs.org/wikibase-sdk/-/wikibase-sdk-7.15.0.tgz",
|
||||
"integrity": "sha512-EZvOVz2Ezx1IsiSTlJ5XF1SLLudzWvtm7CV5DYKhO7CIX4EkB0Pc8seb8h6ZNEPRgYqnmrTx5aLsaIQW7GBe2w==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">= 6.4"
|
||||
}
|
||||
},
|
||||
"node_modules/winston": {
|
||||
"version": "3.13.0",
|
||||
"license": "MIT",
|
||||
|
@ -35251,12 +35263,25 @@
|
|||
}
|
||||
},
|
||||
"wikibase-sdk": {
|
||||
"version": "7.15.0"
|
||||
"version": "10.1.1",
|
||||
"resolved": "https://registry.npmjs.org/wikibase-sdk/-/wikibase-sdk-10.1.1.tgz",
|
||||
"integrity": "sha512-ePSfVhHeJ5ljAxde7O9ryzIBeNF54RB+LTn5naF+mUitDJeRkrgz2ZTxl89EMDzJeHUV4VnwVmLRWRcDqPA9Ng=="
|
||||
},
|
||||
"wikidata-sdk": {
|
||||
"version": "7.14.4",
|
||||
"resolved": "https://registry.npmjs.org/wikidata-sdk/-/wikidata-sdk-7.14.4.tgz",
|
||||
"integrity": "sha512-UAFBXWLxEWvB0Pn/c+ekc1voU8o0zR7T3kRt9xHLyfy2OiV7W1htk2iErwJdfisBPDb2a35HUgf2x1+ZAdrM8A==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"wikibase-sdk": "^7.14.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"wikibase-sdk": {
|
||||
"version": "7.15.0",
|
||||
"resolved": "https://registry.npmjs.org/wikibase-sdk/-/wikibase-sdk-7.15.0.tgz",
|
||||
"integrity": "sha512-EZvOVz2Ezx1IsiSTlJ5XF1SLLudzWvtm7CV5DYKhO7CIX4EkB0Pc8seb8h6ZNEPRgYqnmrTx5aLsaIQW7GBe2w==",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"winston": {
|
||||
|
|
|
@ -224,8 +224,7 @@
|
|||
"turndown": "^7.1.3",
|
||||
"vite-node": "^0.28.3",
|
||||
"vitest": "^0.28.3",
|
||||
"wikibase-sdk": "^7.14.0",
|
||||
"wikidata-sdk": "^7.14.0",
|
||||
"wikibase-sdk": "^10.1.1",
|
||||
"xml2js": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* Some meta-info (e.g. RTL) is exported too
|
||||
*/
|
||||
|
||||
import * as wds from "wikidata-sdk"
|
||||
import { Utils } from "../src/Utils"
|
||||
import ScriptUtils from "./ScriptUtils"
|
||||
import { existsSync, readFileSync, writeFileSync } from "fs"
|
||||
|
@ -44,10 +43,10 @@ async function fetchRegularLanguages() {
|
|||
" ?lang wdt:P424 ?code. \n" + // Wikimedia language code seems to be close to the weblate entries
|
||||
' SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } \n' +
|
||||
"} "
|
||||
const url = wds.sparqlQuery(sparql)
|
||||
const url = Wikidata.wds.sparqlQuery(sparql)
|
||||
|
||||
// request the generated URL with your favorite HTTP request library
|
||||
const result = await Utils.downloadJson(url, { "User-Agent": "MapComplete script" })
|
||||
const result = await Utils.downloadJson<{results: {bindings: any[]}}>(url, { "User-Agent": "MapComplete script" })
|
||||
const bindings = <LanguageSpecResult[]>result.results.bindings
|
||||
|
||||
// Traditional chinese = 繁體中文 or 正體中文
|
||||
|
@ -97,9 +96,9 @@ async function fetchSpecial(id: number, code: string): Promise<LanguageSpecResul
|
|||
' SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } \n' +
|
||||
"} "
|
||||
console.log("Special sparql:", sparql)
|
||||
const url = wds.sparqlQuery(sparql)
|
||||
const url = Wikidata.wds.sparqlQuery(sparql)
|
||||
|
||||
const result = await Utils.downloadJson(url, { "User-Agent": "MapComplete script" })
|
||||
const result = await Utils.downloadJson<{results: {bindings: any[]}}>(url, { "User-Agent": "MapComplete script" })
|
||||
const bindings = result.results.bindings
|
||||
bindings.forEach((binding) => (binding["code"] = { value: code }))
|
||||
return bindings
|
||||
|
@ -133,9 +132,9 @@ async function getOfficialLanguagesPerCountry(): Promise<Map<string, string[]>>
|
|||
?language wdt:P218 ?languageCode.
|
||||
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
|
||||
}`
|
||||
const url = wds.sparqlQuery(sparql)
|
||||
const url = Wikidata.wds.sparqlQuery(sparql)
|
||||
|
||||
const result = await Utils.downloadJson(url, { "User-Agent": "MapComplete script" })
|
||||
const result = await Utils.downloadJson<{results: {bindings: any[]}}>(url, { "User-Agent": "MapComplete script" })
|
||||
const bindings: { countryCode: { value: string }; languageCode: { value: string } }[] =
|
||||
result.results.bindings
|
||||
for (const binding of bindings) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Utils } from "../../Utils"
|
||||
import { Store, UIEventSource } from "../UIEventSource"
|
||||
import * as wds from "wikidata-sdk"
|
||||
import { WBK} from "wikibase-sdk"
|
||||
|
||||
export class WikidataResponse {
|
||||
public readonly id: string
|
||||
|
@ -54,7 +54,8 @@ export class WikidataResponse {
|
|||
}
|
||||
|
||||
static extractClaims(claimsJson: any): Map<string, Set<string>> {
|
||||
const simplified = wds.simplify.claims(claimsJson, {
|
||||
// @ts-ignore
|
||||
const simplified = Wikidata.wds.simplify.claims(claimsJson, {
|
||||
timeConverter: "simple-day",
|
||||
})
|
||||
|
||||
|
@ -127,6 +128,12 @@ interface SparqlResult {
|
|||
* Utility functions around wikidata
|
||||
*/
|
||||
export default class Wikidata {
|
||||
|
||||
public static wds = WBK({
|
||||
instance: "https://wikidata.org",
|
||||
sparqlEndpoint: "https://query.wikidata.org/bigdata/namespace/wdq/sparql"
|
||||
})
|
||||
|
||||
public static readonly neededUrls = [
|
||||
"https://www.wikidata.org/",
|
||||
"https://wikidata.org/",
|
||||
|
@ -204,7 +211,7 @@ export default class Wikidata {
|
|||
${instanceOf}
|
||||
${minusPhrases.join("\n ")}
|
||||
} ORDER BY ASC(?num) LIMIT ${options?.maxCount ?? 20}`
|
||||
const url = wds.sparqlQuery(sparql)
|
||||
const url = Wikidata. wds.sparqlQuery(sparql)
|
||||
|
||||
const result = await Utils.downloadJson<SparqlResult>(url)
|
||||
/*The full uri of the wikidata-item*/
|
||||
|
@ -245,9 +252,9 @@ export default class Wikidata {
|
|||
lang +
|
||||
"&type=item&origin=*" +
|
||||
"&props=" // props= removes some unused values in the result
|
||||
const response = await Utils.downloadJsonCached(url, 10000)
|
||||
const response = await Utils.downloadJsonCached<{search: any[]}>(url, 10000)
|
||||
|
||||
const result: any[] = response.search
|
||||
const result = response.search
|
||||
|
||||
if (result.length < pageCount) {
|
||||
// No next page
|
||||
|
@ -375,7 +382,7 @@ export default class Wikidata {
|
|||
/**
|
||||
* Build a SPARQL-query, return the result
|
||||
*
|
||||
* @param keys: how variables are named. Every key not ending with 'Label' should appear in at least one statement
|
||||
* @param keys how variables are named. Every key not ending with 'Label' should appear in at least one statement
|
||||
* @param statements
|
||||
* @constructor
|
||||
*/
|
||||
|
@ -392,9 +399,9 @@ export default class Wikidata {
|
|||
statements.map((stmt) => (stmt.endsWith(".") ? stmt : stmt + ".")).join("\n") +
|
||||
' SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }\n' +
|
||||
"}"
|
||||
const url = wds.sparqlQuery(query)
|
||||
const url = Wikidata.wds.sparqlQuery(query)
|
||||
const result = await Utils.downloadJsonCached<SparqlResult>(url, 24 * 60 * 60 * 1000)
|
||||
return result.results.bindings
|
||||
return <any> result.results.bindings
|
||||
}
|
||||
|
||||
private static _cache = new Map<string, Promise<WikidataResponse>>()
|
||||
|
|
Loading…
Reference in a new issue