Esempio n. 1
0
def report_grounding(stmts, list_length=10, bin_interval=10, plot_prefix=None):
    # All agents
    agents = gm.agent_texts_with_grounding(stmts)
    logger.info('Top %d agent strings, with frequencies:' % list_length)
    for i in range(list_length):
        logger.info('%s: %d' % (agents[i][0], agents[i][2]))
    agent_counts = [t[2] for t in agents]
    if plot_prefix:
        plot_filename = '%s_agent_distribution.pdf' % plot_prefix
        logger.info('Plotting occurrences of agent strings in %s' %
                    plot_filename)
        plot_frequencies(agent_counts, plot_filename, bin_interval)
    # Ungrounded agents
    ungrounded = gm.ungrounded_texts(stmts)
    logger.info('Top %d ungrounded strings, with frequencies' % list_length)
    for i in range(list_length):
        logger.info('%s: %d' % (ungrounded[i][0], ungrounded[i][1]))
    ungr_counts = [t[1] for t in ungrounded]
    if plot_prefix:
        plot_filename = '%s_ungrounded_distribution.pdf' % plot_prefix
        logger.info('Plotting occurrences of ungrounded agents in %s' %
                    plot_filename)
        plot_frequencies(ungr_counts, plot_filename, bin_interval)

    # What fraction of statements grounded?
    all_ungrounded = 0
    any_ungrounded = 0
    for stmt in stmts:
        agents_ungrounded = []
        for ag in stmt.agent_list():
            if ag is not None and ag.db_refs.keys() == ['TEXT']:
                agents_ungrounded.append(True)
            else:
                agents_ungrounded.append(False)
        if all(agents_ungrounded):
            all_ungrounded += 1
        if any(agents_ungrounded):
            any_ungrounded += 1

    logger.info('%d of %d (%.1f%%) statements with all agents ungrounded' %
                (all_ungrounded, len(stmts),
                 100 * (all_ungrounded / float(len(stmts)))))
    logger.info('%d of %d (%.1f%%) statements with any agents ungrounded' %
                (any_ungrounded, len(stmts),
                 100 * (any_ungrounded / float(len(stmts)))))
Esempio n. 2
0
def report_grounding(stmts, list_length=10, bin_interval=10, plot_prefix=None):
    # All agents
    agents = gm.agent_texts_with_grounding(stmts)
    logger.info('Top %d agent strings, with frequencies:' % list_length)
    for i in range(list_length):
        logger.info('%s: %d' % (agents[i][0], agents[i][2]))
    agent_counts = [t[2] for t in agents]
    if plot_prefix:
        plot_filename = '%s_agent_distribution.png' % plot_prefix
        logger.info('Plotting occurrences of agent strings in %s' %
                    plot_filename)
        plot_frequencies(agent_counts, plot_filename, bin_interval)
    # Ungrounded agents
    ungrounded = gm.ungrounded_texts(stmts)
    logger.info('Top %d ungrounded strings, with frequencies' % list_length)
    for i in range(min(len(ungrounded), list_length)):
        logger.info('%s: %d' % (ungrounded[i][0], ungrounded[i][1]))
    ungr_counts = [t[1] for t in ungrounded]
    if plot_prefix:
        plot_filename = '%s_ungrounded_distribution.png' % plot_prefix
        logger.info('Plotting occurrences of ungrounded agents in %s' %
                    plot_filename)
        plot_frequencies(ungr_counts, plot_filename, bin_interval)

    # What fraction of statements grounded?
    all_ungrounded = 0
    any_ungrounded = 0
    for stmt in stmts:
        agents_ungrounded = []
        for ag in stmt.agent_list():
            if ag is not None and ag.db_refs.keys() == ['TEXT']:
                agents_ungrounded.append(True)
            else:
                agents_ungrounded.append(False)
        if all(agents_ungrounded):
            all_ungrounded += 1
        if any(agents_ungrounded):
            any_ungrounded += 1

    logger.info('%d of %d (%.1f%%) statements with all agents ungrounded' %
                (all_ungrounded, len(stmts),
                 100 * (all_ungrounded / float(len(stmts)))))
    logger.info('%d of %d (%.1f%%) statements with any agents ungrounded' %
                (any_ungrounded, len(stmts),
                 100 * (any_ungrounded / float(len(stmts)))))