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.
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.
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:
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:
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
?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.
A past alternative to using DBpedia as suggested by Nicolas Raoul was Freebase before it was shut down.
A bit unusual, but might I suggest Villains Wiki and Heroes Wiki?
You would need to learn how to use the Wikia API though.