8

Is there a database of fictional characters from novels, films, dramas etc., grouped by genre?

The most important entries for me are the name, nationality (real or fictional), title of the novel/film/drama and the genre.

6
  • I don't think that a data set of fictional characters fall under the open data concept.
    – Kermit
    Commented May 10, 2013 at 22:41
  • 2
    @FreshPrinceOfSO Why not? Commented May 15, 2013 at 23:23
  • 7
    This seems like a perfectly valid question to me. Why was it closed? The current FAQ doesn't prescribe what kind of data can be discussed, and the question is very clear.
    – ldodds
    Commented May 24, 2013 at 9:04
  • 5
    Please anyone reopen this question, it is a valid question. My answer would be to use SPARQL to query DBpedia for all children of dbpedia.org/describe/…
    – Nicolas Raoul
    Commented Jun 5, 2013 at 7:03
  • It might be on topic, but it's way too broad. You'd have to deal with every book, tv show, movie, play, opera, comic book, etc. In English and in every other language. It'd be challenging enough just trying to get a list of all fiction books in English.
    – Joe
    Commented Jun 5, 2013 at 20:23

3 Answers 3

8

Wikidata contains 158752 fictional characters, you can get them using this query:

SELECT ?item ?itemLabel WHERE {
  # Item's type is: fictional character, or sub-type, or sub-sub-type, etc
  ?item p:P31/ps:P31/wdt:P279* wd:Q95074.  
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}

Just run it by clicking here and download as CSV, TSV or JSON.

https://www.wikidata.org/wiki/Q95074 is the "fictional character" item.

You can get more properties about each by adding OPTIONAL lines (and corresponding label in the first line), like this:

SELECT ?item ?itemLabel ?presentInWorkLabel ?countryOfCitizenshipLabel ?image WHERE {
  # Item's type is: fictional character, or sub-type, or sub-sub-type, etc.
  ?item p:P31/ps:P31/wdt:P279* wd:Q95074.
  OPTIONAL{?item wdt:P18 ?image}
  OPTIONAL{?item wdt:P27 ?countryOfCitizenship}
  OPTIONAL{?item wdt:P1441 ?presentInWork}
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en". # You can specify more languages.
  }
}

The problem is that the query times out easily, so you might have to run it several times with different properties then match the QID identifiers.

Excerpt from the output:

enter image description here

Please note that the same fictional character can appear in different works, which can be of different genres.

To get genres, you could use OPTIONAL{?item wdt:P1441 ?work. OPTIONAL{?work wdt:P136 ?genre}} but timeouts will become difficult to avoid so you will have to limit your query.

Try it to get a result like this:

enter image description here

To reliably get all properties of all fictional characters, I believe (I would love to be proved wrong, if you know another way please comment) that your only option is to write a script that performs many smaller SPARQL requests, similar to this script that gets a dozen properties for all embassies and consulates of the world, please be aware that adapting this script will take a few hours (or a few days if you are new to development) and running it without overloading the server will take days.

License: public domain

2
  • 1
    super helpful answer! Commented Dec 19, 2021 at 0:27
  • 1
    Sir, you introduced me to Wikidata Query Services. This is great. For those having trouble with the second query timing out, consider commenting out the line ?item p:P31/ps:P31/wdt:P279* wd:Q95074. Sure, you'll get some non-character records back. But there aren't that many. And they're easy to post filter.
    – lowndrul
    Commented Sep 26, 2022 at 14:52
7

A past alternative to using DBpedia as suggested by Nicolas Raoul was Freebase before it was shut down.

2
  • 1
    It's up to 703K instances as of this date, but note that characters are linked to their "fictional universe" not books or films directly since they're often shared by a common setting, you'll need to go one hop further to get the name of the book/movie, etc.
    – Tom Morris
    Commented Aug 8, 2013 at 3:35
  • Link does not work anymore unfortunately.
    – Nicolas Raoul
    Commented Feb 17, 2021 at 15:19
0

A bit unusual, but might I suggest Villains Wiki and Heroes Wiki?

You would need to learn how to use the Wikia API though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.