commited all contents created by participants

This commit is contained in:
Bachir Soussi Chiadmi
2017-12-21 18:12:40 +01:00
parent cefd1c2ad0
commit b936b1e616
2137 changed files with 1076319 additions and 730 deletions
@@ -0,0 +1,45 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2017 Constant, Algolit
# 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/>.
'''
Input texts are checked against a dictionary that assigns weights to different vowels.
The script gives a score for a specific sentence.
'''
# create a dictionary
scrabble = {'a': 3, 'e': 1, 'i': 2, 'o': 4, 'u':4, 'y': 6}
# set weight to 0
weights = 0
# find a sentence / string
sentence = "La vie est un mystère qu'il faut vivre, et non un problème à résoudre."
# spllit sentence in list of words
words = sentence.split()
# for each word
for word in words:
# iterate over letters of word
for letter in word:
# check if letter is in dictionary
if letter in scrabble:
# if yes, get weight of the letter
weight = scrabble[letter]
# add letter weight to general weight
weights += weight
# print general weight
print("Le poids de ma phrase est:", weights)
+306
View File
@@ -0,0 +1,306 @@
i
me
my
myself
we
our
ours
ourselves
you
your
yours
yourself
yourselves
he
him
his
himself
she
her
hers
herself
it
its
itself
they
them
their
theirs
themselves
what
which
who
whom
this
that
these
those
am
is
are
was
were
be
been
being
have
has
had
having
do
does
did
doing
a
an
the
and
but
if
or
because
as
until
while
of
at
by
for
with
about
against
between
into
through
during
before
after
above
below
to
from
up
down
in
out
on
off
over
under
again
further
then
once
here
there
when
where
why
how
all
any
both
each
few
more
most
other
some
such
no
nor
not
only
own
same
so
than
too
very
s
t
can
will
just
don
should
now
d
ll
m
o
re
ve
y
ain
aren
couldn
didn
doesn
hadn
hasn
haven
isn
ma
mightn
mustn
needn
shan
shouldn
wasn
weren
won
wouldn
Both
Does
Being
Doesn
Been
Itself
My
M
Then
Up
O
Because
Their
Him
Her
Needn
Until
Has
Other
Have
Ourselves
Shouldn
Than
We
His
Herself
By
Which
Those
Again
Yours
Wasn
After
She
Same
Against
More
Into
Theirs
Don
Your
That
Aren
Now
Themselves
Will
Why
While
Wouldn
Under
For
Over
Below
Too
Me
Most
Or
Our
And
Are
Them
Whom
Here
Who
Further
But
So
Ain
You
Very
Isn
An
Was
In
When
Ours
About
Off
Be
Didn
With
These
S
Were
How
If
Doing
Each
Hadn
Where
Can
Only
Down
Ll
This
Couldn
Himself
To
Yourself
Its
Above
Out
Ve
He
Not
On
It
Myself
A
From
Mustn
I
They
Through
What
Do
Re
Haven
No
Before
Of
Just
Shan
At
Own
Did
Is
Between
Some
Few
T
Hers
Won
Y
D
The
Weren
Such
Should
Yourselves
As
Am
Ma
Having
Once
Mightn
Had
There
All
During
Any
Nor
Hasn
@@ -0,0 +1,25 @@
#!/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
A list is ordered and changeable. It is less efficient than a set/tuple. But it allows to work with index numbers.
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
'''
# Ask to write a sentence
sentence = "Les gouvernements suspectent la littérature parce quelle est une force qui leur échappe"
# print sentence
print("phrase originale:", sentence)
# Split sentence into words
words = sentence.lower().split()
print(words)
# sort words of list
words.sort()
print(words)
# print sorted wordlist as string
#print("phrase dans l'ordre alphabétique:", "+".join(words).capitalize()+'.')
@@ -0,0 +1,3 @@
phrase originale: Les gouvernements suspectent la littérature parce quelle est une force qui leur échappe
['les', 'gouvernements', 'suspectent', 'la', 'littérature', 'parce', 'quelle', 'est', 'une', 'force', 'qui', 'leur', 'échappe']
['est', 'force', 'gouvernements', 'la', 'les', 'leur', 'littérature', 'parce', 'qui', 'quelle', 'suspectent', 'une', 'échappe']
@@ -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,64 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2016 Constant, Algolit
# 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/>.
'''
Input texts are checked against occurences of certain words included in a list of "stopwords" established by NLTK (Natural Language Toolkit). These words are then removed.
In data mining, text processing and machine learning, these so-called high frequency words are filtered out before or after natural language data is processed.
Relational words such as 'the', 'is', 'at', 'which', and 'on' are considered redundant because they are too frequent, and meaningless once the word order is removed.
'''
# A set is a list with unique words
stopwords = set()
# define list of filtered words
filtered_words = []
# read stopwords from file & save them in a list
# read from file
with open("english.txt", "r") as source:
# for each line
for line in source:
# clean returns
line = line.strip()
# add word to set stopwords (cfr difference with list: list.append())
stopwords.add(line)
# define your sentence / string
sentence = 'I was at Synesthésie last night and took a bus to go home.'
# print sentence
print("phrase originale:", sentence)
# convert string to list of words
words = sentence.split(" ")
# for each word of list, check if word is in stopwords, if it isn't, add word to filtered wordlist
for word in words:
if word not in stopwords:
filtered_words.append(word)
# this is the same, but shorter + no need to declare filtered_words as list in the beginning:
#filtered_words = [word for word in words if word not in stopwords]
# turn wordlist into string of characters
new_sentence = " ".join(filtered_words)
# print new sentence
print("phrase réécrite:", new_sentence)
@@ -0,0 +1,41 @@
#!/usr/bin/env python
# encoding=utf8
# Copyright (C) 2016 Constant, Algolit
# 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/>.
# Reduction of letters
# From string to list & back
# A string: a list of characters, unchangeable, but treatable
# See: https://www.tutorialspoint.com/python3/python_strings.htm
# Write sentence as string
sentence = "Je vois La Vie en rose..."
# Print sentence
print("phrase originale:", sentence)
# define new word as list
new_word = []
# Convert sentence in list of words
words = sentence.split(" ")
# For each word in word list
for word in words:
# remove capital letters (string operation)
word = word.lower()
# Clean punctuation (string operation)
word = word.strip(" ;''?:,()!.\").”-")
# add word to new word list
new_word.append(word)
# Write words as one, without punctuation
print("phrase mise en mots:", ''.join(new_word))
@@ -0,0 +1,30 @@
#!/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
A list is ordered and changeable. It is less efficient than a set/tuple. But it allows to work with index numbers.
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.sort()
print(" ".join(words).capitalize(), '.')