<commit_before>import random

from grammar.grammar import Grammar
from grammar.parse_tree import ParseTree


def inspect_parse_tree(genotype=None, grammar_file=None):

    if genotype is None:

        genotype = [raw_input('Enter a genotype (i.e. 34, 1, 93, ...): ').replace(",", "").split()]

    grammar = Grammar(grammar_file)
    parse_tree = ParseTree(grammar, genotype)
    parse_tree.generate()
    print parse_tree


def inspect_simulation(genotype=None, grammar_file=None):

    from simulation.entity import SimAgent, Food, Nest
    from simulation.environment import Environment
    from simulation.simulation import Simulation
    from simulation.utils import generate_mongo

    if genotype is None:

        genotype = [raw_input('Enter a genotype (i.e. 34, 1, 93, ...): ').replace(",", "").split()]

    grammar = Grammar(grammar_file)
    parse_tree = ParseTree(grammar, genotype)
    parse_tree.generate()

    # Create the entities for the simulation.
    agents = [SimAgent(position=(random.randint(0, 20), random.randint(0, 20))) for _ in xrange(5)]
    nest = Nest(position=(8, 8), size=(4, 4))
    food = [Food(position=(random.randint(0, 20), random.randint(0, 20))) for _ in xrange(10)]

    entities = agents + [nest] + food

    # Create the environment for the simulation.
    env = Environment()

    # Create and execute the simulation.
    sim = Simulation(environment=env, entities=entities, parse_tree=parse_tree.root.obj)
    sim.execute()

    generate_mongo(sim)

    # Get the food tags collected, and return as the evaluation score.
    nest = filter(lambda x: isinstance(x, Nest), sim.entities)<commit_msg>Updated Inspect Module<commit_after>import random

from grammar.grammar import Grammar
from grammar.parse_tree import ParseTree
# TODO - Determine proper import for ObjectId
from pymongo import MongoClient


def inspect_parse_tree(genotype=None, grammar_file=None):

    if not isinstance(genotype, list):

        genotype = [raw_input('Enter a genotype (i.e. 34, 1, 93, ...): ').replace(",", "").split()]

    grammar = Grammar(grammar_file)
    parse_tree = ParseTree(grammar, genotype)
    parse_tree.generate()
    print parse_tree


def inspect_simulation(genotype=None, grammar_file=None, host='localhost', port=27017):

    from simulation.entity import SimAgent, Food, Nest
    from simulation.environment import Environment
    from simulation.simulation import Simulation
    from simulation.utils import generate_mongo

    if isinstance(genotype, ObjectId)

        connection = MongoClient(host, port)
        simulations = connection['grove']['simulations']

        # TODO - Determine how to access record. Its probably...
        simulation = simulations[genotype]

    elif not isinstance(genotype, list):

        genotype = [raw_input('Enter a genotype (i.e. 34, 1, 93, ...): ').replace(",", "").split()]

    grammar = Grammar(grammar_file)
    parse_tree = ParseTree(grammar, genotype)
    parse_tree.generate()

    # Create the entities for the simulation.
    agents = [SimAgent(position=(random.randint(0, 20), random.randint(0, 20))) for _ in xrange(5)]
    nest = Nest(position=(8, 8), size=(4, 4))
    food = [Food(position=(random.randint(0, 20), random.randint(0, 20))) for _ in xrange(10)]

    entities = agents + [nest] + food

    # Create the environment for the simulation.
    env = Environment()

    # Create and execute the simulation.
    sim = Simulation(environment=env, entities=entities, parse_tree=parse_tree.root.obj)
    sim.execute()

    generate_mongo(sim)

    # Get the food tags collected, and return as the evaluation score.
    nest = filter(lambda x: isinstance(x, Nest), sim.entities)
{'fraction_non_alphanumeric': 0.11686550976138829, 'fraction_numerical': 0.017082429501084597, 'mean_word_length': 3.86034255599473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3049214', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1076, 'n_words': 317}