MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / readable_label

Method readable_label

python/graphvite/dataset.py:910–942  ·  view source on GitHub ↗
(self, labels, save_file, hierarchy=False)

Source from the content-addressed store, hash-verified

908 return name[:name.find(".")]
909
910 def readable_label(self, labels, save_file, hierarchy=False):
911 wordnet = self.import_wordnet()
912
913 if hierarchy:
914 logger.info("generating human-readable hierarchical labels")
915 else:
916 logger.info("generating human-readable labels")
917 synsets = []
918 for label in labels:
919 pos = label[0]
920 offset = int(label[1:])
921 synset = wordnet.synset_from_pos_and_offset(pos, offset)
922 synsets.append(synset)
923 depth = max([synset.max_depth() for synset in synsets])
924
925 num_sample = len(synsets)
926 labels = [self.get_name(synset) for synset in synsets]
927 num_class = len(set(labels))
928 hierarchies = [labels]
929 while hierarchy and num_class > 1:
930 depth -= 1
931 for i in range(num_sample):
932 if synsets[i].max_depth() > depth:
933 # only takes the first recall
934 synsets[i] = synsets[i].hypernyms()[0]
935 labels = [self.get_name(synset) for synset in synsets]
936 hierarchies.append(labels)
937 num_class = len(set(labels))
938 hierarchies = hierarchies[::-1]
939
940 with open(save_file, "w") as fout:
941 for hierarchy in zip(*hierarchies):
942 fout.write("%s\n" % "\t".join(hierarchy))
943
944 def image_feature_data(self, image_path):
945 """"""

Calls 3

import_wordnetMethod · 0.95
get_nameMethod · 0.95
infoMethod · 0.45

Tested by

no test coverage detected