first scripts
commit
baf2243432
|
@ -0,0 +1,167 @@
|
||||
import csv
|
||||
import spacy
|
||||
|
||||
# opening the CSV file
|
||||
def call_trees(file):
|
||||
data = []
|
||||
with open(file, mode ='r') as source:
|
||||
# reading the CSV file
|
||||
csvFile = csv.DictReader(source)
|
||||
# displaying the contents of the CSV fil
|
||||
for line in csvFile:
|
||||
data.append(line)
|
||||
return data
|
||||
|
||||
# open textfile
|
||||
def open_dreams(textfile):
|
||||
with open(textfile, mode ='r') as dreams:
|
||||
dreaming = dreams.read()
|
||||
return dreaming
|
||||
|
||||
def part_of_speech(text):
|
||||
#load core english library
|
||||
nlp = spacy.load("en_core_web_sm")
|
||||
# import text in spacy
|
||||
doc = nlp(text)
|
||||
# Token and Tag
|
||||
tokens = []
|
||||
for token in doc:
|
||||
tokens.append(token)
|
||||
# You want list of Verb tokens
|
||||
verbs = [token.text for token in doc if token.pos_ == "VERB"]
|
||||
nouns = [token.text for token in doc if token.pos_ == "NOUN"]
|
||||
adjectives = [token.text for token in doc if token.pos_ == "ADJ"]
|
||||
articles = adjectives = [token.text for token in doc if token.pos_ == "DET"]
|
||||
return doc, tokens, verbs, nouns, adjectives, articles
|
||||
|
||||
def convert_token_to_text(doc):
|
||||
new_text = []
|
||||
for i in doc:
|
||||
new_text.append(''+i.text+'')
|
||||
return new_text
|
||||
|
||||
def replace_pos(text, pos_list):
|
||||
position = 0
|
||||
for word in text:
|
||||
if word in pos_list:
|
||||
length = len(word)
|
||||
replacement = length*" "
|
||||
text[position]= replacement
|
||||
position +=1
|
||||
return text
|
||||
|
||||
def highlight_word(text, pos_list):
|
||||
position = 0
|
||||
for word in text:
|
||||
if word in pos_list:
|
||||
replacement = "**"+word.upper()+"**"
|
||||
text[position]= replacement
|
||||
position +=1
|
||||
return text
|
||||
|
||||
def in_between(text, pos_list):
|
||||
position = 0
|
||||
for word in text:
|
||||
if word in pos_list:
|
||||
replacement = " !* "+word + " $& "
|
||||
text[position]= replacement
|
||||
position +=1
|
||||
return text
|
||||
# # distortion individual trees when ration <1
|
||||
# def strong_distortion(text):
|
||||
# vowels = ["a", "e", "i", "o", "u"]
|
||||
# for letter in text:
|
||||
# if letter in vowels:
|
||||
# text = text.replace(letter, "!")
|
||||
# return text
|
||||
|
||||
# --------------
|
||||
# create list of dictionaries with Forest, ha, Tree_1, Tree_2, Tree_3, CO2 in tonnes, ratio
|
||||
file = "data_trees.csv"
|
||||
data = call_trees(file)
|
||||
#print(data)
|
||||
|
||||
# open file with dreams
|
||||
textfile = "dreams_selection_till_p47.txt"
|
||||
dreaming = open_dreams(textfile)
|
||||
#print(dreaming)
|
||||
|
||||
# choose location and tree
|
||||
print("These are locations where you can catch dreams near trees: \n")
|
||||
nr = 0
|
||||
for element in data:
|
||||
print(str(nr) + ' --- ' + element['Forest'])
|
||||
nr += 1
|
||||
print("\n")
|
||||
location = input("Where do you want to receive your dream? Type a number: \n")
|
||||
print("Thanks for choosing "+ data[int(location)]['Forest']+".\n")
|
||||
print("There are 3 trees that offer dream services: \n")
|
||||
print("1" + ' --- ' + data[int(location)]['Tree_1'])
|
||||
print("2" + ' --- ' + data[int(location)]['Tree_2'])
|
||||
print("3" + ' --- ' + data[int(location)]['Tree_3'])
|
||||
print("\n")
|
||||
tree_number = input("Which tree do you prefer to dream with? Type a number: \n")
|
||||
selected_tree = "Tree_"+tree_number
|
||||
dream_tree = data[int(location)][selected_tree]
|
||||
|
||||
print("\n_________________________________\n")
|
||||
|
||||
# Printing text
|
||||
title = "Dreaming with "+ dream_tree +" in "+ data[int(location)]['Forest']
|
||||
print(title)
|
||||
print("_________________________________\n")
|
||||
|
||||
selected_description = selected_tree + "_description"
|
||||
description_tree = data[int(location)][selected_description]
|
||||
print(description_tree)
|
||||
|
||||
print("\n_________________________________\n")
|
||||
|
||||
template_text = "Trees absorb CO2 from the air and generate oxygen. \
|
||||
In forests and parks, the concentration of trees is high and CO2 emissions are often low,\
|
||||
because traffic is inexistant. The air quality for humans is therefore generally better.\
|
||||
The hypothesis exists that the high concentration of trees allows for more lucid dreaming.\
|
||||
It is said as well that a personal relationship to a tree can enhance lucid dreaming as well,\
|
||||
even if the tree is living in an urban area."
|
||||
print(template_text)
|
||||
|
||||
print("\n_________________________________\n")
|
||||
|
||||
doc, tokens, verbs, nouns, adjectives, articles = part_of_speech(dreaming)
|
||||
# print("Verbs:", verbs)
|
||||
# print("Nouns:", nouns)
|
||||
# print("Adjectives:", adjectives)
|
||||
# print("Articles:", articles)
|
||||
|
||||
# convert spacy token objects to strings in list
|
||||
tokenized_text = convert_token_to_text(doc)
|
||||
|
||||
|
||||
if float(data[int(location)]["CO2"]) < 1:
|
||||
# if ration is <1
|
||||
# replace verbs by spaces of same length
|
||||
article_text = replace_pos(tokenized_text, articles)
|
||||
final_text = replace_pos(article_text, nouns)
|
||||
print("ENJOY YOUR DREAMS ! \n")
|
||||
print("\n_________________________________\n")
|
||||
print(" ".join(final_text))
|
||||
print("\n_________________________________\n")
|
||||
|
||||
elif float(data[int(location)]["CO2"]) > 110000:
|
||||
verb_text = highlight_word(tokenized_text, verbs)
|
||||
final_text = highlight_word(verb_text, nouns)
|
||||
print("ENJOY YOUR DREAMS ! \n")
|
||||
print("\n_________________________________\n")
|
||||
print(" ".join(final_text))
|
||||
print("\n_________________________________\n")
|
||||
else:
|
||||
final_text = in_between(tokenized_text, nouns)
|
||||
print("ENJOY YOUR DREAMS ! \n")
|
||||
print("\n_________________________________\n")
|
||||
print(" ".join(final_text))
|
||||
print("\n_________________________________\n")
|
||||
|
||||
|
||||
|
||||
# create 3 dream convertors depending on where the trees are located
|
||||
# if ratio is < 1, , > 500000
|
@ -0,0 +1,12 @@
|
||||
I was under a tree and was visited by a dear friend of many years; uncle Carlito. He is physically disabled, has lost both legs, is in a wheelchair. Very cheerful and funny person, he was happy as always. We were talking and suddenly I saw a butterfly with silver parts flying over us. I reached out, touched it and many silver particles fell on my arms ... I looked at my arms and hands and my skin was very dark and shone with silver dots. Afterwards, my companion and I were going to leave the house and I remembered to offer Uncle Carlito a bed to rest… My companion had already taken him to a bed.
|
||||
|
||||
I saw a beautiful bird in the middle of trees and plants. I got up to see him better and I was on a beach. In my view was the bird with a dark iridescent color, a colorful light shone. Next to it I noticed some flamingos on the beach and yellow ipe trees in full bloom. I took out my cell phone to take a picture and when I framed the bird there were people in front. I framed a scene of a large group of people sitting in swirling beach chairs, having fun among the ipe trees. I started to get closer and remembered that there shouldn't be groups like that on the beach because of the quarantine. And I realized that I shouldn't be on the beach either. I was in Rio de Janeiro and tried to remember Corona's indexes in RJ, but I couldn't. I met a friend from SP and commented about having so many people on the street with her. I had a plastic bottle in my hand and I didn't remember where it came from, but it could be contaminated. I threw the bottle away and immediately went to wash my hand. The biggest problem was turning off the tap after washing your hands.
|
||||
|
||||
It is all over, population reduced, everyday life is back again. Breathing in fresh air we are glad about surviving. The loss of friends and family is painful, hard to say how we managed to survive. Funerals kept us busy and now we start moving back to work. The sky turns yellow, the city seems powerful although you feel black colour everywhere. A bird comes to say hello. A horse asks me to ride on it. The trees are welcoming everybody and life is celebrated. Breathing in and out is so wonderful.
|
||||
|
||||
As if it were a film showing several cut trees, devastated fields ... In a moment I was in this field. The trees were gray, they were cut at about my height, there was a corridor for me to go through and observe them. I remember the camp being devastated. On the left were fewer trees. On the right much more. There were no people with me. Nothing was green. Even the land was kind of dark and gray. But the sky was clear and more blue than cloudy. Shortly afterwards I see a friend, with a personalized apron, working in a huge restaurant with vegan foods, she was happy! The environment was artificially lit and not very clear, but it was a very large place. She was walking in a little hurry. It looked like he had a lot of work.
|
||||
|
||||
I was at a rave and he was there, we talked as if we already knew each other, and his wife saw us walking along and looked like she was really upset but she didn't say anything. Then he asked me to go home with them (his wife, their baby, me and him) so I accepted and we went. On the way they started to have a DR, and I realized that I was interested in the two of them, I felt a huge desire to kiss them and have sex with them, but I tried to be discreet. The road we were walking on was dirt, it looked like an interior. Suddenly a cow with horns appears at the side of the road, she looked very angry. I started to shake with fear and shouted “CORREE”, we ran each one in one direction and the cow ran right in my direction, I got to the front of a little house and stopped for a few moments until I felt someone holding my hand, it was him asking to go with him, but I didn't want to and I let go and started running again, I look back and the cow is extremely close. I am now inside the house with the two of them, I am holding the baby until he says he is going to the fields to see the marijuana plantation, I ask him to go along and let's go. I realize that again she gets a little upset. Once there, I start to walk around the plantation, it's a big place, so I start to distance myself from it and see other plantations and go towards them. On this way I meet a child, a boy who starts talking to me and out of nowhere he screams: "RUN, ONE OZ". And I run faster than before, look back and see that it is not a jaguar but a jaguar or some kind of cat. I can climb a tree even though I know they climb trees. When I finally reach the top of the tree, I realize that the cat is gone. From the tree top you have a beautiful view.
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue