<commit_before>#!/usr/bin/env python


from nltk.corpus import brown, stopwords
from nltk import ConditionalFreqDist
cfd = ConditionalFreqDist()

stopwords_list = stopwords.words('english')

def is_noun(tag):
    return tag.lower() in ['nn','nns','nn$','nn-tl','nn+bez',
                           'nn+hvz', 'nns$','np','np$','np+bez',
                           'nps', 'nps$','nr','np-tl','nrs','nr$']

for sentence in brown.tagged_sents():
    for (index, tagtuple) in enumerate(sentence):
        (token, tag) = tagtuple
        token = token.lower()
        if token not in stopwords_list and is_noun(tag):
            window = sentence[index+1:index+5]
            for (window_token, window_tag) in window:
                window_token = window_token.lower()
                if window_token not in stopwords_list and is_noun(window_tag):
                    cfd[token].inc(window_token)


# OK. We are done ! Let's start associating !
print('left ->', cfd['left'].max())
print('life ->', cfd['life'].max())
print('man ->', cfd['man'].max())
print('woman ->', cfd['woman'].max())
print('boy ->', cfd['boy'].max())
print('girl ->', cfd['girl'].max())
print('male ->', cfd['male'].max())
print('ball ->', cfd['ball'].max())
print('doctor ->', cfd['doctor'].max())
print('road ->', cfd['road'].max())
<commit_msg>Update task4 for nltk 3<commit_after>#!/usr/bin/env python


from nltk.corpus import brown, stopwords
from nltk import ConditionalFreqDist
cfd = ConditionalFreqDist()

stopwords_list = stopwords.words('english')

def is_noun(tag):
    return tag.lower() in ['nn','nns','nn$','nn-tl','nn+bez',
                           'nn+hvz', 'nns$','np','np$','np+bez',
                           'nps', 'nps$','nr','np-tl','nrs','nr$']

for sentence in brown.tagged_sents():
    for (index, tagtuple) in enumerate(sentence):
        (token, tag) = tagtuple
        token = token.lower()
        if token not in stopwords_list and is_noun(tag):
            window = sentence[index+1:index+5]
            for (window_token, window_tag) in window:
                window_token = window_token.lower()
                if window_token not in stopwords_list and is_noun(window_tag):
                    cfd[token][window_token] += 1


# OK. We are done ! Let's start associating !
print('left ->', cfd['left'].max())
print('life ->', cfd['life'].max())
print('man ->', cfd['man'].max())
print('woman ->', cfd['woman'].max())
print('boy ->', cfd['boy'].max())
print('girl ->', cfd['girl'].max())
print('male ->', cfd['male'].max())
print('ball ->', cfd['ball'].max())
print('doctor ->', cfd['doctor'].max())
print('road ->', cfd['road'].max())

{'fraction_non_alphanumeric': 0.20651762031072377, 'fraction_numerical': 0.002652519893899204, 'mean_word_length': 3.2038216560509554, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '2286800', 'n_tokens_mistral': 904, 'n_tokens_neox': 877, 'n_words': 185}