# Wikidata

> Look up structured facts from Wikidata, the free knowledge base behind Wikipedia: search for entities by name, read an entity's statements as readable property/value pairs, resolve a Wikipedia article to its entity, and run SPARQL queries. No account or API key required.

App · Misc References · 4 actions. Web page: https://docs.lodol.com/docs/integrations/wikidata

## Actions

### Find Wikidata entity by Wikipedia title

Resolve a Wikipedia article title to the Wikidata entity behind it. Use this when you already have an article name and want its structured data. Returns a null entity id when no article matches, rather than failing.

**Inputs**

- Title (`title`, text, required): Wikipedia article title, e.g. Ada Lovelace. Capitalisation and underscores are normalised for you.
- Wikipedia site (`wikipedia_site`, text): Which Wikipedia the title belongs to, e.g. enwiki, frwiki, dewiki. Defaults to enwiki.
- Language (`language`, text): Language code for labels and descriptions, e.g. en, fr, de, ja. Defaults to en.

**Outputs**

- `concept_uri` (text): Stable RDF identifier. Null when nothing matched.
- `description` (text): One-line description. Null when nothing matched.
- `entity_id` (text): Wikidata entity id for the article, e.g. Q7259. Null when no article matches the title.
- `label` (text): Entity name. Null when nothing matched.
- `url` (text): wikidata.org page for the entity. Null when nothing matched.

**Example output**

```json
{
  "concept_uri": "http://www.wikidata.org/entity/Q7259",
  "description": "English mathematician (1815-1852)",
  "entity_id": "Q7259",
  "label": "Ada Lovelace",
  "url": "https://www.wikidata.org/wiki/Q7259"
}
```

### Get Wikidata entity

Get everything Wikidata records about one entity: its name, description, aliases, Wikipedia link, and its statements as readable property/value pairs (e.g. 'date of birth' → 1815-12-10). Optionally narrow it to just the properties you need.

**Inputs**

- Entity ID (`entity_id`, text, required): Wikidata entity id, e.g. Q7259. You can get this from the Search Wikidata action.
- Language (`language`, text): Language code for labels and descriptions, e.g. en, fr, de, ja. Defaults to en.
- Properties (`properties`, text): Optional comma-separated property ids to return, e.g. P569,P570,P106. Leave blank to return every statement, which for a well-covered entity can be a few hundred.
- Wikipedia site (`wikipedia_site`, text): Which Wikipedia to link to, e.g. enwiki, frwiki, dewiki. Defaults to enwiki.

**Outputs**

- `entity` (object)

**Example output**

```json
{
  "entity": {
    "aliases": [
      "Lady Ada",
      "Augusta Ada King, Countess of Lovelace"
    ],
    "concept_uri": "http://www.wikidata.org/entity/Q7259",
    "description": "English mathematician (1815-1852)",
    "id": "Q7259",
    "label": "Ada Lovelace",
    "statement_count": 2,
    "statements": [
      {
        "property_id": "P106",
        "property_label": "occupation",
        "values": [
          {
            "entity_id": "Q170790",
            "unit_id": null,
            "value": "mathematician"
          },
          {
            "entity_id": "Q5482740",
            "unit_id": null,
            "value": "programmer"
          }
        ]
      },
      {
        "property_id": "P569",
        "property_label": "date of birth",
        "values": [
          {
            "entity_id": null,
            "unit_id": null,
            "value": "1815-12-10T00:00:00Z"
          }
        ]
      }
    ],
    "url": "https://www.wikidata.org/wiki/Q7259",
    "wikipedia_url": "https://en.wikipedia.org/wiki/Ada_Lovelace"
  }
}
```

### Run Wikidata SPARQL query

Run a SPARQL query against the Wikidata Query Service. Use this for questions no single lookup answers, such as listing every item matching a set of conditions. Returns one row per result with the query's own variable names as keys.

**Inputs**

- Query (`query`, text, required): SPARQL query text. Add a LIMIT clause: the service caps a query at 60 seconds and will reject one that scans too much. Include the wikibase:label service to get readable names alongside ids.

**Outputs**

- `count` (number): Number of rows returned.
- `rows` (list): One entry per result row, keyed by the query's own variable names with the plain values. A variable left unbound for a row, as an OPTIONAL clause can leave it, is absent from that row.
- `variables` (list): The variable names the query selected, in order. These are the keys on each row.

**Example output**

```json
{
  "count": 1,
  "rows": [
    {
      "item": "http://www.wikidata.org/entity/Q12418",
      "itemLabel": "Mona Lisa"
    }
  ],
  "variables": [
    "item",
    "itemLabel"
  ]
}
```

### Search Wikidata

Search Wikidata for people, places, organisations, works, and concepts by name. Returns the matching entity ids, which the other Wikidata actions take as input.

**Inputs**

- Query (`query`, text, required): Text to search for, e.g. Ada Lovelace.
- Language (`language`, text): Language code for labels and descriptions, e.g. en, fr, de, ja. Defaults to en.
- Limit (`limit`, number): How many results to return, 1 to 50. Defaults to 10.
- Entity type (`entity_type`, text): What kind of entity to search for. Defaults to item, which covers people, places, and things. Use property to find the P-ids used in statements. One of: `item` (Item (Q-id)), `property` (Property (P-id)), `lexeme`, `form`, `sense`.

**Outputs**

- `count` (number): Number of results returned.
- `results` (list): Matching entities, best match first.

**Example output**

```json
{
  "count": 1,
  "results": [
    {
      "concept_uri": "http://www.wikidata.org/entity/Q7259",
      "description": "English mathematician (1815-1852)",
      "id": "Q7259",
      "label": "Ada Lovelace",
      "match_text": "Ada Lovelace",
      "url": "https://www.wikidata.org/wiki/Q7259"
    }
  ]
}
```
