code: def rdfs_classes(rdf):
      
  
      # find out the subclass mappings
      upperclasses = {}  # key: class val: set([superclass1, superclass2..])
      for s, o in rdf.subject_objects(RDFS.subClassOf):
          upperclasses.setdefault(s, set())
          for uc in rdf.transitive_objects(s, RDFS.subClassOf):
              if uc != s:
                  upperclasses[s].add(uc)
  
      # set the superclass type information for subclass instances
      for s, ucs in upperclasses.items():
          logging.debug("setting superclass types: %s -> %s", s, str(ucs))
          for res in rdf.subjects(RDF.type, s):
              for uc in ucs:
                  rdf.add((res, RDF.type, uc))
docs: Perform RDFS subclass inference.
  
      Mark all resources with a subclass type with the upper class.