commited all contents created by participants
This commit is contained in:
@@ -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)
|
||||
@@ -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 = {'au': 'o', 'ie': 'y', 'eau': 'o', 'ai': 'e'}
|
||||
|
||||
# set weight to 0
|
||||
weights = 0
|
||||
|
||||
# find a sentence / string
|
||||
sentence = "J'ai la vie qui est un beau 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)
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/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 = {'au': 'o', 'ie': 'y', 'eau': 'o', 'ai': 'e'}
|
||||
|
||||
# find a sentence / string
|
||||
sentence = "J'ai la vie qui est un beau mystère qu'il faut vivre, et non un problème à résoudre."
|
||||
|
||||
# split sentence in list of words
|
||||
words = sentence.split()
|
||||
|
||||
# for each word
|
||||
for word in words:
|
||||
# iterate over dictionary
|
||||
for k,v in scrabble:
|
||||
word = word.replace(k, v)
|
||||
print(word)
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/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 = {'au': 'o', 'ie': 'y', 'eau': 'o', 'ai': 'e'}
|
||||
|
||||
# find a sentence / string
|
||||
sentence = "J'ai la vie qui est un beau mystère qu'il faut vivre, et non un problème à résoudre."
|
||||
|
||||
# split sentence in list of words
|
||||
words = sentence.split()
|
||||
|
||||
# for each word
|
||||
for word in words:
|
||||
# iterate over dictionary
|
||||
for k,v in scrabble:
|
||||
print("k", scrabble[k])
|
||||
print("v", v)
|
||||
# word = word.replace(k, v)
|
||||
# print(word)
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/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 = {'au': 'o', 'ie': 'y', 'eau': 'o', 'ai': 'e'}
|
||||
|
||||
# find a sentence / string
|
||||
sentence = "J'ai la vie qui est un beau mystère qu'il faut vivre, et non un problème à résoudre."
|
||||
|
||||
# split sentence in list of words
|
||||
words = sentence.split()
|
||||
|
||||
# for each word
|
||||
for word in words:
|
||||
# iterate over dictionary
|
||||
for k in scrabble:
|
||||
if k in word:
|
||||
word = word.replace(k, v)
|
||||
# print(word)
|
||||
@@ -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 qu’elle est une force qui leur échappe"
|
||||
# print sentence
|
||||
print("phrase originale:", sentence)
|
||||
|
||||
# Split sentence into words
|
||||
words = sentence.split()
|
||||
#print(words)
|
||||
|
||||
# sort words of list
|
||||
words.sort()
|
||||
|
||||
# print sorted wordlist as string
|
||||
print("phrase alphabétique:", " ".join(words).capitalize(), '.')
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/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 qu’elle est une force qui leur échappe"
|
||||
# print sentence
|
||||
print("phrase originale:", sentence)
|
||||
|
||||
# Split sentence into words
|
||||
words = sentence.split()
|
||||
#print(words)
|
||||
|
||||
# sort words of list
|
||||
words.sort()
|
||||
|
||||
# print sorted wordlist as string
|
||||
print("phrase alphabétique:", " ".join(words).capitalize(), '.')
|
||||
|
||||
sentence = sentence.replace("e"," ")
|
||||
print(sentence)
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/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 = "« So what are the demands? What are the demands all these people are making? » Either they say there are no demands and that leaves your critics confused - or they say that the demand for social equality and economic justice are impossible demands."
|
||||
# print sentence
|
||||
print("phrase originale:", sentence)
|
||||
|
||||
# Split sentence into words
|
||||
# words = sentence.split()
|
||||
#print(words)
|
||||
|
||||
# sort words of list
|
||||
#words.sort()
|
||||
|
||||
# print sorted wordlist as string
|
||||
#print("phrase alphabétique:", " ".join(words).capitalize(), '.')
|
||||
|
||||
sentence = sentence.replace("impossible","i m p o s s i b l e")
|
||||
print(sentence)
|
||||
@@ -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 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 = "« So what are the demands? What are the demands all these people are making? » Either they say there are no demands and that leaves your critics confused - or they say that the demand for social equality and economic justice are impossible demands."
|
||||
# print sentence
|
||||
print("phrase originale:", sentence)
|
||||
|
||||
# Split sentence into words
|
||||
# words = sentence.split()
|
||||
#print(words)
|
||||
|
||||
# sort words of list
|
||||
#words.sort()
|
||||
|
||||
# print sorted wordlist as string
|
||||
#print("phrase alphabétique:", " ".join(words).capitalize(), '.')
|
||||
|
||||
# define list of filtered words
|
||||
filtered_words = [impossible]
|
||||
|
||||
#sentence = sentence.replace("impossible","i m p o s s i b l e")
|
||||
print(sentence)
|
||||
+64
@@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#!/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
|
||||
# txt = source.readlines()
|
||||
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,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 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 qu’elle 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 alphabétique:", " ".join(words).capitalize()+'.')
|
||||
|
||||
sentence = sentence.replace("e"," ")
|
||||
print(sentence)
|
||||
Reference in New Issue
Block a user