Get article country

POST /service/lw/inference/v1/models/article-country:predict

The article-country inference service uses a Wikipedia article title and the language it was written in to determine which countries are relevant to this article. Check the model card for more info.

Examples

curl

Anonymous access

# Anonymous request
$ curl https://api.wikimedia.org/service/lw/inference/v1/models/article-country:predict -X POST -d '{"lang": "en", "title": "Toni_Morrison"}' -H "Content-type: application/json"

Logged in access

# Authenticated request using Bearer token
$ curl https://api.wikimedia.org/service/lw/inference/v1/models/article-country:predict -X POST -d '{"lang": "en", "title": "Toni_Morrison"}' -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-type: application/json"

Python

# Python 3

import json
import requests

use_auth = False
inference_url = 'https://api.wikimedia.org/service/lw/inference/v1/models/article-country:predict'

if use_auth:
    headers = {
        'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
        'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)',
        'Content-type': 'application/json'
    }
else:
    headers = {}
    
data = {"lang": "en", "title": "Toni_Morrison"}
response = requests.post(inference_url, headers=headers, data=json.dumps(data))
print(response.json())

JavaScript

const inferenceUrl = "https://api.wikimedia.org/service/lw/inference/v1/models/article-country:predict";
const accessToken = "YOUR_ACCESS_TOKEN";
const appName = "YOUR_APP_NAME";
const email = "YOUR_EMAIL_OR_CONTACT_PAGE";
let headers = new Headers({
    "Content-Type": "application/json",
    "Authorization": "Bearer " + accessToken,
    "Api-User-Agent": appName + " ( " + email + " )"
});
let data = {"lang": "en", "title": "Toni_Morrison"};

fetch(inferenceUrl, {
    method: "POST",
    headers: headers,
    body: JSON.stringify(data)
})
.then(response => response.json())
.then(inferenceData => console.log(inferenceData));

POST Parameters

lang

required

The language code for the Wikipedia article.
title

required

The wikipedia article title.

Responses

200 Success: Returns an article country object.
Example
{
  "model_name": "article-country",
  "model_version": "1",
  "prediction": {
    "article": "https://en.wikipedia.org/wiki/Toni_Morrison",
    "wikidata_item": "Q72334",
    "results": [
      {
        "country": "United States",
        "score": 1.0,
        "source": {
          "wikidata_properties": [
            {
              "P27": "country of citizenship"
            }
          ],
          "categories": [
            "Category:21st-century American women writers"
          ]
        }
      }
    ]
  }
}