Access Wikidata in JSKOS format
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
assets
bin
lib
scripts
test
.editorconfig
.eslintrc.js
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
README.md
ecosystem.config.json
package.json
server.js

README.md

Wikidata JSKOS

License Build Status standard-readme compliant

Access Wikidata in JSKOS format

This node module provides a web service, a command line client, and a library to access Wikidata in JSKOS format.

Table of Contents

Background

Wikidata is a large knowledge base with detailed information about all kinds of entities. Mapping its data model to JSKOS data format allows simplified reuse of Wikidata as authority file. The mapping includes concordances between Wikidata and identifiers from other databases.

See Also

Install

Clone and install dependencies

# clone the repository
git clone https://github.com/gbv/wikidata-jskos.git
cd wikidata-jskos

# install dependencies
npm install

Install webservice

For deployment there is a config file to use with pm2:

pm2 start ecosystem.config.json

For development serve with hot reload and auto reconnect at http://localhost:2013/:

npm run start

Configuration

Basic configuration is possible via environment variables, also possible via .env file. See lib/config.js for supported fields and default values.

Usage

Web Service

An instance is available at https://coli-conc.gbv.de/services/wikidata/. The service provides the following endpoints, aligned with JSKOS Server.

/concept

Look up Wikidata items as JSKOS Concepts by their entity URI or QID.

  • URL Params

    uri=[uri] URIs for concepts separated by |.

    language or languages: comma separated list of language codes.

  • Success Response

    JSON array of JSKOS Concepts

/mappings

Look up Wikidata mapping statements as JSKOS Concept Mappings between Wikidata items (query parameter from) and external identifiers (query parameter to). At least one of both parameters must be given.

  • URL Params

    from=[uri|notation] specify the source URI or notation

    to=[uri|notation] specify the target URI or notation

    fromScheme=[uri|notation] only show mappings from this concept scheme (URI or notation)

    toScheme=[uri|notation] only show mappings to this concept scheme (URI or notation)

    language or languages enables inclusion of entity labels. A comma separated list of language codes is used as preference list.

    mode=[mode] specify the mode for from, to, one of and (default) and or

    direction=forward|backward|both searches mappings from from to to (default), reverse, or in both directions

Concept Schemes are identified by BARTOC IDs (e.g. http://bartoc.org/en/node/430 or just 430).

  • Success Response

    JSON array of JSKOS Concept Mappings

  • Examples

    ?from=http://www.wikidata.org/entity/Q42

    ?to=http://d-nb.info/gnd/119033364

Mapping relation types (P4390) are respected, if given, see for example mapping from Wikidata to http://d-nb.info/gnd/7527800-5.

/mappings/voc

Look up Wikidata items with Wikidata properties for authority control as JSKOS Concept Schemes with used for mappings. These schemes need to have a BARTOC-ID (P2689), and be subject item (P1629) of an external identifier property with statements P1921 (URI template) and P1793 (regular expression).

Command Line Interface

The command line client wdjskos provides the same commands as accessible via the web service:

wdjskos concept

Look up Wikidata items as JSKOS Concepts.

wdjskos mappings

Look up JSKOS Concept Mappings.

wdjskos schemes

Look up JSKOS Concept Schemes with Wikidata properties for authority control.

Examples

Get mappings:

wdjskos mappings Q42 | jq .to.memberSet[].uri
wdjskos mappings - http://viaf.org/viaf/113230702

A single hyphen (-) can be used to nullify argument from or to, respectively. Mappings can be limited to a target scheme. These are equivalent:

wdjskos --scheme P227 mappings Q42
wdjskos --scheme 430 mappings Q42
wdjskos --scheme http://bartoc.org/en/node/430 mappings Q42

Mapping schemes are cached in the caching directory of wikidata-cli.

API

jskos = wds.mapEntity(entity)

Entity data can be retrieved via Wikidata API method wbgetentities and from Wikidata database dumps. See JavaScript libraries wikidata-sdk and wikidata-filter for easy access and processing.

Map selected parts of a Wikidata entity

All methods return a JSKOS item.

jskos = wds.mapIdentifier(entity.id)
// { uri: "http://www.wikidata.org/entity/...", notation: [ "..." ] }

jskos = wds.mapLabels(entity.labels)
// { prefLabel: { ... } }

jskos = wds.mapAliases(entity.aliases)
// { altLabel: { ... } }

jskos = wds.mapDescriptions(entity.descriptions)
// { scopeNote: { ... } }

jskos = wds.mapSitelinks(entity.sitelinks)
// ...

jskos = wds.mapClaims(entity.claims)
// ...

// convert claims with mapping properties
jskos = wds.mapMappingClaims(claims)

jskos = wds.mapInfo(entity)
// ...

Map simplified Wikidata entities

Each method has a counterpart to map simplified Wikidata entities.

jskos = wds.mapSimpleEntity(entity)
jskos = wds.mapSimpleIdentifier(entity.id)
jskos = wds.mapSimpleLabels(entity.labels)
...

Contributing

See https://github.com/gbv/wikidata-jskos.

For debugging set environment variable DEBUG, also possible via file .env:

DEBUG=wds:*

See lib/utils/debug.js for details.

License

MIT License