Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
Greffage des arbres
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Package Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
algolit
Greffage des arbres
Commits
423f2092
Commit
423f2092
authored
Sep 21, 2020
by
ana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finetuning lay-out
parent
ad6c82e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
71 deletions
+42
-71
greffer_des_arbres_sketch.py
greffer_des_arbres_sketch.py
+42
-71
No files found.
greffer_des_arbres_sketch.py
View file @
423f2092
...
...
@@ -113,91 +113,62 @@ def greffer(bourgeons):
# replace nouns in quote by their definitions
def
greffes_qui_poussent
(
greffes
,
arbre
):
for
greffe
in
greffes
:
if
greffe
:
mot
=
greffe
[
0
]
print
(
"mot:"
,
mot
)
if
mot
in
arbre
:
definition
=
greffe
[
1
]
print
(
"definition:"
,
definition
)
arbre_greffe
=
arbre
.
replace
(
mot
,
definition
)
return
arbre_greffe
greffe
=
random
.
choice
(
greffes
)
mot
=
greffe
[
0
]
# print("mot:", mot)
if
mot
in
arbre
:
definition
=
greffe
[
1
]
position
=
arbre
.
find
(
mot
)
# print("definition:", definition)
# arbre_greffe = arbre.replace(mot, definition)
return
(
arbre
[:
position
],
mot
,
definition
,
arbre
[
position
+
len
(
mot
):])
def
show
(
state
,
length
=
1
):
os
.
system
(
'clear'
)
# Optionally vertically align here
print
(
state
)
time
.
sleep
(
length
)
# EXECUTE
# find quote & author
jardinier
,
arbre
=
choix_arbre
(
arbres
)
print
(
"jardinier:"
,
jardinier
,
"arbre:"
,
arbre
)
#
print("jardinier:", jardinier, "arbre:", arbre)
# find bio author
short_bio
=
bio_offline
(
jardinier
)
print
(
"bref bio:"
,
short_bio
)
# print("bref bio:", short_bio)
show
(
"L'arbre initial est une citation de {}{}{}
\n\n
"
.
format
(
bold
,
jardinier
,
reset
)
+
short_bio
,
5
)
while
len
(
arbre
)
<
1500
:
# find nouns and their positions in quote
bourgeons
=
trouver_les_bourgeons
(
arbre
)
print
(
"bourgeons:"
,
bourgeons
)
#
print("bourgeons:", bourgeons)
# find definitions for nouns from dictionary
greffes
=
greffer
(
bourgeons
)
print
(
"greffes:"
,
greffes
)
#
print("greffes:", greffes)
# replace nouns in quote by their definitions
arbre_greffe
=
greffes_qui_poussent
(
greffes
,
arbre
)
print
(
'
\n
'
)
print
(
"arbre greffé:"
,
arbre_greffe
)
print
(
'
\n
'
)
head
,
mot
,
definition
,
tail
=
greffes_qui_poussent
(
greffes
,
arbre
)
# Make new tree placeholder for the bud show we can show it in two states and then grow out
arbre_greffe
=
'{} {{}} {}'
.
format
(
head
,
tail
)
show
(
arbre
,
3
)
# Mark the bud, underlined and orange
show
(
arbre_greffe
.
format
(
"{}{}{}{}{}"
.
format
(
bold
,
yellow
,
mot
,
reset
,
reset
)),
2
)
# Mark the new branch green
show
(
arbre_greffe
.
format
(
"{}{}{}"
.
format
(
spring_green
,
definition
,
reset
)),
2
)
show
(
arbre_greffe
.
format
(
"{}{}{}"
.
format
(
fg
(
82
),
definition
,
reset
)),
1
)
show
(
arbre_greffe
.
format
(
"{}{}{}"
.
format
(
fg
(
120
),
definition
,
reset
)),
1
)
show
(
arbre_greffe
.
format
(
"{}{}{}"
.
format
(
fg
(
157
),
definition
,
reset
)),
1
)
show
(
arbre_greffe
.
format
(
"{}{}{}"
.
format
(
fg
(
195
),
definition
,
reset
)),
1
)
# convert changed quote into new tree to be grafted
arbre
=
arbre_greffe
# ---------------------------------------
# GIJS code to show replacements in color
# def show (state, length=1):
# os.system('clear')
# # Optionally vertically align here
# print(state)
# time.sleep(length)
# def grow (tree, generation = 1):
# branches = nltk.pos_tag(word_tokenize(tree))
# # Filter out nouns, pick one
# position, bud = random.choice([(position, bud[0]) for position, bud in enumerate(branches) if bud[1] == 'NN'])
# # Make new tree placeholder for the bud show we can show it in two states and then grow out
# next_tree = '{} {{}} {}'.format(trim_tree(branches[:max(0, position)]), trim_tree(branches[position+1:]))
# new_branch = grow_new_branch(bud)
# show(tree, 3 if generation == 1 else 1)
# # Mark the bud, underlined and orange
# show(next_tree.format("{}{}{}{}{}".format(bold, yellow, bud, reset, white)), 2)
# # Mark the new branch green
# show(next_tree.format("{}{}{}".format(spring_green, new_branch, white)), 2)
# show(next_tree.format("{}{}{}".format(fg(82), new_branch, white)), 1)
# show(next_tree.format("{}{}{}".format(fg(120), new_branch, white)), 1)
# show(next_tree.format("{}{}{}".format(fg(157), new_branch, white)), 1)
# show(next_tree.format("{}{}{}".format(fg(195), new_branch, white)), 1)
# # Let it grow again
# return next_tree.format(new_branch)
# if __name__ == '__main__':
# while True:
# gardener, source, tree = choose_a_tree(trees)
# short_bio = bio_offline(gardener)
# show(
# 'Using a quote by {}{}{}\n\n'.format(bold, gardener, reset) \
# + short_bio, 3
# )
# generation = 1
# while len(tree) < 1500:
# next_tree = grow(tree, generation)
# if next_tree == tree:
# break
# else:
# tree = next_tree
# generation += 1
\ No newline at end of file
arbre
=
arbre_greffe
.
format
(
definition
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment