How to use the wikidata-sdk.simplify function in wikidata-sdk

To help you get started, we’ve selected a few wikidata-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github maxlath / wikidata-filter / lib / format_entity.js View on Github external
const filterLanguages = languages != null

    // keep only the desired attributes
    if (filterAttributes) entity = pick(entity, keep)

    // with the desired languages
    if (filterLanguages) {
      attributesWithLanguages.forEach(attr => {
        if (entity[attr]) entity[attr] = pick(entity[attr], languages)
      })
      entity.sitelinks = keepMatchingSitelinks(entity.sitelinks, languages)
    }

    // with simplify claims and text attributes if requested
    if (simplify) {
      entity = wdk.simplify.entity(entity, simplifyOptions)
    }

    return entity
  }
}
github osmlab / name-suggestion-index / build_wikidata.js View on Github external
}

    // P3836 - Pinterest ID
    const pinterestUser = getClaimValue(entity, 'P3836');
    if (pinterestUser) {
      target.identities.pinterest = pinterestUser;
    }

    // P4264 - LinkedIn Company ID
    const linkedinUser = getClaimValue(entity, 'P4264');
    if (linkedinUser) {
      target.identities.linkedin = linkedinUser;
    }

    // P576 - Dissolution date
    wdk.simplify.propertyClaims(entity.claims.P576, { keepQualifiers: true }).forEach(item => {
      let dissolution = { date: item.value };

      if (item.qualifiers) {
        // P17 - Countries where the brand is dissoluted
        let countries = item.qualifiers.P17;
        if (countries) {
          dissolution.countries = countries;
          countryCodesQueue.push({ qid: qid, index: target.dissolutions.length, countries: countries });
        }

        // P156 - followed by or P1366 - replaced by (successor)
        let successor = item.qualifiers.P156 || item.qualifiers.P1366;
        if (successor) {
          dissolution.upgrade = successor;
        }
      }
github osmlab / name-suggestion-index / check_wikiTags.js View on Github external
Object.keys(result.entities).forEach(qid => {
        let entity = result.entities[qid];
        let target = _data.wikidata[qid];
        let entry = _brands[target];

        let sitelinks = getSitelinks(entity);
        let claims = wdk.simplify.claims(entity.claims, {
            keepReferences: true
        });
        let instance = entity.claims && entity.claims.P31;

        let tag = entry.tags['brand:wikidata'] === qid ? 'brand' : 'operator';
        let wikipedia = entry.tags[`${tag}:wikipedia`];

        // Wikidata entity was either deleted or is a redirect
        if (entity.missing === '') {
            return _deletedWikidata.push([target, qid, `${tag}:wikidata`]);
        }

        // If there is a Wikidata entity specified but no Wikipedia article,
        // try to find a matching article from all possible sitelinks
        if (!wikipedia && sitelinks.length) {
            _foundSitelink.push([target, qid, `${tag}:wikidata`, sitelinks.join(', ')]);
github coala / gci-leaders / lib / scrape.js View on Github external
ids: [wikidata_id],
    props: ['claims'],
  })
  const page = await fetch(wikiAPIurl)
  let data = await page.json()
  data = data.entities[wikidata_id]

  if (!(WIKI_SE_TAG in data.claims)) {
    return null
  }

  data.claims[WIKI_SE_TAG].sort(
    (a, b) => WIKI_CLAIM_PRIORITY[a.rank] - WIKI_CLAIM_PRIORITY[b.rank]
  )

  const url = wdk.simplify.claim(data.claims[WIKI_SE_TAG][0])
  const response = await fetch(url)
  const txt = await response.text()
  const html = cheerio.load(txt)

  const image = html('link')
    .filter((i, el) => html(el).attr('rel') === 'apple-touch-icon image_src')
    .attr('href')

  return {
    url,
    image,
  }
}