def line_syn_replace(line):
    pos = nltk.pos_tag(line)
    nvaa = ['NN', 'NNS', 'NNP', 'NNPS', 'VB', 'VBD', 'VBG', 'VBN', 
            'VBP', 'VBZ', 'JJ', 'JJR', 'JJS']
    candidates = []
    for h in range(len(pos)):
        if pos[h][1] in nvaa:
            candidates.append(h)
        else:
            pass
    synset_count_list = []
    lemma_list = []
    for n in candidates:
        ss = wn.synsets(line[n])
        synset_count_list.append(len(ss))
        lemmas = []
        for i in ss:
            lemmas += i.lemma_names
        lemmas = list(set(lemmas))
        for lem in lemmas[:]:
            if st.stem(line[n]) == st.stem(lem):
                lemmas.remove(lem)
            else:
                pass
        lemma_list.append(lemmas)
    pos_ss_count = [synset_count_list[j] for j in range(len(candidates)) if synset_count_list[j] > 0 and lemma_list[j] != []]
    if pos_ss_count == []:
        synonym = "asdfjkl"
    else:
        min_pos_ss_count = min(pos_ss_count)
        for k in range(len(candidates)):
            if synset_count_list[k] == min_pos_ss_count and lemma_list[k] != []:
                word_index = candidates[k]
                syn_candidates = lemma_list[k]
                break
            else:
                pass
        for l in range(len(syn_candidates)):
            syn_candidates[l] = syn_candidates[l].lower()
            if '_' in syn_candidates[l]:
                tp = syn_candidates[l].split('_')
                tj = ' '.join(tp)
                syn_candidates[l] = tj
            else:
                pass
        synonym = random.choice(syn_candidates)
        line[word_index] = synonym
    
    # if natural line breaks desired, update rhyming dicts...
    
    if "natural" in rhyme_scheme.lower():
        if ' ' in synonym:
            synonym = synonym.split(' ')
        else:
            synonym = [synonym]
        for w in synonym:
            if in_pdict(w):
                rhymes = rhyme_finder(w)
                rhyme_dict[w] = rhymes
                if len(rhymes) > max(rhyme_counts):
                    rhyme_counts.append(len(rhymes))
                    rhyme_freq[len(rhymes)] = [w]
                else:
                    rhyme_counts.append(len(rhymes))
                    rhyme_freq[len(rhymes)].append(w)
            else:
                rhyme_dict[w] = []
                if 0 in rhyme_counts:
                    rhyme_counts.append(0)
                    rhyme_freq[0].append(w)
                else:
                    rhyme_counts.append(0)
                    rhyme_freq[0] = [w]
    
    return line
dataset/ETHPy150Open rossgoodwin/sonnetizer/sonnetizer_n.py/line_syn_replace/original