Class: WikidataAutocompleteAdapter

WikidataAutocompleteAdapter()

This module performs shallow lookups on Wikidata. They are shallow in that they only load the information that needs to be displayed to the user in their current language. The backend version of this adapter performs the actual deep lookup for all languages.

Constructor

new WikidataAutocompleteAdapter()

See AbstractAutocompleteAdapter for parameter documentation, not shown here due to jsdoc bug.

Source:

Extends

  • AbstractAutocompleteAdapter

Members

acDelay :Number

We override the default; Wikidata can take more of a beating than some other sites. :)

Type:
  • Number
Source:

acPrimaryTextKey :String

We override the default, because we may display different text (stored in this field) than what we pass along to the application (stored in the label field). The display text may include a parenthetical component that highlights a match against an alias, rather than the primary label.

Type:
  • String
Source:

displayResults :Number

Type:
  • Number
Source:
See:

excludedItemClasses :Array.<String>

Items with these classes are typically not going to be the target of reviews.

Type:
  • Array.<String>
Source:

fetchResults :Number

Because we exclude certain item classes (e.g., disambiguation pages), we fetch a larger number of results than we may need, since we may eliminate some of them. The ratio configured here has proven to strike a good balance where few queries result in zero "good" results.

Type:
  • Number
Source:

nativeToWikidata :Object

How do lib.reviews language code translate to Wikidata language codes? lib.reviews language code are used as keys, Wikidata codes as values.

Since Wikidata supports a superset of languages and most language code are identical, we only enumerate exceptions.

Type:
  • Object
Source:

queryServiceTimeout :Number

Timeout for query service validation requests in milliseconds

Type:
  • Number
Source:

Methods

_extractRowHandler(item, queryString) → {Object}

Transform a result from the Wikidata item into a row that can be rendered by the autocomplete widget.

This:
  • WikidataAutocompleteAdapter#ac
Parameters:
Name Type Description
item Object

a query result returned by the SPARQL query service (member of bindings array)

queryString String

the original (unescaped) query string is used for highlighting the match in a composite title that includes both the label and the alias against which the query matched

Source:
Returns:

plain object that only contains the data we can use inside the application, plus a derived title property for rendering this row in the autocomplete widget.

Type
Object

_renderNavHandler(spec)

Render next/previous navigation within the autocomplete widget.

This:
  • WikidataAutocompleteAdapter#ac
Parameters:
Name Type Description
spec Object

Navigation settings

Properties
Name Type Description
isFirstPage Boolean

First page of results doesn't get a "previous page" icon and click handler that calls WikidataAutocompleteAdapter#_requestHandler (previously loaded results are not cached)

thereAreMoreResults Boolean

If true, render "next page" icon and attach click handler that calls request handler

bindings Array

the bindings property of a Wikidata query service result from a SPARQL query - this contains the actual search result data

offset Number

the offset that was used for the search we're rendering navigation for

queryString String

the original (unescaped) query string, used by the click handler to fire off subsequent requests

Source:

_requestHandler(query, offsetopt)

Send an autocomplete request to the Wikidata query service and render the result using the autocomplete widget.

Parameters:
Name Type Attributes Description
query String

the query string

offset Number <optional>

the offset from which to continue a previous query.

Source:

lookup(url) → {Promise}

Look up a single item in Wikidata given its URL. Uses the MediaWiki API.

Parameters:
Name Type Description
url String

the URL to look up

Source:
Returns:

resolves to a LookupResult if successful, rejects with error if not.

Type
Promise