def getFuncFileName(self,fid): if str(fid) not in KNN.file_name_map: func=Function(fid) location=func.location() filename=location.split(':')[0].split('/')[-1] KNN.file_name_map[str(fid)]=filename return KNN.file_name_map[str(fid)]
def getFuncFileName(self, fid): if str(fid) not in KNN.file_name_map: func = Function(fid) location = func.location() filename = location.split(':')[0].split('/')[-1] KNN.file_name_map[str(fid)] = filename return KNN.file_name_map[str(fid)]
def getNearestNeighbors(self, entity, allEntities): if len(allEntities) < self.k: return [] nodeId = entity.getId() limit = [str(e.getId()) for e in allEntities] knn = KNN() knn.setEmbeddingDir(self.cachedir) knn.setK(self.k) knn.setLimitArray(limit) knn.setCallerConsideration(self.considerCaller) knn.initialize() #ids = knn.getNeighborsFor(str(nodeId)) #if not ids or ids==[]:return [] #elif str(nodeId) not in ids: #ids.pop() #ids=[str(nodeId)]+ids #return [Function(i) for i in ids] #ids = knn.getNeighborsFor(str(nodeId)) ids, m0, m1, m2, m3 = knn.getSimilarContextNeighborsFor(str(nodeId)) #mean_syntax,mean_fun_name,mean_file_name,mean_caller return ([Function(i) for i in ids], m0, m1, m2, m3)
def lookup_functions_by_variable(code, decl_type=None): lucene_query = 'type:IdentifierDecl' traversal = 'ithChildren(\'1\').filter{{it.code == \'{}\'}}'.format( code) if decl_type: traversal += '.identifierToType().filter{{it.code == \'{}\'}}'.format( decl_type) traversal += '.functions().dedup()' result = jutils.lookup(lucene_query, traversal) return map(lambda x: Function(x[0], x[1]), result)
def _nearestNeighbors(self, entity, k, allEntities): limitFilename = self._createLimitFile(allEntities) nodeId = entity.getId() f = file(limitFilename, 'r') limit = [l.rstrip() for l in f.readlines()] f.close() knn = KNN() knn.setEmbeddingDir(self.cachedir) knn.setK(k) knn.setLimitArray(limit) knn.setNoCache(False) knn.initialize() ids = knn.getNeighborsFor(str(nodeId)) return [Function(i) for i in ids]
def lookup_functions_by_name(name): lucene_query = 'type:Function AND name:"{}"'.format(name) result = jutils.lookup(lucene_query) return map(lambda x: Function(x[0], x[1]), result)
def lookup_all_functions(): lucene_query = 'type:Function' traversal = '' result = jutils.lookup(lucene_query, traversal) return map(lambda x: Function(x[0], x[1]), result)
def lookup_functions_by_symbol(code): lucene_query = 'type:Symbol AND code:"{}"'.format(code) traversal = 'functions().dedup()' result = jutils.lookup(lucene_query, traversal) return map(lambda x: Function(x[0], x[1]), result)
def function(self): from joernInterface.nodes.Function import Function return Function(self.function_id)
def getCallers(self, funcId): fid = str(funcId) if fid not in KNN.caller_map: KNN.caller_map[fid] = Function(funcId).callers() return KNN.caller_map[fid]
def getFuncName(self, fid): if str(fid) not in KNN.func_name_map: func_name = str(Function(fid)) KNN.func_name_map[str(fid)] = func_name return KNN.func_name_map[str(fid)]