(
    candidates: List[Candidate],
    candidate_counts: Dict[str, int],
    unique_candidates: Set[str],
    n_toks: int,
    idf: Optional[Dict[str, float]],
)
return term_weights
Compute term weights from statistical attributes: position of first occurrence,
    not subsumed frequency, and number of constituent words.
Compute term weights from statistical attributes: position of first occurrence,
    not subsumed frequency, and number of constituent words.
Compute term weights from statistical attributes : position of first occurrence not subsumed frequency and number of constituent words .
def _compute_term_weights(
    candidates: List[Candidate],
    candidate_counts: Dict[str, int],
    unique_candidates: Set[str],
    n_toks: int,
    idf: Optional[Dict[str, float]],
) -> Dict[str, float]:
    """
    Compute term weights from statistical attributes: position of first occurrence,
    not subsumed frequency, and number of constituent words.
    """
    clen: float
    term_weights = {}
    seen_terms = set()
    n_toks_p1 = n_toks + 1
    for cand in candidates:
        # we only want the *first* occurrence of a unique term (by its text)
        if cand.text in seen_terms:
            continue
        else:
            seen_terms.add(cand.text)
        pos_first_occ = math.log(n_toks_p1 / (cand.idx + 1))
        # TODO: do we want to sub-linear scale term len or not?
        clen = math.sqrt(cand.length)
        # subtract from subsum_count for the case when ctext == ctext2
        subsum_count = (
            sum(
                candidate_counts[ctext2]
                for ctext2 in unique_candidates
                if cand.text in ctext2
            )
            - cand.count
        )
        term_freq_factor = cand.count - subsum_count
        if idf and clen == 1:
            term_freq_factor *= idf.get(cand.text, 1)
        term_weights[cand.text] = term_freq_factor * pos_first_occ * clen
    return term_weights
def _compute_term_weights ( candidates : List [ Candidate ] , candidate_counts : Dict [ str , int ] , unique_candidates : Set [ str ] , n_toks : int , idf : Optional [ Dict [ str , float ] ] , ) -> Dict [ str , float ] : clen : float term_weights = { } seen_terms = set ( ) n_toks_p1 = n_toks + 1 for cand in candidates : # we only want the *first* occurrence of a unique term (by its text) if cand . text in seen_terms : continue else : seen_terms . add ( cand . text ) pos_first_occ = math . log ( n_toks_p1 / ( cand . idx + 1 ) ) # TODO: do we want to sub-linear scale term len or not? clen = math . sqrt ( cand . length ) # subtract from subsum_count for the case when ctext == ctext2 subsum_count = ( sum ( candidate_counts [ ctext2 ] for ctext2 in unique_candidates if cand . text in ctext2 ) - cand . count ) term_freq_factor = cand . count - subsum_count if idf and clen == 1 : term_freq_factor *= idf . get ( cand . text , 1 ) term_weights [ cand . text ] = term_freq_factor * pos_first_occ * clen return term_weights