Exemple #1
0
def parse_events(text, stem_pos=True, corelex=True, pass_coreference=False):
    pos, tree, deps, corefs = stanford_nlp.get_parses(text, coreferences=True)

    clusters = defaultdict(list)
    for coref in corefs:
        clusters[coref['corefClusterID']].append(coref)
    chains = list()
    for id, chain in clusters.iteritems():
        chains.append(chain)

    for chain in chains:
        l = list()
        for coreference in chain:
            mention = coreference['mentionSpan']
            sentence = coreference['sentNum']
            events = match2(mention=mention,
                dependencies=deps[sentence - 1],
                coreference=coreference)
            if [] != events:
                l.append(events)
        if [] != l:
            print l
    ##over a list of dependencies
    nodes = []
    verbs = []
    for sent in sents:
        negs = get_negs(sent)
        nodes.extend(negs[1])
        verbs.append(negs[0])
    nodes = [node for node in nodes if node['relation'] != "neg"]
    #the verbs and the nodes need to be treated differently, nodes are nodes, verbs are strings
    return (verbs, nodes)

if __name__ == '__main__':
    tag = "?"
    sentence = '"Life threatening condition that is always physically harmful"? What a giant load of steamy BS.'
    print sentence
    pos,meta,dependency = stanford_nlp.get_parses(sentence)
    nodes = question_nodes(dependency)
    print sisters.label(nodes, tag)

    
    tag = "quote"
    sentence = '"Life threatening condition that is always physically harmful"? What a giant load of steamy BS.'
    print sentence
    pos,meta,dependency = stanford_nlp.get_parses(sentence)
    words = quote_nodes(pos, dependency)
    print sisters.label(words, tag)
    
    tag = "quote"
    sentence = "John said 'I like cookies.'"
    print sentence
    pos,meta,dependency = stanford_nlp.get_parses(sentence)