def create_type_portmap(self, ports): result = {} for port_name, port_descs in ports.iteritems(): for port_desc in port_descs: sp = tuple(port_desc) append_to_dict_of_lists(result, sp, port_name) return result
def run(self, vistrail, name): result = [] self.tupleLength = 2 for version in self.versions_to_check: p = vistrail.getPipeline(version) matches = set() queryModuleNameIndex = {} for moduleId, module in p.modules.iteritems(): append_to_dict_of_lists(queryModuleNameIndex, module.name, moduleId) for querySourceId in self.queryPipeline.graph.sources(): querySourceName = self.queryPipeline.modules[ querySourceId].name if not queryModuleNameIndex.has_key(querySourceName): # need to reset matches here! matches = set() continue candidates = queryModuleNameIndex[querySourceName] atLeastOneMatch = False for candidateSourceId in candidates: querySource = self.queryPipeline.modules[querySourceId] candidateSource = p.modules[candidateSourceId] if not self.matchQueryModule(candidateSource, querySource): continue (match, targetIds) = self.heuristicDAGIsomorphism \ (template = self.queryPipeline, target = p, template_ids = [querySourceId], target_ids = [candidateSourceId]) if match: atLeastOneMatch = True matches.update(targetIds) # We always perform AND operation if not atLeastOneMatch: matches = set() break for m in matches: result.append((version, m)) self.queryResult = result self.computeIndices() return result
def run(self, vistrail, name): result = [] self.tupleLength = 2 for version in self.versions_to_check: p = vistrail.getPipeline(version) matches = set() queryModuleNameIndex = {} for moduleId, module in p.modules.iteritems(): append_to_dict_of_lists(queryModuleNameIndex, module.name, moduleId) for querySourceId in self.queryPipeline.graph.sources(): querySourceName = self.queryPipeline.modules[querySourceId].name if not queryModuleNameIndex.has_key(querySourceName): # need to reset matches here! matches = set() continue candidates = queryModuleNameIndex[querySourceName] atLeastOneMatch = False for candidateSourceId in candidates: querySource = self.queryPipeline.modules[querySourceId] candidateSource = p.modules[candidateSourceId] if not self.matchQueryModule(candidateSource, querySource): continue (match, targetIds) = self.heuristicDAGIsomorphism \ (template = self.queryPipeline, target = p, template_ids = [querySourceId], target_ids = [candidateSourceId]) if match: atLeastOneMatch = True matches.update(targetIds) # We always perform AND operation if not atLeastOneMatch: matches = set() break for m in matches: result.append((version, m)) self.queryResult = result self.computeIndices() return result
def heuristicDAGIsomorphism(self, target, template, target_ids, template_ids): resultIds = set() while 1: templateNames = set([(i, template.modules[i].name) for i in template_ids]) targetNames = {} for i in target_ids: append_to_dict_of_lists(targetNames, target.modules[i].name, i) nextTargetIds = set() nextTemplateIds = set() for (i, templateName) in templateNames: if templateName not in targetNames: return (False, resultIds) else: templateModule = template.modules[i] matched = [ tId for tId in targetNames[templateName] if self.matchQueryModule(target.modules[tId], templateModule) ] resultIds.update(matched) for matchedTargetId in matched: nextTargetIds.update([ moduleId for (moduleId, edgeId ) in target.graph.edges_from(matchedTargetId) ]) nextTemplateIds.update([ moduleId for (moduleId, edgeId) in template.graph.edges_from(i) ]) if not len(nextTemplateIds): return (True, resultIds) target_ids = nextTargetIds template_ids = nextTemplateIds
def heuristicDAGIsomorphism(self, target, template, target_ids, template_ids): resultIds = set() while 1: templateNames = set([(i, template.modules[i].name) for i in template_ids]) targetNames = {} for i in target_ids: append_to_dict_of_lists(targetNames, target.modules[i].name, i) nextTargetIds = set() nextTemplateIds = set() for (i, templateName) in templateNames: if templateName not in targetNames: return (False, resultIds) else: templateModule = template.modules[i] matched = [tId for tId in targetNames[templateName] if self.matchQueryModule(target.modules[tId], templateModule)] resultIds.update(matched) for matchedTargetId in matched: nextTargetIds.update([moduleId for (moduleId, edgeId) in target.graph.edges_from(matchedTargetId)]) nextTemplateIds.update([moduleId for (moduleId, edgeId) in template.graph.edges_from(i)]) if not len(nextTemplateIds): return (True, resultIds) target_ids = nextTargetIds template_ids = nextTemplateIds
def matchQueryModule(self, template, target): """ matchQueryModule(template, target: Module) -> bool Return true if the target module can be matched to the template module """ if target.name != template.name: return False if target.getNumFunctions()>template.getNumFunctions(): return False candidateFunctions = {} for fid in xrange(template.getNumFunctions()): f = template.functions[fid] append_to_dict_of_lists(candidateFunctions, f.name, f) for f in target.functions: if not candidateFunctions.has_key(f.name): return False fNotMatch = True candidates = candidateFunctions[f.name] for cf in candidates: if len(cf.params)!=len(f.params): continue pMatch = True for pid in xrange(len(cf.params)): cp = cf.params[pid] p = f.params[pid] if not self.matchQueryParam(p, cp): pMatch= False break if pMatch: fNotMatch = False break if fNotMatch: return False return True
def matchQueryModule(self, template, target): """ matchQueryModule(template, target: Module) -> bool Return true if the target module can be matched to the template module """ if target.name != template.name: return False if target.getNumFunctions() > template.getNumFunctions(): return False candidateFunctions = {} for fid in xrange(template.getNumFunctions()): f = template.functions[fid] append_to_dict_of_lists(candidateFunctions, f.name, f) for f in target.functions: if f.name not in candidateFunctions: return False fNotMatch = True candidates = candidateFunctions[f.name] for cf in candidates: if len(cf.params) != len(f.params): continue pMatch = True for pid in xrange(len(cf.params)): cp = cf.params[pid] p = f.params[pid] if not self.matchQueryParam(p, cp): pMatch = False break if pMatch: fNotMatch = False break if fNotMatch: return False return True
def subscribe(self, field, callable_): """subscribe(field, callable_): call observer callable_ when self.field is set. """ append_to_dict_of_lists(self.__subscribers__, field, Ref(callable_))