Esempio n. 1
0
def elaborate_on_topic(sdb, state):
    if len(state.topics) > 0:
        prev = state.topics[-1]
    else:
        prev = None
    subj, d = random_sentence_for_nsubj(sdb, prev)
    if prev is not None and len(state.subj_orth) > 0 \
            and state.subj_orth[-1].lower() in ('it', 'they'):
        subj = "the " + prev.root.orth_
    state.subj_orth.append(subj)
    return replace_span(d['span'], d['nsubj'], subj)
Esempio n. 2
0
def elaborate_on_topic(sdb, state):
    if len(state.topics) > 0:
        prev = state.topics[-1]
    else:
        prev = None
    subj, d = random_sentence_for_nsubj(sdb, prev)
    if prev is not None and len(state.subj_orth) > 0 \
            and state.subj_orth[-1].lower() in ('it', 'they'):
        subj = "the " + prev.root.orth_
    state.subj_orth.append(subj)
    return replace_span(d['span'], d['nsubj'], subj)
Esempio n. 3
0
def random_sentences(sdb):
    qualified_sg = [x for x in sdb \
            if x['nsubj'] is not None and x['plural'] is False]
    qualified_pl = [x for x in sdb \
            if x['nsubj'] is not None and x['plural'] is True]
    no_nsubjs = [x for x in sdb if x['nsubj'] is None]
    all_pps = reduce(
            list.__add__, [x['pps'] for x in sdb if len(x['pps']) > 0])
    while True:
        choice = random.randrange(10)
        if choice == 0:
            no_nsubj = random.choice(no_nsubjs)
            yield Sentence(text=no_nsubj['text'], nsubj=None)
        else:
            c, d = random_sentences_match_agreement(sdb)
            if len(c['pps']) > 0 and random.randrange(2) == 0:
                stext = replace_span(c['span'], random.choice(c['pps']),
                        ""+random.choice(all_pps).text+"")
                yield Sentence(text=stext, nsubj=c['nsubj'])
            else:
                stext = replace_span(c['span'], c['nsubj'], d['nsubj'].text)
                yield Sentence(text=stext, nsubj=d['nsubj'])
Esempio n. 4
0
def random_sentences(sdb):
    qualified_sg = [x for x in sdb \
            if x['nsubj'] is not None and x['plural'] is False]
    qualified_pl = [x for x in sdb \
            if x['nsubj'] is not None and x['plural'] is True]
    no_nsubjs = [x for x in sdb if x['nsubj'] is None]
    all_pps = reduce(list.__add__,
                     [x['pps'] for x in sdb if len(x['pps']) > 0])
    while True:
        choice = random.randrange(10)
        if choice == 0:
            no_nsubj = random.choice(no_nsubjs)
            yield Sentence(text=no_nsubj['text'], nsubj=None)
        else:
            c, d = random_sentences_match_agreement(sdb)
            if len(c['pps']) > 0 and random.randrange(2) == 0:
                stext = replace_span(c['span'], random.choice(c['pps']),
                                     "" + random.choice(all_pps).text + "")
                yield Sentence(text=stext, nsubj=c['nsubj'])
            else:
                stext = replace_span(c['span'], c['nsubj'], d['nsubj'].text)
                yield Sentence(text=stext, nsubj=d['nsubj'])