Permalink
24a2ff4 Jun 28, 2018
2 contributors

Users who have contributed to this file

@maxlath @nichtich
93 lines (78 sloc) 2.74 KB

Simplify entities data

Summary

Simplify entity

Applying all simplifiers at once: labels, descriptions, aliases, claims, sitelinks. See next sections for details.

wdk.simplify.entity(entity)

You can also pass options as a second argument, that will then be passed the subfunctions: currently only simplify claims and simplify sitelinks.

const simplificationOptions = {
  // claims
  entityPrefix: 'wd',
  propertyPrefix: 'wdt',
  keepRichValues: true,
  keepQualifiers: true,
  keepReferences: true,
  keepIds: true,
  keepHashes: true,
  keepNonTruthy: true,
  // sitelinks
  addUrl: true
}
wdk.simplify.entity(entity, simplificationOptions)

Simplify entities

Same as wdk.simplify.entity, but accepts the all the entities sent by the Wikidata API at once:

const url = wdk.getEntities(['Q1', 'Q2', 'Q3'])
fetch(url)
.then(res => {
  const { entities } = res.json()
  # simplificationOptions: see wdk.simplify.entity doc above
  const simplifiedEntities = wdk.simplify.entities(entities, simplificationOptions)
})

Simplify claims

That's a huge chunk so it got it's own doc page: simplify claims

Simplify labels

wdk.simplify.labels(entity.labels)

Before: { pl: { language: 'pl', value: 'książka' } }
After: { pl: 'książka' }

Simplify descriptions

wdk.simplify.descriptions(entity.descriptions)

Before: { pl: { language: 'pl', value: 'dokument piśmienniczy [...]' } }
After: { pl: 'dokument piśmienniczy [...]' }

Simplify aliases

wdk.simplify.aliases(entity.aliases)

Before: { pl: [ { language: 'pl', value: 'Tom' }, { language: 'pl', value: 'Tomik' } ] }
After: { pl: [ 'Tom', 'Tomik' ] }

Simplify sitelinks

wdk.simplify.sitelinks(entity.sitelinks)

Before: { plwiki: { site: 'plwiki', title: 'Książka', badges: [] } }
After: { plwiki: 'Książka' }

add sitelinks URLs

wdk.simplify.sitelinks(entity.sitelinks, { addUrl: true })

Before: { plwiki: { site: 'plwiki', title: 'Książka', badges: [] } }
After: { plwiki: { title: 'Książka', url: 'https://pl.wikipedia.org/wiki/Książka' }