<commit_before>from collections import Counter
import math
import numpy

from nlp import nlp_utils
from utils.constants import Constants

__author__ = 'fpena'


def get_review_metrics(record):
    """
    Returns a list with the metrics of a review. This list is composed
    in the following way: [log(num_sentences + 1), log(num_words + 1),
    log(num_past_verbs + 1), log(num_verbs + 1),
    (log(num_past_verbs + 1) / log(num_verbs + 1))

    :type record: dict
    :param record: the review that wants to be analyzed, it should contain the
    text of the review
    :rtype: list[float]
    :return: a list with numeric metrics
    """
    review_text = record[Constants.TEXT_FIELD]
    log_sentences = math.log(len(nlp_utils.get_sentences(review_text)) + 1)
    log_words = math.log(len(nlp_utils.get_words(review_text)) + 1)
    # log_time_words = math.log(len(self.get_time_words(review.text)) + 1)
    tagged_words = record[Constants.POS_TAGS_FIELD]
    counts = Counter(tag for word, tag, lemma in tagged_words)
    # print(counts)
    log_past_verbs = math.log(counts['VBD'] + 1)
    log_verbs = math.log(nlp_utils.count_verbs(counts) + 1)
    log_personal_pronouns = math.log(counts['PRP'] + 1)
    # log_sentences = float(len(get_sentences(review.text)) + 1)
    # log_words = float(len(get_words(review.text)) + 1)
    # log_time_words = float(len(self.get_time_words(review.text)) + 1)
    # tagged_words = review.tagged_words<commit_msg>Fixed small bug. Words in reviews where being counted wrong, they were including punctuation marks<commit_after>from collections import Counter
import math
import numpy

from nlp import nlp_utils
from utils.constants import Constants

__author__ = 'fpena'


def get_review_metrics(record):
    """
    Returns a list with the metrics of a review. This list is composed
    in the following way: [log(num_sentences + 1), log(num_words + 1),
    log(num_past_verbs + 1), log(num_verbs + 1),
    (log(num_past_verbs + 1) / log(num_verbs + 1))

    :type record: dict
    :param record: the review that wants to be analyzed, it should contain the
    text of the review
    :rtype: list[float]
    :return: a list with numeric metrics
    """
    review_text = record[Constants.TEXT_FIELD]
    log_sentences = math.log(len(nlp_utils.get_sentences(review_text)) + 1)
    # log_time_words = math.log(len(self.get_time_words(review.text)) + 1)
    tagged_words = record[Constants.POS_TAGS_FIELD]
    log_words = math.log(len(tagged_words) + 1)
    counts = Counter(tag for word, tag, lemma in tagged_words)
    # print(counts)
    log_past_verbs = math.log(counts['VBD'] + 1)
    log_verbs = math.log(nlp_utils.count_verbs(counts) + 1)
    log_personal_pronouns = math.log(counts['PRP'] + 1)
    # log_sentences = float(len(get_sentences(review.text)) + 1)
    # log_words = float(len(get_words(review.text)) + 1)
    # log_time_words = float(len(self.get_time_words(review.text)) + 1)
    # tagged_words = review.tagged_words
{'fraction_non_alphanumeric': 0.10931718802556341, 'fraction_numerical': 0.010090817356205853, 'mean_word_length': 4.136442141623489, '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': '1462379', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1026, 'n_words': 251}