Beispiel #1
0
def process_graphs(graphs):
    engine = Engine(idd3.all_rulesets, idd3.all_transformations)
    stats = defaultdict(int)

    for index in range(len(graphs)):
        print('-' * int(columns))
        relations = []
        for relation in graphs[index].nodes.values():
            relations.append(Relation(**relation))

        print(colored('Sentence %d:' % (index + 1), 'white', attrs=['bold']))
        print('\t' + get_sentence(graphs[index]))

        print(colored('Propositions:', 'white', attrs=['bold']))
        try:
            engine.analyze(relations)
            for i, prop in enumerate(engine.props):
                print(str(i + 1) + ' ' + str(prop))
                stats[prop.kind] += 1
        except Exception as e:
            logger.error('{0} in engine.analyze: {1}'.format(
                e.__class__.__name__, e))

    print('-' * int(columns))
    return stats
Beispiel #2
0
def process_graphs(graphs):
    engine = Engine(idd3.all_rulesets, idd3.all_transformations)
    stats = defaultdict(int)

    for index in range(len(graphs)):
        print('-' * int(columns))
        relations = []
        for relation in graphs[index].nodes.values():
            relations.append(Relation(**relation))

        print(colored('Sentence %d:' % (index + 1), 'white', attrs=['bold']))
        print('\t' + get_sentence(graphs[index]))

        print(colored('Propositions:', 'white', attrs=['bold']))
        try:
            engine.analyze(relations)
            for i, prop in enumerate(engine.props):
                print(str(i + 1) + ' ' + str(prop))
                stats[prop.kind] += 1
        except Exception as e:
            logger.error('{0} in engine.analyze: {1}'.format(
                e.__class__.__name__, e))

    print('-' * int(columns))
    return stats
Beispiel #3
0
def process_graphs(graphs, verbose=False):
    engine = Engine(rules.all_rulesets, transform.all_transformations)
    stats = defaultdict(int)

    for index in range(len(graphs) - 1):
        if verbose:
            print('-' * int(columns))
        relations = []
        for node in graphs[index].nodes:
            relation = graphs[index].nodes[node]
            if relation['rel'] == 'ROOT':
                relation['rel'] = 'root'
            relations.append(Relation(**relation))

        if verbose:
            print(colored('Sentence %d:' % (index + 1), 'white', attrs=['bold']))
            print('\t' + get_sentence(graphs[index]))

            print(colored('Propositions:', 'white', attrs=['bold']))
        try:
            engine.analyze(relations)
            for i, prop in enumerate(engine.props):
                if verbose:
                    print(str(i + 1) + ' ' + str(prop))
                stats[prop.kind] += 1
        except Exception:
            pass

    if verbose:
        print('-' * int(columns))
    return stats
Beispiel #4
0
def demo():
    graphs = nltk.parse.dependencygraph.DependencyGraph.load(argv[1])
    index = int(argv[2]) - 1

    engine = Engine(rules.all_rulesets, transform.all_transformations)

    relations = []
    for relation in graphs[index].nodelist:
        relations.append(Relation(**relation))

    print(colored('Sentence %d:' % (index + 1), 'white', attrs=['bold']))
    pprint.pprint(relations)

    print(colored('Propositions:', 'white', attrs=['bold']))
    engine.analyze(relations)
    for i, prop in enumerate(engine.props):
        print(str(i + 1) + ' ' + str(prop))

    print(colored('Unprocessed relations:', 'white', attrs=['bold']))
    for relation in engine.get_unprocessed_relations(relations):
        print(relation)
Beispiel #5
0
def demo():
    graphs = nltk.parse.dependencygraph.DependencyGraph.load(argv[1])
    index = int(argv[2]) - 1

    engine = Engine(rules.all_rulesets, transform.all_transformations)

    relations = []
    for relation in graphs[index].nodelist:
        relations.append(Relation(**relation))

    print(colored('Sentence %d:' % (index + 1), 'white', attrs=['bold']))
    pprint.pprint(relations)

    print(colored('Propositions:', 'white', attrs=['bold']))
    engine.analyze(relations)
    for i, prop in enumerate(engine.props):
        print(str(i + 1) + ' ' + str(prop))

    print(colored('Unprocessed relations:', 'white', attrs=['bold']))
    for relation in engine.get_unprocessed_relations(relations):
        print(relation)
Beispiel #6
0
def process_graphs(graphs):
    engine = Engine(rules.all_rulesets, transform.all_transformations)
    stats = defaultdict(int)

    for index in range(len(graphs) - 1):
        print('-' * int(columns))
        relations = []
        for relation in graphs[index].nodelist:
            relations.append(Relation(**relation))

        print(colored('Sentence %d:' % (index + 1), 'white', attrs=['bold']))
        print('\t' + get_sentence(graphs[index]))

        print(colored('Propositions:', 'white', attrs=['bold']))
        try:
            engine.analyze(relations)
            for i, prop in enumerate(engine.props):
                print(str(i + 1) + ' ' + str(prop))
                stats[prop.kind] += 1
        except Exception:
            pass

    print('-' * int(columns))
    return stats