wikidata-entity-store v3.0.0
wikidata-entity-store
Handles loading and caching of Wikidata Entities for you
This library is meant to be used in a NodeJS environment. Internally got is used to get the wikidata entities which is a library meant for NodeJS usage.
Install
$ npm install wikidata-entity-store
Usage
const WikidataEntityStore = require('wikidata-entity-store');
const store = new WikidataEntityStore();
// cache Q2 and Q5 into the store
await store.addResourceKeyDict({human: 'Q5', earth: 'Q2'});
store.qNumber('human');
//=> 'Q5'
store.entity('human')
//=> {id: 'Q5', …}
// or use it for unnamed entities
await store.preloadQNumbers('Q42', 'Q1337')
store.entity('Q42')
//=> {id: 'Q42', …}
API
new WikidataEntityStore
const store = new WikidataEntityStore([options])
options
Type: Object
properties
Type: Array<Property>
Properties (props) to be loaded for each Entity. If not supplied it defaults to everything. Its strongly advised to limit it to only what you need in order to save bandwidth and storage space.
entityStore
Type: Map<string, EntitySimplified>
Supply your own persistant cache for entities. Per default entities are cached in memory.
store.addResourceKeyDict
await store.addResourceKeyDict(resourceKeys);
await store.addResourceKeyDict({human: 'Q5', earth: 'Q2'});
resourceKeys
Type: Record<string, string>
- Key: human readable key for easier development of your tool
- Value: Q-Number
store.addResourceKeyArr
await store.addResourceKeyArr(resourceKeys);
await store.addResourceKeyArr([
{key: 'human', qNumber: 'Q5'},
{key: 'earth', qNumber: 'Q2'}
]);
resourceKeys
Type: ReadonlyArray<{key: string; qNumber: string}>
key
: human readable key for easier development of your toolqNumber
: Q-Number
store.preloadQNumbers
Load Q-Numbers into cache. If a Q-Number is already cached it is not loaded again.
await store.preloadQNumbers(...qNumbers)
await store.preloadQNumbers('Q42', 'Q1337')
store.forceloadQNumbers
Load Q-Numbers into cache. If a Q-Number is already cached it is loaded again.
await store.forceloadQNumbers(...qNumbers)
await store.forceloadQNumbers('Q42', 'Q1337')
store.qNumber
Get the qNumber of the given key or Q-Number
const qNumber = store.qNumber(keyOrQNumber);
const qNumber = store.qNumber('human');
const qNumber = store.qNumber('Q42');
store.entity
Get the entity of the given key or Q-Number.
This is currently the simplified version of the entity (EntitySimplified
) in order to have a smaller cache.
See wikibase-sdk for more information about it.
const entity = store.entity(keyOrQNumber);
const entity = store.entity('human');
const entity = store.entity('Q42');
store.availableResourceKeys
List of all available resource keys specified with addResourceKeyDict
or addResourceKeyArr
.
const results = store.availableResourceKeys();
//=> ['human', 'earth']
store.availableEntities
List all cached entity Q-Numbers.
const results = store.availableEntities()
//=> ['Q5', 'Q2', 'Q42', 'Q1337']
store.allEntities
Get all EntitySimplified
currently cached.
const results = store.allEntities()
//=> [{id: 'Q5', …}, …]
License
MIT © EdJoPaTo