<commit_before>from sklearn.feature_extraction.text import CountVectorizer
from github_database import engine, Commit, File
from sqlalchemy.orm import sessionmaker
from numpy import mean
from collections import Counter
from analyze.helper import extract_commit_components, extract_commit_file_components


def _get_word_frequency(lines):
    count_vect = CountVectorizer()

    X_train_counts = count_vect.fit_transform(lines)
    word_rates = [(word, X_train_counts.getcol(idx).sum()) for word, idx in count_vect.vocabulary_.items()]
    return sorted(word_rates, key=lambda x: -x[1])


def _get_string_frequency(strings):
    counter = Counter(strings)
    return zip(counter.keys(), counter.values())


def _print_general_stats(sample_size=100):
    db_session = sessionmaker(bind=engine)()
    commits = db_session \
        .query(Commit) \
        .all()
    commit_files = db_session \
        .query(File) \
        .all()

    commit_components = extract_commit_components(commits[:sample_size])
    commit_file_components = extract_commit_file_components(commit_files[:sample_size])

    print "Commit Patch Word Frequency"
    print _get_word_frequency(commit_components['messages'])
    print "Commit Repo Frequency"
    print _get_string_frequency(commit_components['repositories'])
    print "Committer Email Frequency"
    print _get_string_frequency(commit_components['emails'])
    # Get Freq of dates
    print "Mean of File Changes in a Commit"
    print mean(commit_components['changed_files'])
    print "\n"

    print "File Path Word Frequency"
    print _get_word_frequency([patch for patch in commit_file_components['patches'] if patch])
    print "Mean of Additions for a File"
    print mean(commit_file_components['additions'])
    print "Mean of Changes for a File"
    print mean(commit_file_components['changes'])
    print "Mean of Deletions for a File"
    print mean(commit_file_components['deletions'])
    # Do something with filename
    print "File Status Frequency"
    print _get_string_frequency(commit_file_components['statuses'])


def run():
    _print_general_stats()

if __name__ == "__main__":
    run()<commit_msg>Fixed typo with print statement<commit_after>from sklearn.feature_extraction.text import CountVectorizer
from github_database import engine, Commit, File
from sqlalchemy.orm import sessionmaker
from numpy import mean
from collections import Counter
from analyze.helper import extract_commit_components, extract_commit_file_components


def _get_word_frequency(lines):
    count_vect = CountVectorizer()

    X_train_counts = count_vect.fit_transform(lines)
    word_rates = [(word, X_train_counts.getcol(idx).sum()) for word, idx in count_vect.vocabulary_.items()]
    return sorted(word_rates, key=lambda x: -x[1])


def _get_string_frequency(strings):
    counter = Counter(strings)
    return zip(counter.keys(), counter.values())


def _print_general_stats(sample_size=100):
    db_session = sessionmaker(bind=engine)()
    commits = db_session \
        .query(Commit) \
        .all()
    commit_files = db_session \
        .query(File) \
        .all()

    commit_components = extract_commit_components(commits[:sample_size])
    commit_file_components = extract_commit_file_components(commit_files[:sample_size])

    print "Commit Message Word Frequency"
    print _get_word_frequency(commit_components['messages'])
    print "Commit Repo Frequency"
    print _get_string_frequency(commit_components['repositories'])
    print "Committer Email Frequency"
    print _get_string_frequency(commit_components['emails'])
    # Get Freq of dates
    print "Mean of File Changes in a Commit"
    print mean(commit_components['changed_files'])
    print "\n"

    print "File Path Word Frequency"
    print _get_word_frequency([patch for patch in commit_file_components['patches'] if patch])
    print "Mean of Additions for a File"
    print mean(commit_file_components['additions'])
    print "Mean of Changes for a File"
    print mean(commit_file_components['changes'])
    print "Mean of Deletions for a File"
    print mean(commit_file_components['deletions'])
    # Do something with filename
    print "File Status Frequency"
    print _get_string_frequency(commit_file_components['statuses'])


def run():
    _print_general_stats()

if __name__ == "__main__":
    run()
{'fraction_non_alphanumeric': 0.08793738489871086, 'fraction_numerical': 0.001841620626151013, 'mean_word_length': 4.709592641261498, 'pattern_counts': {'":': 2, '<': 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': '3168189', 'n_tokens_mistral': 1293, 'n_tokens_neox': 1247, 'n_words': 325}