示例#1
0
 def convert_model(self, model: Snippet) -> BOW:
     bags = [self._uasts2bow(uast) for uast in model.uasts]
     data = list(zip(*[(bag_[x], i, x) for i, bag_ in enumerate(bags) for x in bag_]))
     matrix = csr_matrix((data[0], (data[1], data[2])),
                         shape=(len(bags), len(self._uasts2bow.vocabulary)),
                         dtype=numpy.float32)
     bow = BOW(log_level=logging.WARNING)
     bow.construct(repos=model.names, matrix=matrix, tokens=self._tokens)
     bow.meta["dependencies"] = [self._uasts2bow.docfreq]
     return bow
示例#2
0
 def convert_model(self, model: UASTModel) -> BOW:
     bag = self._uasts2bow(model.uasts)
     data = numpy.array(list(bag.values()), dtype=numpy.float32)
     indices = numpy.array(list(bag.keys()), dtype=numpy.int32)
     matrix = csr_matrix((data, indices, [0, len(data)]),
                         shape=(1, len(self._uasts2bow.vocabulary)))
     bow = BOW(log_level=logging.WARNING)
     bow.construct(repos=[model.repository],
                   matrix=matrix,
                   tokens=self._tokens)
     bow.meta["dependencies"] = [self._uasts2bow.docfreq]
     return bow