def extract_max_weight_indep_terms_greedy(terms_weights, term_occ, freq, size, min_occ = 0.7):
    #build the occ_graph
    G = nx.Graph()
    l = len(terms_weights)
    term_weights = dict(terms_weights)

    # add nodes
    for t in term_weights:
        G.add_node(t, score = term_weights[t])

    # add edges
    terms = term_weights.keys()
    for i,t in enumerate(terms):
        if i == l-1:
            break
        for j in range(i+1,l):
            occ = float(term_occ.get((t,terms[j]),0)+term_occ.get((terms[j],t),0))
            try:
                edge_weight = occ/(freq[t]+freq[terms[j]]-occ)
            except:
                edge_weight = 0
            if edge_weight >= min_occ:
                G.add_edge(t,terms[j])

    indep = list()
    sorted_terms = sorted(term_weights, key=term_weights.get, reverse=True)
    while True:
        if len(sorted_terms)==0:
            break
        node = sorted_terms[0]
        indep.append(node)
        ng = G.neighbors(node)
        sorted_terms.remove(node)
        for n in ng:
            sorted_terms.remove(n)
            G.remove_node(n)
        G.remove_node(node)
    return set(indep[:size])
dataset/ETHPy150Open sajao/CrisisLex/src-create/build.py/extract_max_weight_indep_terms_greedy/original