def get_target_words(iphod,sound,sylpos,wordpos):
    targets = []
    for w in iphod:
        w = Word(w['Word'],w['UnTrn'])
        if w.istitle():
            continue
        if not w.in_position(sound,sylpos,wordpos):
            continue
        bad_segment = False
        for s in SETTINGS['Avoided segments']:
            if w.contains(s):
                bad_segment = True
        other_critical_segs = filter(lambda x: x != sound, SETTINGS['Critical segments']) + SETTINGS['Avoided segments']
        for oc in other_critical_segs:
            if w.neighbour_transcription(oc,sylpos,wordpos) in TRANS:
                bad_segment = True
                break
            if w.segment_count(oc) > 0:
                bad_segment = True
                break
        if bad_segment:
            continue
        if w.segment_count(sound) > 1:
            continue
        targets.append({'Word':w.orthography,'Transcription':w.render_transcription()})
    return targets
def get_continuum_words(iphod):
    words = []
    sylpos = 'coda'
    wordpos = 'final'
    sound = 'S'
    oc = 'SH'
    for w in iphod:
        w = Word(w['Word'],w['UnTrn'],frequency=np.log(float(w['SFreq'])))
        if not w.in_position(sound,sylpos,wordpos):
            continue
        neighbour_trans = w.neighbour_transcription(oc,sylpos,wordpos)
        if not neighbour_trans in TRANS:
            continue
        for w2 in iphod:
            if w2['UnTrn'] == neighbour_trans:
                words.append((w.orthography,w2['Word'],np.abs(w.frequency-np.log(float(w2['SFreq'])))))
    return sorted(words,key=lambda x: x[2])