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.

Patrick Hoefler
  • 5,790
  • 4
  • 31
  • 47
  • I don't think that a data set of fictional characters fall under the open data concept. – Kermit May 10 '13 at 22:41
  • 2
    @FreshPrinceOfSO Why not? – Patrick Hoefler May 15 '13 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 May 24 '13 at 09: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 http://dbpedia.org/describe/?url=http%3A%2F%2Fdbpedia.org%2Fresource%2FCategory%3AFictional_characters – Nicolas Raoul Jun 05 '13 at 07: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 Jun 05 '13 at 20:23
  • This question was closed? No wonder the site can't attract a following! – Tom Morris Aug 08 '13 at 03:36

3 Answers3

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

Nicolas Raoul
  • 8,426
  • 5
  • 28
  • 61
  • 1
    super helpful answer! – Fred Zimmerman Dec 19 '21 at 00: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 Sep 26 '22 at 14:52
7

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

ramiro
  • 1,046
  • 1
  • 9
  • 12
  • 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 Aug 08 '13 at 03:35
  • Link does not work anymore unfortunately. – Nicolas Raoul Feb 17 '21 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.

madprogramer
  • 101
  • 1
  • 1
  • 4