コード例 #1
0
ファイル: parse_functions.py プロジェクト: wrightjb/bolt
def get_parse(s):
    """Returns a dictionary with the parse results returned by
    the Stanford parser for the provided sentence."""

    sparse = parse_sentence(s)['parsetree']
    mparse = modify_parse(sparse)
    return mparse
コード例 #2
0
ファイル: parse_functions.py プロジェクト: colinwinslow/bolt
def get_parse(s):
    """Returns a dictionary with the parse results returned by
    the Stanford parser for the provided sentence."""

    sparse = parse_sentence(s)['parsetree']
    mparse = modify_parse(sparse)
    return mparse
コード例 #3
0
ファイル: counter.py プロジェクト: wrightjb/bolt
    print 'appending...'
    with open('sentences2.csv') as f:
        reader = csv.reader(f)
        next(reader)  # skip headers
        sentence_number = 0
        for row in reader:
            sentence_number += 1
            print 'Sentence #%d' % sentence_number
            # unpack row and convert to the rigth types
            location, region, nearfar, precise, utterance, parse = row
            location = int(location) / 100.0
            # precise = (precise == 'T')
            # parse sentence
            # parse = parse_sentence(phrase)['parsetree']
            rel_words, lmk_words, rel_phrases, lmk_phrases = modify_parse(
                parse)
            # sample landmark, relation and degree
            for j in range(iters):
                lmk_name, lmk_loc = sample_landmark(location)
                relation, degree = sample_reldeg(lmk_loc, location)

                if verbose:
                    print '-' * 70
                    print 'Utterance: %r' % utterance
                    print 'Location: %s' % location
                    print 'Landmark: %s (%s)' % (lmk_loc, lmk_name)
                    print 'Relation: %s' % relation
                    print 'Degree: %s' % degree
                    print 'Parse tree:\n%s' % parse
                    #print 'Modified parse tree:\n%s' % modparse
                    #print 'Parse tree as list:\n%s' % pf(lparse)
コード例 #4
0
ファイル: counter.py プロジェクト: crdawson/bolt
        next(reader)  # skip headers
        sentence_number = 0
        for row in reader:
            sentence_number += 1
            print "Sentence #%d" % sentence_number
            # unpack row and convert to the rigth types
            location, region, nearfar, precise, utterance, parse = row
            location = int(location) / 100.0
            # precise = (precise == 'T')
            # sample landmark, relation and degree
            for j in range(iters):
                lmk_name, lmk_loc = sample_landmark(location)
                relation, degree = sample_reldeg(location, lmk_loc)
                # parse sentence
                # parse = parse_sentence(phrase)['parsetree']
                rel_words, lmk_words, rel_phrases, lmk_phrases = modify_parse(parse)

                if verbose:
                    print "-" * 70
                    print "Utterance: %r" % utterance
                    print "Location: %s" % location
                    print "Landmark: %s (%s)" % (lmk_loc, lmk_name)
                    print "Relation: %s" % relation
                    print "Degree: %s" % degree
                    print "Parse tree:\n%s" % parse
                    # print 'Modified parse tree:\n%s' % modparse
                    # print 'Parse tree as list:\n%s' % pf(lparse)
                    # print 'Modified parse tree as list:\n%s' % pf(lmodparse)
                    # print 'Relation chunk:\n%s' % pf(rel_chunk)
                    # print 'Landmark chunk:\n%s' % pf(lmk_chunk)
                    print "Relation structure: %s" % rel_phrases[0][1]