def showsuffix(self, path, minorder=1, maxorder=1): feats = {} for feat in self.features.keys(): thispath = getpathtype(feat) order = getorder(feat) if thispath.endswith(path) and order >= minorder and order <= maxorder: feats[feat] = self.features[feat] values = sorted(feats.items(), key=itemgetter(1), reverse=True) print values
def createvector(self,token,featurelist,type): self.vectors[type][token]=WordVector(token) featurelist.reverse() #reverse list so can pop features and scores off while (len(featurelist)>0): f=featurelist.pop() sc=float(featurelist.pop()) forder=getorder(f,delim=self.pathdelim) if forder>=SimEngine.minorder and forder<=SimEngine.maxorder: #filter features by path length if self.includepath(f): #filter by path type self.vectors[type][token].addfeature(f,sc) self.allfeatures[f]=1 self.vectors[type][token].reducesaliency(self.saliency,saliencyperpath=self.saliencyperpath)
def view(self, minorder=0, maxorder=10, cutoff=100): features = {} for feat in self.features.keys(): order = getorder(feat) if order >= minorder and order <= maxorder: features[feat] = self.features[feat] aview = sorted(features.items(), key=itemgetter(1), reverse=True) line = "" for i, pair in enumerate(aview[: cutoff - 1]): if i % 5 == 4: line += pair[0] + " " + str(pair[1]) print line line = "" else: line += pair[0] + " " + str(pair[1]) + "\t"
def profile(self, minorder=0, maxorder=10): paths = {} totalweight = 0 thisorderweight = 0 for feat in self.features.keys(): path = getpathtype(feat) order = getorder(feat) weight = self.features[feat] sofar = paths.get(path, 0) if order >= minorder and order <= maxorder: paths[path] = sofar + weight thisorderweight += weight totalweight += weight print "total weight of features", totalweight print "total weight of required order features", thisorderweight profile = sorted(paths.items(), key=itemgetter(1), reverse=True) print profile