
In the above, we’ve stated that a mother (X) is a parent of someone and (written as a comma in Prolog) is female. Once done, a rule to identify mothers is created by the following: mother(X, Y) :- parent(X, Y), female(X). For example, to create a mother/father relationship, more facts on every character’s gender in Game of Thrones is needed. More interesting and specific rules are created by combining facts. This rule is efficient for Game of Thrones, as it only requires a handful of facts, for the few who are still alive. The not indicates that, if X is not found to be alive, then X is dead. The query searches the database for all instances where person X is alive. Here, I’ve expanded the database to include a set of rules for every character that is still alive. In another instance, suppose you want to make a rule determined by the absence of a fact… status(X, dead) :- not(status(X, alive)). This essentially reverses the parent rule, and allows searches up and down the family tree. From our last example, make a simple rule from the parent fact, to determine a child relationship X is the child of Y if (written as :- in Prolog) Y is the parent of X. Now that there are facts in the database, begin creating rules. For instance, if you wanted to see that Arya has parents, but don’t care who they are, query the following: ?-parent(_, arya_stark).true Season 1 Episode 1: The last time anyone smiled in GoT. Use underscores as anonymous variables to filter out information that doesn’t matter. A period terminates the search all together. Hit semicolon conducts searches for further true answers (catelyn_stark), until there are none remaining. To find who the parents of Arya are, ask: ?-parent(Parent, arya_stark).Parent = eddard_stark Parent = catelyn_stark.Įddard returns first in this example, for this is the first true fact listed in the database. You can also query with variables in Prolog by using uppercase. If you input relationships that aren’t within the database, it returns false. The most basic query checks whether a fact is present within the database. These facts alone are enough to start making queries. You can then extrapolate these queries across the entire Game of Thrones universe, for all the houses, to create a complete database (or, poach the whole dataset from my GitHub). Here, two separate facts have been defined, saying that Eddard and Catelyn are the parents of Arya. Take the case of Arya Stark: parent(eddard_stark, arya_stark).parent(catelyn_stark, arya_stark). For family trees, a good place to start is linking characters through their parents. Simplify things by starting the database with one set of facts, which can be applied to all characters. Game of Thrones is renowned for its complex (and often incestuous) family trees, so breaking things down into simple facts starts a great basis for a Prolog database. To use Prolog, queries are passed through a structured database of facts. Prolog is a logic programming language, which forms rules and relationships from facts. But, the Prolog remains the same since 1972, with no plot twists and an easy to follow structure that this tutorial will help you ace. If you aren’t up to speed, proceed with caution. Image via HBO Obligatory Game of Thrones SPOILER WARNING! Events included are up to Season 7, disregarding anything that occurs only in the books.
#Game of thrones character list no spoilers how to
By Rachel Wiles How to learn Prolog by watching Game of Thrones Are they dead? Are they alive? Is she his aunt? Instead of casting your mind back to 2011, save the exhaustion and build your own expert using Prolog.
