lookup(url) {
    return new Promise((resolve, reject) => {
      let qNumber = (url.match(this.supportedPattern) || [])[4];
      if (!qNumber)
        return reject(new Error('URL does not appear to contain a Q number (e.g., Q42) or is not a Wikidata URL.'));

      // in case the URL had a lower case "q"
      qNumber = qNumber.toUpperCase();

      let language = this.nativeToWikidata[config.language] || config.language;
      language = language.toLowerCase();

      let queryObj = {
        action: 'wbgetentities',
        format: 'json',
        languages: language,
        uselang: language,
        languagefallback: 1,
        props: 'labels|descriptions',
        ids: qNumber
      };

      $.get({
          url: this.apiBaseURL,
          jsonp: 'callback',
          dataType: 'jsonp',
          data: queryObj
        })
        .done(data => {
          if (typeof data !== 'object' || !data.success || !data.entities || !data.entities[qNumber])
            return reject(new Error('Did not get a valid Wikidata entity for query: ' + qNumber));

          // Descriptions result will be an empty object if no description is available, so
          const entity = data.entities[qNumber];
          // will always pass this test
          if (!entity.labels || !entity.descriptions)
            return reject(new Error('Did not get label and description information for query: ' + qNumber));

          if (!entity.labels[language])
            return reject(new Error('Did not get a label for ' + qNumber + 'for the specified language: ' + language));

          let label = entity.labels[language].value,
            description;

          if (entity.descriptions[language])
            description = entity.descriptions[language].value;

          resolve({
            data: {
              label,
              description
            },
            sourceID: this.sourceID
          });
        })
        .fail(reject);
    });
  }
/**
   * Look up a single item in Wikidata given its URL. Uses the MediaWiki API.
   *
   * @param  {String} url
   *  the URL to look up
   * @returns {Promise}
   *  resolves to a {@link LookupResult} if successful, rejects with
   *  error if not.
   */
Look up a single item in Wikidata given its URL. Uses the MediaWiki API.
@param  {String} url
the URL to look up
@returns {Promise}
resolves to a  LookupResult if successful, rejects with
error if not.
Look up a single item in Wikidata given its URL . Uses the MediaWiki API . @param { String } url the URL to look up @returns { Promise } resolves to a LookupResult if successful rejects with error if not .
lookup(url) {
    return new Promise((resolve, reject) => {
      let qNumber = (url.match(this.supportedPattern) || [])[4];
      if (!qNumber)
        return reject(new Error('URL does not appear to contain a Q number (e.g., Q42) or is not a Wikidata URL.'));
      qNumber = qNumber.toUpperCase();
      let language = this.nativeToWikidata[config.language] || config.language;
      language = language.toLowerCase();
      let queryObj = {
        action: 'wbgetentities',
        format: 'json',
        languages: language,
        uselang: language,
        languagefallback: 1,
        props: 'labels|descriptions',
        ids: qNumber
      };
      $.get({
          url: this.apiBaseURL,
          jsonp: 'callback',
          dataType: 'jsonp',
          data: queryObj
        })
        .done(data => {
          if (typeof data !== 'object' || !data.success || !data.entities || !data.entities[qNumber])
            return reject(new Error('Did not get a valid Wikidata entity for query: ' + qNumber));
          const entity = data.entities[qNumber];
          if (!entity.labels || !entity.descriptions)
            return reject(new Error('Did not get label and description information for query: ' + qNumber));
          if (!entity.labels[language])
            return reject(new Error('Did not get a label for ' + qNumber + 'for the specified language: ' + language));
          let label = entity.labels[language].value,
            description;
          if (entity.descriptions[language])
            description = entity.descriptions[language].value;
          resolve({
            data: {
              label,
              description
            },
            sourceID: this.sourceID
          });
        })
        .fail(reject);
    });
  }
lookup ( url ) { return new Promise ( ( resolve , reject ) => { let qNumber = ( url . match ( this . supportedPattern ) || [ ] ) [ 4 ] ; if ( ! qNumber ) return reject ( new Error ( 'URL does not appear to contain a Q number (e.g., Q42) or is not a Wikidata URL.' ) ) ; qNumber = qNumber . toUpperCase ( ) ; let language = this . nativeToWikidata [ config . language ] || config . language ; language = language . toLowerCase ( ) ; let queryObj = { action : 'wbgetentities' , format : 'json' , languages : language , uselang : language , languagefallback : 1 , props : 'labels|descriptions' , ids : qNumber } ; $ . get ( { url : this . apiBaseURL , jsonp : 'callback' , dataType : 'jsonp' , data : queryObj } ) . done ( data => { if ( typeof data !== 'object' || ! data . success || ! data . entities || ! data . entities [ qNumber ] ) return reject ( new Error ( 'Did not get a valid Wikidata entity for query: ' + qNumber ) ) ; const entity = data . entities [ qNumber ] ; if ( ! entity . labels || ! entity . descriptions ) return reject ( new Error ( 'Did not get label and description information for query: ' + qNumber ) ) ; if ( ! entity . labels [ language ] ) return reject ( new Error ( 'Did not get a label for ' + qNumber + 'for the specified language: ' + language ) ) ; let label = entity . labels [ language ] . value , description ; if ( entity . descriptions [ language ] ) description = entity . descriptions [ language ] . value ; resolve ( { data : { label , description } , sourceID : this . sourceID } ) ; } ) . fail ( reject ) ; } ) ; }
Look up a single item in Wikidata given its URL.
Look up a single item in Wikidata given its URL .
// in case the URL had a lower case "q" // Descriptions result will be an empty object if no description is available, so // will always pass this test