From baf2243432655a1b89243e32e2ad88509b8b140f Mon Sep 17 00:00:00 2001 From: ana Date: Sat, 15 Oct 2022 16:09:52 +0200 Subject: [PATCH] first scripts --- data_trees.csv | 4 + dreaming_trees.py | 167 ++++++++++++++++++++++++++++++++++ dreams_selection_till_p47.txt | 12 +++ 3 files changed, 183 insertions(+) create mode 100644 data_trees.csv create mode 100644 dreaming_trees.py create mode 100644 dreams_selection_till_p47.txt diff --git a/data_trees.csv b/data_trees.csv new file mode 100644 index 0000000..88ba1e0 --- /dev/null +++ b/data_trees.csv @@ -0,0 +1,4 @@ +Forest,ha,Tree_1,Tree_1_description,Tree_2,Tree_2_description,Tree_3,Tree_3_description,CO2,ratio +Sonian Forest,4421,Beech,"Beech (Fagus) is a genus of deciduous trees in the family Fagaceae, native to temperate Europe, Asia and North America. Recent classifications recognize 10 to 13 species in two distinct subgenera, Engleriana and Fagus. The better known Fagus subgenus beeches are high-branching with tall, stout trunks and smooth silver-grey bark. The European beech (Fagus sylvatica) is the most commonly cultivated.",Oak,"An oak is a tree or shrub in the genus Quercus of the beech family, Fagaceae. There are approximately 500 extant species of oaks. The genus Quercus is native to the Northern Hemisphere, and includes deciduous and evergreen species extending from cool temperate to tropical latitudes in the Americas, Asia, Europe, and North Africa. North America has the largest number of oak species, with approximately 160 species in Mexico of which 109 are endemic and about 90 in the United States. The second greatest area of oak diversity is China, with approximately 100 species.",Hornbeam,"In the Sonian Forest lives a very old hornbeam that became my friend. It took me a long time to establish a relationship. The hornbeam is a very trustworthy companion. The tree helps me to center my thoughts, to answer personal questions, the tree also advises me in my work.",53052,<100000 +Congolian Coastal Forest,18970000,Khaya,"Khaya is a genus of five tree species in the mahogany family Meliaceae. The timber of Khaya is called African mahogany, and is valued as a substitute to American mahogany (of the genus Swietenia). The genus is native to tropical Africa and Madagascar. All species grow to around 30–35m tall, rarely 45m, with a trunk over 1m diameter, often buttressed at the base.",Oil palm,"Khaya is a genus of five tree species in the mahogany family Meliaceae. The timber of Khaya is called African mahogany, and is valued as a substitute to American mahogany (of the genus Swietenia). The genus is native to tropical Africa and Madagascar. All species grow to around 30–35m tall, rarely 45m, with a trunk over 1m diameter, often buttressed at the base.",Okoume,"Aucoumea klaineana (angouma, gaboon, or okoumé) is a tree in the family Burseraceae, native to equatorial west Africa in Gabon, the Republic of the Congo, and Río Muni. It is a large hardwood tree growing to 30–40 m (100–130 feet) tall, rarely larger, with a trunk 1.0–2.5 m (3.5–8 feet) diameter above the often large basal buttresses. The tree generally grows in small stands, with the roots of the trees intertwined with neighboring trees. In Gabon, it is the primary timber species.",227640000,>220000000 +Berlin,,Maple,"In front of my window there is a beautiful maple that whistles in the wind. The tree invites me to contemplate on the weather, the different seasons, the changing colours.",Plane,"Platanus is a genus consisting of a small number of tree species native to the Northern Hemisphere. All mature members of Platanus are tall, reaching 30–50 m (98–164 ft) in height. The hybrid London plane (Platanus × acerifolia) has proved particularly tolerant of urban conditions, and has been widely planted in cities. They are often known in English as planes or plane trees. ",Horse chestnut,"The genus Aesculus, with species called buckeye and horse chestnut, comprises 13–19 species of flowering plants in the family Sapindaceae or soaptrees. Carl Linnaeus named the genus Aesculus after the Roman name for an edible acorn. Common names for these trees include ""buckeye"" and ""horse chestnut"", though they are not in the same order as the true chestnuts, Castanea. ",0.003,<1 diff --git a/dreaming_trees.py b/dreaming_trees.py new file mode 100644 index 0000000..9060251 --- /dev/null +++ b/dreaming_trees.py @@ -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 diff --git a/dreams_selection_till_p47.txt b/dreams_selection_till_p47.txt new file mode 100644 index 0000000..f5c1a33 --- /dev/null +++ b/dreams_selection_till_p47.txt @@ -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. + + +