Exemple #1
0
def main():
    text_file = "Chapter01/sherlock_holmes.txt"
    text = read_text_file(text_file)
    #sherlock_data = Image.open("Chapter08/sherlock.png")
    #sherlock_mask = np.array(sherlock_data)
    create_wordcloud(text, compile_stopwords_list_frequency(text),
                     "Chapter08/sherlock_wc.png")
def main():
    text = read_text_file("Chapter01/sherlock_holmes.txt")
    sentences = divide_into_sentences_nltk(text)
    model = SentenceTransformer('bert-base-nli-mean-tokens')
    sentence_embeddings = model.encode(["the beautiful lake"])

    print("Sentence embeddings:")
    print(sentence_embeddings)
Exemple #3
0
def visualize_verbs(text_file):
    text = read_text_file(text_file)
    doc = nlp(text)
    verb_dict = {"Inf": 0, "Past": 0, "Present": 0}
    for token in doc:
        if (token.tag_ == "VB"):
            verb_dict["Inf"] = verb_dict["Inf"] + 1
        if (token.tag_ in past_tags):
            verb_dict["Past"] = verb_dict["Past"] + 1
        if (token.tag_ in present_tags):
            verb_dict["Present"] = verb_dict["Present"] + 1
    plt.bar(range(len(verb_dict)),
            list(verb_dict.values()),
            align='center',
            color=["red", "green", "blue"])
    plt.xticks(range(len(verb_dict)), list(verb_dict.keys()))
    plt.show()
Exemple #4
0
def get_sherlock_holmes_noun_chunks():
    text = read_text_file("Chapter01/sherlock_holmes_1.txt")
    text = preprocess_text(text)
    doc = nlp(text)
    for noun_chunk in doc.noun_chunks:
        print(noun_chunk.text)
def get_sentences(filename):
    sherlock_holmes_text = read_text_file(filename)
    sherlock_holmes_text = preprocess_text(sherlock_holmes_text)
    sentences = divide_into_sentences_nltk(sherlock_holmes_text)
    return sentences