Semantic networks, inheritance, and default reasoning
Not all knowledge is best written as logical formulas. A semantic network represents concepts as nodes and relations as labelled links, with is-a links linking an individual or category to a more general one. Frames add structured slots for each concept. These structures make it easy to inherit properties: a bird has two legs, so a parrot, being a bird, has two legs too, without that fact being stored on the parrot.
Python
parents = {"tweety": "penguin", "penguin": "bird", "bird": "animal", "polly": "parrot", "parrot": "bird"}
properties = {
"animal": {"alive": True},
"bird": {"flies": True, "legs": 2},
"penguin": {"flies": False},
}
def lookup(thing, attribute):
while thing is not None:
if attribute in properties.get(thing, {}):
return properties[thing][attribute]
thing = parents.get(thing)
return None
print(lookup("polly", "flies"))
print(lookup("tweety", "flies"))
print(lookup("tweety", "legs"), lookup("tweety", "alive"))
print(lookup("tweety", "color"))