commited all contents created by participants
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/python
|
||||
# this is a shebang: https://en.wikipedia.org/wiki/Shebang_%28Unix%29
|
||||
|
||||
'''
|
||||
This script takes a sentence you write in the terminal, and gives it back in alphabetical order
|
||||
Check out other options for list comprehension: https://docs.python.org/3/tutorial/datastructures.html
|
||||
Made for OLA #5, Paris, 15-17 décembre 2017
|
||||
'''
|
||||
|
||||
# Run script in loop:
|
||||
while True:
|
||||
|
||||
# Ask to write a sentence
|
||||
sentence = input("Ecrivez votre phrase: ").lower().strip('\., \?')
|
||||
|
||||
# Split sentence into words
|
||||
words = sentence.split()
|
||||
#print(words)
|
||||
|
||||
# sort wordlist
|
||||
words.sort()
|
||||
print(" ".join(words).capitalize(), '.')
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
*.pyc
|
||||
*.egg-info
|
||||
build/
|
||||
dist/
|
||||
@@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
@@ -0,0 +1 @@
|
||||
include README.rst LICENSE
|
||||
@@ -0,0 +1,60 @@
|
||||
ANSI colors for Python
|
||||
======================
|
||||
|
||||
A simple module to add ANSI colors and decorations to your strings.
|
||||
|
||||
Install
|
||||
--------
|
||||
python set_up.py install
|
||||
|
||||
Example Usage
|
||||
-------------
|
||||
|
||||
You can choose one of the 8 basic ANSI colors: black, red, green, yellow, blue,
|
||||
magenta, cyan, white.
|
||||
|
||||
::
|
||||
|
||||
from colors import red, green, blue
|
||||
print red('This is red')
|
||||
print green('This is green')
|
||||
print blue('This is blue')
|
||||
|
||||
Optionally you can specify a background color.
|
||||
|
||||
::
|
||||
|
||||
print red('red on blue', bg='blue')
|
||||
print green('green on black', bg='black')
|
||||
|
||||
You can additionally specify one of the supported styles: bold, faint, italic,
|
||||
underline, blink, blink2, negative, concealed, crossed. Not all styles are
|
||||
supported by all terminals.
|
||||
|
||||
::
|
||||
|
||||
from colors import bold, underline
|
||||
print bold('This is bold')
|
||||
print underline('underline red on blue', fg='red', bg='blue')
|
||||
print green('bold green on black', bg='black', style='bold')
|
||||
|
||||
You can also use more than one styles at once.
|
||||
|
||||
::
|
||||
|
||||
print red('This is very important', style='bold+underline')
|
||||
|
||||
xterm-256 colors are supported as well, to use them give an integer instead of
|
||||
a color name.
|
||||
|
||||
::
|
||||
|
||||
from colors import color
|
||||
for i in range(256):
|
||||
print color('Color #%d' % i, fg=i)
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
colors is licensed under the ISC license.
|
||||
@@ -0,0 +1,85 @@
|
||||
# Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
# copyright notice and this permission notice appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import re
|
||||
|
||||
from functools import partial
|
||||
|
||||
|
||||
__version__ = '1.0.2'
|
||||
|
||||
COLORS = ('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan',
|
||||
'white')
|
||||
STYLES = ('bold', 'faint', 'italic', 'underline', 'blink', 'blink2',
|
||||
'negative', 'concealed', 'crossed')
|
||||
|
||||
|
||||
def color(s, fg=None, bg=None, style=None):
|
||||
sgr = []
|
||||
|
||||
if fg:
|
||||
if fg in COLORS:
|
||||
sgr.append(str(30 + COLORS.index(fg)))
|
||||
elif isinstance(fg, int) and 0 <= fg <= 255:
|
||||
sgr.append('38;5;%d' % int(fg))
|
||||
else:
|
||||
raise Exception('Invalid color "%s"' % fg)
|
||||
|
||||
if bg:
|
||||
if bg in COLORS:
|
||||
sgr.append(str(40 + COLORS.index(bg)))
|
||||
elif isinstance(bg, int) and 0 <= bg <= 255:
|
||||
sgr.append('48;5;%d' % bg)
|
||||
else:
|
||||
raise Exception('Invalid color "%s"' % bg)
|
||||
|
||||
if style:
|
||||
for st in style.split('+'):
|
||||
if st in STYLES:
|
||||
sgr.append(str(1 + STYLES.index(st)))
|
||||
else:
|
||||
raise Exception('Invalid style "%s"' % st)
|
||||
|
||||
if sgr:
|
||||
prefix = '\x1b[' + ';'.join(sgr) + 'm'
|
||||
suffix = '\x1b[0m'
|
||||
return prefix + s + suffix
|
||||
else:
|
||||
return s
|
||||
|
||||
|
||||
def strip_color(s):
|
||||
return re.sub('\x1b\[.+?m', '', s)
|
||||
|
||||
|
||||
# Foreground shortcuts
|
||||
black = partial(color, fg='black')
|
||||
red = partial(color, fg='red')
|
||||
green = partial(color, fg='green')
|
||||
yellow = partial(color, fg='yellow')
|
||||
blue = partial(color, fg='blue')
|
||||
magenta = partial(color, fg='magenta')
|
||||
cyan = partial(color, fg='cyan')
|
||||
white = partial(color, fg='white')
|
||||
|
||||
# Style shortcuts
|
||||
bold = partial(color, style='bold')
|
||||
faint = partial(color, style='faint')
|
||||
italic = partial(color, style='italic')
|
||||
underline = partial(color, style='underline')
|
||||
blink = partial(color, style='blink')
|
||||
blink2 = partial(color, style='blink2')
|
||||
negative = partial(color, style='negative')
|
||||
concealed = partial(color, style='concealed')
|
||||
crossed = partial(color, style='crossed')
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from setuptools import setup
|
||||
|
||||
import colors
|
||||
|
||||
|
||||
setup(
|
||||
name='ansicolors',
|
||||
version=colors.__version__,
|
||||
description='ANSI colors for Python',
|
||||
long_description=open('README.rst').read(),
|
||||
author='Giorgos Verigakis',
|
||||
author_email='verigak@gmail.com',
|
||||
url='http://github.com/verigak/colors/',
|
||||
license='ISC',
|
||||
py_modules=['colors'],
|
||||
classifiers=[
|
||||
'Environment :: Console',
|
||||
'Intended Audience :: Developers',
|
||||
'License :: OSI Approved :: ISC License (ISCL)',
|
||||
'Programming Language :: Python :: 2.6',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3'
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from colors import color, COLORS, STYLES
|
||||
|
||||
|
||||
for bg in (None,) + COLORS:
|
||||
for fg in (None,) + COLORS:
|
||||
for style in (None,) + STYLES:
|
||||
text = ('%s' % (fg or 'normal')).ljust(7)
|
||||
print(color(text, fg=fg, bg=bg, style=style), end=' ')
|
||||
print()
|
||||
|
||||
for i in range(256):
|
||||
if i % 64 == 0:
|
||||
print()
|
||||
print(color(' ', bg=i), end='')
|
||||
|
||||
print()
|
||||
+3
File diff suppressed because one or more lines are too long
@@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env/ python
|
||||
|
||||
# This script rewrites the novel by replacing the name of the principal
|
||||
# character in the novel by another name.
|
||||
# It writes the new version of novel to a file called starring_me.txt and to a Logbook in Context
|
||||
# The idea for this script comes from the book 'Think Python'.
|
||||
|
||||
# Copyright (C) 2016 Constant, Algolit, An Mertens
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details: <http://www.gnu.org/licenses/>.
|
||||
|
||||
import colors
|
||||
from colors import red, green, yellow, blue, magenta, cyan, bold, underline
|
||||
import time
|
||||
import os, sys
|
||||
|
||||
## FUNCTIONS
|
||||
# print on screen character per character
|
||||
def typewrite(sentence):
|
||||
words = sentence.split(" ")
|
||||
for word in words:
|
||||
for char in word:
|
||||
sys.stdout.write('%s' % char)
|
||||
sys.stdout.flush()
|
||||
time.sleep(0.1)
|
||||
sys.stdout.write(" ")
|
||||
sys.stdout.flush()
|
||||
|
||||
# write to file
|
||||
def archive(sentence):
|
||||
with open("novel_starring_you.txt", "a") as destination:
|
||||
destination.write(sentence)
|
||||
|
||||
# loop script
|
||||
while True:
|
||||
|
||||
# introduction, getting the variables
|
||||
print("\n\t\tDear visitor, we will rewrite the opening scene of ", green("Kurt Vonnegut's 2BRO2B"), " using your name and favourite city.\n")
|
||||
#time.sleep(2)
|
||||
first_name = input("\t\tPlease type your first name: ")
|
||||
#time.sleep(2)
|
||||
last_name = input("\n\t\tPlease type your last name: ")
|
||||
#time.sleep(2)
|
||||
country = input("\n\t\tChoose a country: ")
|
||||
#time.sleep(2)
|
||||
city = input("\n\t\tChoose a city in that country: ")
|
||||
#time.sleep(2)
|
||||
print("\n\t\tDo you want to be", green('female'), "or", green('male?'))
|
||||
gender = input("\t\tPlease type f or m: ")
|
||||
#time.sleep(5)
|
||||
print("\n")
|
||||
|
||||
# specify input text
|
||||
source = open("vonnegut.txt", "r")
|
||||
sentences =[]
|
||||
|
||||
# write & replace
|
||||
archive("\n\nNovel Starring You\n")
|
||||
archive("-------------\n\n")
|
||||
|
||||
with source as text:
|
||||
for line in text:
|
||||
line = line.replace("the United States", country)
|
||||
line = line.replace("Chicago", city)
|
||||
line = line.replace("Edward K.", first_name)
|
||||
line = line.replace("Wehling", last_name)
|
||||
if gender == 'f':
|
||||
line = line.replace(" man ", " woman ")
|
||||
line = line.replace(" man,", " woman,")
|
||||
line = line.replace(" his ", " her ")
|
||||
line = line.replace(" him ", " her ")
|
||||
line = line.replace(" His ", " Her ")
|
||||
line = line.replace(" wife ", " husband ")
|
||||
line = line.replace(" he ", " she ")
|
||||
line = line.replace(" He ", " She ")
|
||||
typewrite(line)
|
||||
archive(line)
|
||||
# break before relaunching the script
|
||||
time.sleep(10)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
|
||||
Novel Starring You
|
||||
-------------
|
||||
|
||||
Everything was perfectly swell.
|
||||
|
||||
There were no prisons, no slums, no insane asylums, no cripples, no poverty, no wars.
|
||||
|
||||
All diseases were conquered. So was old age.
|
||||
|
||||
Death, barring accidents, was an adventure for volunteers.
|
||||
|
||||
|
||||
|
||||
Novel Starring You
|
||||
-------------
|
||||
|
||||
Everything was perfectly swell.
|
||||
|
||||
There were no prisons, no slums, no insane asylums, no cripples, no poverty, no wars.
|
||||
|
||||
All diseases were conquered. So was old age.
|
||||
|
||||
Death, barring accidents, was an adventure for volunteers.
|
||||
|
||||
The population of Belgiumm was stabilized at forty-million souls.
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/python
|
||||
# this is a shebang: https://en.wikipedia.org/wiki/Shebang_%28Unix%29
|
||||
|
||||
'''
|
||||
This script looks at each word in a given text, if the word contains the letters of Perec, the word is printed to another textfile
|
||||
Made for OLA #5, Paris, 15-17 décembre 2017
|
||||
'''
|
||||
|
||||
# import external modules
|
||||
import re
|
||||
import string
|
||||
|
||||
# define textfiles
|
||||
source = open("../data/1984_all.txt", 'r')
|
||||
destination = open("../data/perec.txt", 'w')
|
||||
|
||||
# define regular expression
|
||||
regex = r'(\w*p+\w*e+\w*r+\w*e+\w*c+)'
|
||||
|
||||
|
||||
# write title to destination
|
||||
destination.write("Source: George Orwell's 1984\n\n\n")
|
||||
|
||||
# search for pattern in source, print in terminal & write to destination
|
||||
sentences = []
|
||||
# read source line by line
|
||||
for line in source:
|
||||
# split each line into list of words, split on white spaces
|
||||
words = line.split(" ")
|
||||
for word in words:
|
||||
# look if pattern is in word
|
||||
if re.search(regex, word):
|
||||
# if yes, print word in terminal
|
||||
print(word)
|
||||
# write word to file without punctuation
|
||||
destination.write(word.strip('\., \,')+'\n')
|
||||
|
||||
# close textfiles
|
||||
source.close()
|
||||
destination.close()
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env/ python
|
||||
# This script automatises the following Oulipo constraint:
|
||||
# http://oulipo.net/fr/contraintes/litterature-definitionnelle
|
||||
# The output is printed in a txt-file and in a Logbook in Context
|
||||
|
||||
# Copyright (C) 2016 Constant, Algolit, An Mertens
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details: <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
from __future__ import division
|
||||
import nltk
|
||||
from nltk.corpus import wordnet as wn
|
||||
from pattern.en import tag
|
||||
import nltk.data
|
||||
from random import shuffle, choice
|
||||
|
||||
|
||||
# VARIABLES
|
||||
|
||||
|
||||
# textfiles
|
||||
source = open("frankenstein_for_machines.txt", 'r')
|
||||
destination = open("litterature_definitionelle.txt", "wt")
|
||||
|
||||
|
||||
## SCRIPT
|
||||
|
||||
|
||||
# select 4 sentences from source
|
||||
## split source text into list of sentences
|
||||
finding_sentences = nltk.data.load('tokenizers/punkt/english.pickle')
|
||||
sentences_list = []
|
||||
with source as text:
|
||||
for line in text:
|
||||
# this returns a list with 1 element containing the entire text, sentences separated by \n
|
||||
sentences = '\n'.join(finding_sentences.tokenize(line.strip()))
|
||||
# transform string into list of sentences
|
||||
sentences_list = sentences.split("\n")
|
||||
|
||||
# pick 4 random sentences
|
||||
selected_sentences = []
|
||||
number = 0
|
||||
while number < 5:
|
||||
selected_sentences.append(choice(sentences_list))
|
||||
number += 1
|
||||
|
||||
|
||||
# tokenize source and get Part-of-Speech tags for each word
|
||||
definitions = []
|
||||
|
||||
for sentence in selected_sentences:
|
||||
# create tuple of tuples with pairs of word + POS-tag
|
||||
collection = tag(sentence, tokenize=True, encoding='utf-8')
|
||||
# transform tuple into list to be able to manipulate it
|
||||
collection = list(collection)
|
||||
# for each pair:
|
||||
for element in collection:
|
||||
# look for nouns & replace them with their definition
|
||||
if element[1] == "NN":
|
||||
if wn.synsets(element[0]):
|
||||
synset = wn.synsets(element[0])
|
||||
definitions.append("<")
|
||||
definitions.append(synset[0].definition())
|
||||
definitions.append(">")
|
||||
else:
|
||||
break
|
||||
else:
|
||||
# non-nouns are left as words
|
||||
definitions.append(element[0])
|
||||
|
||||
|
||||
# write the transformed sentence
|
||||
#print(" ".join(definitions))
|
||||
with destination as text:
|
||||
text.write("ORIGINAL TEXT\n\n\n")
|
||||
for sentence in selected_sentences:
|
||||
text.write(sentence+"\n")
|
||||
text.write("\n\n")
|
||||
text.write("\n\nLITTERATURE DEFINITIONELLE\n\n\n")
|
||||
text.write(" ".join(definitions))
|
||||
|
||||
|
||||
# close the text file
|
||||
source.close()
|
||||
destination.close()
|
||||
|
||||
# -------------------------------------------
|
||||
|
||||
# # Write in logbook
|
||||
|
||||
# # print chapters
|
||||
|
||||
# #writetologbook('\setuppagenumber[state=start]')
|
||||
# writetologbook('\n\section{LITTERATURE DEFINITIONELLE}\n')
|
||||
# # print_sentences(spring_chapter)
|
||||
# writetologbook('\nORIGINAL TEXT\crlf\crlf\n')
|
||||
# for sentence in selected_sentences:
|
||||
# writetologbook(sentence+"\n")
|
||||
# writetologbook("\crlf\crlf\n\n\n")
|
||||
# writetologbook('\nLITTERATURE DEFINITIONELLE\crlf\crlf\n')
|
||||
# writetologbook(" ".join(definitions))
|
||||
@@ -0,0 +1,195 @@
|
||||
#!/usr/bin/env/ python
|
||||
|
||||
# This script makes you choose 1 out of 2 Oulipo constraints:
|
||||
|
||||
# Constraint 1: http://oulipo.net/fr/contraintes/litterature-definitionnelle
|
||||
# Constraint 2: rewrites the beginning of a novel by replacing the principal names/places/gender
|
||||
# The idea for this script comes from the book 'Think Python'.
|
||||
|
||||
# Copyright (C) 2016 Constant, Algolit, An Mertens
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details: <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import division
|
||||
import nltk
|
||||
from nltk.corpus import wordnet as wn
|
||||
from pattern.en import tag
|
||||
import nltk.data
|
||||
from random import shuffle, choice, randrange
|
||||
|
||||
import colors
|
||||
from colors import red, green, yellow, blue, magenta, cyan, bold, underline
|
||||
import time
|
||||
import os, sys
|
||||
|
||||
|
||||
## FUNCTIONS
|
||||
# print on screen character per character
|
||||
def typewrite(sentence):
|
||||
words = sentence.split(" ")
|
||||
for word in words:
|
||||
for char in word:
|
||||
if char != "<" and char != ">":
|
||||
sys.stdout.write('%s' % char)
|
||||
sys.stdout.flush()
|
||||
time.sleep(0.1)
|
||||
sys.stdout.write(" ")
|
||||
sys.stdout.flush()
|
||||
|
||||
# loop script
|
||||
while True:
|
||||
|
||||
print "\n\t\tDear visitor, you can choose between", red(" two Oulipo applications.\n")
|
||||
#source = open("frankenstein_for_machines.txt", 'r')
|
||||
print "\t\tOption a is ", green("Litterature Definitionnelle"), " with sentences from Mary Shelley's Frankenstein.\n"
|
||||
#source = open("frankenstein_for_machines.txt", 'r')
|
||||
print "\t\tOption b is ", green("A Novel Starring You.\n")
|
||||
#source = open("frankenstein_for_machines.txt", 'r')
|
||||
print "\t\tType ", green('a'), " if you want to play with Litterature Definitionnelle.\n"
|
||||
#source = open("frankenstein_for_machines.txt", 'r')
|
||||
print "\t\tType ", green('b'), " if you want to be a star in the opening scene of Kurt Vonneguts' 2BRO2B.\n"
|
||||
#source = open("frankenstein_for_machines.txt", 'r')
|
||||
choice = raw_input("\t\tYour choice is: ")
|
||||
#source = open("frankenstein_for_machines.txt", 'r')
|
||||
print "\n"
|
||||
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
print "\n"
|
||||
|
||||
|
||||
### MEET ---------------------------------------------------------------------------------------------
|
||||
### --------------------------------------------------------------------------------------------------
|
||||
|
||||
### MEET/INTRO ---------------------------------------------------------------------------------------------
|
||||
|
||||
# retrain model
|
||||
if choice == 'a':
|
||||
|
||||
### Litterature definitionnelle
|
||||
|
||||
# textfiles
|
||||
source = open("frankenstein_for_machines.txt", 'r')
|
||||
#source = open("1984_fragment.txt", 'r')
|
||||
destination = open("litterature_definitionelle.txt", "wt")
|
||||
|
||||
|
||||
## SCRIPT
|
||||
|
||||
|
||||
# select 4 sentences from source
|
||||
## split source text into list of sentences
|
||||
finding_sentences = nltk.data.load('tokenizers/punkt/english.pickle')
|
||||
sentences_list = []
|
||||
with source as text:
|
||||
for line in text:
|
||||
# this returns a list with 1 element containing the entire text, sentences separated by \n
|
||||
sentences = '\n'.join(finding_sentences.tokenize(line.strip()))
|
||||
# transform string into list of sentences
|
||||
sentences_list = sentences.split("\n")
|
||||
|
||||
selected_sentences = [sentences_list[randrange(len(sentences_list))]
|
||||
for s in range(4)]
|
||||
|
||||
|
||||
|
||||
# tokenize source and get Part-of-Speech tags for each word
|
||||
definitions = []
|
||||
|
||||
for sentence in selected_sentences:
|
||||
# create tuple of tuples with pairs of word + POS-tag
|
||||
collection = tag(sentence, tokenize=True, encoding='utf-8')
|
||||
# transform tuple into list to be able to manipulate it
|
||||
collection = list(collection)
|
||||
# for each pair:
|
||||
for element in collection:
|
||||
# look for nouns & replace them with their definition
|
||||
if element[1] == "NN":
|
||||
if wn.synsets(element[0]):
|
||||
synset = wn.synsets(element[0])
|
||||
definitions.append("<")
|
||||
definitions.append(synset[0].definition())
|
||||
definitions.append(">")
|
||||
else:
|
||||
break
|
||||
else:
|
||||
# non-nouns are left as words
|
||||
definitions.append(element[0])
|
||||
|
||||
|
||||
# write the transformed sentence
|
||||
#print " ".join(definitions)
|
||||
for d in definitions:
|
||||
typewrite(d)
|
||||
|
||||
raw_input("\nPress Enter to continue...")
|
||||
# time.sleep(10)
|
||||
|
||||
# -------------------------------------------
|
||||
|
||||
elif choice == 'b':
|
||||
|
||||
### A Novel Starring You
|
||||
|
||||
# introduction, getting the variables
|
||||
print "\n\t\tDear visitor, we will rewrite the opening scene of ", green("Kurt Vonnegut's 2BRO2B"), " using your name and favourite city.\n"
|
||||
##source = open("frankenstein_for_machines.txt", 'r')
|
||||
first_name = raw_input("\t\tPlease type your first name: ")
|
||||
##source = open("frankenstein_for_machines.txt", 'r')
|
||||
last_name = raw_input("\n\t\tPlease type your last name: ")
|
||||
##source = open("frankenstein_for_machines.txt", 'r')
|
||||
country = raw_input("\n\t\tChoose a country: ")
|
||||
##source = open("frankenstein_for_machines.txt", 'r')
|
||||
city = raw_input("\n\t\tChoose a city in that country: ")
|
||||
##source = open("frankenstein_for_machines.txt", 'r')
|
||||
print "\n\t\tDo you want to be", green('female'), "or", green('male?')
|
||||
gender = raw_input("\t\tPlease type f or m: ")
|
||||
#time.sleep(5)
|
||||
print "\n"
|
||||
|
||||
# specify input text
|
||||
source = open("vonnegut.txt", "r")
|
||||
sentences =[]
|
||||
|
||||
# write & replace
|
||||
archive("\n\nNovel Starring You\n")
|
||||
archive("-------------\n\n")
|
||||
|
||||
with source as text:
|
||||
for line in text:
|
||||
line = line.replace("the United States", country)
|
||||
line = line.replace("Chicago", city)
|
||||
line = line.replace("Edward K.", first_name)
|
||||
line = line.replace("Wehling", last_name)
|
||||
if gender == 'f':
|
||||
line = line.replace(" man ", " woman ")
|
||||
line = line.replace(" man,", " woman,")
|
||||
line = line.replace(" his ", " her ")
|
||||
line = line.replace(" him ", " her ")
|
||||
line = line.replace(" His ", " Her ")
|
||||
line = line.replace(" wife ", " husband ")
|
||||
line = line.replace(" he ", " she ")
|
||||
line = line.replace(" He ", " She ")
|
||||
typewrite(line)
|
||||
archive(line)
|
||||
# break before relaunching the script
|
||||
raw_input("\nPress Enter to continue...")
|
||||
time.sleep(10)
|
||||
|
||||
### ELSE --------------------------------------------------------------------------------------
|
||||
### -------------------------------------------------------------------------------------------
|
||||
|
||||
# try again
|
||||
else:
|
||||
print "\t\tYou must have typed something else."
|
||||
#time.sleep(30)
|
||||
raw_input("\nPress Enter to continue...")
|
||||
os.system('cls' if os.name == 'nt' else 'clear')
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/python
|
||||
# this is a shebang: https://en.wikipedia.org/wiki/Shebang_%28Unix%29
|
||||
|
||||
'''
|
||||
This script takes a sentence you write in the terminal, and gives it back in reverse mode
|
||||
Check out other options for list comprehension: https://docs.python.org/3/tutorial/datastructures.html
|
||||
Made for OLA #5, Paris, 15-17 décembre 2017
|
||||
'''
|
||||
|
||||
# Run script in loop:
|
||||
while True:
|
||||
|
||||
# Ask to write a sentence
|
||||
sentence = input("Ecrivez votre phrase: ").lower().strip('\., \?')
|
||||
|
||||
# Split sentence into words
|
||||
words = sentence.split()
|
||||
#print(words)
|
||||
|
||||
# if sentence is only 1 word, reverse word
|
||||
if len(words) < 2:
|
||||
for word in words:
|
||||
word = word[::-1]
|
||||
print(word.capitalize())
|
||||
# if sentence is more than 1 word
|
||||
else:
|
||||
words.reverse()
|
||||
print(" ".join(words).capitalize(), '.')
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
Everything was perfectly swell.
|
||||
|
||||
There were no prisons, no slums, no insane asylums, no cripples, no poverty, no wars.
|
||||
|
||||
All diseases were conquered. So was old age.
|
||||
|
||||
Death, barring accidents, was an adventure for volunteers.
|
||||
|
||||
The population of the United States was stabilized at forty-million souls.
|
||||
|
||||
One bright morning in the Chicago Lying-in Hospital, a man named Edward K. Wehling, Jr., waited for his wife to give birth. He was the only man waiting. Not many people were born a day any more.
|
||||
|
||||
Wehling was fifty-six, a mere stripling in a population whose average age was one hundred and twenty-nine.
|
||||
|
||||
X-rays had revealed that his wife was going to have triplets. The children would be his first.
|
||||
|
||||
Young Wehling was hunched in his chair, his head in his hand. He was so rumpled, so still and colorless as to be virtually invisible. His camouflage was perfect, since the waiting room had a disorderly and demoralized air, too. Chairs and ashtrays had been moved away from the walls. The floor was paved with spattered dropcloths.
|
||||
|
||||
The room was being redecorated. It was being redecorated as a memorial to a man who had volunteered to die.
|
||||
|
||||
A sardonic old man, about two hundred years old, sat on a stepladder, painting a mural he did not like. Back in the days when people aged visibly, his age would have been guessed at thirty-five or so. Aging had touched him that much before the cure for aging was found.
|
||||
|
||||
The mural he was working on depicted a very neat garden. Men and women in white, doctors and nurses, turned the soil, planted seedlings, sprayed bugs, spread fertilizer.
|
||||
|
||||
Men and women in purple uniforms pulled up weeds, cut down plants that were old and sickly, raked leaves, carried refuse to trash-burners.
|
||||
|
||||
Never, never, never—not even in medieval Holland nor old Japan—had a garden been more formal, been better tended. Every plant had all the loam, light, water, air and nourishment it could use.
|
||||
|
||||
A hospital orderly came down the corridor, singing under his breath a popular song.
|
||||
|
||||
The orderly looked in at the mural and the muralist. "Looks so real," he said, "I can practically imagine I'm standing in the middle of it."
|
||||
|
||||
"What makes you think you're not in it?" said the painter. He gave a satiric smile. "It's called 'The Happy Garden of Life,' you know."
|
||||
Reference in New Issue
Block a user