Skip to content

Latest commit

 

History

History
131 lines (109 loc) · 3.88 KB

simplify_entities_data.md

File metadata and controls

131 lines (109 loc) · 3.88 KB

Simplify entities data

Summary

Simplify entity

Applying all simplifiers at once. See next sections for details.

wbk.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, // For each property, keep claims with preferred rank, or normal rank if no claims has the preferred rank
  keepNonDeprecated: true, // For each property, keep all claims with preferred or normal rank

  // sitelinks
  keepBadges: true,
  addUrl: true,
}
wbk.simplify.entity(entity, simplificationOptions)

Simplify entities

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

const url = wbk.getEntities({ ids: [ 'Q1', 'P2', 'L3' ] })
const { entities } = await fetch(url).then(res => res.json())
const simplifiedEntities = wbk.simplifyEntities(entities)
// Do your thing with those entities data)

Simplify claims

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

Simplify labels

wbk.simplify.labels(entity.labels)

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

Simplify descriptions

wbk.simplify.descriptions(entity.descriptions)

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

Simplify aliases

wbk.simplify.aliases(entity.aliases)

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

Simplify sitelinks

wbk.simplify.sitelinks(entity.sitelinks)

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

keep badges

wbk.simplify.sitelinks(entity.sitelinks, { keepBadges: true })

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

NB: setting keepAll would also imply keeping sitelinks badges

add sitelinks URLs

wbk.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' }

Simplify lemmas

Specific to lexemes

wbk.simplify.lemmas(entity.lemmas)

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

Simplify forms

Specific to lexemes

// return an array of simplified forms, that is,
// the forms but with simplified representations and claims
wbk.simplify.forms(entity.forms)

Simplify senses

Specific to lexemes

// return an array of simplified senses, that is,
// the senses but with simplified glosses and claims
wbk.simplify.senses(entity.senses)