def rdfs_classes(rdf):
<EOL>upperclasses = {}  <EOL>for s, o in rdf.subject_objects(RDFS.subClassOf):<EOL><INDENT>upperclasses.setdefault(s, set())<EOL>for uc in rdf.transitive_objects(s, RDFS.subClassOf):<EOL><INDENT>if uc != s:<EOL><INDENT>upperclasses[s].add(uc)<EOL><DEDENT><DEDENT><DEDENT>for s, ucs in upperclasses.items():<EOL><INDENT>logging.debug("<STR_LIT>", s, str(ucs))<EOL>for res in rdf.subjects(RDF.type, s):<EOL><INDENT>for uc in ucs:<EOL><INDENT>rdf.add((res, RDF.type, uc))<EOL><DEDENT><DEDENT><DEDENT>
Perform RDFS subclass inference.

    Mark all resources with a subclass type with the upper class.