Image sources¶
Collect images connected to the following sources:
Wikidata image property
Wikidata Commons category property
Wikipedia article lead images
Commons depicts statements
- image_suggestions.entity_images.get_wikidata(spark, hive_db, weekly_snapshot)[source]¶
Gather image and Commons category Wikidata claims.
This function invokes
image_suggestions.shared.load_wikidata()and aggregates claims by image.- Parameters:
- Return type:
DataFrame- Returns:
the dataframe of:
item_id (string) - Wikidata QID
page_id (bigint) - Commons image page ID
tag (array<string>) -
image.linked.from.wikidata.p18and/orimage.linked.from.wikidata.p373tags
- image_suggestions.entity_images.get_depicts(spark, hive_db, weekly_snapshot)[source]¶
Gather Commons depicts statements.
- image_suggestions.entity_images.get(spark, hive_db, weekly_snapshot, include_wikidata=True, include_lead_images=True, include_sdc=True, limit_per_qid=0)[source]¶
Aggregate all sources of image connections.
Compute an image suggestion confidence score between 0 and 100 based on the sources: if an image has one source, it will inherit its score. Otherwise, it will be a combined or probability.
For instance, Commons categories and depicts statements have a score of
80and70respectively. If an image is connected to both of them, then the final score will be:100 x ( 1 - (1 - 0.8) x (1 - 0.7) ) = 97
More details here.
- Parameters:
spark (
SparkSession) – an active Spark sessionhive_db (
str) –a Data Lake’s Hive database name
weekly_snapshot (
str) – aYYYY-MM-DDdateinclude_wikidata (
bool) – whether to include Wikidata claimsinclude_lead_images (
bool) – whether to include Wikipedia article lead imagesinclude_sdc (
bool) – whether to include Commons depicts statementslimit_per_qid (
int) – an integer that limits the amount of suggestions per Wikidata QID. If> 0, suggestions are ordered by confidence.0stands for no limit
- Return type:
DataFrame- Returns:
the dataframe of:
item_id (string) - Wikidata QID
page_title (string) - Commons image page title, in original case and underscored
found_on (array<string>) - wikis where the image was found
kind (array<string>) - sources of image connections. Values can be
istype-depicts,istype-wikidata-image,istype-commons-category, and/oristype-lead-imageconfidence (int) - suggestion confidence score