def partitioner(numCPUs, V, H): E = generate_E(V, H) cm = len(max(E, key=len)) # maximum hyperdegree m = len(H) for d in range(m - cm): S_star, k = minimum_k_and_d(generate_T(H, cm + d), E) if k > numCPUs: # create new E E = set() used_hypernodes = set() for idx, s in enumerate(S_star): E_i = set() E_i_hypernodes = set() for e in s: E_i.update(e) # add only hypernodes to the element E_i that aren't already used in another element E_j diff = e.contained_hypernodes - used_hypernodes used_hypernodes.update(diff) E_i_hypernodes.update(diff) E.add(Elem("E" + str(idx + 1), E_i, E_i_hypernodes)) else: # extract partitions partitions = set() for idx, s in enumerate(S_star): partition = set() for e in s: partition.update(e.contained_hypernodes) partitions.add(Elem("Partition" + str(idx + 1), partition)) return partitions
def __init__(self, data, selected=None, attr=None, indent=None): """ Represents an 'option' html element. If selected is True this Elem will be selected when nested in a 'select' Elem. """ self.selected = selected Elem.__init__(self, data, attr=attr, indent=indent)
def otag(self): """ Adds the word 'selected' before the closing angle brace with no value to select option when nested in a 'select' Elem. """ if self.selected: return Elem.otag(self)[:-1] + ' selected' + '>' return Elem.otag(self)
def partition_file_to_hypergraph(file_path): V_raw, H_raw = converter.partition_file_to_hypergraph(file_path) V = set(V_raw) H = set() for idx, h in enumerate(H_raw): H.add(Elem("H" + str(idx + 1), set(h))) return V, H
def generate_E(V: set, H: set): E = set() for idx, v in enumerate(V): e_i = set() for h in H: if v in h: e_i.add(h) E.add(Elem("E" + str(idx + 1), e_i, {v})) return E
def generate_S(T, E): S = set() # for all sets in T create a set in S for t in T: S_j = set() # in the set in S are all e that are a subset of t for e in E: if all(x in t for x in e): S_j.add(e) S.add(Elem("S_" + "".join(map(str, S_j)), S_j)) return S
def find_minimum_set_in_S_covering_E(E, S): P = set() result = set() while P != E: # find longest difference set longest_diffset = set() for S_j in S: diff = S_j - P if len(diff) > len(longest_diffset): longest_diffset = diff P.update(longest_diffset) result.add( Elem("S_" + "".join(map(str, longest_diffset)), longest_diffset)) return result
def __init__(self, sessionsName, sessions, n): self.sessionsName = sessionsName self.sessions = sessions self.validations = {} self.validationsRel = {} self.validationType = {} self.validationLabels = {} self.N = 0 self.NRel = 0 self.n = n db = MySQLdb.connect(host="127.0.0.1", user="******", db="validRKB") cur = db.cursor() for session in sessions: cur.execute("SELECT * FROM TripleValidation WHERE idSession='"+session+"'") nbTaxon = 0 nbNewUri = 0 for row in cur.fetchall() : if(row[3] == 'Inst'): nbTaxon += 1 elem = None if(self.validations.has_key(row[2])): elem = self.validations[row[2]] else: nbNewUri += 1 #print "new uri "+row[2] elem = Elem(row[2], self.n) self.validations[row[2]] = elem self.N += 1 if(row[4] == "valid"): elem.majElemValid() if(row[1].endswith("Triticum")): elem.triticum += 1 elif(row[1].endswith("Aegilops")): elem.aegilops += 1 else: elem.dontKnowCat += 1 elif(row[4] == "notValid"): elem.majElemNotValid() elem.dontKnowCat += 1 elif(row[4] == "dontKnow"): elem.majElemDontKnow() elem.dontKnowCat += 1 else: loutre = 42 #print "ERROR !! " #print "Session : "+session+" --> "+str(nbTaxon) + "--> "+str(nbNewUri) elif(row[3] == 'hasHigherRank'): elem = None if(self.validationsRel.has_key(row[2])): elem = self.validationsRel[row[2]] else: elem = Elem(row[2], self.n) self.validationsRel[row[2]] = elem self.NRel += 1 if(row[4] == "valid"): elem.majElemValid() elif(row[4] == "notValid"): elem.majElemNotValid() elif(row[4] == "dontKnow"): elem.majElemDontKnow() else: loutre = 42 elif(row[3] == 'Type'): elem = None if(self.validationType.has_key(row[2])): elem = self.validationType[row[2]] else: elem = Elem(row[2], self.n) self.validationType[row[2]] = elem if(row[4] == "valid"): elem.majElemValid() elif(row[4] == "notValid"): elem.majElemNotValid() elif(row[4] == "dontKnow"): elem.majElemDontKnow() else: loutre = 42 elif(row[3] == 'Labels'): elem = None if(self.validationLabels.has_key(row[2])): elem = self.validationLabels[row[2]] else: elem = Elem(row[2], self.n) self.validationLabels[row[2]] = elem if(row[4] == "valid"): elem.majElemValid() elif(row[4] == "notValid"): elem.majElemNotValid() elif(row[4] == "dontKnow"): elem.majElemDontKnow() else: loutre = 42
def __init__(self, data, attr=None, indent=None): """ Represents an 'a' html element. An href attribute is required. """ Elem.__init__(self, data, attr=attr, indent=indent) self.reqiure_attr('href')